Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
laholmes committed Dec 16, 2016
0 parents commit 051c4f7
Show file tree
Hide file tree
Showing 1,580 changed files with 134,577 additions and 0 deletions.
Empty file added __init__.py
Empty file.
Binary file added __pycache__/d_alembert.cpython-35.pyc
Binary file not shown.
108 changes: 108 additions & 0 deletions d_alembert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import sys
import random

# startingFunds = float(sys.argv[1])
# wagerSize = float(sys.argv[2])
# wagerCount = float(sys.argv[3])
# daSampSize = float(sys.argv[4])

counter = 1
ret = 0.0
da_busts = 0.0
da_profits = 0.0

def rollDice():
roll = random.randint(1,100)

if roll <= 50:
return False
elif roll >= 51:
return True

def dAlembert(funds,initial_wager,wager_count):
global ret
global da_busts
global da_profits

value = funds
wager = initial_wager
currentWager = 1
previousWager = 1
previousWagerAmount = initial_wager

while currentWager <= wager_count:
if previousWager == 1:
if wager == initial_wager:
pass
else:
wager -= initial_wager

if rollDice():
value += wager
previousWagerAmount = wager
else:
value -= wager
previousWager = 0
previousWagerAmount = wager

if value <= 0:
da_busts += 1
break

elif previousWager == 0:
wager = previousWagerAmount + initial_wager
if(value - wager) <= 0:
wager = value

if rollDice():
value += wager
previousWager = 1
previousWagerAmount = wager
else:
value -= wager
previousWagerAmount = wager

if value <= 0:
da_busts += 1
break

currentWager += 1

ret += value

if value > funds:
da_profits += 1

# while counter <= daSampSize:
# dAlembert(startingFunds, wagerSize, wagerCount)
# counter += 1

# results = {
# 'totalInvested': daSampSize*startingFunds,
# 'totalReturn': ret,
# 'roi': ret - (daSampSize*startingFunds),
# 'bustRate': (da_busts/daSampSize) * 100.00,
# 'profitRate': (da_profits/daSampSize) * 100.00
# }

# sys.stdout.write(str(results))
# print(str(results))
# sys.stdout.flush()
# sys.exit(0)

def simulate(startingFunds, wagerSize, wagerCount, daSampSize):
counter = 1

while counter <= daSampSize:
dAlembert(startingFunds, wagerSize, wagerCount)
counter += 1

results = {
'totalInvested': daSampSize*startingFunds,
'totalReturn': ret,
'roi': ret - (daSampSize*startingFunds),
'bustRate': (da_busts/daSampSize) * 100.00,
'profitRate': (da_profits/daSampSize) * 100.00
}
return results

34 changes: 34 additions & 0 deletions messaging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python
import pika
import d_alembert
import json

connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()

channel.queue_declare(queue='simulations')
channel.queue_declare(queue='results')

def callback(ch, method, properties, body):
requestParams = json.loads(body.decode('utf-8'))
funds = int(requestParams[0])
size = int(requestParams[1])
count = int(requestParams[2])
sims = int(requestParams[3])

results = d_alembert.simulate(funds, size, count, sims)
print(results)

# send a message back
channel.basic_publish(exchange='',
routing_key='results',
body=json.dumps(results, ensure_ascii=False))

# connection.close()

# receive message and complete simulation
channel.basic_consume(callback,
queue='simulations',
no_ack=True)

channel.start_consuming()
1 change: 1 addition & 0 deletions node_modules/.bin/mime

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

212 changes: 212 additions & 0 deletions node_modules/accepts/HISTORY.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions node_modules/accepts/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 051c4f7

Please sign in to comment.