Commit 49c9936f15801ec4dd0fbe1864bed33856546fb6

Authored by Adabriand Furtado
2 parents 320de04a 37dd2c89
Exists in master and in 1 other branch dynamic

Merge remote-tracking branch 'origin/dynamic'

Conflicts:
	.gitignore
.gitignore
  1 +.*
  2 +!*.gitignore
  3 +!*.gitempty
  4 +*~
  5 +*.log
  6 +*.pyc
  7 +corretor.conf
  8 +corretor.wsgi
  9 +settings_local.py
  10 +env/
  11 +videos/
  12 +tmp/
  13 +uploads/
  14 +
1 15 *.egg-info
2 16 *.tox
3 17 .*.swp
4   -env/
5   -events.log
6   -*.pyc
7 18 *.db
8 19 settings_local.py
9   -env/
10 20 doc/_build
11 21 *.un~
12 22 *.wsgi
... ...
requirements.txt
1 1 Flask==0.9
2 2 pybossa-client
3   -flask-cors
4 3 \ No newline at end of file
  4 +flask-cors
  5 +requests >= 1.2
... ...
settings_local.py
1 1 # -*- coding: utf-8 -*-
2   -# Corretor Server Configuration
3   -SERVER_HOST = "0.0.0.0"
  2 +# WikiLibras Server Configuration
  3 +SERVER_HOST = "150.165.204.35"
4 4 SERVER_PORT = 8003
5 5 AGREEMENT_NUMBER = 2
6   -API_HOST = "http://0.0.0.0:5001"
  6 +API_HOST = "http://150.165.204.35:201"
  7 +API_DB_HOST = "http://150.165.204.35:200"
  8 +UPLOAD_SIGN_HOST = "http://150.165.204.35:200/addsinal"
  9 +HOMEPAGE_URL = "http://wikilibras.lavid.ufpb.br"
7 10  
8 11 # Apache Configuration
9   -APACHE_HOST = False
  12 +APACHE_HOST = True
10 13 APACHE_HOST_ENDPOINT = "/wikilibras-backend"
11 14 APACHE_STATIC_FILES_ENDPOINT = "/wikilibras"
12 15  
13 16 # PyBossa Configuration
14 17 PYBOSSA_APP_NAME = "WikiLibras"
15   -PYBOSSA_APP_SHORT_NAME = "wikilibras"
  18 +PYBOSSA_APP_SHORT_NAME = "wikilibras"
16 19 PYBOSSA_APP_DESCRIPTION = "Esse projeto possibilitará que voluntários contribuam na expansão de um dicionário de LIBRAS."
17   -PYBOSSA_ENDPOINT = "http://0.0.0.0:5000"
18   -#PYBOSSA_API_KEY = "263302c0-07eb-44e4-956c-9b34cc301553"
19   -PYBOSSA_API_KEY = "ed85ccd7-1417-4886-88bb-2e760509cef2"
  20 +PYBOSSA_ENDPOINT = "http://150.165.204.35/pybossa"
  21 +PYBOSSA_API_KEY = "0176e74e-4f70-45ef-bc75-6c6ebae8d170"
... ...
settings_local.py.tmpl
... ... @@ -16,5 +16,5 @@ APACHE_STATIC_FILES_ENDPOINT = "/wikilibras"
16 16 PYBOSSA_APP_NAME = "WikiLibras"
17 17 PYBOSSA_APP_SHORT_NAME = "wikilibras"
18 18 PYBOSSA_APP_DESCRIPTION = "Esse projeto possibilitará que voluntários contribuam na expansão de um dicionário de LIBRAS."
19   -PYBOSSA_ENDPOINT = "http://localhost:5000"
  19 +PYBOSSA_ENDPOINT = "http://localhost:201"
20 20 PYBOSSA_API_KEY = "my-api-key"
21 21 \ No newline at end of file
... ...
view/assets/css/main.css
... ... @@ -500,7 +500,8 @@ ul.rig.columns-4 li {
500 500  
501 501 #approval-msg {
502 502 display: none;
503   - margin: 0px;
  503 + margin: 0px;
  504 + padding-left: 14px;
504 505 }
505 506  
506 507 /* Thanks Screen */
... ... @@ -519,4 +520,4 @@ ul.rig.columns-4 li {
519 520  
520 521 #completed-all-task-msg {
521 522 display: none;
522   -}
523 523 \ No newline at end of file
  524 +}
... ...
view/assets/js/wikilibras.js
... ... @@ -324,22 +324,50 @@
324 324 _getRenderedAvatarUrl(userId, signName));
325 325 $("#render-avatar").fadeIn(300);
326 326 }
  327 +
  328 + function _showInitialScreen(toShow) {
  329 + if (toShow) {
  330 + $("#initial-screen").fadeIn(300);
  331 + $("#initial-screen video").get(0).play();
  332 + } else {
  333 + $("#initial-screen").hide();
  334 + $("#initial-screen video").get(0).pause();
  335 + }
  336 + }
  337 +
  338 + function _showConfigurationScreen(toShow) {
  339 + if (toShow) {
  340 + $("#configuration-screen").show();
  341 + $("#ref-video-container video").get(0).play();
  342 + } else {
  343 + $("#configuration-screen").hide();
  344 + $("#ref-video-container video").get(0).pause();
  345 + }
  346 + }
  347 +
  348 + function _showRenderScreen(toShow) {
  349 + if (toShow) {
  350 + $("#render-screen").fadeIn(300);
  351 + $("#render-ref video").get(0).play();
  352 + $("#render-avatar video").get(0).play();
  353 + } else {
  354 + $("#render-screen").hide();
  355 + $("#render-ref video").get(0).pause();
  356 + $("#render-avatar video").get(0).pause();
  357 + }
  358 + }
327 359  
328 360 function _setupRenderScreen() {
329   - $("#configuration-screen").hide();
  361 + _showConfigurationScreen(false);
  362 + _showRenderScreen(true);
330 363 $("#render-avatar").hide();
331   - $("#render-screen").show();
332 364 $("#render-loading").fadeIn(300);
333   - $("#render-ref video").prop("controls", false);
334   - $("#render-ref video").get(0).pause();
335 365 $("#render-button-container .btn").hide();
336 366 $("#finish-button").addClass("disabled");
337 367 $("#finish-button").show();
338 368  
339 369 _submitParameterJSON(function() {
340 370 $("#render-loading").fadeOut(300);
341   - $("#render-ref video").prop("controls", true);
342   - $("#render-ref video").get(0).play();
343 371 $("#finish-button").removeClass("disabled");
344 372 _showRenderedAvatar(parsedParameterJSON);
345 373 });
... ... @@ -349,10 +377,9 @@
349 377 $("#render-button-container .btn").hide();
350 378 $("#approval-button").show();
351 379 $("#approval-msg").show();
352   - $("#render-ref video").get(0).play();
353 380  
354 381 _showRenderedAvatar(parameterJSON);
355   - $("#render-screen").fadeIn(300);
  382 + _showRenderScreen(true);
356 383 }
357 384  
358 385 function _submitAnswer(task, deferred, status) {
... ... @@ -362,7 +389,7 @@
362 389 } else {
363 390 _saveAnswer(task, deferred, answer);
364 391 }
365   - $("#render-screen").hide();
  392 + _showRenderScreen(false);
366 393 $("#thanks-screen").show();
367 394 }
368 395  
... ... @@ -383,12 +410,12 @@
383 410 if (hasLastAnswer) {
384 411 _setupApprovalScreen(last_answer.parameter_json);
385 412 } else {
386   - $("#initial-screen").fadeIn(300);
  413 + _showInitialScreen(true);
387 414 }
388 415  
389 416 $("#start-button").off("click").on("click", function() {
390   - $("#initial-screen").hide();
391   - $("#configuration-screen").show();
  417 + _showInitialScreen(false);
  418 + _showConfigurationScreen(true);
392 419 });
393 420 $("#ready-button").off("click").on("click", function() {
394 421 if ($(this).hasClass('disabled')) {
... ... @@ -398,8 +425,8 @@
398 425 _setupRenderScreen();
399 426 });
400 427 $("#render-edit").off("click").on("click", function() {
401   - $("#render-screen").hide();
402   - $("#configuration-screen").show();
  428 + _showRenderScreen(false);
  429 + _showConfigurationScreen(true);
403 430 });
404 431 $("#finish-button").off("click").on("click", function() {
405 432 if ($(this).hasClass('disabled')) {
... ...
view/template.html
... ... @@ -63,7 +63,7 @@
63 63 <div id="ref-video-panel" class="col-sm-12">
64 64 <div id="ref-video-container" class="col-sm-10">
65 65 <video src="" preload="metadata"
66   - class="ref-video video-body-main video-border" autoplay loop
  66 + class="ref-video video-body-main video-border" loop
67 67 controls>
68 68 <source type="video/webm">
69 69 </video>
... ... @@ -298,11 +298,11 @@
298 298 </div>
299 299 <div id="teached-signs-container" class="sub-main-container">
300 300 <h4 class="teached-signs-msg" type="none">Você ainda não ensinou
301   - sinais a Ícaro.</h4>
302   - <h4 class="teached-signs-msg" type="one">Você já ensinou a Ícaro
  301 + sinais ao Ícaro.</h4>
  302 + <h4 class="teached-signs-msg" type="one">Você já ensinou ao Ícaro
303 303 1 sinal de LIBRAS.</h4>
304 304 <h4 class="teached-signs-msg" type="more">
305   - Você já ensinou a Ícaro <span>x</span> sinais de LIBRAS.
  305 + Você já ensinou ao Ícaro <span>x</span> sinais de LIBRAS.
306 306 </h4>
307 307 <div id="signs-list-container" class="row"></div>
308 308 <div id="teached-sign-modal" class="modal fade" tabindex="-1"
... ... @@ -318,11 +318,11 @@
318 318 </div>
319 319 </div>
320 320 <div id="tutorial-container" class="sub-main-container">
321   - <h4>Aprenda como ensinar uma expressão a Ícaro.</h4>
  321 + <h4>Aprenda como ensinar o Ícaro uma expressão.</h4>
322 322 <iframe width="560" height="315"
323 323 src="http://www.youtube.com/embed/AFRxTpNJc4I?controls=2&showinfo=0">
324 324 </iframe>
325   - <h4>Aprenda como ensinar uma configuração de mão a Ícaro.</h4>
  325 + <h4>Aprenda como ensinar o Ícaro uma configuração de mão.</h4>
326 326 <iframe width="560" height="315"
327 327 src="http://www.youtube.com/embed/JJV2DX8s1rg?controls=2&showinfo=0">
328 328 </iframe>
... ... @@ -351,4 +351,4 @@
351 351 <script type="text/javascript">
352 352 wikilibras.run("{{ server }}", "{{ server_backend }}",
353 353 "{{ app_shortname }}", "{{ api_host }}", "{{ upload_sign_host }}");
354   -</script>
355 354 \ No newline at end of file
  355 +</script>
... ...
view/videos/CALAR_REF.webm
No preview for this file type
wikilibras.py
... ... @@ -4,42 +4,37 @@ from werkzeug import secure_filename
4 4 import pbclient
5 5 import os
6 6 import pyutil
  7 +import requests
  8 +import tempfile
  9 +import shutil
7 10  
8 11 class Wikilibras:
9   -
  12 +
10 13 def __init__(self, configuration, template_env):
11 14 self.config = configuration
12 15 self.env = template_env
13 16 self.__setup_pb_client()
14   -
  17 +
15 18 def __setup_pb_client(self):
16   - pbclient.set('endpoint', self.config['PYBOSSA_ENDPOINT'])
  19 + pbclient.set('endpoint', self.config['PYBOSSA_ENDPOINT'])
17 20 pbclient.set('api_key', self.config['PYBOSSA_API_KEY'])
18   -
  21 +
19 22 def __find_project(self, app_short_name):
20 23 projects = pbclient.find_project(short_name=app_short_name)
21 24 return projects[0] if len(projects) > 0 else None
22   -
  25 +
23 26 def __setup_project(self, project):
24   - self.__create_tasks(project)
25 27 self.__update_project_info(project)
26   -
27   - def __create_tasks(self, project):
28   - test_signs = ["CALAR", "ENSINADO", "ENTANTO", "ENTENDIDO"]
29   - #test_signs = ["CALAR"]
30   - for sign in test_signs:
31   - task = dict(sign_name=sign, submission_date=pyutil.get_date_now())
32   - pbclient.create_task(project.id, task)
33   -
  28 +
34 29 def __update_project_info(self, project):
35 30 template = self.env.get_template('template.html')
36 31 project.info['task_presenter'] = template.render(server=self.config['HOST_STATIC_FILES_ENDPOINT'], server_backend=self.config['HOST_ENDPOINT'], app_shortname=self.config['PYBOSSA_APP_SHORT_NAME'], api_host=self.config['API_HOST'], homepage_url=self.config['HOMEPAGE_URL'], upload_sign_host=self.config['UPLOAD_SIGN_HOST'])
37 32 project.info['thumbnail'] = self.config['HOST_STATIC_FILES_ENDPOINT'] + "/img/thumbnail.png"
38 33 project.info['sched'] = "incremental"
  34 + project.info['published'] = True
39 35 project.allow_anonymous_contributors = False
40   - project.published = True
41 36 pbclient.update_project(project)
42   -
  37 +
43 38 def create_project(self):
44 39 app_short_name = self.config['PYBOSSA_APP_SHORT_NAME']
45 40 project = self.__find_project(app_short_name)
... ... @@ -51,30 +46,30 @@ class Wikilibras:
51 46 if (project):
52 47 self.__setup_project(project)
53 48 result_msg = "The project " + app_short_name + " was created."
54   - else:
  49 + else:
55 50 result_msg = "The project " + app_short_name + " couldn't be created. Check the server log for details."
56 51 pyutil.log(result_msg)
57   - return result_msg
  52 + return result_msg
58 53  
59   - def update_project(self):
  54 + def update_project(self):
60 55 app_short_name = self.config['PYBOSSA_APP_SHORT_NAME']
61 56 project = self.__find_project(app_short_name)
62 57 self.__update_project_info(project)
63 58 result_msg = "The project " + app_short_name + " was updated."
64 59 pyutil.log(result_msg)
65 60 return result_msg
66   -
  61 +
67 62 def __find_task(self, project_id, task_id):
68 63 tasks = pbclient.find_tasks(project_id, id=task_id)
69 64 return tasks[0] if len(tasks) > 0 else None
70   -
  65 +
71 66 def __find_taskruns(self, project_id, task_id):
72 67 return pbclient.find_taskruns(project_id, id=task_id)
73   -
  68 +
74 69 def __number_of_taskruns(self, project_id, task_id):
75 70 taskruns = self.__find_taskruns(project_id, task_id)
76 71 return len(taskruns)
77   -
  72 +
78 73 def __close_task(self, project_id, task_id):
79 74 pyutil.log("Closing the task with ID=" + str(task_id) + ".")
80 75 task = self.__find_task(project_id, task_id)
... ... @@ -82,15 +77,41 @@ class Wikilibras:
82 77 task.n_answers = number_of_taskruns + 1
83 78 pbclient.update_task(task)
84 79 return "The task with ID=" + str(task_id) + " was closed."
85   -
  80 +
  81 + def get_file(self, url, filename):
  82 + r = requests.get(url, stream = True)
  83 + if (r.status_code == 200):
  84 + with open(filename, 'wb') as f:
  85 + for chunk in r.iter_content(chunk_size = 1024):
  86 + if chunk:
  87 + f.write(chunk)
  88 + return True
  89 + return False
  90 +
86 91 def finish_task(self):
87 92 task_id = request.form['task_id']
  93 + api_host = self.config['API_HOST']
  94 + api_dbhost = self.config['API_DB_HOST']
  95 + user_id = request.form['user_id']
  96 + sign_name = request.form['sign_name']
88 97 project_id = request.form['project_id']
89 98 number_of_approval = int(request.form['number_of_approval'])
90 99 agreement_number = self.config['AGREEMENT_NUMBER']
91 100 result_msg = ""
92 101 code = 200
93 102 if (number_of_approval >= agreement_number):
  103 + tmp_dir = tempfile.NamedTemporaryFile().name
  104 + if not os.path.exists(tmp_dir):
  105 + os.makedirs(tmp_dir)
  106 + blend_path = os.path.join(tmp_dir, sign_name + ".blend")
  107 + video_path = os.path.join(tmp_dir, sign_name + ".webm")
  108 + blend_downloaded = self.get_file(('%s/public/%s/%s.blend' % (api_host, user_id, sign_name)), blend_path)
  109 + video_downloaded = self.get_file(('%s/public/%s/%s.webm' % (api_host, user_id, sign_name)), video_path)
  110 + if (blend_downloaded and video_downloaded):
  111 + files = [ ("video", (video_path, open(video_path,"rb"))), ("video", (blend_path, open(blend_path, "rb"))) ]
  112 + values = { "nome": sign_name, "selo": 1, "wikilibras": True, "overwrite": True }
  113 + r = requests.post(("%s/addsinal" % (api_dbhost)), files=files, data=values)
  114 + shutil.rmtree(tmp_dir)
94 115 result_msg = self.__close_task(project_id, task_id)
95 116 else:
96 117 result_msg = "The task with ID=" + str(task_id) + " didn't reach the agreement number yet."
... ...