-
Notifications
You must be signed in to change notification settings - Fork 0
/
analysis.py
96 lines (76 loc) · 2.12 KB
/
analysis.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
import pandas as pd
import xlrd
import plotly
import plotly.plotly as py
import plotly.graph_objs as go
plotly.tools.set_credentials_file(username='colejump', api_key='Mh3sATfsUKQtelXlZTNP')
df = pd.read_excel("Book.xlsx")
#counts the number of events for each day
numberCategoryPerDay = {}
numberPerDay = {}
xValues = []
yValues = []
categoryXValues = []
categoryYValues = []
count = 0
for index, row in df.iterrows():
count = count + 1
for i in range(count):
if (df.iloc[i][1]) in numberPerDay:
numberPerDay[(df.iloc[i][1])] = numberPerDay[(df.iloc[i][1])] + 1
else:
numberPerDay[(df.iloc[i][1])] = 1
categoryList = df.iloc[i][9].split(",")
for x in categoryList:
if (x) in numberCategoryPerDay:
if (df.iloc[i][1]) in numberCategoryPerDay[x]:
numberCategoryPerDay[x][(df.iloc[i][1])] = numberCategoryPerDay[x][(df.iloc[i][1])] + 1
else:
numberCategoryPerDay[x][(df.iloc[i][1])] = 1
continue
numberCategoryPerDay[x] = {df.iloc[i][1] : 1}
for x, y in numberPerDay.items():
xValues.append(x)
yValues.append(y)
trace = go.Scatter(
x = xValues,
y = yValues,
name = 'Events',
line = dict(
color = ('rgb(0, 0, 0)'),
width = 2)
)
data = [trace]
count = 0
tmpDic = {}
for i in numberCategoryPerDay:
for k in numberPerDay:
if k in numberCategoryPerDay[i]:
tmpDic[k] = numberCategoryPerDay[i][k]
continue
else:
tmpDic[k] = 0
red = str(int(count * (255/len(numberCategoryPerDay))))
green = str(int(255 - (count * (255/len(numberCategoryPerDay)))))
blue = str(int((255/4) + (count * ((255/4)/len(numberCategoryPerDay)))))
for x, y in tmpDic.items():
categoryXValues.append(x)
categoryYValues.append(y)
trace = go.Scatter(
x = categoryXValues,
y = categoryYValues,
name = i,
line = dict(
color = ('rgb(' + red + ', ' + green + ', ' + blue + ')'),
width = 2)
)
data.append(trace)
categoryXValues = []
categoryYValues = []
count = count + 1
layout = dict(title = 'Events over time',
xaxis = dict(title = 'Day'),
yaxis = dict(title = 'Number of Events'),
)
fig = dict(data=data, layout=layout)
py.iplot(fig, filename='styled-line')