34 lines
1.3 KiB
Python
34 lines
1.3 KiB
Python
![]() |
from apiflask import APIBlueprint
|
||
|
from flask import abort
|
||
|
from flask_sqlalchemy import get_debug_queries
|
||
|
|
||
|
from ...dependencies import db
|
||
|
from ...examination_schedule.models import ExaminationSchedule, Enrollment, Committee
|
||
|
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,
|
||
|
db.func.count(Enrollment.group_id),
|
||
|
db.func.count(Committee.id),
|
||
|
).join(Committee.members). \
|
||
|
join(Enrollment, isouter=True). \
|
||
|
group_by(ProjectSupervisor.id).all()
|
||
|
|
||
|
# print(statistics)
|
||
|
# print(len(statistics))
|
||
|
# print(get_debug_queries())
|
||
|
workloads = ({"full_name": s[0], "groups_assigned_to_his_committee": s[1], "assigned_to_committee": s[2]} for s in
|
||
|
statistics)
|
||
|
return {'workloads': workloads}
|