Skip to content

Instantly share code, notes, and snippets.

@jribnik
Last active February 4, 2016 18:16
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/2d50cfda836e32ea287b to your computer and use it in GitHub Desktop.
Save jribnik/2d50cfda836e32ea287b to your computer and use it in GitHub Desktop.
for (var i = 0; i < 100000; i++) {
match = {"$match":
{
"OffenseTeam": "DEN",
"$or": [{"PlayType": "PASS"}, {"PlayType": "RUSH"}],
"IsNoPlay": 0
}
}
sample = {"$sample":
{
"size": 60
}
}
proj = {"$project":
{
"team": "$OffenseTeam",
"yards": "$Yards",
"turnovers": {"$sum": ["$IsInterception", "$IsFumble"]}
}
}
group = {"$group":
{
"_id": "$team",
"yards": {"$sum": "$yards"},
"turnovers": {"$sum": "$turnovers"}
}
}
res = db.pbp_2015.aggregate([match, sample, proj, group])
simulation_doc = res['result'][0]
simulation_doc["team"] = simulation_doc["_id"]
simulation_doc["i"] = i
delete simulation_doc["_id"]
db.pbp_2015_simulations.insert(simulation_doc)
match["$match"]["OffenseTeam"] = "CAR"
res = db.pbp_2015.aggregate([match, sample, proj, group])
simulation_doc = res['result'][0]
simulation_doc["team"] = simulation_doc["_id"]
simulation_doc["i"] = i
delete simulation_doc["_id"]
db.pbp_2015_simulations.insert(simulation_doc)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment