-
Notifications
You must be signed in to change notification settings - Fork 1
/
p2_vedba_classes.py
69 lines (61 loc) · 2.9 KB
/
p2_vedba_classes.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
from variables import *
from config import *
import os
from matplotlib import pyplot as plt
from math import log
import powerlaw
DataDir = PROJECTROOT + DATA + "FeaturesInTotal/"
Files = [f for f in os.listdir(DataDir) if f[-3:] == "csv"]
def hl(mlv):
if mlv > -3.4:
return "HM"
else:
return "LOW"
def time_vs_activity_levels():
HyenaNames = [x for (x,y) in TAG_LOOKUP.items()]
FeaturesDir = PROJECTROOT + DATA + "FeaturesInTotal/"
for Hyena in HyenaNames:
print("Now working on", Hyena)
ArrayOfLogMeanVeDBAs, ArrayOfTimes = [], []
with open(FeaturesDir + Hyena +".csv") as File:
FirstLine = True
for line in File:
if FirstLine:
FirstLine=False
continue
ArrayOfLogMeanVeDBAs.append(log(float(line.rstrip("\n").split(",")[14])))
ArrayOfTimes.append(int(line.rstrip("\n").split(",")[0]))
ArrayOfTimes = [HYENA_REC_START_TIMES[Hyena] + dt.timedelta(seconds=x) for x in ArrayOfTimes]
ArrayOfTimes = [x + dt.timedelta(hours=3) for x in ArrayOfTimes]
ArrayOfStates = [hl(vedba) for vedba in ArrayOfLogMeanVeDBAs]
TwentyFourHourProps = []
for x in range(24):
TwentyFourHourProps.append([])
CurrDate = ArrayOfTimes[0].date()
CurrHour = ArrayOfTimes[0].hour
i = 0
count = 0
count_act = 0
while i < len(ArrayOfTimes):
if ArrayOfTimes[i].hour == CurrHour:
if ArrayOfStates[i] == "HM":
count_act +=3
count += 3
else:
TwentyFourHourProps[CurrHour].append(count_act/count)
#print("{},{}".format(CurrHour, count_act/count))
CurrHour = ArrayOfTimes[i].hour
count, count_act = 0, 0
i += 1
TwentyFourHourProps = [sum(x)/len(x)*100 for x in TwentyFourHourProps]
plt.plot(range(24), TwentyFourHourProps, label=Hyena)
plt.xlabel("Hour of the day")
plt.ylabel("Percentage time in High or Medium activity leveks")
plt.axvspan(-2, 6, facecolor='black', alpha=0.2)
plt.axvspan(18, 26, facecolor='black', alpha=0.2)
plt.xlim(-1, 24)
plt.legend()
plt.savefig(PROJECTROOT + FIGURES + "ActivityPatterns_VeDBA.pgf")
plt.savefig(PROJECTROOT + FIGURES + "ActivityPatterns_VeDBA.png")
if __name__ == "__main__":
time_vs_activity_levels()