update workloads statistics endpoint for coordinator

This commit is contained in:
dominik24c 2022-11-16 21:06:33 +01:00
parent 856372e5ab
commit afffc78537
3 changed files with 9 additions and 10 deletions

View File

@ -6,7 +6,7 @@ from .groups import bp as groups_bp
from .project_supervisor import bp as project_supervisor_bp from .project_supervisor import bp as project_supervisor_bp
from .students import bp as students_bp from .students import bp as students_bp
from .year_group import bp as year_group_bp from .year_group import bp as year_group_bp
# from .workloads import bp as workloads_bp from .workloads import bp as workloads_bp
bp = Blueprint("coordinator", __name__, url_prefix="/coordinator") bp = Blueprint("coordinator", __name__, url_prefix="/coordinator")
@ -16,4 +16,4 @@ bp.register_blueprint(groups_bp)
bp.register_blueprint(year_group_bp) bp.register_blueprint(year_group_bp)
bp.register_blueprint(examination_schedule_bp) bp.register_blueprint(examination_schedule_bp)
bp.register_blueprint(enrollments_bp) bp.register_blueprint(enrollments_bp)
# bp.register_blueprint(workloads_bp) bp.register_blueprint(workloads_bp)

View File

@ -72,7 +72,7 @@ def create_project_supervisor(data: dict) -> dict:
return {"message": "Project Supervisor was created!"} return {"message": "Project Supervisor was created!"}
@bp.get("/<int:id>/") @bp.get("/<int:id>/detail")
@bp.output(ProjectSupervisorSchema) @bp.output(ProjectSupervisorSchema)
def detail_project_supervisor(id: int) -> ProjectSupervisor: def detail_project_supervisor(id: int) -> ProjectSupervisor:
project_supervisor = ProjectSupervisor.query.filter_by(id=id).first() project_supervisor = ProjectSupervisor.query.filter_by(id=id).first()

View File

@ -3,7 +3,7 @@ from flask import abort
from flask_sqlalchemy import get_debug_queries from flask_sqlalchemy import get_debug_queries
from ...dependencies import db from ...dependencies import db
from ...examination_schedule.models import ExaminationSchedule from ...examination_schedule.models import ExaminationSchedule, TermOfDefence
from ...project_supervisor.models import ProjectSupervisor from ...project_supervisor.models import ProjectSupervisor
from ..schemas import WorkloadSchema from ..schemas import WorkloadSchema
@ -19,15 +19,14 @@ def workloads_statistics(examination_schedule_id: int) -> dict:
statistics = db.session.query( statistics = db.session.query(
ProjectSupervisor.first_name + " " + ProjectSupervisor.last_name, ProjectSupervisor.first_name + " " + ProjectSupervisor.last_name,
db.func.count(Enrollment.group_id), db.func.count(TermOfDefence.group_id),
db.func.count(Committee.id), db.func.count(TermOfDefence.id),
).join(Committee.members). \ ).join(TermOfDefence.members_of_committee). \
join(Enrollment, isouter=True). \
group_by(ProjectSupervisor.id).all() group_by(ProjectSupervisor.id).all()
# print(statistics) # print(statistics)
# print(len(statistics)) # print(len(statistics))
# print(get_debug_queries()) # print(get_debug_queries())
workloads = ({"full_name": s[0], "groups_assigned_to_his_committee": s[1], "assigned_to_committee": s[2]} for s in workloads = ({"full_name": s[0], "groups_assigned_to_his_committee": s[1],
statistics) "assigned_to_committee": s[2]} for s in statistics)
return {'workloads': workloads} return {'workloads': workloads}