def backtest_throughput_rate(session_id): obj = Littlefield('group6', 'coronado91', session_id) th_dict = {'queue_th': 100, 'util_th': 0.90} ord = obj.orders.job_arrivals() rev = obj.completed_jobs.revenues() jobs = obj.completed_jobs.count() ave_demand = 0 for ind in range(len(ord) - 5, len(ord)): calculate_station1_R(obj, ind, th_dict) calculate_station2_R(obj, ind, th_dict) calculate_station3_R(obj, ind, th_dict) print("Order at time ", ind, " is ", ord[ind]) #print(jobs) print("Contract 1 completed jobs for ", ind, " is ", jobs[0][2][ind]) print("Contract 2 completed jobs for ", ind, " is ", jobs[1][2][ind]) print("Contract 3 completed jobs for ", ind, " is ", jobs[2][2][ind]) print("Contract 1 Rev at time ", ind, " is ", rev[0][2][ind]) print("Contract 2 Rev at time ", ind, " is ", rev[1][2][ind]) print("Contract 3 Rev at time ", ind, " is ", rev[2][2][ind]) ave_demand = ave_demand + ord[ind][1] print("#####################################################") print("Average Demand = ", ave_demand / 5)
def backtest(session_id): obj = Littlefield('group6', 'coronado91', session_id) th_dict = {'queue_th': 100, 'util_th': 0.99} _orders = [] _average_order = [] _average_sum = 0 ords = obj.completed_jobs.count() ord = obj.orders.job_arrivals() for ind in range(len(ords[0][2])): calculate_station1_R(obj, ind, th_dict) calculate_station2_R(obj, ind, th_dict) calculate_station3_R(obj, ind, th_dict) print("Order at time ", ind, " is ", ord[ind]) _orders.append(ord[ind][1]) print("#####################################################") for ind, val in enumerate(_orders): print(ind, " ,", val) if ind <= len(ords[0][2]) - 5: _average_order.append(sum(_orders[ind:ind + 5]) / 5) print("order 5 day average:") print(_average_order) # export to a csv file import csv with open('average_demand.csv', 'w+') as csvfile: csv_writer = csv.writer(csvfile, delimiter=',') csv_writer.writerow(_average_order)
import sys import os lib = os.getenv("LITTLEFIELD_PATH") if lib is not None: sys.path.append(lib) from raven import Client raven = Client(os.getenv("LITTLEFIELD_RAVEN_DSN")) try: from littlefield import Littlefield config = False if len(sys.argv) > 1: if sys.argv[1] == "config": config = True if config: print("graph_title Cash Sources") print("graph_info Shows the various sources and uses of cash") print("graph_category littlefield") print("graph_vlabel $") print("interest.label interest") print("interest.draw AREA") print("revenue.label revenue") print("revenue.draw STACK") else: littlefield = Littlefield(os.getenv("LITTLEFIELD_USER"), os.getenv("LITTLEFIELD_PW")) data = littlefield.get_cash() print("interest.value %s" % data['interest']) print("revenue.value %s" % data['revenue']) except: raven.captureException()
#!/usr/bin/env python from littlefield import Littlefield from configparser import ConfigParser from bokeh.plotting import figure, output_server, show, gridplot config = ConfigParser() config.read(['littlefield.ini']) littlefield = Littlefield(config['littlefield']['user'], config['littlefield']['password']) output_server("littlefield") datatypes = [ "JOBIN", # Number of jobs accepted per day "JOBQ", # Number of jobs waiting "INV", # Inventory levels "JOBOUT", # Number of completed jobs "JOBT", # Lead times "JOBREV", # Revenue "S1Q", # Number of kits queued for station 1 "S1UTIL", # Station 1 utilitization by day "S2Q", # number of kits queued for station 2 "S2UTIL", # Station 2 utilitization by day "S3Q", # number of kits queued for station 3 "S3UTIL" # Station 3 utilitization by day ] plots = [] for datatype in datatypes: print(datatype) data = littlefield.get_data(datatype) keys = list(data.keys())
#!/usr/bin/env python import sys import os lib = os.getenv("LITTLEFIELD_PATH") if lib is not None: sys.path.append(lib) from raven import Client raven = Client(os.getenv("LITTLEFIELD_RAVEN_DSN")) try: from littlefield import Littlefield config = False if len(sys.argv) > 1: if sys.argv[1] == "config": config = True if config: print("graph_title Game Time") print("graph_info Shows the number of game days that have passed") print("graph_category littlefield") print("graph_vlabel days") littlefield = Littlefield(os.getenv("LITTLEFIELD_USER"), os.getenv("LITTLEFIELD_PW")) if config: print("days.label Game Days") else: key = None data = littlefield.get_status() print("days.value %s" % status['day']) except: raven.captureException()
#!/usr/bin/env python from littlefield import Littlefield from configparser import ConfigParser config = ConfigParser() config.read(['littlefield.ini']) littlefield = Littlefield(config['littlefield']['user'], config['littlefield']['password']) status = littlefield.get_status() for key, value in status.items(): print("%s:\t%s" % (key, value)) def avg(data, size): return sum(util[((size * -1) - 1):-1]) / size print("Station\t\t1 day avg\t\t3 day avg\t\t10 day avg") for station in range(1, 4): machines = littlefield.get_station(station)['number of machines'] util = littlefield.get_data("S%sUTIL" % station)['average'] queue = littlefield.get_data("S%sQ" % station)['average'] print( "Station %s:\t[ %.2f%% | %.2f ]\t[ %.2f%% | %.2f ]\t[ %.2f%% | %.2f ] (%s machines)" % (station, (util[-1] * 100), queue[-1], (avg(util, 3) * 100), avg(queue, 3), (avg(util, 10) * 100), avg(queue, 10), machines)) jobt = littlefield.get_data("JOBT")['average']
#!/usr/bin/env python from littlefield import Littlefield from configparser import ConfigParser from bokeh.plotting import figure, output_server, show, gridplot config = ConfigParser() config.read(['littlefield.ini']) littlefield = Littlefield(config['littlefield']['user'], config['littlefield']['password']) output_server("littlefield") datatypes = [ "JOBIN", # Number of jobs accepted per day "JOBQ", # Number of jobs waiting "INV", # Inventory levels "JOBOUT", # Number of completed jobs "JOBT", # Lead times "JOBREV", # Revenue "S1Q", # Number of kits queued for station 1 "S1UTIL", # Station 1 utilitization by day "S2Q", # number of kits queued for station 2 "S2UTIL", # Station 2 utilitization by day "S3Q", # number of kits queued for station 3 "S3UTIL" # Station 3 utilitization by day ] plots = [] for datatype in datatypes: print(datatype) data = littlefield.get_data(datatype)
#!/usr/bin/env python from littlefield import Littlefield from configparser import ConfigParser config = ConfigParser() config.read(['littlefield.ini']) littlefield = Littlefield(config['littlefield']['user'], config['littlefield']['password']) i = 1 for team in littlefield.get_standings(): print("%s. %s ($%s)" % (i, team['name'], team['cash'])) i += 1
#!/usr/bin/env python from littlefield import Littlefield from configparser import ConfigParser import notify config = ConfigParser() config.read(["littlefield.ini"]) littlefield = Littlefield(config["littlefield"]["user"], config["littlefield"]["password"]) for i in range(1, 4): station = littlefield.get_station(i) utilitization = littlefield.get_data("S%sUTIL" % i)["average"][-1] if utilitization > float(config["littlefield"]["util_high"]): machines = station["number of machines"] + 1 notify.send( "Station %s has a utilitization of %s. Increasing machines from %s to %s" % (i, utilitization, station["number of machines"], machines) ) littlefield.update_machine_count(station, machines) elif utilitization < float(config["littlefield"]["util_low"]) and station["number of machines"] > 1: machines = station["number of machines"] - 1 notify.send( "Station %s has a utilitization of %s. Decreasing machines from %s to %s" % (i, utilitization, station["number of machines"], machines) ) littlefield.update_machine_count(station, machines)
#!/usr/bin/env python import sys import os lib = os.getenv("LITTLEFIELD_PATH") if lib is not None: sys.path.append(lib) from raven import Client raven = Client(os.getenv("LITTLEFIELD_RAVEN_DSN")) try: from littlefield import Littlefield config = False if len(sys.argv) > 1: if sys.argv[1] == "config": config = True if config: print("""graph_title Queue Size graph_info Shows the queue size graph_category littlefield graph_vlabel Kits""") littlefield = Littlefield(os.getenv("LITTLEFIELD_USER"), os.getenv("LITTLEFIELD_PW")) for station in range(1, 4): if config: print("station%s.label Station %s" % (station, station)) else: size = littlefield.get_data("S%sQ" % station)['average'] print("station%s.value %s" % (station, size[-1])) except: raven.captureException()
name = sys.argv[0].split("_")[1] else: name = sys.argv[-1] config = False if len(sys.argv) > 1: if sys.argv[1] == "config": config = True if config: print("graph_title %s" % titles[name]['title']) print("graph_info Shows the %s" % titles[name]['title']) print("graph_category littlefield") print("graph_vlabel %s" % titles[name]['unit']) if "scale" in titles[name]: print("graph_scale no") if config: print("%s.label %s" % (name, titles[name]['title'])) print("%s-3.label %s (3 day average)" % (name, titles[name]['title'])) print("%s-10.label %s (10 day average)" % (name, titles[name]['title'])) else: littlefield = Littlefield(os.getenv("LITTLEFIELD_USER"), os.getenv("LITTLEFIELD_PW")) data = littlefield.get_data(name) key = "average" print("%s.value %s" % (name, data[key][-1])) print("%s-3.value %s" % (name, avg(data[key], 3))) print("%s-10.value %s" % (name, avg(data[key], 10))) except: raven.captureException()
#!/usr/bin/env python from littlefield import Littlefield from configparser import ConfigParser import notify config = ConfigParser() config.read(['littlefield.ini']) littlefield = Littlefield(config['littlefield']['user'], config['littlefield']['password']) for i in range(1, 4): station = littlefield.get_station(i) utilitization = littlefield.get_data("S%sUTIL" % i)['average'][-1] if utilitization > float(config['littlefield']['util_high']): machines = station['number of machines'] + 1 notify.send( "Station %s has a utilitization of %s. Increasing machines from %s to %s" % (i, utilitization, station['number of machines'], machines)) littlefield.update_machine_count(station, machines) elif utilitization < float(config['littlefield']['util_low'] ) and station['number of machines'] > 1: machines = station['number of machines'] - 1 notify.send( "Station %s has a utilitization of %s. Decreasing machines from %s to %s" % (i, utilitization, station['number of machines'], machines)) littlefield.update_machine_count(station, machines)
#!/usr/bin/env python from littlefield import Littlefield from configparser import ConfigParser config = ConfigParser() config.read(['littlefield.ini']) littlefield = Littlefield(config['littlefield']['user'], config['littlefield']['password']) status = littlefield.get_status() for key, value in status.items(): print("%s:\t%s" % (key, value)) def avg(data, size): return sum(util[((size*-1)-1):-1])/size print("Station\t\t1 day avg\t\t3 day avg\t\t10 day avg") for station in range(1, 4): machines = littlefield.get_station(station)['number of machines'] util = littlefield.get_data("S%sUTIL" % station)['average'] queue = littlefield.get_data("S%sQ" % station)['average'] print("Station %s:\t[ %.2f%% | %.2f ]\t[ %.2f%% | %.2f ]\t[ %.2f%% | %.2f ] (%s machines)" % (station, (util[-1]*100), queue[-1], (avg(util, 3)*100), avg(queue, 3), (avg(util, 10)*100), avg(queue, 10), machines)) jobt = littlefield.get_data("JOBT")['average'] print("Job Times:\t[ %.2f ]\t\t[ %.2f ]\t\t[ %.2f ]" % (jobt[-1], avg(jobt, 3), avg(jobt, 10))) jobq = littlefield.get_data("JOBQ")['average'] print("Queue Size:\t[ %.2f ]\t\t[ %.2f ]\t\t[ %.2f ]" % (jobq[-1], avg(jobq, 3), avg(jobq, 10)))
try: config = False derive = "_derative" in sys.argv[0] if len(sys.argv) > 1: if sys.argv[1] == "config": config = True if config: title = "Cash Levels by Team" if not derive else "Cash delta by Team" print("""graph_title %s graph_info Shows the position on the leadership board graph_category littlefield graph_vlabel Cash ($)""" % title) if derive: print("graph_args --upper-limit 5 --lower-limit 0") print("graph_scale no") littlefield = Littlefield(os.getenv("LITTLEFIELD_USER"), os.getenv("LITTLEFIELD_PW")) teams = {} for team in littlefield.get_standings(): teams[team['name']] = team['cash'] for team in sorted(teams.items()): if config: print("%s.label %s" % (team[0], team[0])) if derive: print("%s.type DERIVE" % team[0]) else: print("%s.value %s" % (team[0], team[1])) except: raven.captureException()
lib = os.getenv("LITTLEFIELD_PATH") if lib is not None: sys.path.append(lib) from raven import Client raven = Client(os.getenv("LITTLEFIELD_RAVEN_DSN")) try: from littlefield import Littlefield config = False if len(sys.argv) > 1: if sys.argv[1] == "config": config = True if config: print("graph_title Game Time") print("graph_info Shows the number of game days that have passed") print("graph_category littlefield") print("graph_vlabel days") littlefield = Littlefield(os.getenv("LITTLEFIELD_USER"), os.getenv("LITTLEFIELD_PW")) if config: print("days.label Game Days") else: key = None data = littlefield.get_status() print("days.value %s" % status['day']) except: raven.captureException()
raven = Client(os.getenv("LITTLEFIELD_RAVEN_DSN")) try: config = False derive = "_derative" in sys.argv[0] if len(sys.argv) > 1: if sys.argv[1] == "config": config = True if config: title = "Cash Levels by Team" if not derive else "Cash delta by Team" print("""graph_title %s graph_info Shows the position on the leadership board graph_category littlefield graph_vlabel Cash ($)""" % title) if derive: print("graph_args --upper-limit 5 --lower-limit 0") print("graph_scale no") littlefield = Littlefield(os.getenv("LITTLEFIELD_USER"), os.getenv("LITTLEFIELD_PW")) teams = {} for team in littlefield.get_standings(): teams[team['name']] = team['cash'] for team in sorted(teams.items()): if config: print("%s.label %s" % (team[0], team[0])) if derive: print("%s.type DERIVE" % team[0]) else: print("%s.value %s" % (team[0], team[1])) except: raven.captureException()
from raven import Client raven = Client(os.getenv("LITTLEFIELD_RAVEN_DSN")) try: from littlefield import Littlefield def avg(data, size): return sum(data[((size*-1)-1):-1])/size config = False if len(sys.argv) > 1: if sys.argv[1] == "config": config = True if config: print("""graph_title Station Utilitization graph_info Shows the utilitization of each station graph_category littlefield graph_scale no graph_args --upper-limit 100 -l 0 graph_vlabel %""") for station in range(1, 4): if config: print("station%s.label Station %s" % (station, station)) print("station%s.warning 10:80" % station) else: littlefield = Littlefield(os.getenv("LITTLEFIELD_USER"), os.getenv("LITTLEFIELD_PW")) util = littlefield.get_data("S%sUTIL" % station)['average'] print("station%s.value %s" % (station, util[-1]*100)) except: raven.captureException()
else: name = sys.argv[-1] config = False if len(sys.argv) > 1: if sys.argv[1] == "config": config = True if config: print("graph_title %s" % titles[name]['title']) print("graph_info Shows the %s" % titles[name]['title']) print("graph_category littlefield") print("graph_vlabel %s" % titles[name]['unit']) if "scale" in titles[name]: print("graph_scale no") if config: print("%s.label %s" % (name, titles[name]['title'])) print("%s-3.label %s (3 day average)" % (name, titles[name]['title'])) print("%s-10.label %s (10 day average)" % (name, titles[name]['title'])) else: littlefield = Littlefield(os.getenv("LITTLEFIELD_USER"), os.getenv("LITTLEFIELD_PW")) data = littlefield.get_data(name) key = "average" print("%s.value %s" % (name, data[key][-1])) print("%s-3.value %s" % (name, avg(data[key], 3))) print("%s-10.value %s" % (name, avg(data[key], 10))) except: raven.captureException()