2023-05-19 10:02:29 +02:00
|
|
|
from flask import Flask, jsonify, Response, request
|
2023-06-10 11:10:33 +02:00
|
|
|
from camera import Camera
|
2023-06-16 19:20:29 +02:00
|
|
|
from game import Game
|
2023-05-19 10:02:29 +02:00
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
2023-05-22 20:43:51 +02:00
|
|
|
my_game = Game()
|
2023-06-10 11:10:33 +02:00
|
|
|
my_camera = Camera()
|
2023-05-19 10:02:29 +02:00
|
|
|
|
2023-05-23 19:14:00 +02:00
|
|
|
@app.route('/question', methods=['GET'])
|
2023-05-22 20:43:51 +02:00
|
|
|
def get_question():
|
2023-05-23 19:14:00 +02:00
|
|
|
my_game.get_question()
|
2023-05-26 19:55:32 +02:00
|
|
|
print(my_game.question)
|
2023-05-23 19:14:00 +02:00
|
|
|
return jsonify(my_game.question)
|
2023-05-19 10:02:29 +02:00
|
|
|
|
|
|
|
@app.route('/teamsize', methods=['POST'])
|
|
|
|
def teamsize():
|
|
|
|
team_size = request.json
|
2023-05-22 20:43:51 +02:00
|
|
|
my_game.set_teamsize(team_size.get('teamsize'))
|
2023-05-26 19:55:32 +02:00
|
|
|
print(f'Teamsize: {my_game.teamsize}\n')
|
2023-05-19 10:02:29 +02:00
|
|
|
return Response(status=200)
|
|
|
|
|
|
|
|
@app.route('/scoreboard', methods=['GET'])
|
|
|
|
def scoreboard():
|
2023-05-26 19:55:32 +02:00
|
|
|
print(my_game.scoreboard)
|
|
|
|
return jsonify(my_game.scoreboard)
|
2023-05-19 10:02:29 +02:00
|
|
|
|
|
|
|
@app.route('/check', methods=['GET'])
|
|
|
|
def check():
|
2023-06-16 19:20:29 +02:00
|
|
|
my_camera.start_process = True
|
|
|
|
my_camera.correct_field_frame = my_game.field
|
2023-06-22 09:41:54 +02:00
|
|
|
my_camera.process()
|
2023-06-16 19:20:29 +02:00
|
|
|
my_game.set_scoreboard(my_camera.scores)
|
|
|
|
my_camera.start_process = False
|
|
|
|
return jsonify(my_game.scoreboard)
|
2023-05-19 10:02:29 +02:00
|
|
|
|
|
|
|
@app.route('/reset', methods=['GET'])
|
|
|
|
def reset():
|
2023-05-22 20:43:51 +02:00
|
|
|
my_game.reset_game()
|
2023-05-19 10:02:29 +02:00
|
|
|
return Response(status=200)
|
|
|
|
|
2023-05-23 19:14:00 +02:00
|
|
|
@app.route('/scores', methods=['POST'])
|
2023-05-22 20:43:51 +02:00
|
|
|
def get_scores():
|
2023-05-23 19:14:00 +02:00
|
|
|
scores = request.json
|
|
|
|
my_game.add_score(scores)
|
|
|
|
return Response(status=200)
|
2023-05-19 10:02:29 +02:00
|
|
|
|
2023-05-26 19:55:32 +02:00
|
|
|
@app.route('/winner', methods=['GET'])
|
|
|
|
def set_winner():
|
|
|
|
my_game.final_result()
|
|
|
|
return jsonify(my_game.final_score)
|
|
|
|
|
2023-05-19 10:02:29 +02:00
|
|
|
def main():
|
2023-05-26 19:55:32 +02:00
|
|
|
## Router
|
2023-06-10 11:10:33 +02:00
|
|
|
app.run(host='192.168.50.79', port=5555, debug=True)
|
2023-05-19 10:02:29 +02:00
|
|
|
|
|
|
|
## Postman
|
2023-06-10 11:10:33 +02:00
|
|
|
# app.run(host='127.0.0.1', port=5555, debug=True)
|
2023-05-22 20:43:51 +02:00
|
|
|
|
|
|
|
|
2023-05-19 10:02:29 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|