-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/development' into task/bt-674-pr…
…eview-project-to-real-data
- Loading branch information
Showing
158 changed files
with
2,051 additions
and
842 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { type BadgesResponseDto } from 'shared/build/index.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { defaultShownBadges } from './default-shown-badges.js'; |
12 changes: 12 additions & 0 deletions
12
backend/src/bundles/lms-data/constants/default-shown-badges.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { BsaBadgesTypeEnum } from '../enums/enums.js'; | ||
|
||
const defaultShownBadges = { | ||
[BsaBadgesTypeEnum.ENGLISH_LEVEL]: true, | ||
[BsaBadgesTypeEnum.LECTURE_SCORE]: true, | ||
[BsaBadgesTypeEnum.BEST_LECTURE_SCORE]: false, | ||
[BsaBadgesTypeEnum.PROJECT_SCORE]: true, | ||
[BsaBadgesTypeEnum.COMMUNICATION_SCORE]: false, | ||
[BsaBadgesTypeEnum.TEAM_SCORE]: false, | ||
} as const; | ||
|
||
export { defaultShownBadges }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { BsaBadgesTypeEnum } from 'shared/build/index.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const MOCK_SCORE = 3; | ||
const MAX_SCORE = 5; | ||
const DECIMAL_PLACES = 2; | ||
|
||
const getRandomScore = (): number => { | ||
const randomValue = MOCK_SCORE + Math.random() * (MAX_SCORE - MOCK_SCORE); | ||
return Number(randomValue.toFixed(DECIMAL_PLACES)); | ||
}; | ||
|
||
export { getRandomScore }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export { getRandomScore } from './get-random-score.js'; | ||
export { isNumber } from './is-number.js'; | ||
export { makeLMSDataResponse, parseLMSServerData } from 'shared/build/index.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const isNumber = (value: unknown): value is number => { | ||
return typeof value === 'number' && !Number.isNaN(value); | ||
}; | ||
|
||
export { isNumber }; |
122 changes: 122 additions & 0 deletions
122
backend/src/bundles/lms-data/helpers/map-talent-badges.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import { BsaBadgesTypeEnum } from 'shared/build/index.js'; | ||
|
||
import { type ValueOf } from '~/common/types/types.js'; | ||
|
||
import { defaultShownBadges } from '../constants/constants.js'; | ||
import { badgeTypeToLMSProperty } from '../mappers/mappers.js'; | ||
import { | ||
type BadgesItem, | ||
type BadgesResponseDto, | ||
type LectureDetail, | ||
type LMSDataResponseDto, | ||
type Marks, | ||
type ProjectCoachesFeedback, | ||
type TalentBadgeCreateDto, | ||
} from '../types/types.js'; | ||
import { getRandomScore, isNumber } from './helpers.js'; | ||
|
||
const findScoreForCommunicationAndTeam = ( | ||
projectCoachesFeedback: ProjectCoachesFeedback[], | ||
property: keyof Marks, | ||
): number => { | ||
let totalScore = 0; | ||
let totalLenght = 0; | ||
|
||
for (const week of projectCoachesFeedback) { | ||
if (typeof week.marks[property] === 'number') { | ||
totalScore += week.marks[property]; | ||
totalLenght++; | ||
} | ||
} | ||
|
||
const averageScore = totalScore / totalLenght; | ||
|
||
return isNumber(averageScore) ? averageScore : getRandomScore(); | ||
}; | ||
|
||
const findBestLectureScore = ( | ||
lectureDetails: LectureDetail[], | ||
): number | null => { | ||
if (lectureDetails.length === 0) { | ||
return null; | ||
} | ||
|
||
let bestLecture = lectureDetails[0]; | ||
|
||
for (const lecture of lectureDetails) { | ||
if (Number(lecture.grade) > Number(bestLecture.grade)) { | ||
bestLecture = lecture; | ||
} | ||
} | ||
|
||
return bestLecture.grade; | ||
}; | ||
|
||
const isShown = (type: ValueOf<typeof BsaBadgesTypeEnum>): boolean => { | ||
return defaultShownBadges[type]; | ||
}; | ||
|
||
const getBadgeId = ( | ||
bsaBadges: BadgesItem[], | ||
badgeType: ValueOf<typeof BsaBadgesTypeEnum>, | ||
): string => { | ||
const badge = bsaBadges.find((badge) => badge.type === badgeType); | ||
return badge?.id ?? ''; | ||
}; | ||
|
||
type TalentBadgeCreateBody = Omit<TalentBadgeCreateDto, 'id'>; | ||
|
||
const mapTalentBadges = ( | ||
userDetailsId: string, | ||
lmsData: LMSDataResponseDto, | ||
bsaBadges: BadgesResponseDto, | ||
): TalentBadgeCreateBody[] => { | ||
return Object.keys(badgeTypeToLMSProperty).map((badgeType) => { | ||
const property = | ||
badgeTypeToLMSProperty[ | ||
badgeType as unknown as keyof typeof badgeTypeToLMSProperty | ||
]; | ||
let score = null; | ||
let level = null; | ||
|
||
switch (badgeType) { | ||
case BsaBadgesTypeEnum.COMMUNICATION_SCORE: | ||
case BsaBadgesTypeEnum.TEAM_SCORE: { | ||
score = findScoreForCommunicationAndTeam( | ||
lmsData.projectCoachesFeedback, | ||
property as keyof Marks, | ||
); | ||
break; | ||
} | ||
case BsaBadgesTypeEnum.BEST_LECTURE_SCORE: { | ||
score = findBestLectureScore(lmsData.lectureDetails); | ||
break; | ||
} | ||
case BsaBadgesTypeEnum.ENGLISH_LEVEL: { | ||
score = null; | ||
level = lmsData.talent.english; | ||
break; | ||
} | ||
case BsaBadgesTypeEnum.LECTURE_SCORE: | ||
case BsaBadgesTypeEnum.PROJECT_SCORE: { | ||
score = lmsData[property as keyof LMSDataResponseDto] as number; | ||
isNumber(score) || (score = getRandomScore()); | ||
break; | ||
} | ||
} | ||
|
||
return { | ||
userId: lmsData.talent.id, | ||
badgeId: getBadgeId( | ||
bsaBadges.items, | ||
badgeType as ValueOf<typeof BsaBadgesTypeEnum>, | ||
), | ||
score, | ||
level, | ||
isShown: isShown(badgeType as ValueOf<typeof BsaBadgesTypeEnum>), | ||
userDetailsId, | ||
}; | ||
}); | ||
}; | ||
|
||
export { mapTalentBadges }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
import { bsaBadgesService } from '../bsa-badges/bsa-badges.js'; | ||
import { talentBadgeService } from '../talent-badges/talent-badges.js'; | ||
import { userDetailsService } from '../user-details/user-details.js'; | ||
import { LMSDataModel } from './lms-data.model.js'; | ||
import { LMSDataRepository } from './lms-data.repository.js'; | ||
import { LMSDataService } from './lms-data.service.js'; | ||
|
||
const lmsDataRepository = new LMSDataRepository(LMSDataModel); | ||
const lmsDataService = new LMSDataService(lmsDataRepository); | ||
|
||
const lmsDataService = new LMSDataService({ | ||
lmsDataRepository, | ||
bsaBadgesService: bsaBadgesService, | ||
talentBadgeService: talentBadgeService, | ||
userDetailsService: userDetailsService, | ||
}); | ||
|
||
export { lmsDataService }; |
12 changes: 12 additions & 0 deletions
12
backend/src/bundles/lms-data/mappers/badge-type-to-lms-property.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { BsaBadgesTypeEnum } from '../enums/enums.js'; | ||
|
||
const badgeTypeToLMSProperty = { | ||
[BsaBadgesTypeEnum.ENGLISH_LEVEL]: 'english', | ||
[BsaBadgesTypeEnum.LECTURE_SCORE]: 'averageLectureScore', | ||
[BsaBadgesTypeEnum.BEST_LECTURE_SCORE]: 'grade', | ||
[BsaBadgesTypeEnum.PROJECT_SCORE]: 'averageProjectScore', | ||
[BsaBadgesTypeEnum.COMMUNICATION_SCORE]: 'communication_result', | ||
[BsaBadgesTypeEnum.TEAM_SCORE]: 'team_interaction', | ||
}; | ||
|
||
export { badgeTypeToLMSProperty }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { badgeTypeToLMSProperty } from './badge-type-to-lms-property.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.