Skip to content

Instantly share code, notes, and snippets.

@jribnik
jribnik / mongoimport.out
Last active January 27, 2016 03:09
mongoimport of malformed CSV file
$ mongoimport --type=csv --headerline -d nfl -c pbp_2015 pbp-2015.csv
2016-01-26T21:40:44.549-0500 Failed: fields cannot be identical: '' and ''
2016-01-26T21:40:44.549-0500 imported 0 documents
for (var i = 0; i < 100000; i++) {
match = {"$match":
{
"OffenseTeam": "DEN",
"$or": [{"PlayType": "PASS"}, {"PlayType": "RUSH"}],
"IsNoPlay": 0
}
}
sample = {"$sample":
{
#!/usr/bin/env python
import csv
import dateutil.parser
import pymongo
import sys
if len(sys.argv) != 2:
print("usage: %s csvfile" % sys.argv[0])
sys.exit(1)
@jribnik
jribnik / match.js
Last active February 4, 2016 18:17
$match stage of simulation pipeline
match = {"$match":
{
"OffenseTeam": "DEN",
"$or": [{"PlayType": "PASS"}, {"PlayType": "RUSH"}],
"IsNoPlay": 0
}
}
@jribnik
jribnik / sample.js
Last active February 4, 2016 17:29
$sample stage of simulation pipeline
sample = {"$sample":
{
"size": 60
}
}
@jribnik
jribnik / project.js
Last active February 4, 2016 17:29
$project stage of simulation pipeline
proj = {"$project":
{
"team": "$OffenseTeam",
"yards": "$Yards",
"turnovers": {"$sum": ["$IsInterception", "$IsFumble"]}
}
}
@jribnik
jribnik / group.js
Last active February 4, 2016 17:28
$group stage of simulation pipeline
group = {"$group":
{
"_id": "$team",
"yards": {"$sum": "$yards"},
"turnovers": {"$sum": "$turnovers"}
}
}
@jribnik
jribnik / 2015simulation0.js
Last active February 4, 2016 17:25
Example simulation documents
> db.pbp_2015_simulations.find({"i": 0})
{
"_id": ObjectId("56a7e1bc87776355710ff107"),
"yards": 479,
"turnovers": 2,
"team": "DEN",
"i": 0
}
{
"_id": ObjectId("56a7e1bc87776355710ff108"),
@jribnik
jribnik / final.js
Last active February 4, 2016 18:19
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",
@jribnik
jribnik / 2013simulation.js
Last active February 4, 2016 18:20
2013 simulation
{
"waitedMS": NumberLong("0"),
"result": [
{
"_id": 1,
"DEN_avg_score": 28.743076249999753,
"DEN_avg_score_std": 9.011384256852498,
"DEN_win_pct": 0.58883,
"SEA_avg_score": 25.868169249999788,
"SEA_avg_score_std": 9.032120640996355,