In [7]:
import pandas as pd
import numpy as np
In [323]:
agents = pd.read_csv('agentData.csv')
cemetry = pd.read_csv('cemetryData.csv')
backgroundSpending = pd.read_csv('backgroundSpending.csv')
inventory = pd.read_csv('inventoryinformation.csv')
In [317]:
simDays = 1
In [325]:
def Prob(age):
prob = (0.000002 * age **2 - 0.000109 * age + 0.001155)
return prob
def StatusChange(prob):
randNum = np.random.uniform(low = 0.0, high = 1.0)
if prob > randNum:
status = 'Dead'
elif (prob * 2) > (randNum ):
status = 'Sick'
else:
status = 'Healthy'
return status
In [326]:
for day in range(simDays):
#increase date by one
agents['currentDate'] = agents['currentDate'] + 1
#determine every npc's new age
agents['age'] = (agents['currentDate'] - agents['dob']) /360
#modify agents status based on age
prob = agents['age'].apply(Prob)
prob = prob * agents['livingStatus'].apply(lambda x: 2 if x == 'Sick' else 1)
agents['livingStatus'] = prob.apply(StatusChange)
#determine impacts on population from deaths
newDeaths = agents[agents['livingStatus'] == 'Dead']
cemetry = cemetry.append(newDeaths, ignore_index = True)
agents = agents[agents['livingStatus'] != 'Dead']
#assign marriages, not currently done
#assign pregancy
prob = agents['age'].apply(lambda x: 1.0 / (abs(18 - x) + 2))
prob = prob * (1 - agents['gender'])
prob[agents['age'] < 15] = 0
prob[agents['pregant'] > 0 ] = 0
prob = prob.apply(lambda x: np.random.binomial(n=1, p = x))
agents['pregant'] = agents['pregant'] + 60 * prob
#create new agents, births
newnpcIndex = max(max(agents['npcIndex']), max(cemetry['npcIndex']))
births = agents[agents['pregant'] == 1]
for i in range(len(births)):
newnpcIndex += 1
births['npcIndex'].iloc[i] = newnpcIndex
#births['firstName'] = births['firstName'].apply(lambda x: something to assign random name)
births['dob'] = births['currentDate']
births['age'] = (births['currentDate'] - births['dob']) /360
births['gender'] = np.random.binomial(n=1, p = 0.5, size = len(births))
births['pregant'].iloc[:] = 0
births['gold'].iloc[:] = 0
agents = agents.append(births, ignore_index = True)
agents['pregant'] = agents['pregant'].apply(lambda x: x-1 if x > 0 else 0)
#determine purchases by agentsnew
agents['base_spend'] = agents[['income', 'base_expense']].min(axis = 1)
agents['luxury_spend'] = (agents['income'] - agents['base_spend']) * (1 - agents['saveRate'])
agents['gold'] = agents['gold'] + (agents['income'] - agents['base_expense']) * agents['saveRate']
current_period_spend = agents.groupby('background')['base_spend', 'luxury_spend'].apply(sum)
current_period_spend.reset_index(level=0, inplace=True)
backgroundSpending = backgroundSpending.merge(current_period_spend,
on = 'background',
how = 'left')
backgroundSpending['basicSpend'] = backgroundSpending['base_spend'] * backgroundSpending['basicSpend%']
backgroundSpending['luxurySpend'] = backgroundSpending['luxury_spend'] * backgroundSpending['luxurySpend%']
backgroundSpending = backgroundSpending.drop(labels = ['base_spend', 'luxury_spend'], axis = 1)
#need something here to include in "vistors"
#upfront estimates change in population and wealth for world, by city
#can do this by random normal on population for each city, mean can be based on world event
#each city can have some economic status, which translates to a random normal with different means/variance
#developed, developing, recession, depression, collasping,
#a % of world population will travl, make this some uniform distribution 1% to 10%
#there spilt among cities will be based on share of global wealth
#determine corporate revenue based on agent purchases
itemSpend = backgroundSpending.groupby('item')['basicSpend', 'luxurySpend'].apply(sum)
itemSpend['TotalSpend'] = itemSpend['basicSpend'] + itemSpend['luxurySpend']
itemSpend.reset_index(level=0, inplace=True)
inventory['total_spend'] = itemSpend['TotalSpend']
#inventory['available'] = inventory['available'] - inventory['total_spend'] / inventory['local_price']
#pay agents based on corporate profits
#determine new corporations formed, based on required cash
#agent asset impacts
#when they get enough money people buy homes
#buying a home will result in shifting cash to an asset filed
#homes will generate $$ based on value of the assets
#After buying a home, a portion of luxury spending goes assets, driving higher income
#assets decline on a five year balance
#assign agents to employment to new and existing corporations
In [327]:
inventory
Out[327]:
In [ ]: