mirror of
https://github.com/UniversityOfHelsinkiCS/oodikone.git
synced 2026-10-12 19:03:39 +03:00
[Backend] Extract types for StudyTrackStats
This commit is contained in:
@@ -6,10 +6,7 @@ import { getGraduationStats, getStudyTrackStats, setGraduationStats, setStudyTra
|
|||||||
import { getGraduationStatsForStudyTrack, GraduationTimes } from '../studyProgramme/studyProgrammeGraduations'
|
import { getGraduationStatsForStudyTrack, GraduationTimes } from '../studyProgramme/studyProgrammeGraduations'
|
||||||
import { getMedian } from '../studyProgramme/studyProgrammeHelpers'
|
import { getMedian } from '../studyProgramme/studyProgrammeHelpers'
|
||||||
import { getStudyRightsInProgramme } from '../studyProgramme/studyRightFinders'
|
import { getStudyRightsInProgramme } from '../studyProgramme/studyRightFinders'
|
||||||
import {
|
import { getStudyTrackStatsForStudyProgramme } from '../studyProgramme/studyTrackStats'
|
||||||
getStudyTrackStatsForStudyProgramme,
|
|
||||||
ProgrammeOrStudyTrackGraduationStats,
|
|
||||||
} from '../studyProgramme/studyTrackStats'
|
|
||||||
import type { ProgrammesOfOrganization } from './faculty'
|
import type { ProgrammesOfOrganization } from './faculty'
|
||||||
|
|
||||||
export type LevelGraduationStats = Omit<GraduationTimes['medians'][number], 'y'> & { median: number }
|
export type LevelGraduationStats = Omit<GraduationTimes['medians'][number], 'y'> & { median: number }
|
||||||
@@ -161,7 +158,7 @@ const getStatsByStartYear = async (facultyProgrammes: ProgrammesOfOrganization)
|
|||||||
const { degreeProgrammeType, progId, code } = facultyProgrammes.find(({ code }) => code === programmeCode)!
|
const { degreeProgrammeType, progId, code } = facultyProgrammes.find(({ code }) => code === programmeCode)!
|
||||||
const level = programmeTypes[degreeProgrammeType as keyof typeof programmeTypes]
|
const level = programmeTypes[degreeProgrammeType as keyof typeof programmeTypes]
|
||||||
if (!(programmeCode in graduationTimes)) continue
|
if (!(programmeCode in graduationTimes)) continue
|
||||||
const statsForProgramme = graduationTimes[programmeCode] as ProgrammeOrStudyTrackGraduationStats
|
const statsForProgramme = graduationTimes[programmeCode]
|
||||||
const basicStats = statsForProgramme.medians.basic
|
const basicStats = statsForProgramme.medians.basic
|
||||||
const comboStats = statsForProgramme.medians.combo
|
const comboStats = statsForProgramme.medians.combo
|
||||||
const classSizesByYear = basicStats.reduce<Record<string, number>>(
|
const classSizesByYear = basicStats.reduce<Record<string, number>>(
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import moment from 'moment'
|
|||||||
import { InferAttributes } from 'sequelize'
|
import { InferAttributes } from 'sequelize'
|
||||||
|
|
||||||
import { Credit, SISStudyRight, SISStudyRightElement } from '../../models'
|
import { Credit, SISStudyRight, SISStudyRightElement } from '../../models'
|
||||||
|
import { GraduationTimes, MedianEntry, ProgrammeOrStudyTrackGraduationStats, StudyTrackStats } from '../../shared/types'
|
||||||
import { GenderCode, EnrollmentType, ExtentCode, SemesterEnrollment } from '../../types'
|
import { GenderCode, EnrollmentType, ExtentCode, SemesterEnrollment } from '../../types'
|
||||||
import { createLocaleComparator, keysOf } from '../../util'
|
import { createLocaleComparator, keysOf } from '../../util'
|
||||||
import { countTimeCategories } from '../graduationHelpers'
|
import { countTimeCategories } from '../graduationHelpers'
|
||||||
@@ -22,19 +23,6 @@ import {
|
|||||||
} from './studyProgrammeHelpers'
|
} from './studyProgrammeHelpers'
|
||||||
import { getStudyTracksForProgramme } from './studyRightFinders'
|
import { getStudyTracksForProgramme } from './studyRightFinders'
|
||||||
|
|
||||||
type MedianEntry = {
|
|
||||||
amount: number
|
|
||||||
classSize: number
|
|
||||||
name: string
|
|
||||||
statistics: ReturnType<typeof countTimeCategories>
|
|
||||||
y: number
|
|
||||||
times: number[]
|
|
||||||
}
|
|
||||||
|
|
||||||
export type ProgrammeOrStudyTrackGraduationStats = {
|
|
||||||
medians: { basic: MedianEntry[]; combo: MedianEntry[] }
|
|
||||||
}
|
|
||||||
|
|
||||||
const getCreditCount = (credits: Credit[], startDate: Date) =>
|
const getCreditCount = (credits: Credit[], startDate: Date) =>
|
||||||
credits
|
credits
|
||||||
.filter(credit => moment(credit.attainment_date).isSameOrAfter(startDate))
|
.filter(credit => moment(credit.attainment_date).isSameOrAfter(startDate))
|
||||||
@@ -47,15 +35,8 @@ const getGraduationTimeStats = async (
|
|||||||
mainStatsByTrack: ReturnType<typeof combineStats>['mainStatsByTrack'],
|
mainStatsByTrack: ReturnType<typeof combineStats>['mainStatsByTrack'],
|
||||||
combinedProgramme?: string
|
combinedProgramme?: string
|
||||||
) => {
|
) => {
|
||||||
type Goals = { basic: number; combo: number }
|
|
||||||
|
|
||||||
type GraduationTimes = {
|
|
||||||
goals: Goals
|
|
||||||
[programmeOrStudyTrack: string]: ProgrammeOrStudyTrackGraduationStats | Goals
|
|
||||||
}
|
|
||||||
|
|
||||||
const goal = await getGoal(combinedProgramme ?? studyProgramme)
|
const goal = await getGoal(combinedProgramme ?? studyProgramme)
|
||||||
const finalGraduationTimes: GraduationTimes = { goals: { basic: goal, combo: goal + 36 } }
|
const finalGraduationTimes = { goals: { basic: goal, combo: goal + 36 } }
|
||||||
|
|
||||||
const calculateGraduationTimes = (
|
const calculateGraduationTimes = (
|
||||||
graduationTimes: Record<string, Record<string, number[]>>,
|
graduationTimes: Record<string, Record<string, number[]>>,
|
||||||
@@ -92,7 +73,7 @@ const getGraduationTimeStats = async (
|
|||||||
calculateGraduationTimes(graduationTimes, 'basic')
|
calculateGraduationTimes(graduationTimes, 'basic')
|
||||||
calculateGraduationTimes(graduationTimesCombo, 'combo')
|
calculateGraduationTimes(graduationTimesCombo, 'combo')
|
||||||
|
|
||||||
return finalGraduationTimes
|
return finalGraduationTimes as GraduationTimes
|
||||||
}
|
}
|
||||||
|
|
||||||
const getEmptyYear = () => ({
|
const getEmptyYear = () => ({
|
||||||
@@ -501,13 +482,21 @@ export const getStudyTrackStatsForStudyProgramme = async ({
|
|||||||
return tableTitles.studytracksCombined.master
|
return tableTitles.studytracksCombined.master
|
||||||
}
|
}
|
||||||
const graduatedTitles = combinedProgramme ? getCorrectCombinedTitles() : tableTitles.studytracksBasic
|
const graduatedTitles = combinedProgramme ? getCorrectCombinedTitles() : tableTitles.studytracksBasic
|
||||||
return {
|
|
||||||
id: combinedProgramme ? `${studyProgramme}-${combinedProgramme}` : studyProgramme,
|
const studyTrackStats: StudyTrackStats = {
|
||||||
years,
|
creditCounts: stats.creditCounts,
|
||||||
...stats,
|
creditCountsCombo: stats.creditCountsCombo,
|
||||||
doCombo,
|
doCombo,
|
||||||
studyTracks,
|
graduationTimes: stats.graduationTimes,
|
||||||
|
graduationTimesSecondProg: stats.graduationTimesSecondProg,
|
||||||
|
id: combinedProgramme ? `${studyProgramme}-${combinedProgramme}` : studyProgramme,
|
||||||
includeGraduated: settings.graduated,
|
includeGraduated: settings.graduated,
|
||||||
|
mainStatsByTrack: stats.mainStatsByTrack,
|
||||||
|
mainStatsByYear: stats.mainStatsByYear,
|
||||||
|
otherCountriesCount: stats.otherCountriesCount,
|
||||||
populationTitles: [...tableTitles.studytracksStart, ...graduatedTitles, ...tableTitles.studytracksEnd],
|
populationTitles: [...tableTitles.studytracksStart, ...graduatedTitles, ...tableTitles.studytracksEnd],
|
||||||
|
studyTracks,
|
||||||
|
years,
|
||||||
}
|
}
|
||||||
|
return studyTrackStats
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,4 +11,10 @@ export type {
|
|||||||
export type { Name, NameWithCode } from './name'
|
export type { Name, NameWithCode } from './name'
|
||||||
export type { Release } from './release'
|
export type { Release } from './release'
|
||||||
export type { Role } from './role'
|
export type { Role } from './role'
|
||||||
|
export type {
|
||||||
|
GraduationTimes,
|
||||||
|
MedianEntry,
|
||||||
|
ProgrammeOrStudyTrackGraduationStats,
|
||||||
|
StudyTrackStats,
|
||||||
|
} from './studyProgramme'
|
||||||
export type { NewTag, StudentTag, Tag } from './tag'
|
export type { NewTag, StudentTag, Tag } from './tag'
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
import { Name } from './name'
|
||||||
|
|
||||||
|
export type MedianEntry = {
|
||||||
|
amount: number
|
||||||
|
classSize: number
|
||||||
|
name: string
|
||||||
|
statistics: {
|
||||||
|
onTime: number
|
||||||
|
yearOver: number
|
||||||
|
wayOver: number
|
||||||
|
}
|
||||||
|
times: number[]
|
||||||
|
y: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ProgrammeOrStudyTrackGraduationStats = {
|
||||||
|
medians: {
|
||||||
|
basic: MedianEntry[]
|
||||||
|
combo: MedianEntry[]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Goals = {
|
||||||
|
basic: number
|
||||||
|
combo: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export type GraduationTimes = {
|
||||||
|
goals: Goals
|
||||||
|
} & {
|
||||||
|
[programmeOrStudyTrack: string]: ProgrammeOrStudyTrackGraduationStats
|
||||||
|
}
|
||||||
|
|
||||||
|
export type StudyTrackStats = {
|
||||||
|
creditCounts: Record<string, number[]>
|
||||||
|
creditCountsCombo: Record<string, number[]>
|
||||||
|
doCombo: boolean
|
||||||
|
graduationTimes: GraduationTimes
|
||||||
|
graduationTimesSecondProg: GraduationTimes
|
||||||
|
id: string
|
||||||
|
includeGraduated: boolean
|
||||||
|
mainStatsByTrack: Record<string, (number | string)[][]>
|
||||||
|
mainStatsByYear: Record<string, (number | string)[][]>
|
||||||
|
otherCountriesCount: Record<string, Record<string, Record<string, number>>>
|
||||||
|
populationTitles: string[]
|
||||||
|
studyTracks: Record<string, string | Name>
|
||||||
|
years: string[]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user