-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
123 lines (100 loc) · 3.37 KB
/
main.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
from flask import Flask, render_template, redirect, url_for, request,jsonify
from flask_socketio import SocketIO,emit
from demo_utils import start_bicepcurl, start_pushups, start_squats
from GlobalHelpers import global_state
# from GymTrainerBot import *
import demo
from threading import Thread
# import mayank
# import threading
# from GlobalHelpers import accuracy_queue
import os
app = Flask(__name__)
socketio = SocketIO(app)
exercise_thread = 0
# import demo
# import mayank
# demo = None
# def queueMessageEmit():
# while True:
# text = accuracy_queue.get(block=True)
# socketio.emit("pysend", {"data": text})
# @socketio.on('connect')
# def handle_connection():
# socketio.start_background_task(target=queueMessageEmit)
# def sendPySend():
# while True:
# text = accuracy_queue.get(blo
# @socketio.on('uisend')
# def handle_my_custom_event(json):
# print('received call from UI: ' + str(json))
# emit("pysend",{"data":"I am Python calling to UI"})
@app.route("/")
def home():
return render_template("template.html")
@app.route("/leaderboard")
def leaderboard():
return render_template("leaderboard.html")
@app.route("/bicepcurls")
def start_bicepcurls_async():
global_state.exercise = "bicepcurls"
return start_exercise_async(start_bicepcurl)
@app.route("/pushups")
def start_pushups_async():
global_state.exercise = "pushups"
return start_exercise_async(start_pushups)
@app.route("/squats")
def start_squats_async():
global_state.exercise = "squats"
return start_exercise_async(start_squats)
@app.route("/leaderboarddata")
def get_leaderboards():
sorted_board = global_state.get_leaderboard()
print(jsonify(sorted_board))
return jsonify(sorted_board)
@app.route("/stop")
def stop_exercise():
global_state.continue_training = False
while not global_state.stopped:
a = 1
global_state.stopped = False
global_state.continue_training = True
print("The rep count is ", global_state.rep_count, global_state.name)
global_state.update_leaderboard()
global_state.save_leaderboard()
return jsonify(rep_count = global_state.rep_count)
@app.route("/closeall")
def close_all():
exit()
def start_exercise_async(excercise_function):
global_state.name = request.args['name']
print(global_state.name)
exercise_thread = Thread(target = excercise_function)
exercise_thread.daemon = True
exercise_thread.start()
return jsonify(exercise_status = "started")
# @app.route("/bot")
# def startTrainerBot():
# startBot()
# return "nothing just run bot"
# @app.route("/botintro")
# def startTrainerBotIntro():
# greet = startBotGreeting()
# return jsonify(buttonName = "Your Name?",botanswers=greet)
# @app.route("/humanIntro")
# def startTrainerHumanIntro():
# greet = humanIntroduction()
# return jsonify(buttonName = "Hey there!",botanswers=greet)
# @app.route("/askExercise")
# def startTrainerAskExercise():
# greet = askExercise()
# if "Great" in greet:
# demo.start_planks(0)
# return jsonify(buttonName = "Lets do it!",botanswers=greet)
# @app.route("/trainer")
# def startTrainerForced():
# demo.start_planks(1)
# return "nothing"
if __name__ == "__main__":
# app.run(debug=True)
socketio.run(app)