2022-10-27 19:53:39 +02:00
|
|
|
from apiflask import APIBlueprint
|
|
|
|
from flask import abort
|
|
|
|
from flask_sqlalchemy import get_debug_queries
|
|
|
|
|
|
|
|
from ...dependencies import db
|
2022-11-16 21:06:33 +01:00
|
|
|
from ...examination_schedule.models import ExaminationSchedule, TermOfDefence
|
2022-10-27 19:53:39 +02:00
|
|
|
from ...project_supervisor.models import ProjectSupervisor
|
|
|
|
from ..schemas import WorkloadSchema
|
|
|
|
|
|
|
|
bp = APIBlueprint("workloads", __name__, url_prefix="/")
|
|
|
|
|
|
|
|
|
|
|
|
@bp.get('/examination_schedule/<int:examination_schedule_id>/workloads/')
|
|
|
|
@bp.output(WorkloadSchema)
|
|
|
|
def workloads_statistics(examination_schedule_id: int) -> dict:
|
|
|
|
es = ExaminationSchedule.query.filter_by(id=examination_schedule_id).first()
|
|
|
|
if es is None:
|
|
|
|
abort(404, "Not found examination schedule!")
|
|
|
|
|
|
|
|
statistics = db.session.query(
|
|
|
|
ProjectSupervisor.first_name + " " + ProjectSupervisor.last_name,
|
2022-11-16 21:06:33 +01:00
|
|
|
db.func.count(TermOfDefence.group_id),
|
|
|
|
db.func.count(TermOfDefence.id),
|
|
|
|
).join(TermOfDefence.members_of_committee). \
|
2022-10-27 19:53:39 +02:00
|
|
|
group_by(ProjectSupervisor.id).all()
|
|
|
|
|
|
|
|
# print(statistics)
|
|
|
|
# print(len(statistics))
|
|
|
|
# print(get_debug_queries())
|
2022-11-16 21:06:33 +01:00
|
|
|
workloads = ({"full_name": s[0], "groups_assigned_to_his_committee": s[1],
|
|
|
|
"assigned_to_committee": s[2]} for s in statistics)
|
2022-10-27 19:53:39 +02:00
|
|
|
return {'workloads': workloads}
|