From bbf062f324c84522a133b1b412385785b237c8a4 Mon Sep 17 00:00:00 2001 From: Atreya Ghosh Date: Mon, 29 Sep 2025 17:48:36 -0500 Subject: [PATCH] added courses and professors pipeline --- .../trends_course_and_prof_section.go | 76 +++++++++++++++++++ uploader/uploader.go | 1 + 2 files changed, 77 insertions(+) create mode 100644 uploader/pipelines/trends_course_and_prof_section.go diff --git a/uploader/pipelines/trends_course_and_prof_section.go b/uploader/pipelines/trends_course_and_prof_section.go new file mode 100644 index 0000000..8bb3276 --- /dev/null +++ b/uploader/pipelines/trends_course_and_prof_section.go @@ -0,0 +1,76 @@ +package pipelines + +import ( + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/mongo" +) + +var TrendsCourseProfSectionsPipeline = mongo.Pipeline{ + + bson.D{ + {Key: "$lookup", + Value: bson.D{ + {Key: "from", Value: "sections"}, + {Key: "localField", Value: "sections"}, + {Key: "foreignField", Value: "_id"}, + {Key: "as", Value: "sections"}, + }, + }, + }, + bson.D{ + {Key: "$group", + Value: bson.D{ + {Key: "subject_prefix", Value: 1}, + {Key: "course_number", Value: 1}, + {Key: "sections", Value: 1}, + }, + }, + }, + + bson.D{ + {Key: "$unwind", + Value: bson.D{ + {Key: "path", Value: "$sections"}, + {Key: "preserveNullAndEmptyArrays", Value: false}, + }, + }, + }, + bson.D{ + {Key: "$lookup", + Value: bson.D{ + {Key: "from", Value: "professors"}, + {Key: "localField", Value: "sections.professors"}, + {Key: "foreignField", Value: "_id"}, + {Key: "as", Value: "professors"}, + }, + }, + }, + bson.D{ + {Key: "$unwind", + Value: bson.D{ + {Key: "path", Value: "$sections"}, + {Key: "preserveNullAndEmptyArrays", Value: false}, + }, + }, + }, + + bson.D{ + {Key: "$group", + Value: bson.D{ + {Key: "_id", + Value: bson.D{ + {Key: "$concat", + Value: bson.A{ + "$subject_prefix", + "$course_number", + "$professors.first_name", + "$professors.last_name", + }, + }, + }, + }, + {Key: "sections", Value: bson.D{{Key: "$addToSet", Value: "$sections"}}}, + }, + }, + }, +} diff --git a/uploader/uploader.go b/uploader/uploader.go index 85dac86..dc34561 100644 --- a/uploader/uploader.go +++ b/uploader/uploader.go @@ -67,6 +67,7 @@ func Upload(inDir string, replace bool, staticOnly bool) { buildStaticAggregation(client, ctx, "sections", "events", pipelines.EventsPipeline) buildStaticAggregation(client, ctx, "courses", "trends_course_sections", pipelines.TrendsCourseSectionsPipeline) buildStaticAggregation(client, ctx, "professors", "trends_prof_sections", pipelines.TrendsProfSectionsPipeline) + buildStaticAggregation(client, ctx, "courses+professors", "trends_course_and_prof_section", pipelines.TrendsCourseProfSectionsPipeline) log.Print("Done building static aggregations!") }