Skip to content

Instantly share code, notes, and snippets.

@jribnik
Last active February 4, 2016 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jribnik/51aa3379afaa98004170 to your computer and use it in GitHub Desktop.
Save jribnik/51aa3379afaa98004170 to your computer and use it in GitHub Desktop.
Aggregation stages for ensemble calculation
proj0 = {"$project":
{
"i": 1,
"DEN_score": {"$sum": {"$cond": [{"$eq": ["$team", "DEN"]}, {"$multiply": [{"$subtract": [{"$divide": ["$yards", 80]}, "$turnovers"]}, 7]}, 0]}},
"CAR_score": {"$sum": {"$cond": [{"$eq": ["$team", "CAR"]}, {"$multiply": [{"$subtract": [{"$divide": ["$yards", 80]}, "$turnovers"]}, 7]}, 0]}}
}
}
group0 = {"$group":
{
"_id": "$i",
"DEN_score": {"$sum": "$DEN_score"},
"CAR_score": {"$sum": "$CAR_score"}
}
}
proj1 = {"$project":
{
"DEN_score": 1,
"DEN_win": {"$cond": [{"$gt": ["$DEN_score", "$CAR_score"]}, 1, 0]},
"CAR_score": 1,
"CAR_win": {"$cond": [{"$gt": ["$CAR_score", "$DEN_score"]}, 1, 0]}
}
}
group1 = {"$group":
{
"_id": 1,
"DEN_avg_score": {"$avg": "$DEN_score"},
"DEN_avg_score_std": {"$stdDevSamp": "$DEN_score"},
"DEN_win_pct": {"$avg": "$DEN_win"},
"CAR_avg_score": {"$avg": "$CAR_score"},
"CAR_avg_score_std": {"$stdDevSamp": "$CAR_score"},
"CAR_win_pct": {"$avg": "$CAR_win"}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment