Commit 3910f074ae5fc4169f19ef1cfbbedcefcae0dafe
1 parent
66daa65d
Exists in
master
Atualiza endpoint do banco de sinais
Showing
2 changed files
with
45 additions
and
27 deletions
Show diff stats
settings_local.py.tmpl
1 | 1 | # -*- coding: utf-8 -*- |
2 | + | |
2 | 3 | # Validador Server Configuration |
3 | 4 | SERVER_HOST = "localhost" |
4 | 5 | SERVER_PORT = 8002 |
... | ... | @@ -12,7 +13,7 @@ APACHE_STATIC_FILES_ENDPOINT = "/validador" |
12 | 13 | |
13 | 14 | # PyBossa Configuration |
14 | 15 | PYBOSSA_APP_NAME = "Validador de Sinais" |
15 | -PYBOSSA_APP_SHORT_NAME = "validador_sinais" | |
16 | +PYBOSSA_APP_SHORT_NAME = "validador_sinais" | |
16 | 17 | PYBOSSA_APP_DESCRIPTION = "Esse projeto possibilitará que especialistas aprovem sinais gerados pela comunidade." |
17 | 18 | PYBOSSA_ENDPOINT = "http://localhost/pybossa" |
18 | 19 | PYBOSSA_API_KEY = "my-api-key" |
19 | 20 | \ No newline at end of file | ... | ... |
validador.py
... | ... | @@ -2,21 +2,20 @@ |
2 | 2 | from flask import request, make_response |
3 | 3 | from werkzeug import secure_filename |
4 | 4 | import pbclient |
5 | -import os | |
6 | 5 | import pyutil |
7 | 6 | import requests |
8 | -import tempfile | |
7 | + | |
9 | 8 | |
10 | 9 | class Validador: |
11 | 10 | |
12 | 11 | def __init__(self, configuration, template_env): |
13 | - self.config = configuration | |
14 | - self.env = template_env | |
15 | - self.__setup_pb_client() | |
12 | + self.config = configuration | |
13 | + self.env = template_env | |
14 | + self.__setup_pb_client() | |
16 | 15 | |
17 | 16 | def __setup_pb_client(self): |
18 | - pbclient.set('endpoint', self.config['PYBOSSA_ENDPOINT']) | |
19 | - pbclient.set('api_key', self.config['PYBOSSA_API_KEY']) | |
17 | + pbclient.set('endpoint', self.config['PYBOSSA_ENDPOINT']) | |
18 | + pbclient.set('api_key', self.config['PYBOSSA_API_KEY']) | |
20 | 19 | |
21 | 20 | def __find_project(self, app_short_name): |
22 | 21 | projects = pbclient.find_project(short_name=app_short_name) |
... | ... | @@ -24,23 +23,26 @@ class Validador: |
24 | 23 | |
25 | 24 | def __setup_project(self, project): |
26 | 25 | self.__update_project_info(project) |
27 | - | |
26 | + | |
28 | 27 | def __create_tasks(self, project): |
29 | 28 | test_signs = ["ENSINADO", "ENTANTO", "ENTENDIDO"] |
30 | 29 | for sign in test_signs: |
31 | 30 | video_ref = "/videos/" + sign + "_REF.webm" |
32 | 31 | video_ava = "/videos/" + sign + "_AVATAR.webm" |
33 | - task = dict(sign_name=sign, submission_date=pyutil.get_date_now(), | |
34 | - video_ref=video_ref, video_ava=video_ava) | |
32 | + task = dict( | |
33 | + sign_name=sign, | |
34 | + submission_date=pyutil.get_date_now(), | |
35 | + video_ref=video_ref, | |
36 | + video_ava=video_ava) | |
35 | 37 | pbclient.create_task(project.id, task) |
36 | 38 | |
37 | 39 | def __update_project_info(self, project): |
38 | 40 | template = self.env.get_template('index.html') |
39 | 41 | project.info['task_presenter'] = template.render( |
40 | - server=self.config['HOST_STATIC_FILES_ENDPOINT'], | |
41 | - server_backend=self.config['HOST_ENDPOINT'], | |
42 | - app_shortname=self.config['PYBOSSA_APP_SHORT_NAME'], | |
43 | - api_db_host=self.config['API_DB_HOST']) | |
42 | + server=self.config['HOST_STATIC_FILES_ENDPOINT'], | |
43 | + server_backend=self.config['HOST_ENDPOINT'], | |
44 | + app_shortname=self.config['PYBOSSA_APP_SHORT_NAME'], | |
45 | + api_db_host=self.config['API_DB_HOST']) | |
44 | 46 | project.info['thumbnail'] = self.config['HOST_STATIC_FILES_ENDPOINT'] + "/img/thumbnail.png" |
45 | 47 | project.info['sched'] = "incremental" |
46 | 48 | project.info['published'] = True |
... | ... | @@ -92,10 +94,10 @@ class Validador: |
92 | 94 | return "The task with ID=" + str(task_id) + " was closed." |
93 | 95 | |
94 | 96 | def get_file(self, url, filename): |
95 | - r = requests.get(url, stream = True) | |
97 | + r = requests.get(url, stream=True) | |
96 | 98 | if (r.status_code == 200): |
97 | 99 | with open(filename, 'wb') as f: |
98 | - for chunk in r.iter_content(chunk_size = 1024): | |
100 | + for chunk in r.iter_content(chunk_size=1024): | |
99 | 101 | if chunk: |
100 | 102 | f.write(chunk) |
101 | 103 | return True |
... | ... | @@ -109,24 +111,39 @@ class Validador: |
109 | 111 | number_of_approval = int(request.form['number_of_approval']) |
110 | 112 | number_of_avatar_disapproval = int(request.form['number_of_avatar_disapproval']) |
111 | 113 | number_of_ref_disapproval = int(request.form['number_of_ref_disapproval']) |
114 | + # pyutil.log("[VALIDADOR] number_of_approval: %d" % (number_of_approval)) | |
115 | + # pyutil.log("[VALIDADOR] agreement_number: %d" % (agreement_number)) | |
116 | + # pyutil.log("[VALIDADOR] number_of_avatar_disapproval: %d" % (number_of_avatar_disapproval)) | |
112 | 117 | agreement_number = self.config['AGREEMENT_NUMBER'] |
113 | 118 | result_msg = "" |
114 | 119 | code = 200 |
115 | 120 | selo = None |
116 | 121 | if (number_of_approval >= agreement_number): |
117 | 122 | selo = 2 |
118 | - result_msg = "selo was changed to 2 - especialista" | |
119 | - elif(number_of_avatar_disapproval >= agreement_number): | |
123 | + elif (number_of_avatar_disapproval >= agreement_number): | |
120 | 124 | selo = 4 |
121 | - result_msg = "selo was changed to 4 - invalido_especialista" | |
122 | - elif(number_of_ref_disapproval >= agreement_number): | |
125 | + elif (number_of_ref_disapproval >= agreement_number): | |
123 | 126 | selo = 6 |
124 | - result_msg = "selo was changed to 6 - invalido_animadores" | |
127 | + | |
128 | + if (selo is None): | |
129 | + result_msg = "[VALIDADOR] The task with ID=" + str(task_id) + " didn't reach the agreement number yet." | |
125 | 130 | else: |
126 | - result_msg = "The task with ID=" + str(task_id) + " didn't reach the agreement number yet." | |
127 | - if (selo != None): | |
128 | - values = { "nome": sign_name, "selo": selo, "wikilibras": True, "overwrite": True } | |
129 | - r = requests.post(("%s/gsinal" % (api_dbhost)), data = values) | |
131 | + body = { | |
132 | + "nome": sign_name, | |
133 | + "idtask": task_id, | |
134 | + "selo": selo | |
135 | + } | |
136 | + r = requests.put("%s/updateselo" % (api_dbhost), data=body) | |
137 | + code = r.status_code | |
138 | + if (code == 200): | |
139 | + tipo_selo = dict({ | |
140 | + 2: "especialista", | |
141 | + 4: "invalido_especialista", | |
142 | + 6: "invalido_animadores" | |
143 | + }) | |
144 | + pyutil.log("[VALIDADOR] selo was changed to: %d - %s" % (selo, tipo_selo[selo])) | |
145 | + else: | |
146 | + result_msg = r.text | |
130 | 147 | result_msg = self.__close_task(project_id, task_id) |
131 | - pyutil.log(result_msg) | |
148 | + pyutil.log(str(result_msg).encode("UTF-8", errors="ignore")) | |
132 | 149 | return make_response(result_msg, code) | ... | ... |