summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ustayml/schema.sql16
-rw-r--r--ustayml/static/img/sample-bar_chart.pngbin0 -> 14541 bytes
-rw-r--r--ustayml/static/style.css40
-rw-r--r--ustayml/templates/students/details.html27
-rw-r--r--ustayml/templates/students/index.html2
-rw-r--r--ustayml/views/students.py34
6 files changed, 101 insertions, 18 deletions
diff --git a/ustayml/schema.sql b/ustayml/schema.sql
index e7e3e68..a160605 100644
--- a/ustayml/schema.sql
+++ b/ustayml/schema.sql
@@ -75,7 +75,21 @@ CREATE TABLE student (
-- REFERENCES administrative_division (id)
-- ;
--- Sample data (later move to tests)
+-- VIEWS
+
+create view view_student as
+select stu.*, adm.subdivision3 as "district", puc.name as "pucp_unit",
+ des.name as "est_desertion_risk_class"
+from student stu
+ left join administrative_division adm
+ on stu.administrative_division_id = adm.id
+ left join pucp_unit as puc
+ on stu.pucp_unit_id = puc.id
+ left join desertion_risk_class as des
+ on stu.est_desertion_risk_class_id = des.id
+;
+
+-- SAMPLE DATA (LATER MOVE TO TESTS)
INSERT INTO user_role ("id", "name") VALUES
(1, 'admin'),
diff --git a/ustayml/static/img/sample-bar_chart.png b/ustayml/static/img/sample-bar_chart.png
new file mode 100644
index 0000000..35f5ccc
--- /dev/null
+++ b/ustayml/static/img/sample-bar_chart.png
Binary files differ
diff --git a/ustayml/static/style.css b/ustayml/static/style.css
index 9246706..0ff4975 100644
--- a/ustayml/static/style.css
+++ b/ustayml/static/style.css
@@ -19,9 +19,26 @@ h5,
h6 {
font-family: serif;
color: #377ba8;
+ margin: 0;
+}
+
+h1 {
+ font-size: 22pt;
margin: 1rem 0;
}
+h2 {
+ font-size: 18pt;
+}
+
+h3 {
+ font-size: 14pt;
+}
+
+p {
+ font-size: 12pt;
+}
+
a {
color: #377ba8;
}
@@ -84,6 +101,7 @@ header .action {
border-bottom: 1px solid lightgray;
display: flex;
align-items: flex-end;
+ margin-bottom: 1em;
}
.content > header h1 {
@@ -172,6 +190,28 @@ header .action {
margin-right: 2em;
}
+/* student.details */
+
+.student-details-container {
+ display: flex;
+ justify-content: space-between;
+ min-height: 20em;
+}
+
+.student-details-container > div {
+ padding: .5em;
+ border: 1px solid black;
+}
+
+.student-details-container > #information-left {
+ width: 40%;
+ margin-right: 1em;
+}
+
+.student-details-container > #information-right {
+ flex: auto;
+}
+
/* post */
.post > header {
diff --git a/ustayml/templates/students/details.html b/ustayml/templates/students/details.html
new file mode 100644
index 0000000..6c28ea4
--- /dev/null
+++ b/ustayml/templates/students/details.html
@@ -0,0 +1,27 @@
+{% extends 'base.html' %}
+
+{% block header %}
+ <h1>{% block title %}Reporte del estudiante{% endblock %}</h1>
+ <span>Reporte generado el {{ date.strftime("%Y-%m-%d") }}</span>
+{% endblock %}
+
+{% block content %}
+ <div class="student-details-container">
+ <div id="information-left">
+ <h3>Información general:</h3>
+ <h3>Información socioeconómica:</h3>
+ <h3>Información académica:</h3>
+ </div>
+ <div id="information-right">
+ <h2>Resultado:</h2>
+ <span class="high-risk">Riesgo de deserción alto</span>
+ <ul>
+ <li>Factor de riesgo: 666</li>
+ </ul>
+ <span>Significancia de variables:</span>
+ <div class="chart">
+ <img src="{{ url_for('static', filename='img/sample-bar_chart.png') }}">
+ </div>
+ </div>
+ </div>
+{% endblock %} \ No newline at end of file
diff --git a/ustayml/templates/students/index.html b/ustayml/templates/students/index.html
index 6fb5312..050783b 100644
--- a/ustayml/templates/students/index.html
+++ b/ustayml/templates/students/index.html
@@ -79,7 +79,7 @@
<tbody>
{% for student in students %}
<tr>
- <td>{{ student['pucp_code'] }}</td>
+ <td><a href="{{ url_for('students.details', id=student['id']) }}">{{ student['pucp_code'] }}</a></td>
<td>{{ student['fullname'] }}</td>
<td>{{ student['email'] }}</td>
<td>{{ student['district'] }}</td>
diff --git a/ustayml/views/students.py b/ustayml/views/students.py
index b96907e..fef1a82 100644
--- a/ustayml/views/students.py
+++ b/ustayml/views/students.py
@@ -1,4 +1,5 @@
import math
+import datetime
from flask import (
Blueprint, flash, g, redirect, render_template, request, url_for
)
@@ -18,6 +19,7 @@ def index():
semester = [{'id': x, 'name': x} for x in range(1, 13)]
desertion_risks_class = db.execute("select * from desertion_risk_class;").fetchall()
+ # pagination
pagination = { 'pagesize': 100, 'page': None , 'n_pages': None, 'rowcount': None}
pagination['page'] = int(request.args.get('page', 0))
@@ -30,37 +32,27 @@ def index():
where_stmt = "where 1=1\n"
params = []
if fc['pucp_unit'] != 0:
- where_stmt += " and stu.pucp_unit_id = %s\n"
+ where_stmt += " and pucp_unit_id = %s\n"
params.append(fc['pucp_unit'])
if fc['semester'] != 0:
- where_stmt += " and stu.current_semester = %s\n"
+ where_stmt += " and current_semester = %s\n"
params.append(fc['semester'])
if fc['desertion_risk_class'] != 0:
- where_stmt += " and stu.est_desertion_risk_class_id = %s\n"
+ where_stmt += " and est_desertion_risk_class_id = %s\n"
params.append(fc['desertion_risk_class'])
query = f"""
- select stu.*, adm.subdivision3 as "district", puc.name as "pucp_unit",
- des.name as "est_desertion_risk_class"
- from student stu
- left join administrative_division adm
- on stu.administrative_division_id = adm.id
- left join pucp_unit as puc
- on stu.pucp_unit_id = puc.id
- left join desertion_risk_class as des
- on stu.est_desertion_risk_class_id = des.id
+ select * from view_student
{where_stmt}
"""
- students = get_paginated_items(query, params=params, pagination=pagination)
- # formatting
+ # output & formatting
+ students = get_paginated_items(query, params=params, pagination=pagination)
for s in students:
s['fullname'] = f"{s['first_name']} {s['last_name']}"
s['current_attendance'] = f"{s['current_attendance']*100:.2f}%"
s['current_merit'] = f"{s['current_merit']*100:.2f}%"
- print(query, params)
-
return render_template(
'students/index.html',
students=students, pagination=pagination,
@@ -70,6 +62,16 @@ def index():
fc=fc
)
[email protected]('/<int:id>', methods=('GET', 'POST'))
+@login_required
+def details(id):
+ db = get_db()
+ pucp_unit = db.execute("select * from view_student;").fetchall()
+ return render_template(
+ 'students/details.html',
+ date=datetime.datetime.now()
+ )
+
# Helper functions