diff --git a/rh/api.py b/rh/api.py index dc7b78a..edda4dd 100755 --- a/rh/api.py +++ b/rh/api.py @@ -6,6 +6,7 @@ import frappe from frappe import _ +from frappe.utils import nowdate, get_datetime @frappe.whitelist() @@ -27,21 +28,55 @@ def complete_test(data): # DEBUG: # with open('respuestas.json', 'w') as f: # f.write(json.dumps(res, indent=2)) + total_questions = len(res.get('extraversion')) + len(res.get('agreeableness')) + len(res.get('conscientiousness')) + \ len(res.get('neuroticism')) + len(res.get('openness')) + # Deben completarse las 100 preguntar para completar el proceso if total_questions != 100: frappe.msgprint(msg=_(f'{total_questions} {_("de")} 100 {_("fueron respondidas, por favor responda todas las preguntas y presione completar")}'), title=_('Process not completed'), indicator='yellow') return False, 'Not Completed' - return True, { + results = { 'total_extraversion': sum(x['value'] for x in res.get('extraversion')), # extraversión 'total_agreeableness': sum(x['value'] for x in res.get('agreeableness')), # simpatía 'total_conscientiousness': sum(x['value'] for x in res.get('conscientiousness')), # concienciación 'total_neuroticism': sum(x['value'] for x in res.get('neuroticism')), # neuroticismo - 'total_openness': sum(x['value'] for x in res.get('openness')) # apertura + 'total_openness': sum(x['value'] for x in res.get('openness')), # apertura + 'user': frappe.db.get_value('User', {'name': frappe.session.user}, 'full_name'), + 'datetimetest': str(get_datetime()) } + + # DATOS PRUEBA + # results = { + # 'total_extraversion': 62, # extraversión + # 'total_agreeableness': 56, # simpatía + # 'total_conscientiousness': 63, # concienciación + # 'total_neuroticism': 57, # neuroticismo + # 'total_openness': 63, # apertura + # 'user': frappe.db.get_value('User', {'name': frappe.session.user}, 'full_name'), + # 'datetimetest': str(get_datetime()) + # } + + # Se registran los resultados + doc = frappe.get_doc({ + 'doctype': 'Big Five Results', + 'completed_by': frappe.session.user, + 'date_time': results.get('datetimetest'), + 'results': [ + {'category': 'EXTRAVERSION', 'score': results.get('total_extraversion')}, + {'category': 'AGREEABLENESS', 'score': results.get('total_agreeableness')}, + {'category': 'CONSCIENTIOUSNESS', 'score': results.get('total_conscientiousness')}, + {'category': 'NEUROTICISM', 'score': results.get('total_neuroticism')}, + {'category': 'OPENNESS', 'score': results.get('total_openness')}, + ], + 'docstatus': 1 + }) + doc.insert(ignore_permissions=True) + + return True, results + except: frappe.msgprint(msg=_(f'Calculo no pudo ser completado, copie o tome una captura de pantalla completo de todo este mensaje, \ para ayudarlo lo mas pronto posible. \n
{frappe.get_traceback()}'), diff --git a/rh/public/js/MainBigFive.vue b/rh/public/js/MainBigFive.vue index ed085cc..677f901 100755 --- a/rh/public/js/MainBigFive.vue +++ b/rh/public/js/MainBigFive.vue @@ -1,20 +1,23 @@ @@ -41,6 +49,9 @@ export default { }, data() { return { + dateTimeTest: "", + userTest: "", + completed: false, counter: 0, questions: [], responseByCategory: [], @@ -57,7 +68,7 @@ export default { __("NEUROTICISM"), __("OPENNESS"), ], - datasets: [{ values: [18, 40, 30, 35, 8] }], + datasets: [{ values: [0, 0, 0, 0, 0] }], // Valores default para graficas }, }; }, @@ -72,39 +83,32 @@ export default { // console.log(data.message); }, }); - - new frappe.Chart("#chart", { - data: this.dd, - type: "bar", - height: 180, - colors: ["red"], - }); }, methods: { // Emision de eventos: ver componente Question.vue => emitirEvento() optSelected(option) { - console.log("Seleccionó: ", JSON.stringify(option)); + // console.log("Seleccionó: ", JSON.stringify(option)); if (option.category === "EXTRAVERSION") { - console.log("ES EXTRAVERSION"); + // console.log("ES EXTRAVERSION"); // Si el elemento ya existe en el array, se elimina y se vuelve a agregar let index = this.EXTRAVERSION.findIndex((x) => x.name === option.name); // Si el valor ya existe en el array, se elimina para volverlo a agregarlo // asi asegurar que los calculos se generen correctamente if (index >= 0) { - console.log("Ya existe"); + // console.log("Ya existe"); this.EXTRAVERSION.splice(index, 1); this.EXTRAVERSION.push(option); } else { // Si no existe se agrega - console.log("No existe"); + // console.log("No existe"); this.EXTRAVERSION.push(option); this.counter++; } } if (option.category === "AGREEABLENESS") { - console.log("ES AGREEABLENESS"); + // console.log("ES AGREEABLENESS"); // Si el elemento ya existe en el array, se elimina y se vuelve a agregar let index = this.AGREEABLENESS.findIndex((x) => x.name === option.name); @@ -112,19 +116,19 @@ export default { // Si el valor ya existe en el array, se elimina para volverlo a agregarlo // asi asegurar que los calculos se generen correctamente if (index >= 0) { - console.log("Ya existe"); + // console.log("Ya existe"); this.AGREEABLENESS.splice(index, 1); this.AGREEABLENESS.push(option); } else { // Si no existe se agrega - console.log("No existe"); + // console.log("No existe"); this.AGREEABLENESS.push(option); this.counter++; } } if (option.category === "CONSCIENTIOUSNESS") { - console.log("ES CONSCIENTIOUSNESS"); + // console.log("ES CONSCIENTIOUSNESS"); // Si el elemento ya existe en el array, se elimina y se vuelve a agregar let index = this.CONSCIENTIOUSNESS.findIndex( @@ -134,19 +138,19 @@ export default { // Si el valor ya existe en el array, se elimina para volverlo a agregarlo // asi asegurar que los calculos se generen correctamente if (index >= 0) { - console.log("Ya existe"); + // console.log("Ya existe"); this.CONSCIENTIOUSNESS.splice(index, 1); this.CONSCIENTIOUSNESS.push(option); } else { // Si no existe se agrega - console.log("No existe"); + // console.log("No existe"); this.CONSCIENTIOUSNESS.push(option); this.counter++; } } if (option.category === "NEUROTICISM") { - console.log("ES NEUROTICISM"); + // console.log("ES NEUROTICISM"); // Si el elemento ya existe en el array, se elimina y se vuelve a agregar let index = this.NEUROTICISM.findIndex((x) => x.name === option.name); @@ -154,19 +158,19 @@ export default { // Si el valor ya existe en el array, se elimina para volverlo a agregarlo // asi asegurar que los calculos se generen correctamente if (index >= 0) { - console.log("Ya existe"); + // console.log("Ya existe"); this.NEUROTICISM.splice(index, 1); this.NEUROTICISM.push(option); } else { // Si no existe se agrega - console.log("No existe"); + // console.log("No existe"); this.NEUROTICISM.push(option); this.counter++; } } if (option.category === "OPENNESS") { - console.log("ES OPENNESS"); + // console.log("ES OPENNESS"); // Si el elemento ya existe en el array, se elimina y se vuelve a agregar let index = this.OPENNESS.findIndex((x) => x.name === option.name); @@ -174,12 +178,12 @@ export default { // Si el valor ya existe en el array, se elimina para volverlo a agregarlo // asi asegurar que los calculos se generen correctamente if (index >= 0) { - console.log("Ya existe"); + // console.log("Ya existe"); this.OPENNESS.splice(index, 1); this.OPENNESS.push(option); } else { // Si no existe se agrega - console.log("No existe"); + // console.log("No existe"); this.OPENNESS.push(option); this.counter++; } @@ -205,17 +209,45 @@ export default { openness: this.OPENNESS, }, }, - callback: function (data) { - // _this.questions = data.message; - // console.log(data.message); + freeze: true, + callback: function (r) { + if (r.message[0]) { + // Si se completo correctamente + _this.completed = true; // Para mostrar los resultado + + // Descomentar el console si quiere saber la estrucutura retornada por el server + _this.dd.datasets[0].values[0] = r.message[1].total_extraversion; + _this.dd.datasets[0].values[1] = r.message[1].total_agreeableness; + _this.dd.datasets[0].values[2] = + r.message[1].total_conscientiousness; + _this.dd.datasets[0].values[3] = r.message[1].total_neuroticism; + _this.dd.datasets[0].values[4] = r.message[1].total_openness; + + _this.dateTimeTest = r.message[1].datetimetest; + _this.userTest = r.message[1].user; + + _this.$forceUpdate(); + + new frappe.Chart("#chart", { + data: _this.dd, + type: "bar", + height: 225, + animate: 1, + colors: ["#0069a1"], + }); + + _this.$forceUpdate(); + } else { + _this.completed = false; + } + + // console.log(r.message); }, }); }, - contar() { - console.log("Presiono"); - }, }, computed: { + // Clase dinamica para div que refleja el avance del progress bar progressForm: function () { return `width: ${this.counter}%`; }, @@ -224,4 +256,7 @@ export default { \ No newline at end of file diff --git a/rh/rh/doctype/big_five_category/__init__.py b/rh/rh/doctype/big_five_category/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/rh/rh/doctype/big_five_category/big_five_category.json b/rh/rh/doctype/big_five_category/big_five_category.json new file mode 100644 index 0000000..364b7a9 --- /dev/null +++ b/rh/rh/doctype/big_five_category/big_five_category.json @@ -0,0 +1,41 @@ +{ + "actions": [], + "allow_rename": 1, + "creation": "2021-10-25 12:02:35.265856", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "category", + "score" + ], + "fields": [ + { + "fieldname": "category", + "fieldtype": "Select", + "in_list_view": 1, + "label": "Category", + "options": "EXTRAVERSION\nAGREEABLENESS\nCONSCIENTIOUSNESS\nNEUROTICISM\nOPENNESS", + "read_only": 1 + }, + { + "fieldname": "score", + "fieldtype": "Float", + "in_list_view": 1, + "label": "Score", + "read_only": 1 + } + ], + "index_web_pages_for_search": 1, + "istable": 1, + "links": [], + "modified": "2021-10-25 12:38:09.902258", + "modified_by": "Administrator", + "module": "RH", + "name": "Big Five Category", + "owner": "Administrator", + "permissions": [], + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 +} \ No newline at end of file diff --git a/rh/rh/doctype/big_five_category/big_five_category.py b/rh/rh/doctype/big_five_category/big_five_category.py new file mode 100644 index 0000000..29b4677 --- /dev/null +++ b/rh/rh/doctype/big_five_category/big_five_category.py @@ -0,0 +1,8 @@ +# Copyright (c) 2021, Si Hay Sistema and contributors +# For license information, please see license.txt + +# import frappe +from frappe.model.document import Document + +class BigFiveCategory(Document): + pass diff --git a/rh/rh/doctype/big_five_results/__init__.py b/rh/rh/doctype/big_five_results/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/rh/rh/doctype/big_five_results/big_five_results.js b/rh/rh/doctype/big_five_results/big_five_results.js new file mode 100644 index 0000000..28ddc07 --- /dev/null +++ b/rh/rh/doctype/big_five_results/big_five_results.js @@ -0,0 +1,8 @@ +// Copyright (c) 2021, Si Hay Sistema and contributors +// For license information, please see license.txt + +frappe.ui.form.on('Big Five Results', { + // refresh: function(frm) { + + // } +}); diff --git a/rh/rh/doctype/big_five_results/big_five_results.json b/rh/rh/doctype/big_five_results/big_five_results.json new file mode 100644 index 0000000..142cde3 --- /dev/null +++ b/rh/rh/doctype/big_five_results/big_five_results.json @@ -0,0 +1,80 @@ +{ + "actions": [], + "allow_rename": 1, + "autoname": "RES-.#######", + "creation": "2021-10-25 11:54:42.169944", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "completed_by", + "full_name", + "date_time", + "results", + "amended_from" + ], + "fields": [ + { + "fieldname": "completed_by", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Completed By", + "options": "User", + "read_only": 1 + }, + { + "fieldname": "date_time", + "fieldtype": "Datetime", + "in_list_view": 1, + "label": "Date Time", + "read_only": 1 + }, + { + "fieldname": "amended_from", + "fieldtype": "Link", + "label": "Amended From", + "no_copy": 1, + "options": "Big Five Results", + "print_hide": 1, + "read_only": 1 + }, + { + "fieldname": "results", + "fieldtype": "Table", + "label": "Results", + "options": "Big Five Category" + }, + { + "fetch_from": "completed_by.full_name", + "fieldname": "full_name", + "fieldtype": "Data", + "label": "Full Name", + "read_only": 1 + } + ], + "index_web_pages_for_search": 1, + "is_submittable": 1, + "links": [], + "modified": "2021-10-25 12:40:08.752703", + "modified_by": "Administrator", + "module": "RH", + "name": "Big Five Results", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "write": 1 + } + ], + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 +} \ No newline at end of file diff --git a/rh/rh/doctype/big_five_results/big_five_results.py b/rh/rh/doctype/big_five_results/big_five_results.py new file mode 100644 index 0000000..c64141f --- /dev/null +++ b/rh/rh/doctype/big_five_results/big_five_results.py @@ -0,0 +1,8 @@ +# Copyright (c) 2021, Si Hay Sistema and contributors +# For license information, please see license.txt + +# import frappe +from frappe.model.document import Document + +class BigFiveResults(Document): + pass diff --git a/rh/rh/doctype/big_five_results/test_big_five_results.py b/rh/rh/doctype/big_five_results/test_big_five_results.py new file mode 100644 index 0000000..7097107 --- /dev/null +++ b/rh/rh/doctype/big_five_results/test_big_five_results.py @@ -0,0 +1,8 @@ +# Copyright (c) 2021, Si Hay Sistema and Contributors +# See license.txt + +# import frappe +import unittest + +class TestBigFiveResults(unittest.TestCase): + pass diff --git a/rh/rh/workspace/rh/rh.json b/rh/rh/workspace/rh/rh.json index 6da0bd8..3b00a18 100644 --- a/rh/rh/workspace/rh/rh.json +++ b/rh/rh/workspace/rh/rh.json @@ -18,12 +18,28 @@ { "hidden": 0, "is_query_report": 0, - "label": "Big Five", + "label": "Questions", + "link_type": "DocType", + "onboard": 0, + "type": "Card Break" + }, + { + "hidden": 0, + "is_query_report": 0, + "label": "Big Five Factor Model", "link_to": "Big Five Factor Model", "link_type": "DocType", "onboard": 0, "type": "Link" }, + { + "hidden": 0, + "is_query_report": 0, + "label": "Tests", + "link_type": "DocType", + "onboard": 0, + "type": "Card Break" + }, { "hidden": 0, "is_query_report": 0, @@ -32,9 +48,26 @@ "link_type": "Page", "onboard": 0, "type": "Link" + }, + { + "hidden": 0, + "is_query_report": 0, + "label": "Results", + "link_type": "DocType", + "onboard": 0, + "type": "Card Break" + }, + { + "hidden": 0, + "is_query_report": 0, + "label": "Big Five Results", + "link_to": "Big Five Results", + "link_type": "DocType", + "onboard": 0, + "type": "Link" } ], - "modified": "2021-10-04 14:46:44.715257", + "modified": "2021-10-25 12:29:40.698138", "modified_by": "Administrator", "module": "RH", "name": "RH",