2022-10-27 19:53:39 +02:00
|
|
|
from apiflask import APIBlueprint
|
|
|
|
from flask import abort
|
|
|
|
|
|
|
|
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
|
2023-01-14 17:38:03 +01:00
|
|
|
from ..schemas.examination_schedule import WorkloadSchema
|
2022-10-27 19:53:39 +02:00
|
|
|
|
|
|
|
bp = APIBlueprint("workloads", __name__, url_prefix="/")
|
|
|
|
|
|
|
|
|
2023-01-14 17:38:03 +01:00
|
|
|
@bp.get("/examination_schedule/<int:examination_schedule_id>/workloads/")
|
2022-10-27 19:53:39 +02:00
|
|
|
@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!")
|
|
|
|
|
2023-01-14 17:38:03 +01:00
|
|
|
statistics = (
|
|
|
|
db.session.query(
|
|
|
|
ProjectSupervisor.first_name + " " + ProjectSupervisor.last_name,
|
|
|
|
db.func.count(TermOfDefence.group_id),
|
|
|
|
db.func.count(TermOfDefence.id),
|
|
|
|
)
|
|
|
|
.join(TermOfDefence.members_of_committee)
|
|
|
|
.group_by(ProjectSupervisor.id)
|
|
|
|
.all()
|
|
|
|
)
|
2022-10-27 19:53:39 +02:00
|
|
|
|
2023-01-14 17:38:03 +01:00
|
|
|
workloads = (
|
|
|
|
{
|
|
|
|
"full_name": s[0],
|
|
|
|
"groups_assigned_to_his_committee": s[1],
|
|
|
|
"assigned_to_committee": s[2],
|
|
|
|
}
|
|
|
|
for s in statistics
|
|
|
|
)
|
|
|
|
return {"workloads": workloads}
|