Skip to content

Commit

Permalink
feat: get all clo, plo and po in course portfolio
Browse files Browse the repository at this point in the history
  • Loading branch information
Porping committed May 10, 2024
1 parent d6e8bdc commit 1434452
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 15 deletions.
8 changes: 7 additions & 1 deletion entity/course_learning_outcome.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ type CourseLearningOutcome struct {

type CourseLearningOutcomeWithPO struct {
CourseLearningOutcome
ProgramOutcomeName string `json:"programOutcomeName"`
ProgramOutcomeCode string `json:"programOutcomeCode"`
ProgramOutcomeName string `json:"programOutcomeName"`
ProgramLearningOutcomeCode string `json:"programLearningOutcomeCode"`
ExpectedPassingCloPercentage float64 `json:"expectedPassingCloPercentage"`
ProgramLearningOutcomeName string `json:"programLearningOutcomeName"`
SubProgramLearningOutcomeCode string `json:"subProgramLearningOutcomeCode"`
SubProgramLearningOutcomeName string `json:"subProgramLearningOutcomeName"`
}

type CreateCourseLearningOutcomeDto struct {
Expand Down
27 changes: 22 additions & 5 deletions entity/course_portfolio.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ type Assessment struct {
}

type CourseOutcome struct {
Name string `json:"name"`
Assessments []Assessment `json:"assessments"`
Name string `json:"name"`
ExpectedPassingAssignmentPercentage float64 `json:"expectedPassingAssignmentPercentage"`
Assessments []Assessment `json:"assessments"`
}

type TabeeOutcome struct {
Name string `json:"name"`
CourseOutcomes []CourseOutcome `json:"courseOutcomes"`
MinimumPercentage float64 `json:"minimumPercentage"`
Name string `json:"name"`
CourseOutcomes []CourseOutcome `json:"courseOutcomes"`
MinimumPercentage float64 `json:"minimumPercentage"`
ExpectedCloPercentage float64 `json:"expectedCloPercentage"`
}

// [3.2] Grade Distribution
Expand All @@ -53,8 +55,23 @@ type GradeDistribution struct {
ScoreFrequencies []ScoreFrequency `json:"scoreFrequencies"`
}

type Outcome struct {
Code string `json:"code"`
Name string `json:"name"`
}

type NestedOutcome struct {
Code string `json:"code"`
Name string `json:"name"`
Nested []Outcome `json:"nested,omitempty"`
}

// [3] Result
type CourseResult struct {
Plos []NestedOutcome `json:"plos"`
Clos []Outcome `json:"clos"`
Pos []Outcome `json:"pos"`

TabeeOutcomes []TabeeOutcome `json:"tabeeOutcomes"`
GradeDistribution GradeDistribution `json:"gradeDistribution"`
}
Expand Down
2 changes: 1 addition & 1 deletion repository/course_learning_outcome.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (r courseLearningOutcomeRepositoryGorm) GetById(id string) (*entity.CourseL

func (r courseLearningOutcomeRepositoryGorm) GetByCourseId(courseId string) ([]entity.CourseLearningOutcomeWithPO, error) {
var clos []entity.CourseLearningOutcomeWithPO
err := r.gorm.Raw("SELECT clo.*, po.id as programOutcomeId, po.name as program_outcome_name FROM course_learning_outcome AS clo INNER JOIN program_outcome as po ON clo.program_outcome_id = po.id WHERE clo.course_id = ?", courseId).Scan(&clos).Error
err := r.gorm.Raw("SELECT clo.*, po.id as programOutcomeId, po.name as program_outcome_name, po.code as program_outcome_code, course.expected_passing_clo_percentage, splo.code as sub_program_learning_outcome_code, splo.description_thai as sub_program_learning_outcome_name, plo.code as program_learning_outcome_code, plo.description_thai as program_learning_outcome_name FROM course_learning_outcome AS clo INNER JOIN program_outcome as po ON clo.program_outcome_id = po.id JOIN clo_subplo ON clo_subplo.course_learning_outcome_id = clo.id JOIN sub_program_learning_outcome AS splo ON splo.id = clo_subplo.sub_program_learning_outcome_id JOIN program_learning_outcome AS plo ON plo.id = splo.program_learning_outcome_id JOIN course ON clo.course_id = course.id WHERE clo.course_id = ?", courseId).Scan(&clos).Error

if err == gorm.ErrRecordNotFound {
return nil, nil
Expand Down
98 changes: 90 additions & 8 deletions usecase/course_portfolio.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,84 @@ func (u coursePortfolioUseCase) Generate(courseId string) (*entity.CoursePortfol
return nil, errs.New(errs.SameCode, "cannot evaluate tabee outcomes while generate course portfolio", err)
}

closWithPos, err := u.CourseLearningOutcomeUseCase.GetByCourseId(courseId)
if err != nil {
return nil, errs.New(errs.SameCode, "cannot get clo while evaluate tabee outcome", err)
}

generateOutcome := func(cloWithPos []entity.CourseLearningOutcomeWithPO) ([]entity.NestedOutcome, []entity.Outcome, []entity.Outcome) {
addedSubPlo := make(map[string]bool, 0)

plosByPloId := make(map[string]entity.NestedOutcome, 0)
closByCloId := make(map[string]entity.Outcome, 0)
posByPoId := make(map[string]entity.Outcome, 0)

plos := make([]entity.NestedOutcome, 0)
clos := make([]entity.Outcome, 0)
pos := make([]entity.Outcome, 0)

for _, c := range cloWithPos {
plosFromMap, found := plosByPloId[c.ProgramLearningOutcomeCode]

if !found {
addedSubPlo[c.SubProgramLearningOutcomeCode] = true

plosByPloId[c.ProgramLearningOutcomeCode] = entity.NestedOutcome{
Code: c.ProgramLearningOutcomeCode,
Name: c.ProgramLearningOutcomeName,
Nested: []entity.Outcome{
{
Code: c.SubProgramLearningOutcomeCode,
Name: c.SubProgramLearningOutcomeName,
},
},
}
} else {
if _, isSubPloAdded := addedSubPlo[c.SubProgramLearningOutcomeCode]; !isSubPloAdded {
addedSubPlo[c.SubProgramLearningOutcomeCode] = true

plosFromMap.Nested = append(
plosByPloId[c.ProgramLearningOutcomeCode].Nested,
entity.Outcome{
Code: c.SubProgramLearningOutcomeCode,
Name: c.SubProgramLearningOutcomeName,
},
)

plosByPloId[c.ProgramLearningOutcomeCode] = plosFromMap
}
}

closByCloId[c.Code] = entity.Outcome{
Code: c.Code,
Name: c.Description,
}

posByPoId[c.ProgramOutcomeName] = entity.Outcome{
Code: c.ProgramOutcomeCode,
Name: c.ProgramOutcomeName,
}

}
for _, plo := range plosByPloId {
plos = append(plos, plo)
}
for _, clo := range closByCloId {
clos = append(clos, clo)
}
for _, po := range posByPoId {
pos = append(pos, po)
}

return plos, clos, pos
}

plos, clos, pos := generateOutcome(closWithPos)

courseResult := entity.CourseResult{
Plos: plos,
Clos: clos,
Pos: pos,
GradeDistribution: *gradeDistribution,
TabeeOutcomes: tabeeOutcomes,
}
Expand Down Expand Up @@ -317,11 +394,14 @@ func (u coursePortfolioUseCase) EvaluateTabeeOutcomes(courseId string) ([]entity
}

courseOutcomeByPoId := make(map[string][]entity.CourseOutcome, 0)
expectedPassingCloByPoId := make(map[string]float64, 0)
for _, clo := range clos {
courseOutcomeByPoId[clo.ProgramOutcomeId] = append(courseOutcomeByPoId[clo.ProgramOutcomeId], entity.CourseOutcome{
Name: clo.Description,
Assessments: assessmentsByCloId[clo.Id],
Name: clo.Description,
ExpectedPassingAssignmentPercentage: clo.ExpectedPassingAssignmentPercentage,
Assessments: assessmentsByCloId[clo.Id],
})
expectedPassingCloByPoId[clo.ProgramOutcomeId] = clo.ExpectedPassingCloPercentage
}

passingPoPercentages, err := u.CoursePortfolioRepository.EvaluatePassingPoPercentage(courseId)
Expand Down Expand Up @@ -352,9 +432,10 @@ func (u coursePortfolioUseCase) EvaluateTabeeOutcomes(courseId string) ([]entity
foundOutcome, found := tabeeOutcomesByPoId[clo.ProgramOutcomeId]
if !found {
tabeeOutcomesByPoId[clo.ProgramOutcomeId] = append(tabeeOutcomesByPoId[clo.ProgramOutcomeId], entity.TabeeOutcome{
Name: clo.ProgramOutcomeName,
CourseOutcomes: courseOutcomeByPoId[clo.ProgramOutcomeId],
MinimumPercentage: passingPoPercentageByPoId[clo.ProgramOutcomeId],
Name: clo.ProgramOutcomeName,
CourseOutcomes: courseOutcomeByPoId[clo.ProgramOutcomeId],
MinimumPercentage: passingPoPercentageByPoId[clo.ProgramOutcomeId],
ExpectedCloPercentage: expectedPassingCloByPoId[clo.ProgramOutcomeId],
})
continue
}
Expand All @@ -365,9 +446,10 @@ func (u coursePortfolioUseCase) EvaluateTabeeOutcomes(courseId string) ([]entity
}

tabeeOutcomesByPoId[clo.ProgramOutcomeId] = append(tabeeOutcomesByPoId[clo.ProgramOutcomeId], entity.TabeeOutcome{
Name: clo.ProgramOutcomeName,
CourseOutcomes: courseOutcomeByPoId[clo.ProgramOutcomeId],
MinimumPercentage: passingPoPercentageByPoId[clo.ProgramOutcomeId],
Name: clo.ProgramOutcomeName,
CourseOutcomes: courseOutcomeByPoId[clo.ProgramOutcomeId],
MinimumPercentage: passingPoPercentageByPoId[clo.ProgramOutcomeId],
ExpectedCloPercentage: expectedPassingCloByPoId[clo.ProgramOutcomeId],
})
}

Expand Down

0 comments on commit 1434452

Please sign in to comment.