forked from wncc/helloFOSS-21-LifeAudit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimulation.py
130 lines (110 loc) · 4.11 KB
/
simulation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import random as rnd ## For generating random choices/numbers
import matplotlib.pyplot as plt ## For plotting the graphs
import seaborn as sns ## For data visualization and analysis
import sys
import people #Importing the people module
def on_press(event):
"""
Close sim on pressing any key
"""
sys.exit(0)
#Initializing the people
population = []
for i in range(100):
population.append(people.people())
## Loop runs for each day in a month and each day the activities array is emptied
fig, ax = plt.subplots()
for days in range(30):
activities = [[]]*100
for hours in range(24):
for i in range(100):
person = population[i]
if(hours >= rnd.randint(8, 8+person.laziness*4) or hours <= 17): #Depending on how lazy the person is, it decides when the person starts his day
## Randomly choosing between study, hobby and relax according to their weights defined earlier
work = rnd.choices(['s', 'h', 'r'], person.probs)
if work == ["s"]:
activities[i].append("studied")
person.study()
elif work == ["h"]:
activities[i].append("hobby")
person.hobby()
else:
activities[i].append("relaxed")
person.relax()
elif((hours > 4 and hours <= 7) or (hours < 20 and hours > 17)):
# For exercising in morning or evening, depends on the laziness of the person
e = rnd.choices(['e', 'ne'], [1-person.laziness, person.laziness])[0]
if e == "e":
person.exercise()
if hours == 23 and (activities[i].count("studied")/len(activities[i])) > 0.4:
#Studying above a certain limit in a day can cause some amount of mental health detrioration
person.mental_health -= 1
person.academics -= 0.02 #To simulate forgetfullnes, each day you tend to a forget a few things from days back
## Appending the arrays according to the activities and the choices in a day
acads = []
for person in population:
acads.append(person.academics)
extracurs = []
for person in population:
extracurs.append(person.extracur)
mental_healths = []
for person in population:
mental_healths.append(person.mental_health)
physical_healths = []
for person in population:
physical_healths.append(person.fitness)
## Plotting the results
plt.subplot(4, 1, 1)
plt.plot(range(100), acads)
plt.xlabel("Person")
plt.ylabel("Academic Level")
plt.subplot(4, 1, 2)
plt.plot(range(100), extracurs)
plt.xlabel("Person")
plt.ylabel("Extracurricular Level")
plt.subplot(4, 1, 3)
plt.plot(range(100), mental_healths)
plt.xlabel("Person")
plt.ylabel("Mental Health")
plt.subplot(4, 1, 4)
plt.plot(range(100), physical_healths)
plt.xlabel("Person")
plt.ylabel("Physical Fitness")
plt.tight_layout()
fig.canvas.mpl_connect("key_press_event", on_press) #Detect key press
plt.draw()
plt.pause(1)
fig.clf()
## Compile data and draw the final graph at the end of the month
acads = []
for person in population:
acads.append(person.academics)
extracurs = []
for person in population:
extracurs.append(person.extracur)
mental_healths = []
for person in population:
mental_healths.append(person.mental_health)
physical_healths = []
for person in population:
physical_healths.append(person.fitness)
## Plotting the results
plt.subplot(4, 1, 1)
plt.plot(range(100), acads)
plt.xlabel("Person")
plt.ylabel("Academic Level")
plt.subplot(4, 1, 2)
plt.plot(range(100), extracurs)
plt.xlabel("Person")
plt.ylabel("Extracurricular Level")
plt.subplot(4, 1, 3)
plt.plot(range(100), mental_healths)
plt.xlabel("Person")
plt.ylabel("Mental Health")
plt.subplot(4, 1, 4)
plt.plot(range(100), physical_healths)
plt.xlabel("Person")
plt.ylabel("Physical Fitness")
plt.tight_layout()
fig.canvas.mpl_connect("key_press_event", on_press) #Detect key press
plt.show()