39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
from apiflask import APIBlueprint
|
|
from flask import abort
|
|
|
|
from ...dependencies import db
|
|
from ...examination_schedule.models import ExaminationSchedule, TermOfDefence
|
|
from ...project_supervisor.models import ProjectSupervisor
|
|
from ..schemas.examination_schedule 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,
|
|
db.func.count(TermOfDefence.group_id),
|
|
db.func.count(TermOfDefence.id),
|
|
)
|
|
.join(TermOfDefence.members_of_committee)
|
|
.group_by(ProjectSupervisor.id)
|
|
.all()
|
|
)
|
|
|
|
workloads = (
|
|
{
|
|
"full_name": s[0],
|
|
"groups_assigned_to_his_committee": s[1],
|
|
"assigned_to_committee": s[2],
|
|
}
|
|
for s in statistics
|
|
)
|
|
return {"workloads": workloads}
|