main.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import json
  2. from calc_scores import calc_scores
  3. from firebase import pushToFirebase
  4. from games import get_history, get_games_serializable
  5. from leader import leadersStorage
  6. from nations import nations_storage
  7. from players_storage import playerStorage
  8. def main():
  9. games = get_history()
  10. for i in range(len(games)):
  11. calc_scores(games[i])
  12. # print('Результаты партии ' + str(i + 1))
  13. playerStorage.sort()
  14. # Наивысшую/Низшую и изменение позиции
  15. for j in range(len(playerStorage.players)):
  16. playerStorage.players[j].top_position = min(playerStorage.players[j].top_position, j + 1)
  17. playerStorage.players[j].lowest_position = max(playerStorage.players[j].lowest_position, j + 1)
  18. playerStorage.players[j].change_position = playerStorage.players[j].previous_position - j - 1
  19. playerStorage.players[j].previous_position = j + 1
  20. # playerStorage.print()
  21. # print()
  22. res_json = dict()
  23. res_json['players'] = playerStorage.get_serializable()
  24. res_json['games'] = get_games_serializable(games)
  25. res_json['leaders'] = leadersStorage.get_serializable()
  26. res_json['nations'] = nations_storage.get_serializable()
  27. pushToFirebase(res_json)
  28. with open('data.json', 'w', encoding='utf-8') as f:
  29. json.dump(res_json, f, ensure_ascii=False, indent=4)
  30. # for game in games:
  31. # game.print()
  32. # ps.sort()
  33. # ps.print()
  34. if __name__ == "__main__":
  35. main()