def bar(request): #Getting the progress info from the cache progress = memcache.get("progress") refresh = '' simulating = 0 <= progress < 100 done = progress == 100 if done: #Showing results if we are done progress = 100 iRun = 0 sim = simulation.simulation() NRun = memcache.get("NRun") #Aggregating all jobs while iRun < NRun: simTemp = memcache.get("run" + str(iRun)) sim.houseAdvantage.extend(simTemp.houseAdvantage) sim.finalMoney.extend(simTemp.finalMoney) iRun = iRun + 1 #Aggregating stats sim.hist.build(sim) houseAdvantage = round(sum(sim.houseAdvantage)/len(sim.houseAdvantage),4) expectedGain = round(sum(sim.finalMoney)/len(sim.finalMoney),2) standardDev = int(round(math.sqrt(sum([(x - expectedGain)**2 for x in sim.finalMoney])/len(sim.finalMoney)),0)) maximumGain = int(round(max(sim.finalMoney),0)) minGain = int(round(min(sim.finalMoney),0)) #Building stats dictionary sim.stats = [{'name' : 'House Advantage','value': houseAdvantage}, {'name' : 'Expected Loss (or Gain)','value': expectedGain}, {'name' : 'Standard Deviation', 'value' : standardDev}, {'name' : 'Maximum Gain','value': maximumGain} ,{'name' : 'Maximum Loss' , 'value' : minGain}] return render_to_response("Bar.html",{'sim' : sim, 'progress' : str(progress) + '%', 'refresh' : refresh, 'simulating' : simulating, 'done' : done}) elif simulating: #We are refreshing every 5 seconds while simulating refresh = '<meta http-equiv="refresh" content="5" >' return render_to_response("Bar.html",{'progress' : str(progress) + '%', 'refresh' : refresh, 'simulating' : simulating}) else: #When the simulation hasn't started yet. return render_to_response("Bar.html",{'progress' : str(progress) + '%', 'refresh' : refresh, 'simulating' : simulating, 'done' : done})
def simulation_queue(request): #Getting the parameters betType = request.POST.get('betType', 'JP') nDeck = int(request.POST.get('nDeck', '2')) maxBet = int(request.POST.get('maxBet', '0')) iRun = int(request.POST.get('iRun', '0')) NRun = int(request.POST.get('NRun', '0')) #Simulating sim = simulation.simulation(betType, nDeck, 1000, maxBet=maxBet) sim.run() #Saving results to cache memcache.incr("counter") count = memcache.get("counter") memcache.set("run" + str(iRun), sim) memcache.set("progress", count * 100 / NRun) return HttpResponse()
def simulation_queue(request): #Getting the parameters betType = request.POST.get('betType', 'JP') nDeck = int(request.POST.get('nDeck', '2')) maxBet = int(request.POST.get('maxBet','0')) iRun = int(request.POST.get('iRun','0')) NRun = int(request.POST.get('NRun','0')) #Simulating sim = simulation.simulation(betType,nDeck,1000,maxBet = maxBet) sim.run() #Saving results to cache memcache.incr("counter") count = memcache.get("counter") memcache.set("run" + str(iRun), sim) memcache.set("progress", count*100/NRun) return HttpResponse()
def bar(request): #Getting the progress info from the cache progress = memcache.get("progress") refresh = '' simulating = 0 <= progress < 100 done = progress == 100 if done: #Showing results if we are done progress = 100 iRun = 0 sim = simulation.simulation() NRun = memcache.get("NRun") #Aggregating all jobs while iRun < NRun: simTemp = memcache.get("run" + str(iRun)) sim.houseAdvantage.extend(simTemp.houseAdvantage) sim.finalMoney.extend(simTemp.finalMoney) iRun = iRun + 1 #Aggregating stats sim.hist.build(sim) houseAdvantage = round( sum(sim.houseAdvantage) / len(sim.houseAdvantage), 4) expectedGain = round(sum(sim.finalMoney) / len(sim.finalMoney), 2) standardDev = int( round( math.sqrt( sum([(x - expectedGain)**2 for x in sim.finalMoney]) / len(sim.finalMoney)), 0)) maximumGain = int(round(max(sim.finalMoney), 0)) minGain = int(round(min(sim.finalMoney), 0)) #Building stats dictionary sim.stats = [{ 'name': 'House Advantage', 'value': houseAdvantage }, { 'name': 'Expected Loss (or Gain)', 'value': expectedGain }, { 'name': 'Standard Deviation', 'value': standardDev }, { 'name': 'Maximum Gain', 'value': maximumGain }, { 'name': 'Maximum Loss', 'value': minGain }] return render_to_response( "Bar.html", { 'sim': sim, 'progress': str(progress) + '%', 'refresh': refresh, 'simulating': simulating, 'done': done }) elif simulating: #We are refreshing every 5 seconds while simulating refresh = '<meta http-equiv="refresh" content="5" >' return render_to_response( "Bar.html", { 'progress': str(progress) + '%', 'refresh': refresh, 'simulating': simulating }) else: #When the simulation hasn't started yet. return render_to_response( "Bar.html", { 'progress': str(progress) + '%', 'refresh': refresh, 'simulating': simulating, 'done': done })