Changeset - 2a3c04d47300
[Not reviewed]
default
0 2 0
Laman - 3 years ago 2021-10-20 11:50:32

limited promotion when pushing the personal best
2 files changed with 9 insertions and 1 deletions:
0 comments (0 inline, 0 general)
rank_progress.py
Show inline comments
 
@@ -36,6 +36,7 @@ class RankTracker:
 
	def __init__(self, rating):
 
		assert rating >= -900
 
		self._rounded_rating = round_rating(rating)
 
		self._best = self._rounded_rating
 

	
 
	@property
 
	def rank(self):
 
@@ -53,15 +54,22 @@ class RankTracker:
 
		if rounded_rating == self._rounded_rating:
 
			pass
 
		elif rounded_rating > self._rounded_rating:  # promotion
 
			# when pushing the best by 2 and more ranks you have to cross the hundred, not just the fifty
 
			if rounded_rating >= self._best+200 and rating < rounded_rating:
 
				self._rounded_rating = rounded_rating-100
 
			else:
 
			self._rounded_rating = rounded_rating
 
		else:  # demotion
 
			# 100 points for 5k and better
 
			if self._rounded_rating >= 1600 and self._rounded_rating - rating > 100:
 
				self._rounded_rating = rounded_rating
 
			# 150 points for the others
 
			elif self._rounded_rating - rating > 150:
 
				self._rounded_rating = rounded_rating+100
 
			else:
 
				pass
 

	
 
		self._best = max(self._best, self._rounded_rating)
 
		new_rank = self.rank
 
		return new_rank if new_rank != old_rank else False
 

	
test.py
Show inline comments
 
@@ -18,7 +18,7 @@ class TestRankTracker(TestCase):
 
		# 2+ ranks leaps
 

	
 
		# limited when pushing the personal best
 
		self.skipTest("not yet implemented")
 
		# self.skipTest("not yet implemented")
 
		t = RankTracker(1100)
 
		self.assertEqual(t.update(1299), "9k")
 
		self.assertEqual(t.update(1250), "8k")
0 comments (0 inline, 0 general)