Skip to content

Instantly share code, notes, and snippets.

View mattdennewitz's full-sized avatar

Matt Dennewitz mattdennewitz

  • Lancaster, OH
View GitHub Profile
@mattdennewitz
mattdennewitz / es.sh
Last active December 14, 2015 05:09 — forked from johnvilsack/es.sh
cd ~
sudo apt-get update
sudo apt-get install openjdk-7-jre -y
wget http://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.20.5.tar.gz -O elasticsearch.tar.gz
tar -xf elasticsearch.tar.gz
rm elasticsearch.tar.gz
sudo mv elasticsearch-* elasticsearch
sudo mv elasticsearch /opt
chown matt:matt -R /opt/elasticsearch
@mattdennewitz
mattdennewitz / gist:4736652
Last active December 12, 2015 07:28
Adding QS to Steamer export from Fangraphs
@mattdennewitz
mattdennewitz / run_exp.py
Last active December 12, 2015 04:58
1999-2002 Run Expectancy (from CSV)
import csv
import glob
import os
import sys
from mattreduce import Job
get_state = lambda outs, bases: '%s:%s' % (outs, bases)
#!/usr/bin/env python
import sys
last = ''
punc = ','
while True:
c = sys.stdin.read(1)
if c:
@mattdennewitz
mattdennewitz / gist:4073404
Created November 14, 2012 17:14
Formatted TZ offset by name
import datetime
import dateutil.tz
import pytz
def get_formatted_tz(zone):
"""Returns +/-HH:MM formatted time zone offset.
@mattdennewitz
mattdennewitz / gist:2847650
Created June 1, 2012 00:47
M2M-aware RealTimeSearchIndex
from django.db.models import signals
from haystack.indexes import RealTimeSearchIndex
class ManyAwareRealTimeSearchIndex(RealTimeSearchIndex):
"""Many-to-many aware real-time search index base class
"""
def _on_m2m_changed(self, instance, using=None, **kwargs):
@mattdennewitz
mattdennewitz / wOBA.py
Created September 18, 2011 23:26
Calculate 2010 batting wOBA
from bson.code import Code
import pymongo
connection = pymongo.connection.Connection()
db = connection['retrosheet']
tbl = db['events_2010']
# limit results to complete plate appearances.
@mattdennewitz
mattdennewitz / woba_finalize.js
Created September 18, 2011 23:10
Retrosheet/wOBA calculation
function(key, result) {
return ((0.72 * result.nibb) + (0.75 * result.hbp) + (0.9 * result._1b) + (0.92 * result.rboe) +
(1.24 * result._2b) + (1.56 * result._3b) + (1.95 * result.hr)) / result.pa;
}
@mattdennewitz
mattdennewitz / woba_reduce.js
Created September 18, 2011 23:09
Retrosheet/wOBA reducer
function(key, values) {
var result = {nibb: 0, hbp: 0, _1b: 0, _2b: 0, _3b: 0, hr: 0, rboe: 0, pa: 0};
for(var i in values) {
result.nibb += values[i].nibb;
result.hbp += values[i].hbp;
result._1b += values[i]._1b;
result._2b += values[i]._2b;
result._3b += values[i]._3b;
result.hr += values[i].hr;
@mattdennewitz
mattdennewitz / woba_map.js
Created September 18, 2011 23:09
Retrosheet/wOBA mapping function
function() {
var woba_fields = {nibb: (this.EVENT_CD == '14') ? 1 : 0,
hbp: (this.EVENT_CD == '15') ? 1 : 0,
_1b: (this.EVENT_CD == '20') ? 1 : 0,
_2b: (this.EVENT_CD == '21') ? 1 : 0,
_3b: (this.EVENT_CD == '22') ? 1 : 0,
hr: (this.EVENT_CD == '23') ? 1 : 0,
rboe: (this.BAT_SAFE_ERR_FL == 'T') ? 1 : 0,
pa: 1};
emit(this.BAT_ID, woba_fields);