pipelines

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 22, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package pipelines defines reusable MongoDB aggregation pipelines for derived data.

Index

Constants

This section is empty.

Variables

View Source
var EventsPipeline = mongo.Pipeline{

	{{Key: "$unwind", Value: "$meetings"}},

	{{Key: "$match", Value: bson.D{
		{Key: "meetings.location.building", Value: bson.D{{Key: "$ne", Value: "No"}}},
	}}},

	{{Key: "$addFields", Value: bson.D{
		{Key: "meetings.start_date", Value: bson.D{
			{Key: "$dateTrunc", Value: bson.D{
				{Key: "date", Value: "$meetings.start_date"},
				{Key: "unit", Value: "day"},
			}},
		}},
	}}},

	{{Key: "$addFields", Value: bson.D{
		{Key: "meeting_dates", Value: bson.D{
			{Key: "$filter", Value: bson.D{
				{Key: "input", Value: bson.D{
					{Key: "$map", Value: bson.D{
						{Key: "input", Value: bson.D{
							{Key: "$range", Value: bson.A{
								0,
								bson.D{{Key: "$dateDiff", Value: bson.D{
									{Key: "startDate", Value: bson.D{{Key: "$toDate", Value: "$meetings.start_date"}}},
									{Key: "endDate", Value: bson.D{{Key: "$toDate", Value: "$meetings.end_date"}}},
									{Key: "unit", Value: "day"},
								}}},
								1,
							}},
						}},
						{Key: "as", Value: "offset"},
						{Key: "in", Value: bson.D{
							{Key: "$dateAdd", Value: bson.D{
								{Key: "startDate", Value: bson.D{{Key: "$toDate", Value: "$meetings.start_date"}}},
								{Key: "unit", Value: "day"},
								{Key: "amount", Value: "$$offset"},
							}},
						}},
					}},
				}},
				{Key: "as", Value: "date"},
				{Key: "cond", Value: bson.D{
					{Key: "$in", Value: bson.A{
						bson.D{{Key: "$dayOfWeek", Value: "$$date"}},
						bson.D{{Key: "$map", Value: bson.D{
							{Key: "input", Value: "$meetings.meeting_days"},
							{Key: "as", Value: "day"},
							{Key: "in", Value: bson.D{
								{Key: "$switch", Value: bson.D{
									{Key: "branches", Value: bson.A{
										bson.D{{Key: "case", Value: bson.D{{Key: "$eq", Value: bson.A{"$$day", "Sunday"}}}}, {Key: "then", Value: 1}},
										bson.D{{Key: "case", Value: bson.D{{Key: "$eq", Value: bson.A{"$$day", "Monday"}}}}, {Key: "then", Value: 2}},
										bson.D{{Key: "case", Value: bson.D{{Key: "$eq", Value: bson.A{"$$day", "Tuesday"}}}}, {Key: "then", Value: 3}},
										bson.D{{Key: "case", Value: bson.D{{Key: "$eq", Value: bson.A{"$$day", "Wednesday"}}}}, {Key: "then", Value: 4}},
										bson.D{{Key: "case", Value: bson.D{{Key: "$eq", Value: bson.A{"$$day", "Thursday"}}}}, {Key: "then", Value: 5}},
										bson.D{{Key: "case", Value: bson.D{{Key: "$eq", Value: bson.A{"$$day", "Friday"}}}}, {Key: "then", Value: 6}},
										bson.D{{Key: "case", Value: bson.D{{Key: "$eq", Value: bson.A{"$$day", "Saturday"}}}}, {Key: "then", Value: 7}},
									}},
									{Key: "default", Value: nil},
								}},
							}},
						}}},
					}},
				}},
			}},
		}},
	}}},

	{{Key: "$unwind", Value: "$meeting_dates"}},

	{{Key: "$match", Value: bson.D{
		{Key: "$expr", Value: bson.D{
			{Key: "$gte", Value: bson.A{
				"$meeting_dates",
				bson.D{{Key: "$dateSubtract", Value: bson.D{
					{Key: "startDate", Value: bson.D{{Key: "$dateTrunc", Value: bson.D{
						{Key: "date", Value: "$$NOW"},
						{Key: "unit", Value: "day"},
					}}}},
					{Key: "unit", Value: "day"},
					{Key: "amount", Value: 7},
				}}},
			}},
		}},
	}}},

	{{Key: "$group", Value: bson.D{
		{Key: "_id", Value: bson.D{
			{Key: "date", Value: "$meeting_dates"},
			{Key: "building", Value: "$meetings.location.building"},
			{Key: "room", Value: "$meetings.location.room"},
		}},
		{Key: "events", Value: bson.D{
			{Key: "$push", Value: bson.D{
				{Key: "section", Value: "$_id"},
				{Key: "start_time", Value: "$meetings.start_time"},
				{Key: "end_time", Value: "$meetings.end_time"},
			}},
		}},
	}}},
	{{Key: "$group", Value: bson.D{
		{Key: "_id", Value: bson.D{
			{Key: "date", Value: "$_id.date"},
			{Key: "building", Value: "$_id.building"},
		}},
		{Key: "rooms", Value: bson.D{
			{Key: "$push", Value: bson.D{
				{Key: "room", Value: "$_id.room"},
				{Key: "events", Value: "$events"},
			}},
		}},
	}}},
	{{Key: "$group", Value: bson.D{
		{Key: "_id", Value: bson.D{
			{Key: "date", Value: "$_id.date"},
		}},
		{Key: "buildings", Value: bson.D{
			{Key: "$push", Value: bson.D{
				{Key: "building", Value: "$_id.building"},
				{Key: "rooms", Value: "$rooms"},
			}},
		}},
	}}},

	{{Key: "$project", Value: bson.D{
		{Key: "_id", Value: 0},
		{Key: "date", Value: bson.D{
			{Key: "$dateToString", Value: bson.D{
				{Key: "format", Value: "%Y-%m-%d"},
				{Key: "date", Value: "$_id.date"},
			}},
		}},
		{Key: "buildings", Value: 1},
	}}},
}

EventsPipeline aggregates section meetings into building and room event summaries.

View Source
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: "$project",
			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: "$professors"},
				{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"}}},
			},
		},
	},
}
View Source
var TrendsCourseSectionsPipeline = 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: "$project",
			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: "$group",
			Value: bson.D{
				{Key: "_id",
					Value: bson.D{
						{Key: "$concat",
							Value: bson.A{
								"$subject_prefix",
								"$course_number",
							},
						},
					},
				},
				{Key: "sections", Value: bson.D{{Key: "$addToSet", Value: "$sections"}}},
			},
		},
	},
}

TrendsCourseSectionsPipeline links course documents to their section records for trend reporting.

View Source
var TrendsProfSectionsPipeline = 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: "$project",
			Value: bson.D{
				{Key: "first_name", Value: 1},
				{Key: "last_name", Value: 1},
				{Key: "sections", Value: 1},
			},
		},
	},
}

TrendsProfSectionsPipeline denormalizes professor records with their taught sections for analytics.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL