Skip to content

Commit

Permalink
Merge pull request #37 from team-inu/development
Browse files Browse the repository at this point in the history
Fix course portfolio usecase
  • Loading branch information
Porping committed Mar 22, 2024
2 parents 6981559 + 2d407ce commit fb97bcb
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
1 change: 0 additions & 1 deletion infrastructure/fiber/controller/course_portfolio.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,5 @@ func (c coursePortfolioController) Generate(ctx *fiber.Ctx) error {
if err != nil {
return err
}

return response.NewSuccessResponse(ctx, fiber.StatusOK, coursePortfolio)
}
4 changes: 2 additions & 2 deletions repository/assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (r assignmentRepositoryGorm) GetByParams(params *entity.Assignment, limit i

func (r assignmentRepositoryGorm) GetByCourseId(courseId string) ([]entity.Assignment, error) {
var clos []entity.Assignment
err := r.gorm.Raw("SELECT DISTINCT a.*, clo.course_id FROM clo_assignment AS clo_a INNER JOIN course_learning_outcome AS clo ON clo_a.course_learning_outcome_id = clo.id INNER JOIN assignment AS a ON a.id = clo_a.assignment_id WHERE clo.course_id = ?", courseId).Find(&clos).Error
err := r.gorm.Raw("SELECT DISTINCT a.*, clo.course_id FROM clo_assignment AS clo_a INNER JOIN course_learning_outcome AS clo ON clo_a.course_learning_outcome_id = clo.id INNER JOIN assignment AS a ON a.id = clo_a.assignment_id WHERE clo.course_id = ?", courseId).Scan(&clos).Error

if err == gorm.ErrRecordNotFound {
return nil, nil
Expand Down Expand Up @@ -79,7 +79,7 @@ func (r assignmentRepositoryGorm) GetPassingStudentPercentage(assignmentId strin
passing_student, scores_count;
`

err := r.gorm.Raw(query, assignmentId, assignmentId).Find(&passingStudentPercentage).Error
err := r.gorm.Raw(query, assignmentId, assignmentId).Scan(&passingStudentPercentage).Error
if err != nil {
return 0, fmt.Errorf("cannot query to get passingStudentPercentage: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion repository/course_portfolio.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func (r coursePortfolioRepositoryGorm) evaluateTabeeOutcomes(courseId string, se

query := fmt.Sprintf(template, selector)

err := r.gorm.Raw(query, courseId).Find(x).Error
err := r.gorm.Raw(query, courseId).Scan(x).Error
if err != nil {
return fmt.Errorf("cannot query to evaluate tabee outcomes: %w", err)
}
Expand Down
17 changes: 9 additions & 8 deletions usecase/course.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,15 @@ func (u courseUseCase) Create(user entity.User, semesterId string, userId string
}

course := entity.Course{
Id: ulid.Make().String(),
SemesterId: semesterId,
UserId: userId,
Name: name,
Code: code,
Curriculum: curriculum,
Description: description,
CriteriaGrade: criteriaGrade,
Id: ulid.Make().String(),
SemesterId: semesterId,
UserId: userId,
Name: name,
Code: code,
Curriculum: curriculum,
Description: description,
ExpectedPassingCloPercentage: expectedPassingCloPercentage,
CriteriaGrade: criteriaGrade,
}

err = u.courseRepo.Create(&course)
Expand Down
11 changes: 8 additions & 3 deletions usecase/course_portfolio.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,20 @@ func (u coursePortfolioUseCase) CalculateGradeDistribution(courseId string) (*en

studentAmount := len(studentScoreByStudentId)

gpa := 0.0
totalStudentGPA := 0.0
for grade, frequency := range frequenciesByGrade {
gpa += float64(frequency) * course.CriteriaGrade.GradeToGPA(grade)
totalStudentGPA += float64(frequency) * course.CriteriaGrade.GradeToGPA(grade)
}

gpa := 0.0
if totalStudentGPA != 0.0 {
gpa = totalStudentGPA / float64(studentAmount)
}

return &entity.GradeDistribution{
GradeFrequencies: gradeFrequencies,
StudentAmount: studentAmount,
GPA: gpa / float64(studentAmount),
GPA: gpa,
ScoreFrequencies: scoreFrequencies,
}, nil
}
Expand Down

0 comments on commit fb97bcb

Please sign in to comment.