Skip to content

Commit 73510d6

Browse files
committed
Move all the pipelines together
1 parent 78f57d6 commit 73510d6

File tree

4 files changed

+149
-160
lines changed

4 files changed

+149
-160
lines changed

uploader/pipelines/trends.go

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
package pipelines
2+
3+
import (
4+
"go.mongodb.org/mongo-driver/bson"
5+
"go.mongodb.org/mongo-driver/mongo"
6+
)
7+
8+
// TrendsCourseSectionsPipeline links course documents to their section records for trends-specific aggregation.
9+
var TrendsCourseSectionsPipeline = mongo.Pipeline{
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: "$project",
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+
bson.D{
30+
{Key: "$unwind",
31+
Value: bson.D{
32+
{Key: "path", Value: "$sections"},
33+
{Key: "preserveNullAndEmptyArrays", Value: false},
34+
},
35+
},
36+
},
37+
bson.D{
38+
{Key: "$group",
39+
Value: bson.D{
40+
{Key: "_id",
41+
Value: bson.D{
42+
{Key: "$concat",
43+
Value: bson.A{
44+
"$subject_prefix",
45+
"$course_number",
46+
},
47+
},
48+
},
49+
},
50+
{Key: "sections", Value: bson.D{{Key: "$addToSet", Value: "$sections"}}},
51+
},
52+
},
53+
},
54+
}
55+
56+
// TrendsProfSectionsPipeline denormalizes professor records with their taught sections for trends-specific aggregation.
57+
var TrendsProfSectionsPipeline = mongo.Pipeline{
58+
bson.D{
59+
{Key: "$lookup",
60+
Value: bson.D{
61+
{Key: "from", Value: "sections"},
62+
{Key: "localField", Value: "sections"},
63+
{Key: "foreignField", Value: "_id"},
64+
{Key: "as", Value: "sections"},
65+
},
66+
},
67+
},
68+
bson.D{
69+
{Key: "$project",
70+
Value: bson.D{
71+
{Key: "first_name", Value: 1},
72+
{Key: "last_name", Value: 1},
73+
{Key: "sections", Value: 1},
74+
},
75+
},
76+
},
77+
}
78+
79+
// TrendsCourseProfSectionsPipeline links combination of professor and course to the sections for trends-specific aggregation.
80+
var TrendsCourseProfSectionsPipeline = mongo.Pipeline{
81+
bson.D{
82+
{Key: "$lookup",
83+
Value: bson.D{
84+
{Key: "from", Value: "sections"},
85+
{Key: "localField", Value: "sections"},
86+
{Key: "foreignField", Value: "_id"},
87+
{Key: "as", Value: "sections"},
88+
},
89+
},
90+
},
91+
bson.D{
92+
{Key: "$project",
93+
Value: bson.D{
94+
{Key: "subject_prefix", Value: 1},
95+
{Key: "course_number", Value: 1},
96+
{Key: "sections", Value: 1},
97+
},
98+
},
99+
},
100+
101+
bson.D{
102+
{Key: "$unwind",
103+
Value: bson.D{
104+
{Key: "path", Value: "$sections"},
105+
{Key: "preserveNullAndEmptyArrays", Value: false},
106+
},
107+
},
108+
},
109+
bson.D{
110+
{Key: "$lookup",
111+
Value: bson.D{
112+
{Key: "from", Value: "professors"},
113+
{Key: "localField", Value: "sections.professors"},
114+
{Key: "foreignField", Value: "_id"},
115+
{Key: "as", Value: "professors"},
116+
},
117+
},
118+
},
119+
bson.D{
120+
{Key: "$unwind",
121+
Value: bson.D{
122+
{Key: "path", Value: "$professors"},
123+
{Key: "preserveNullAndEmptyArrays", Value: false},
124+
},
125+
},
126+
},
127+
128+
bson.D{
129+
{Key: "$group",
130+
Value: bson.D{
131+
{Key: "_id",
132+
Value: bson.D{
133+
{Key: "$concat",
134+
Value: bson.A{
135+
"$subject_prefix",
136+
"$course_number",
137+
" ",
138+
"$professors.first_name",
139+
" ",
140+
"$professors.last_name",
141+
},
142+
},
143+
},
144+
},
145+
{Key: "sections", Value: bson.D{{Key: "$addToSet", Value: "$sections"}}},
146+
},
147+
},
148+
},
149+
}

uploader/pipelines/trends_course_and_prof_section.go

Lines changed: 0 additions & 77 deletions
This file was deleted.

uploader/pipelines/trends_course_sections.go

Lines changed: 0 additions & 54 deletions
This file was deleted.

uploader/pipelines/trends_prof_sections.go

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)