Skip to content

Commit cad0192

Browse files
authored
Merge pull request #90 from AtreyaG/82-add-pipeline-to-combine-course-and-professor
added courses and professors pipeline
2 parents 2ef178d + 4f36a7f commit cad0192

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package pipelines
2+
3+
import (
4+
"go.mongodb.org/mongo-driver/bson"
5+
"go.mongodb.org/mongo-driver/mongo"
6+
)
7+
8+
var TrendsCourseProfSectionsPipeline = mongo.Pipeline{
9+
10+
bson.D{
11+
{Key: "$lookup",
12+
Value: bson.D{
13+
{Key: "from", Value: "sections"},
14+
{Key: "localField", Value: "sections"},
15+
{Key: "foreignField", Value: "_id"},
16+
{Key: "as", Value: "sections"},
17+
},
18+
},
19+
},
20+
bson.D{
21+
{Key: "$group",
22+
Value: bson.D{
23+
{Key: "subject_prefix", Value: 1},
24+
{Key: "course_number", Value: 1},
25+
{Key: "sections", Value: 1},
26+
},
27+
},
28+
},
29+
30+
bson.D{
31+
{Key: "$unwind",
32+
Value: bson.D{
33+
{Key: "path", Value: "$sections"},
34+
{Key: "preserveNullAndEmptyArrays", Value: false},
35+
},
36+
},
37+
},
38+
bson.D{
39+
{Key: "$lookup",
40+
Value: bson.D{
41+
{Key: "from", Value: "professors"},
42+
{Key: "localField", Value: "sections.professors"},
43+
{Key: "foreignField", Value: "_id"},
44+
{Key: "as", Value: "professors"},
45+
},
46+
},
47+
},
48+
bson.D{
49+
{Key: "$unwind",
50+
Value: bson.D{
51+
{Key: "path", Value: "$sections"},
52+
{Key: "preserveNullAndEmptyArrays", Value: false},
53+
},
54+
},
55+
},
56+
57+
bson.D{
58+
{Key: "$group",
59+
Value: bson.D{
60+
{Key: "_id",
61+
Value: bson.D{
62+
{Key: "$concat",
63+
Value: bson.A{
64+
"$subject_prefix",
65+
"$course_number",
66+
"$professors.first_name",
67+
"$professors.last_name",
68+
},
69+
},
70+
},
71+
},
72+
{Key: "sections", Value: bson.D{{Key: "$addToSet", Value: "$sections"}}},
73+
},
74+
},
75+
},
76+
}

uploader/uploader.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func Upload(inDir string, replace bool, staticOnly bool) {
6767
buildStaticAggregation(client, ctx, "sections", "events", pipelines.EventsPipeline)
6868
buildStaticAggregation(client, ctx, "courses", "trends_course_sections", pipelines.TrendsCourseSectionsPipeline)
6969
buildStaticAggregation(client, ctx, "professors", "trends_prof_sections", pipelines.TrendsProfSectionsPipeline)
70+
buildStaticAggregation(client, ctx, "courses+professors", "trends_course_and_prof_section", pipelines.TrendsCourseProfSectionsPipeline)
7071

7172
log.Print("Done building static aggregations!")
7273
}

0 commit comments

Comments
 (0)