statistics.dart 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import 'dart:convert';
  2. class Statistics {
  3. int id = 0;
  4. late String gameId;
  5. late int start;
  6. int end = 0;
  7. int jump = 0;
  8. int squat = 0;
  9. int step = 0;
  10. int distance = 0;
  11. int level = 0;
  12. double score = 0.0;
  13. int record = 0;
  14. int mode = 0;
  15. int opponentId = 0;
  16. int status = 1;
  17. List<int> data = List.filled(MOTION_COUNT_TYPE.values.length, 0);
  18. Statistics();
  19. Statistics.name(this.gameId, this.start);
  20. Map<String, dynamic> toJson() {
  21. final Map<String, dynamic> data = new Map<String, dynamic>();
  22. data['game_id'] = this.gameId;
  23. data['start_time'] = this.start;
  24. data['end_time'] = this.end;
  25. data['jump'] = this.jump;
  26. data['squat'] = this.squat;
  27. data['step'] = this.step;
  28. data['distance'] = this.step;
  29. data['level'] = this.level;
  30. data['score'] = this.score;
  31. data['mode'] = this.mode;
  32. data['opponent_id'] = this.opponentId;
  33. data['data'] = json.encode(this.data);
  34. data['status'] = this.status;
  35. return data;
  36. }
  37. String get movements {
  38. return convertMovements(this.data);
  39. }
  40. static String convertMovements(List<dynamic> data) {
  41. List<String> args = ["step", "jump", "crouch", "tick", "scissors", "rock", "paper", "trample"];
  42. Map<String, int> params = {};
  43. for (var i = 0; i < data.length; i++) {
  44. params[args[i]] = data[i];
  45. }
  46. params["trample"] = params["step"] ?? 0;
  47. return json.encode(params);
  48. }
  49. }
  50. enum MOTION_COUNT_TYPE {
  51. STEP_COUNT,
  52. JUMP_COUNT,
  53. DOWN_COUNT,
  54. KICK_COUNT,
  55. PAPER_COUNT,
  56. SCISSORS_COUNT,
  57. ROCK_COUNT,
  58. }