Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ranking displaying aliased courses that have fewer than 3 reviews #293

Open
Nicholas-Sliter opened this issue Jul 10, 2023 · 2 comments

Comments

@Nicholas-Sliter
Copy link
Owner

image

@Nicholas-Sliter
Copy link
Owner Author

Bug occurs only on production and is not replicated in local dev envs

@Nicholas-Sliter
Copy link
Owner Author

Query in question

`
export function generateBaseCourseAverages(qb: Knex.QueryBuilder, count: number = 3) {

return qb.with("CourseReview", (qb) => {
    qb.from("Review")
        .where(
            {
                "Review.deleted": false,
                "Review.archived": false
            })
        .select(reviewInfo)
})
    .with("CourseAliases", (qb) => {
        qb.from("Course")
            .joinRaw("LEFT JOIN \"Alias\" ON \"Alias\".\"aliasID\" = \"Course\".\"courseID\"")
            .select({
                courseID: "Course.courseID",
                primaryCourseID: knex.raw("COALESCE(\"Alias\".\"courseID\", \"Course\".\"courseID\")"),
            });
    })
    .from("CourseReview")
    .leftJoin("CourseAliases", "CourseAliases.courseID", "CourseReview.courseID")
    .groupBy("primaryCourseID")
    .havingRaw(`count(*) >= ?`, [count])
    .select(["primaryCourseID as courseID"])
    .avg({
        /* Instructor specific */
        avgInstructorEffectiveness: "CourseReview.instructorEffectiveness",
        avgInstructorAccommodationLevel: "CourseReview.instructorAccommodationLevel",
        avgInstructorEnthusiasm: "CourseReview.instructorEnthusiasm",
        avgInstructorAgain: knex.raw(`CAST("CourseReview"."instructorAgain" = 'True' as int)`),
        avgInstructorEnjoyed: knex.raw(`CAST("CourseReview"."instructorEnjoyed" = 'True' as int)`),
        /* Course specific */
        avgRating: "CourseReview.rating",
        avgValue: "CourseReview.value",
        avgDifficulty: "CourseReview.difficulty",
        avgHours: "CourseReview.hours",
        avgAgain: knex.raw(`CAST("CourseReview"."again" = 'True' as int)`),
        // topTags: knex.raw(`array_agg(DISTINCT(UNNEST("CourseReview"."tags")))`)
    })
    .count({
        numReviews: "CourseReview.reviewID"
    });

}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant