Skip to content

Commit

Permalink
issues #1, #4
Browse files Browse the repository at this point in the history
- OK Page para realizar test
- Feat: Mostrando grafica con resultados
- Ok guardando resultados en doctype
- OK Workspace RH
  • Loading branch information
monroy95 committed Oct 25, 2021
1 parent 5329e8e commit 6c0b519
Show file tree
Hide file tree
Showing 11 changed files with 301 additions and 45 deletions.
39 changes: 37 additions & 2 deletions rh/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import frappe
from frappe import _
from frappe.utils import nowdate, get_datetime


@frappe.whitelist()
Expand All @@ -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 <hr> <code>{frappe.get_traceback()}</code>'),
Expand Down
117 changes: 76 additions & 41 deletions rh/public/js/MainBigFive.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
<template>
<div>
<div class="progress mb-4 Const" style="height: 25px">
<div v-if="completed === false">
<div
class="progress-bar"
role="progressbar"
:style="progressForm"
:aria-valuenow="counter"
aria-valuemin="0"
aria-valuemax="100"
class="progress mb-4 Const"
style="height: 25px"
v-if="completed === false"
>
60%
<div
class="progress-bar"
role="progressbar"
:style="progressForm"
:aria-valuenow="counter"
aria-valuemin="0"
aria-valuemax="100"
>
{{ counter }}%
</div>
</div>
</div>

<div>
<code>{{ counter }}</code>
<Question
v-for="(question, index) in questions"
:key="question.name"
Expand All @@ -28,6 +31,11 @@
</button>
</div>

<div v-if="completed === true" class="mb-4">
<h3 class="texto-res">Resultados</h3>
<p class="texto-res">Fecha y hora: {{ dateTimeTest }}</p>
<p class="texto-res">Test completado por: {{ userTest }}</p>
</div>
<div id="chart"></div>
</div>
</template>
Expand All @@ -41,6 +49,9 @@ export default {
},
data() {
return {
dateTimeTest: "",
userTest: "",
completed: false,
counter: 0,
questions: [],
responseByCategory: [],
Expand All @@ -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
},
};
},
Expand All @@ -72,59 +83,52 @@ 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);
// 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(
Expand All @@ -134,52 +138,52 @@ 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);
// 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);
// 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++;
}
Expand All @@ -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}%`;
},
Expand All @@ -224,4 +256,7 @@ export default {
</script>

<style scoped>
.texto-res {
color: #333c44;
}
</style>
Empty file.
41 changes: 41 additions & 0 deletions rh/rh/doctype/big_five_category/big_five_category.json
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 8 additions & 0 deletions rh/rh/doctype/big_five_category/big_five_category.py
Original file line number Diff line number Diff line change
@@ -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
Empty file.
8 changes: 8 additions & 0 deletions rh/rh/doctype/big_five_results/big_five_results.js
Original file line number Diff line number Diff line change
@@ -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) {

// }
});
Loading

0 comments on commit 6c0b519

Please sign in to comment.