-
Notifications
You must be signed in to change notification settings - Fork 2
/
backend.py
165 lines (150 loc) · 3.29 KB
/
backend.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
import os
from emotion import EmotiRecog
from flask import Flask,jsonify,request
import time
from threading import Thread
import json
obj1=EmotiRecog.Emotion()
#from werkzeug import secure_filename
#os.system("./ngrok http 5000")
class Function:
def __init__(self):
self.stop=False
self.time=0
self.rurl=None
def Work(self):
i=1
while(i):
if(self.stop):
break
obj1.capture()
obj1.send()
i+=1
return
def Loging(self,session,Time,hr,attention=None,Type=None,):
with open("data.json") as json_file:
data=json.load(json_file)
l=len(data['today'])
print(l)
data['today'].append({})
print(len(data['today']))
data['today'][l]["session"] = session
data['today'][l]["time"] = Time
data['today'][l]["heartrate"] = hr
if(attention):
data['today'][l+1]["attention"] =attention
if(Type):
data['today'][l+1]["type"] = Type
json_file.seek(0)
json.dump(data, json_file, indent=4)
json_file.truncate()
pass
def TrainigStencile(self):
before=time.time()
while(not self.stop):
print("Stencile")
after=time.time()
self.time=before-after
#self.Loging("writing",obj.time,[])
return
# obj.capture()
# res=obj.send()
def Rhymes(self):
before=time.time()
while(not self.stop):
print(self.rurl)
after=time.time()
self.time=before-after
#self.Loging("writing",obj.time,[])
return
def Beats(self):
before=time.time()
while(not self.stop):
print("Beates")
after=time.time()
self.time=before-after
#self.Loging("writing",obj.time,[])
return
def Play(self):
before=time.time()
while(not self.stop):
print("play")
after=time.time()
self.time=before-after
#self.Loging("writing",obj.time,[])
return
obj=Function()
app=Flask(__name__)
@app.route("/")
def hello():
return "hello world!"
@app.route("/emotirecog/start")
def rec():
thread=Thread(target=obj.Work)
if(obj.stop):
obj.stop=False
thread.start()
print("ended")
return "started"
@app.route("/emotirecog/stop")
def stop():
obj.stop=True
return 'ended'
@app.route("/training/stensile/start")
def trainigStencileStart():
thread=Thread(target=obj.TrainigStencile)
if(obj.stop):
obj.stop=False
thread.start()
value=None
Type=request.args.get('name')
if(Type=='English'):
value="started english"
elif Type=='Hindi':
value="started Hindi"
elif Type=='Maths':
value="started Maths"
return(value)
@app.route("/training/stensile/stop")
def trainigStencileStop():
obj.stop=True
return("stopped")
@app.route("/training/Rhymes/start")
def StartRhymes():
obj.rurl=request.args.get("url")
thread=Thread(target=obj.Rhymes)
if(obj.stop):
obj.stop=False
thread.start()
#send the hit the url to play video
return("rhyme started")
@app.route("/training/Rhymes/stop")
def StopRhymes():
obj.stop=True
return("stopped")
@app.route('/beats/start')
def StartBeats():
thread=Thread(target=obj.Beats)
if(obj.stop):
obj.stop=False
thread.start()
#send the hit the url to play video
return("beat started")
@app.route('/beats/stop')
def StopBeats():
obj.stop=True
return("stopped")
@app.route('/play/start')
def StartPlay():
thread=Thread(target=obj.Play)
if(obj.stop):
obj.stop=False
thread.start()
#send the hit the url to play video
return("video started")
@app.route('/play/stop')
def StopPlay():
obj.stop=True
return("stopped")
#stop video
pass