Skip to content

Commit

Permalink
feat: add team distribution to schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
valerydluski committed Nov 5, 2024
1 parent 9404a0b commit eea004c
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 8 deletions.
10 changes: 7 additions & 3 deletions client/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,9 @@ export const CourseScheduleItemDtoStatusEnum = {
Archived: 'archived',
Future: 'future',
Missed: 'missed',
Review: 'review'
Review: 'review',
Registered: 'registered',
Unavailable: 'unavailable'
} as const;

export type CourseScheduleItemDtoStatusEnum = typeof CourseScheduleItemDtoStatusEnum[keyof typeof CourseScheduleItemDtoStatusEnum];
Expand All @@ -1176,13 +1178,15 @@ export const CourseScheduleItemDtoTagEnum = {
Interview: 'interview',
CrossCheckSubmit: 'cross-check-submit',
CrossCheckReview: 'cross-check-review',
Test: 'test'
Test: 'test',
TeamDistribution: 'team-distribution'
} as const;

export type CourseScheduleItemDtoTagEnum = typeof CourseScheduleItemDtoTagEnum[keyof typeof CourseScheduleItemDtoTagEnum];
export const CourseScheduleItemDtoTypeEnum = {
CourseTask: 'courseTask',
CourseEvent: 'courseEvent'
CourseEvent: 'courseEvent',
CourseTeamDistribution: 'courseTeamDistribution'
} as const;

export type CourseScheduleItemDtoTypeEnum = typeof CourseScheduleItemDtoTypeEnum[keyof typeof CourseScheduleItemDtoTypeEnum];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const tabsOrder = [
CourseScheduleItemDtoStatusEnum.Future,
CourseScheduleItemDtoStatusEnum.Missed,
CourseScheduleItemDtoStatusEnum.Done,
CourseScheduleItemDtoStatusEnum.Registered,
CourseScheduleItemDtoStatusEnum.Unavailable,
CourseScheduleItemDtoStatusEnum.Archived,
];

Expand Down
4 changes: 4 additions & 0 deletions client/src/modules/Schedule/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export function getTaskStatusColor(value: CourseScheduleItemDtoStatusEnum) {
return '#13c2c2';
case CourseScheduleItemDtoStatusEnum.Review:
return '#722ed1';
case CourseScheduleItemDtoStatusEnum.Registered:
return '#73d13d';
case CourseScheduleItemDtoStatusEnum.Unavailable:
return '#faad14';
default:
return '#d9d9d9';
}
Expand Down
98 changes: 96 additions & 2 deletions nestjs/src/courses/course-schedule/course-schedule.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { Repository } from 'typeorm';
import { EventType } from '../course-events/dto/course-event.dto';
import { Course } from '@entities/course';
import * as dayjs from 'dayjs';
import { TeamDistribution } from '@entities/teamDistribution';
import { TeamDistributionStudent } from '@entities/teamDistributionStudent';

export type CourseScheduleItem = Pick<CourseTask, 'id' | 'courseId'> &
Partial<Pick<CourseTask, 'maxScore' | 'scoreWeight'>> & {
Expand All @@ -29,6 +31,7 @@ export type CourseScheduleItem = Pick<CourseTask, 'id' | 'courseId'> &
export enum CourseScheduleDataSource {
CourseTask = 'courseTask',
CourseEvent = 'courseEvent',
CourseTeamDistribution = 'courseTeamDistribution',
}

export enum CourseScheduleItemTag {
Expand All @@ -39,6 +42,7 @@ export enum CourseScheduleItemTag {
CrossCheckSubmit = 'cross-check-submit',
CrossCheckReview = 'cross-check-review',
Test = 'test',
TeamDistribution = 'team-distribution',
}

export enum CourseScheduleItemStatus {
Expand All @@ -48,6 +52,8 @@ export enum CourseScheduleItemStatus {
Future = 'future',
Missed = 'missed',
Review = 'review',
Registered = 'registered',
Unavailable = 'unavailable',
}

@Injectable()
Expand All @@ -69,6 +75,10 @@ export class CourseScheduleService {
readonly taskSolutionRepository: Repository<TaskSolution>,
@InjectRepository(TaskChecker)
readonly taskCheckerRepository: Repository<TaskChecker>,
@InjectRepository(TeamDistribution)
readonly courseTeamDistributionRepository: Repository<TeamDistribution>,
@InjectRepository(TeamDistributionStudent)
private teamDistributionStudentRepository: Repository<TeamDistributionStudent>,
) {}

private scheduleSort(a: CourseScheduleItem, b: CourseScheduleItem) {
Expand All @@ -89,18 +99,86 @@ export class CourseScheduleService {
return aTagPriority - bTagPriority;
}

private async getCourseTeamDistributions(courseId: number, studentId?: number) {
return this.courseTeamDistributionRepository.find({
where: { courseId },
cache: studentId ? 90 * 1000 : undefined,
});
}

private async getTeamDistributionStudents(courseId: number, studentId?: number) {
if (!studentId) {
return [];
}

const teamDistributionStudents = await this.teamDistributionStudentRepository.find({
where: { courseId, studentId },
relations: { student: true },
});
return teamDistributionStudents;
}

private getTeamDistributionStatus(
teamDistribution: TeamDistribution,
teamDistributionStudents: TeamDistributionStudent[],
) {
const currTimestampUTC = dayjs();
const distributionStartDate = dayjs(teamDistribution.startDate);
const teamDistributionStudent = teamDistributionStudents.find(el => el.teamDistributionId === teamDistribution.id);

if (currTimestampUTC < distributionStartDate) {
return CourseScheduleItemStatus.Future;
}

if (teamDistributionStudent?.distributed) {
return CourseScheduleItemStatus.Done;
}

if (teamDistributionStudent?.active) {
return CourseScheduleItemStatus.Registered;
}

if (
teamDistributionStudent?.student == null ||
teamDistributionStudent.student.isExpelled ||
teamDistribution.minTotalScore > teamDistributionStudent.student.totalScore
) {
return CourseScheduleItemStatus.Unavailable;
}

const distributionEndDate = dayjs(teamDistribution.endDate);
if (currTimestampUTC <= distributionEndDate && currTimestampUTC >= distributionStartDate) {
return CourseScheduleItemStatus.Available;
}

if (currTimestampUTC > distributionEndDate) {
return CourseScheduleItemStatus.Missed;
}

return CourseScheduleItemStatus.Unavailable;
}

public async getAll(courseId: number, studentId?: number): Promise<CourseScheduleItem[]> {
const [courseTasks, courseEvents] = await Promise.all([
const [courseTasks, courseEvents, teamDistribution] = await Promise.all([
this.getActiveCourseTasks(courseId, studentId),
this.getCourseEvents(courseId, studentId),
this.getCourseTeamDistributions(courseId, studentId),
]);

const [taskResults, interviewResults, technicalScreeningResults, taskSolutions, taskCheckers] = await Promise.all([
const [
taskResults,
interviewResults,
technicalScreeningResults,
taskSolutions,
taskCheckers,
teamDistributionStudents,
] = await Promise.all([
this.getTaskResults(studentId),
this.getInterviewResults(studentId),
this.getPrescreeningResults(studentId),
this.getTaskSolutions(studentId),
this.getTaskCheckers(studentId),
this.getTeamDistributionStudents(courseId, studentId),
]);

const schedule = courseTasks
Expand Down Expand Up @@ -164,6 +242,22 @@ export class CourseScheduleService {
} as CourseScheduleItem;
}),
)
.concat(
teamDistribution.map(teamDistribution => {
teamDistribution.description;
return {
id: teamDistribution.id,
name: teamDistribution.name,
courseId,
startDate: teamDistribution.startDate,
endDate: teamDistribution.endDate,
status: this.getTeamDistributionStatus(teamDistribution, teamDistributionStudents),
type: CourseScheduleDataSource.CourseTeamDistribution,
tag: CourseScheduleItemTag.TeamDistribution,
descriptionUrl: teamDistribution.descriptionUrl,
};
}),
)
.sort(this.scheduleSort);

return schedule;
Expand Down
18 changes: 15 additions & 3 deletions nestjs/src/spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -3682,7 +3682,10 @@
"score": { "type": "number", "nullable": true },
"name": { "type": "string" },
"id": { "type": "number" },
"status": { "type": "string", "enum": ["done", "available", "archived", "future", "missed", "review"] },
"status": {
"type": "string",
"enum": ["done", "available", "archived", "future", "missed", "review", "registered", "unavailable"]
},
"startDate": { "type": "string" },
"endDate": { "type": "string" },
"crossCheckEndDate": { "type": "string" },
Expand All @@ -3692,9 +3695,18 @@
"descriptionUrl": { "type": "string", "nullable": true },
"tag": {
"type": "string",
"enum": ["lecture", "coding", "self-study", "interview", "cross-check-submit", "cross-check-review", "test"]
"enum": [
"lecture",
"coding",
"self-study",
"interview",
"cross-check-submit",
"cross-check-review",
"test",
"team-distribution"
]
},
"type": { "type": "string", "enum": ["courseTask", "courseEvent"] }
"type": { "type": "string", "enum": ["courseTask", "courseEvent", "courseTeamDistribution"] }
},
"required": [
"score",
Expand Down

0 comments on commit eea004c

Please sign in to comment.