def usage(): print "usage: %s " % sys.argv[0] sys.exit(1) db = DB.connect() cursor = db.cursor() try: (opts, args) = getopt.getopt(sys.argv[1:], 'L:sSt:r:y:') except getopt.GetoptError, err: print str(err) usage() try: f = open( DB.bin_dir() + '/data/tiers.yml', 'rU') except IOError, err: print str(err) sys.exit(1) y = yaml.safe_load(f) if y.has_key('year'): year = str( y['year'] ) else: # default is year + 1 year = int(time.strftime("%Y")) year = "%s" % ( int(year) + 1 ) skip = 0 remove = 0
def main(): do_json = False is_cgi = False if 'GATEWAY_INTERFACE' in os.environ: import cgi #import cgitb; cgitb.enable() form = cgi.FieldStorage() is_cgi = True if form.has_key('json'): import json do_json = True print "Content-Type: application/json" print else: do_json = False print "Content-Type: text/html" print print "<html><head><title>Free Agent signing order</title></head><body>" #dumpenv(form) db = DB.connect() cursor = db.cursor() boxes = 0 results = 1 def late(team): # array is (boxes, results) # teams on probation pick last if team in y['probation']: return 2 # teams under caretaker control are exempt from late penalty if team in y['exempt']: return 0 # results or boxes must be current if status[team][results] < week and status[team][boxes] < week: return 1 # boxes must be no more than 1 week behind if week > 1: if status[team][boxes] < week - 1: return 1 # return 0, team has nothing outstanding return 0 week = 1 check_late = True if is_cgi and form.has_key('week'): week = int(form.getfirst('week')) else: for ( opt, arg ) in opts: if opt == '-w': week = int(arg) elif opt == '-r': check_late = False # user inputs FA signing week (not results week), so subtract 1 week -= 1 if week == 0: # find latest week with reported results cursor.execute("select week, count(*) from games\ group by week order by week desc;"); # need to have more than 2 series reported to set week for week, num in cursor.fetchall(): if num > 8: break # start with last year # lastyear should be ordered to break ties fa = [] lastyear = {} try: f = open( DB.bin_dir() + '/data/fa.yml', 'rU' ) except IOError, err: print str(err) sys.exit(1)
import os import sys import yaml import subprocess import re import getopt import time import DB batters = "d1.genbat" pitchers = "d1.genpit" try: f = open( DB.bin_dir() + '/data/avgcard.yml', 'rU' ) except IOError, err: print str(err) sys.exit(1) y = yaml.safe_load(f) # wOBA consts wBB = y['wBB'] w1B = y['w1B'] w2B = y['w2B'] w3B = y['w3B'] wHR = y['wHR'] # cardengine consts.h IFR1B = y['IFR1B']