diff --git a/.gitignore b/.gitignore index aa6bcfc..75c8b79 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,22 @@ +.* +!*.gitignore +!*.gitempty +*~ +*.log +*.pyc +corretor.conf +corretor.wsgi +settings_local.py +env/ +videos/ +tmp/ +uploads/ + *.egg-info *.tox .*.swp -*.pyc *.db settings_local.py -env/ doc/_build *.un~ *.wsgi diff --git a/requirements.txt b/requirements.txt index 28647d4..241ea2a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ Flask==0.9 pybossa-client -flask-cors \ No newline at end of file +flask-cors +requests >= 1.2 diff --git a/settings_local.py b/settings_local.py index 818e83d..fe4fd29 100644 --- a/settings_local.py +++ b/settings_local.py @@ -1,19 +1,21 @@ # -*- coding: utf-8 -*- -# Corretor Server Configuration -SERVER_HOST = "0.0.0.0" +# WikiLibras Server Configuration +SERVER_HOST = "150.165.204.35" SERVER_PORT = 8003 AGREEMENT_NUMBER = 2 -API_HOST = "http://0.0.0.0:5001" +API_HOST = "http://150.165.204.35:201" +API_DB_HOST = "http://150.165.204.35:200" +UPLOAD_SIGN_HOST = "http://150.165.204.35:200/addsinal" +HOMEPAGE_URL = "http://wikilibras.lavid.ufpb.br" # Apache Configuration -APACHE_HOST = False +APACHE_HOST = True APACHE_HOST_ENDPOINT = "/wikilibras-backend" APACHE_STATIC_FILES_ENDPOINT = "/wikilibras" # PyBossa Configuration PYBOSSA_APP_NAME = "WikiLibras" -PYBOSSA_APP_SHORT_NAME = "wikilibras" +PYBOSSA_APP_SHORT_NAME = "wikilibras" PYBOSSA_APP_DESCRIPTION = "Esse projeto possibilitará que voluntários contribuam na expansão de um dicionário de LIBRAS." -PYBOSSA_ENDPOINT = "http://0.0.0.0:5000" -#PYBOSSA_API_KEY = "263302c0-07eb-44e4-956c-9b34cc301553" -PYBOSSA_API_KEY = "ed85ccd7-1417-4886-88bb-2e760509cef2" +PYBOSSA_ENDPOINT = "http://150.165.204.35/pybossa" +PYBOSSA_API_KEY = "0176e74e-4f70-45ef-bc75-6c6ebae8d170" diff --git a/settings_local.py.tmpl b/settings_local.py.tmpl index 7036153..2a6784d 100644 --- a/settings_local.py.tmpl +++ b/settings_local.py.tmpl @@ -16,5 +16,5 @@ APACHE_STATIC_FILES_ENDPOINT = "/wikilibras" PYBOSSA_APP_NAME = "WikiLibras" PYBOSSA_APP_SHORT_NAME = "wikilibras" PYBOSSA_APP_DESCRIPTION = "Esse projeto possibilitará que voluntários contribuam na expansão de um dicionário de LIBRAS." -PYBOSSA_ENDPOINT = "http://localhost:5000" +PYBOSSA_ENDPOINT = "http://localhost:201" PYBOSSA_API_KEY = "my-api-key" \ No newline at end of file diff --git a/view/assets/css/main.css b/view/assets/css/main.css index 70c4a31..d8a7298 100644 --- a/view/assets/css/main.css +++ b/view/assets/css/main.css @@ -500,7 +500,8 @@ ul.rig.columns-4 li { #approval-msg { display: none; - margin: 0px; + margin: 0px; + padding-left: 14px; } /* Thanks Screen */ @@ -519,4 +520,4 @@ ul.rig.columns-4 li { #completed-all-task-msg { display: none; -} \ No newline at end of file +} diff --git a/view/assets/js/wikilibras.js b/view/assets/js/wikilibras.js index 2dc9f69..c6f91c6 100644 --- a/view/assets/js/wikilibras.js +++ b/view/assets/js/wikilibras.js @@ -324,22 +324,50 @@ _getRenderedAvatarUrl(userId, signName)); $("#render-avatar").fadeIn(300); } + + function _showInitialScreen(toShow) { + if (toShow) { + $("#initial-screen").fadeIn(300); + $("#initial-screen video").get(0).play(); + } else { + $("#initial-screen").hide(); + $("#initial-screen video").get(0).pause(); + } + } + + function _showConfigurationScreen(toShow) { + if (toShow) { + $("#configuration-screen").show(); + $("#ref-video-container video").get(0).play(); + } else { + $("#configuration-screen").hide(); + $("#ref-video-container video").get(0).pause(); + } + } + + function _showRenderScreen(toShow) { + if (toShow) { + $("#render-screen").fadeIn(300); + $("#render-ref video").get(0).play(); + $("#render-avatar video").get(0).play(); + } else { + $("#render-screen").hide(); + $("#render-ref video").get(0).pause(); + $("#render-avatar video").get(0).pause(); + } + } function _setupRenderScreen() { - $("#configuration-screen").hide(); + _showConfigurationScreen(false); + _showRenderScreen(true); $("#render-avatar").hide(); - $("#render-screen").show(); $("#render-loading").fadeIn(300); - $("#render-ref video").prop("controls", false); - $("#render-ref video").get(0).pause(); $("#render-button-container .btn").hide(); $("#finish-button").addClass("disabled"); $("#finish-button").show(); _submitParameterJSON(function() { $("#render-loading").fadeOut(300); - $("#render-ref video").prop("controls", true); - $("#render-ref video").get(0).play(); $("#finish-button").removeClass("disabled"); _showRenderedAvatar(parsedParameterJSON); }); @@ -349,10 +377,9 @@ $("#render-button-container .btn").hide(); $("#approval-button").show(); $("#approval-msg").show(); - $("#render-ref video").get(0).play(); _showRenderedAvatar(parameterJSON); - $("#render-screen").fadeIn(300); + _showRenderScreen(true); } function _submitAnswer(task, deferred, status) { @@ -362,7 +389,7 @@ } else { _saveAnswer(task, deferred, answer); } - $("#render-screen").hide(); + _showRenderScreen(false); $("#thanks-screen").show(); } @@ -383,12 +410,12 @@ if (hasLastAnswer) { _setupApprovalScreen(last_answer.parameter_json); } else { - $("#initial-screen").fadeIn(300); + _showInitialScreen(true); } $("#start-button").off("click").on("click", function() { - $("#initial-screen").hide(); - $("#configuration-screen").show(); + _showInitialScreen(false); + _showConfigurationScreen(true); }); $("#ready-button").off("click").on("click", function() { if ($(this).hasClass('disabled')) { @@ -398,8 +425,8 @@ _setupRenderScreen(); }); $("#render-edit").off("click").on("click", function() { - $("#render-screen").hide(); - $("#configuration-screen").show(); + _showRenderScreen(false); + _showConfigurationScreen(true); }); $("#finish-button").off("click").on("click", function() { if ($(this).hasClass('disabled')) { diff --git a/view/template.html b/view/template.html index 9f1a1ee..55c86d1 100755 --- a/view/template.html +++ b/view/template.html @@ -63,7 +63,7 @@
@@ -298,11 +298,11 @@

Você ainda não ensinou - sinais a Ícaro.

-

Você já ensinou a Ícaro + sinais ao Ícaro.

+

Você já ensinou ao Ícaro 1 sinal de LIBRAS.

- Você já ensinou a Ícaro x sinais de LIBRAS. + Você já ensinou ao Ícaro x sinais de LIBRAS.

-

Aprenda como ensinar uma expressão a Ícaro.

+

Aprenda como ensinar o Ícaro uma expressão.

-

Aprenda como ensinar uma configuração de mão a Ícaro.

+

Aprenda como ensinar o Ícaro uma configuração de mão.

@@ -351,4 +351,4 @@ \ No newline at end of file + diff --git a/view/videos/CALAR_REF.webm b/view/videos/CALAR_REF.webm index 48aa8b6..19f4dfc 100644 Binary files a/view/videos/CALAR_REF.webm and b/view/videos/CALAR_REF.webm differ diff --git a/wikilibras.py b/wikilibras.py index 91077eb..ebf7642 100644 --- a/wikilibras.py +++ b/wikilibras.py @@ -4,42 +4,37 @@ from werkzeug import secure_filename import pbclient import os import pyutil +import requests +import tempfile +import shutil class Wikilibras: - + def __init__(self, configuration, template_env): self.config = configuration self.env = template_env self.__setup_pb_client() - + def __setup_pb_client(self): - pbclient.set('endpoint', self.config['PYBOSSA_ENDPOINT']) + pbclient.set('endpoint', self.config['PYBOSSA_ENDPOINT']) pbclient.set('api_key', self.config['PYBOSSA_API_KEY']) - + def __find_project(self, app_short_name): projects = pbclient.find_project(short_name=app_short_name) return projects[0] if len(projects) > 0 else None - + def __setup_project(self, project): - self.__create_tasks(project) self.__update_project_info(project) - - def __create_tasks(self, project): - test_signs = ["CALAR", "ENSINADO", "ENTANTO", "ENTENDIDO"] - #test_signs = ["CALAR"] - for sign in test_signs: - task = dict(sign_name=sign, submission_date=pyutil.get_date_now()) - pbclient.create_task(project.id, task) - + def __update_project_info(self, project): template = self.env.get_template('template.html') 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']) project.info['thumbnail'] = self.config['HOST_STATIC_FILES_ENDPOINT'] + "/img/thumbnail.png" project.info['sched'] = "incremental" + project.info['published'] = True project.allow_anonymous_contributors = False - project.published = True pbclient.update_project(project) - + def create_project(self): app_short_name = self.config['PYBOSSA_APP_SHORT_NAME'] project = self.__find_project(app_short_name) @@ -51,30 +46,30 @@ class Wikilibras: if (project): self.__setup_project(project) result_msg = "The project " + app_short_name + " was created." - else: + else: result_msg = "The project " + app_short_name + " couldn't be created. Check the server log for details." pyutil.log(result_msg) - return result_msg + return result_msg - def update_project(self): + def update_project(self): app_short_name = self.config['PYBOSSA_APP_SHORT_NAME'] project = self.__find_project(app_short_name) self.__update_project_info(project) result_msg = "The project " + app_short_name + " was updated." pyutil.log(result_msg) return result_msg - + def __find_task(self, project_id, task_id): tasks = pbclient.find_tasks(project_id, id=task_id) return tasks[0] if len(tasks) > 0 else None - + def __find_taskruns(self, project_id, task_id): return pbclient.find_taskruns(project_id, id=task_id) - + def __number_of_taskruns(self, project_id, task_id): taskruns = self.__find_taskruns(project_id, task_id) return len(taskruns) - + def __close_task(self, project_id, task_id): pyutil.log("Closing the task with ID=" + str(task_id) + ".") task = self.__find_task(project_id, task_id) @@ -82,15 +77,41 @@ class Wikilibras: task.n_answers = number_of_taskruns + 1 pbclient.update_task(task) return "The task with ID=" + str(task_id) + " was closed." - + + def get_file(self, url, filename): + r = requests.get(url, stream = True) + if (r.status_code == 200): + with open(filename, 'wb') as f: + for chunk in r.iter_content(chunk_size = 1024): + if chunk: + f.write(chunk) + return True + return False + def finish_task(self): task_id = request.form['task_id'] + api_host = self.config['API_HOST'] + api_dbhost = self.config['API_DB_HOST'] + user_id = request.form['user_id'] + sign_name = request.form['sign_name'] project_id = request.form['project_id'] number_of_approval = int(request.form['number_of_approval']) agreement_number = self.config['AGREEMENT_NUMBER'] result_msg = "" code = 200 if (number_of_approval >= agreement_number): + tmp_dir = tempfile.NamedTemporaryFile().name + if not os.path.exists(tmp_dir): + os.makedirs(tmp_dir) + blend_path = os.path.join(tmp_dir, sign_name + ".blend") + video_path = os.path.join(tmp_dir, sign_name + ".webm") + blend_downloaded = self.get_file(('%s/public/%s/%s.blend' % (api_host, user_id, sign_name)), blend_path) + video_downloaded = self.get_file(('%s/public/%s/%s.webm' % (api_host, user_id, sign_name)), video_path) + if (blend_downloaded and video_downloaded): + files = [ ("video", (video_path, open(video_path,"rb"))), ("video", (blend_path, open(blend_path, "rb"))) ] + values = { "nome": sign_name, "selo": 1, "wikilibras": True, "overwrite": True } + r = requests.post(("%s/addsinal" % (api_dbhost)), files=files, data=values) + shutil.rmtree(tmp_dir) result_msg = self.__close_task(project_id, task_id) else: result_msg = "The task with ID=" + str(task_id) + " didn't reach the agreement number yet." -- libgit2 0.21.2