def run(seq): with open('log.dat', 'rb') as infile: ledger = pickle.load(infile) kmeans = genExtractor(seq, ledger) functionLog = [] print("Thread " + str(seq) + " partito") for i in range(1, POINTS_PER_SEQ): short = randint(1, AVG_LEN) # forcing long != short long = short while (long == short): long = randint(1, AVG_LEN) value = simulate(seq, short, long, kmeans, ledger, 0) print("Num: " + str(i) + "\t" + "Seq: " + str(seq) + "\t" + "Short: " + str(short) + "\t" + "Long: " + str(long) + "\t" + "Value: " + str(float("{0:.2f}".format(value)))) # just keep configurations with value above X if (value > 100): functionLog.append(Function(seq, short, long, value)) with open('function' + str(seq) + '.dat', 'wb') as outfile: pickle.dump(functionLog, outfile)
def run(seq, id): with open('log.dat', 'rb') as infile: ledger = pickle.load(infile) kmeans = genExtractor(seq, ledger) functionLog = [] print("Thread " + str(seq) + " partito") for i in range(1, POINTS_PER_SEQ): # modify values. INSERT HERE !!!!!! short = randint(675, 1400) long = short while (long == short): # modify values. INSERT HERE !!!!!! long = randint(600, 800) value = simulate(seq, short, long, kmeans, ledger, 0) print("Num: " + str(i) + "\t" + "Seq: " + str(seq) + "\t" + "Short: " + str(short) + "\t" + "Long: " + str(long) + "\t" + "Value: " + str(float("{0:.2f}".format(value)))) functionLog.append(Function(seq, short, long, value)) with open('function' + str(id) + '.dat', 'wb') as outfile: pickle.dump(functionLog, outfile)
def run(seq): with open('log.dat', 'rb') as infile: ledger = pickle.load(infile) kmeans = genExtractor(seq, ledger) functionLog = [] print("Partita l'analisi per la sequenza", seq) for i in range(1, POINTS_PER_SEQ): try: short = randint(1, AVG_LEN) #forcing long > short long = randint(short + 1, AVG_LEN + 1) value = simulate(seq, short, long, kmeans, ledger, 0) print("Num: " + str(i) + "\t" + "Seq: " + str(seq) + "\t" + "Short: " + str(short) + "\t" + "Long: " + str(long) + "\t" + "Value: " + str(float("{0:.2f}".format(value)))) # just keep configurations with value above X if (value > 100): functionLog.append(Function(seq, short, long, value)) with open('function' + str(seq) + '.dat', 'wb') as outfile: pickle.dump(functionLog, outfile) except: print("Errore")
def main_loop(): functions.printHeadings(data_sh) for r in range(2, data_sh.max_row+1): functions.simulate(data_sh, r, filters, ss) wb.save(ss.data_workbook)
import pickle from recordclass import recordclass import sys import numpy from functions import genExtractor, getAvg, getFloatingAvg, SuperQueue, simulate Log = recordclass('Log', ['coin', 'value_ask', 'value_bid']) SEQ_SIZE = int(sys.argv[1]) SHORT = int(sys.argv[2]) LONG = int(sys.argv[3]) with open('log.dat', 'rb') as infile: ledger = pickle.load(infile) kmeans = genExtractor(SEQ_SIZE, ledger) value, history, coins = simulate(SEQ_SIZE, SHORT, LONG, kmeans, ledger, 1) # printing statistics. 100 is the initial budget used for the simulation print("\n\nFinal budget: " + str(float("{0:.4f}".format((value)))) + " with " + str(coins) + " coins. The final budget accounts for those coins as sold.") print("Profit: " + str(float("{0:.4f}".format((value - 100))))) with open('history', 'wb') as outfile: pickle.dump(history, outfile)