-
Notifications
You must be signed in to change notification settings - Fork 0
/
report_generation_fun.py
178 lines (168 loc) · 5.18 KB
/
report_generation_fun.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import matplotlib.pylab as plt
import json
import datetime
def generatereport(data):
def infer(s_date,e_date):
t={'angry':[],'happy':[],'surprised':[],'neutral':[],'sad':[],'scared':[]}
for i in get_ind:
t['angry'].append(angry[i])
t['happy'].append(happy[i])
t['surprised'].append(surprised[i])
t['neutral'].append(neutral[i])
t['sad'].append(sad[i])
t['scared'].append(scared[i])
n=len(get_ind)
l=['angry','happy','surprised','neutral','sad','scared']
for key,val in t.items():
d=0
for i in val:
if(i>0.4):
d+=1
dataGet[key]=d/n
names=list(dataGet.keys())
values=list(dataGet.values())
plt.bar(range(len(dataGet)),values,tick_label=names)
plt.savefig('barchart.png',dpi=400)
plt.show()
def convertTime():
for i in data['timedataa']:
epoch_time = i
date_time = datetime.datetime.fromtimestamp( epoch_time )
time.append(date_time)
def dataCollect():
for i in data['angry']:
angry.append(i)
for i in data['happy']:
happy.append(i)
for i in data['surprised']:
surprised.append(i)
for i in data['neutral']:
neutral.append(i)
for i in data['sad']:
sad.append(i)
for i in data['scared']:
scared.append(i)
def inference(type):
count=0
flag=0
timeVal=[]
if type==1:
for i in get_ind:
if data['neck_inclination'][i]>28:
count+=1
timeVal.append(time[i])
neck.append(data['neck_inclination'][i])
if count==len(get_ind)/2:
flag=1
plt.plot(timeVal,neck)
plt.savefig('linechart1.png')
plt.show()
elif type==2:
for i in get_ind:
if data['torso_inclination'][i]>8:
count+=1
timeVal.append(time[i])
torso.append(data['torso_inclination'][i])
if count==len(get_ind)/2:
flag=1
plt.plot(timeVal,torso)
plt.savefig('linechart2.png')
plt.show()
return flag
def drowsiness():
count=0
flag=0
timeVal=[]
for i in get_ind:
if data['drowsiness_score'][i] > 4:
count+=1
timeVal.append(time[i])
drowsy.append(data['drowsiness_score'][i])
if count==len(get_ind)/2:
flag=1
plt.scatter(timeVal,drowsy)
plt.savefig('scatterplot.png')
plt.show()
return flag
def getIndex():
for i in range(0,len(time)):
if time[i]>s_date and time[i]<e_date:
get_ind.append(i)
# f=open('jsondata.txt')
time=[]
neck=[]
torso=[]
drowsy=[]
get_ind=[]
angry=[]
happy=[]
surprised=[]
neutral=[]
sad=[]
scared=[]
dataGet={}
# data={"timedataa": [1655905835.898674, 1655905836.2186744, 1655905836.554753, 1655905836.8737855, 1655905837.2108657], "angry": [0.028052526, 0.05529974, 0.06660403, 0.03480012, 0.042934477], "scared": [0.05360156, 0.11929174, 0.12533213, 0.06200477, 0.06341797], "happy": [0.001959382, 0.0019642594, 0.0019402344, 0.0027830706, 0.0017529961], "sad": [0.17062306, 0.23376366, 0.30682296, 0.27529377, 0.21328765], "neutral": [0.7413039, 0.5839874, 0.49332088, 0.62301064, 0.67564404], "surprised": [0.0044595483, 0.005693131, 0.005979621, 0.0021076729, 0.0029628891], "neck_inclination": [35, 36, 36, 36, 36], "torso_inclination": [11, 10, 10, 10, 10], "drowsiness_score": [0, 0, 0, 0, 0]}
# data=json.load(f)
s_time_data = "20/06/22 18:54:02.2616"
format_data = "%d/%m/%y %H:%M:%S.%f"
s_date = datetime.datetime.strptime(s_time_data, format_data)
e_time_data = "22/06/22 18:54:04.2620"
e_date = datetime.datetime.strptime(e_time_data, format_data)
convertTime()
getIndex()
dataCollect()
infer(s_date,e_date)
flag1=inference(1)
flag2=inference(2)
flag3=drowsiness()
# f.close()
# !pip install fpdf
from fpdf import FPDF
pdf = FPDF()
pdf.add_page()
pdf.set_font('Arial','B',16)
pdf.cell(40,10,"Report")
pdf.ln(20)
pdf.set_font('Arial','B',12)
pdf.cell(20,10,"The following report is for the data between "+s_time_data[:17]+" and "+e_time_data[:17])
pdf.ln(10)
pdf.set_font('Arial','B',10)
pdf.cell(20,1,"Emotion")
pdf.ln(5)
pdf.image('barchart.png',w=100,h=60)
pdf.ln(10)
pdf.cell(20,1,"Neck inclination")
pdf.ln(5)
pdf.image('linechart1.png',w=100,h=60)
pdf.ln(2)
if flag1==1:
pdf.set_font('Arial','',8)
pdf.cell(20,1,"Your neck is not properly inclined")
else:
pdf.set_font('Arial','',8)
pdf.cell(20,1,"Your neck is properly inclined")
pdf.ln(10)
pdf.set_font('Arial','B',10)
pdf.cell(20,1,"Torso inclination")
pdf.ln(5)
pdf.image('linechart2.png',w=100,h=60)
pdf.ln(2)
if flag2==1:
pdf.set_font('Arial','',8)
pdf.cell(20,1,"Your torso is not properly inclined")
else:
pdf.set_font('Arial','',8)
pdf.cell(20,1,"Your torso is properly inclined")
pdf.ln(15)
pdf.set_font('Arial','B',10)
pdf.cell(20,1,"Drowsiness Score")
pdf.ln(5)
pdf.image('scatterplot.png',w=100,h=60)
pdf.ln(2)
if flag3==1:
pdf.set_font('Arial','',8)
pdf.cell(20,1,"You are too drowsy")
else:
pdf.set_font('Arial','',8)
pdf.cell(20,1,"You are active")
pdf.output('document.pdf','F')