import 'dart:convert'; class Statistics { int id = 0; late String gameId; late int start; int end = 0; int jump = 0; int squat = 0; int step = 0; int distance = 0; int level = 0; double score = 0.0; int record = 0; int mode = 0; int opponentId = 0; int status = 1; List data = List.filled(MOTION_COUNT_TYPE.values.length, 0); Statistics(); Statistics.name(this.gameId, this.start); Map toJson() { final Map data = new Map(); data['game_id'] = this.gameId; data['start_time'] = this.start; data['end_time'] = this.end; data['jump'] = this.jump; data['squat'] = this.squat; data['step'] = this.step; data['distance'] = this.step; data['level'] = this.level; data['score'] = this.score; data['mode'] = this.mode; data['opponent_id'] = this.opponentId; data['data'] = json.encode(this.data); data['status'] = this.status; return data; } String get movements { return convertMovements(this.data); } static String convertMovements(List data) { List args = ["step", "jump", "crouch", "tick", "scissors", "rock", "paper", "trample"]; Map params = {}; for (var i = 0; i < data.length; i++) { params[args[i]] = data[i]; } params["trample"] = params["step"] ?? 0; return json.encode(params); } } enum MOTION_COUNT_TYPE { STEP_COUNT, JUMP_COUNT, DOWN_COUNT, KICK_COUNT, PAPER_COUNT, SCISSORS_COUNT, ROCK_COUNT, }