|
11 | 11 |
|
12 | 12 | from carball.analysis.utils.proto_manager import ProtobufManager
|
13 | 13 | from flask import jsonify, Blueprint, current_app, request, send_from_directory, Response
|
| 14 | +from sqlalchemy import desc |
14 | 15 | from werkzeug.utils import secure_filename, redirect
|
15 | 16 |
|
16 | 17 | from backend.blueprints.spa_api.service_layers.homepage.patreon import PatreonProgress
|
|
25 | 26 | player_id, heatmap_query_params
|
26 | 27 | from backend.database.startup import lazy_get_redis
|
27 | 28 | from backend.tasks.add_replay import create_replay_task, parsed_replay_processing
|
| 29 | +from backend.tasks.celery_tasks import create_training_pack |
28 | 30 | from backend.utils.logging import ErrorLogger
|
29 | 31 | from backend.utils.global_functions import get_current_user_id
|
30 | 32 | from backend.blueprints.spa_api.service_layers.replay.visualizations import Visualizations
|
|
45 | 47 | REPLAY_BUCKET = config.REPLAY_BUCKET
|
46 | 48 | PROTO_BUCKET = config.PROTO_BUCKET
|
47 | 49 | PARSED_BUCKET = config.PARSED_BUCKET
|
| 50 | + TRAINING_PACK_BUCKET = config.TRAINING_PACK_BUCKET |
48 | 51 | except:
|
49 | 52 | print('Not uploading to buckets')
|
50 | 53 | REPLAY_BUCKET = ''
|
51 | 54 | PROTO_BUCKET = ''
|
52 | 55 | PARSED_BUCKET = ''
|
| 56 | + TRAINING_PACK_BUCKET = '' |
53 | 57 |
|
54 | 58 | from backend.blueprints.spa_api.service_layers.stat import get_explanations
|
55 | 59 | from backend.blueprints.spa_api.service_layers.utils import with_session
|
56 | 60 | from backend.blueprints.steam import get_vanity_to_steam_id_or_random_response, steam_id_to_profile
|
57 |
| -from backend.database.objects import Game, GameVisibilitySetting |
| 61 | +from backend.database.objects import Game, GameVisibilitySetting, TrainingPack |
58 | 62 | from backend.database.wrapper.chart.chart_data import convert_to_csv
|
59 | 63 | from backend.tasks import celery_tasks
|
60 | 64 | from backend.blueprints.spa_api.errors.errors import CalculatedError, NotYetImplemented, PlayerNotFound, \
|
|
76 | 80 | from backend.blueprints.spa_api.utils.decorators import require_user, with_query_params
|
77 | 81 | from backend.blueprints.spa_api.utils.query_params_handler import QueryParam, get_query_params
|
78 | 82 |
|
| 83 | +try: |
| 84 | + from backend.tasks.training_packs.task import TrainingPackCreation |
| 85 | +except (ModuleNotFoundError, ImportError): |
| 86 | + TrainingPackCreation = None |
| 87 | + print("Missing config or AES Key and CRC, not creating training packs") |
| 88 | + |
79 | 89 | logger = logging.getLogger(__name__)
|
80 | 90 |
|
81 | 91 | bp = Blueprint('api', __name__, url_prefix='/api/')
|
@@ -270,8 +280,12 @@ def api_get_replay_basic_team_stats_download(id_):
|
270 | 280 |
|
271 | 281 |
|
272 | 282 | @bp.route('replay/<id_>/positions')
|
273 |
| -@with_query_params(accepted_query_params=[QueryParam(name='frame', type_=int, optional=True, is_list=True), |
274 |
| - QueryParam(name='as_proto', type_=bool, optional=True)]) |
| 283 | +@with_query_params(accepted_query_params=[ |
| 284 | + QueryParam(name='frame', type_=int, optional=True, is_list=True), |
| 285 | + QueryParam(name='frame_start', type_=int, optional=True), |
| 286 | + QueryParam(name='frame_count', type_=int, optional=True), |
| 287 | + QueryParam(name='as_proto', type_=bool, optional=True) |
| 288 | +]) |
275 | 289 | def api_get_replay_positions(id_, query_params=None):
|
276 | 290 | positions = ReplayPositions.create_from_id(id_, query_params=query_params)
|
277 | 291 | if query_params is None or 'as_proto' not in query_params:
|
@@ -514,6 +528,31 @@ def api_handle_error(error: CalculatedError):
|
514 | 528 | return response
|
515 | 529 |
|
516 | 530 |
|
| 531 | +@bp.route('/training/create') |
| 532 | +@require_user |
| 533 | +@with_query_params(accepted_query_params=[ |
| 534 | + QueryParam(name="date_start", type_=str, optional=True), |
| 535 | + QueryParam(name="date_end", type_=str, optional=True) |
| 536 | +]) |
| 537 | +def api_create_trainingpack(query_params=None): |
| 538 | + date_start = None |
| 539 | + date_end = None |
| 540 | + if 'date_start' in query_params: |
| 541 | + date_start = query_params['date_start'] |
| 542 | + if 'date_end' in query_params: |
| 543 | + date_end = query_params['date_end'] |
| 544 | + task = create_training_pack.delay(get_current_user_id(), 10, date_start, date_end) |
| 545 | + return better_jsonify({'status': 'Success', 'id': task.id}) |
| 546 | + |
| 547 | + |
| 548 | +@bp.route('/training/list') |
| 549 | +@require_user |
| 550 | +@with_session |
| 551 | +def api_find_trainingpack(session=None): |
| 552 | + player = get_current_user_id() |
| 553 | + return better_jsonify(TrainingPackCreation.list_packs(player, session)) |
| 554 | + |
| 555 | + |
517 | 556 | # Homepage
|
518 | 557 |
|
519 | 558 | @bp.route('/home/twitch')
|
|
0 commit comments