Thibault Duplessis commited on
Commit
3d714ae
·
1 Parent(s): 8044210

proper __str__ for models

Browse files
Files changed (2) hide show
  1. main.py +4 -4
  2. model.py +14 -5
main.py CHANGED
@@ -66,7 +66,7 @@ def start(li, user_profile, max_games, max_queued, engine_factory, config):
66
  else:
67
  try:
68
  li.decline_challenge(chlng.id)
69
- print(" Decline {}".format(chlng.show()))
70
  except HTTPError as exception:
71
  if exception.response.status_code != 404: # ignore missing challenge
72
  raise exception
@@ -84,12 +84,12 @@ def start(li, user_profile, max_games, max_queued, engine_factory, config):
84
  chlng = challenge_queue.pop(0)
85
  try:
86
  response = li.accept_challenge(chlng.id)
87
- print(" Accept {}".format(chlng.show()))
88
  queued_processes += 1
89
  print("--- Process Queue. Total Queued: {}. Total Used: {}".format(queued_processes, busy_processes))
90
  except HTTPError as exception:
91
  if exception.response.status_code == 404: # ignore missing challenge
92
- print(" Skip missing {}".format(chlng.show()))
93
  else:
94
  raise exception
95
 
@@ -108,7 +108,7 @@ def play_game(li, game_id, control_queue, engine_factory):
108
  conversation = Conversation(game, engine, li)
109
  abort_at = time.time() + 20
110
 
111
- print("+++ {}".format(game.show()))
112
 
113
  engine.pre_game(game)
114
 
 
66
  else:
67
  try:
68
  li.decline_challenge(chlng.id)
69
+ print(" Decline {}".format(chlng))
70
  except HTTPError as exception:
71
  if exception.response.status_code != 404: # ignore missing challenge
72
  raise exception
 
84
  chlng = challenge_queue.pop(0)
85
  try:
86
  response = li.accept_challenge(chlng.id)
87
+ print(" Accept {}".format(chlng))
88
  queued_processes += 1
89
  print("--- Process Queue. Total Queued: {}. Total Used: {}".format(queued_processes, busy_processes))
90
  except HTTPError as exception:
91
  if exception.response.status_code == 404: # ignore missing challenge
92
+ print(" Skip missing {}".format(chlng))
93
  else:
94
  raise exception
95
 
 
108
  conversation = Conversation(game, engine, li)
109
  abort_at = time.time() + 20
110
 
111
+ print("+++ {}".format(game))
112
 
113
  engine.pre_game(game)
114
 
model.py CHANGED
@@ -22,8 +22,11 @@ class Challenge():
22
  modes = config["supported_modes"]
23
  return self.is_supported_speed(tc) and self.is_supported_variant(variants) and self.is_supported_mode(modes)
24
 
25
- def show(self):
26
- return "{} challenge from {}".format(self.perf_name, self.challenger)
 
 
 
27
 
28
  class Game():
29
  def __init__(self, json, username, base_url):
@@ -49,8 +52,11 @@ class Game():
49
  def url(self):
50
  return "{}/{}/{}".format(self.base_url, self.id, self.my_color)
51
 
52
- def show(self):
53
- return "{} {} vs {}".format(self.url(), self.perf_name, self.opponent.show())
 
 
 
54
 
55
 
56
  class Player():
@@ -62,9 +68,12 @@ class Player():
62
  self.provisional = json.get("provisional")
63
  self.aiLevel = json.get("aiLevel")
64
 
65
- def show(self):
66
  if self.aiLevel:
67
  return "AI level {}".format(self.aiLevel)
68
  else:
69
  rating = "{}{}".format(self.rating, "?" if self.provisional else "")
70
  return "{}{}({})".format(self.title + " " if self.title else "", self.name, rating)
 
 
 
 
22
  modes = config["supported_modes"]
23
  return self.is_supported_speed(tc) and self.is_supported_variant(variants) and self.is_supported_mode(modes)
24
 
25
+ def __str__(self):
26
+ return "{} challenge from {}({})".format(self.perf_name, self.challengerName, self.challengerRating)
27
+
28
+ def __repr__(self):
29
+ return self.__str__()
30
 
31
  class Game():
32
  def __init__(self, json, username, base_url):
 
52
  def url(self):
53
  return "{}/{}/{}".format(self.base_url, self.id, self.my_color)
54
 
55
+ def __str__(self):
56
+ return "{} {} vs {}".format(self.url(), self.perf_name, self.opponent.__str__())
57
+
58
+ def __repr__(self):
59
+ return self.__str__()
60
 
61
 
62
  class Player():
 
68
  self.provisional = json.get("provisional")
69
  self.aiLevel = json.get("aiLevel")
70
 
71
+ def __str__(self):
72
  if self.aiLevel:
73
  return "AI level {}".format(self.aiLevel)
74
  else:
75
  rating = "{}{}".format(self.rating, "?" if self.provisional else "")
76
  return "{}{}({})".format(self.title + " " if self.title else "", self.name, rating)
77
+
78
+ def __repr__(self):
79
+ return self.__str__()