Search Results
7/18/2025, 12:45:16 PM
>this section tracks the player and player match history
import datetime
class Match:
def __init__(self, timestamp, result): # 'W' or 'L'
self.timestamp = timestamp
self.result = result
class Player:
def __init__(self, matches):
self.matches = sorted(matches, key=lambda m: m.timestamp)
def hours_since_last_match(self):
if not self.matches: return float('inf')
return (datetime.datetime.now() - self.matches[-1].timestamp).total_seconds() / 3600
>this section tracks how long since they played their last match and if they're on a streak as defined by the company
def hours_since_last_match(self):
if not self.matches: return float('inf')
return (datetime.datetime.now() - self.matches[-1].timestamp).total_seconds() / 3600
def last_streaks(self, n=5):
streaks, current = [], {'r': None, 'len': 0}
for m in self.matches:
if m.result == current['r']: current['len'] += 1
else:
if current['len']: streaks.append(current.copy())
current = {'r': m.result, 'len': 1}
if current['len']: streaks.append(current)
return streaks[-n:]
>if the player quits after a certain amount of losses or variable wins that are insufficient to keep them playing past the retention threshold, they are likely to quit the game
def churn_risk(self):
hours = self.hours_since_last_match()
streaks = self.last_streaks()
balance = sum(1 if s['r'] == 'W' else -1 for s in streaks)
if hours > 72: return True
if any(s['r'] == 'L' and s['len'] >= 3 for s in streaks) and hours > 24: return True
if balance >= 4 or balance <= -3: return True
return False
import datetime
class Match:
def __init__(self, timestamp, result): # 'W' or 'L'
self.timestamp = timestamp
self.result = result
class Player:
def __init__(self, matches):
self.matches = sorted(matches, key=lambda m: m.timestamp)
def hours_since_last_match(self):
if not self.matches: return float('inf')
return (datetime.datetime.now() - self.matches[-1].timestamp).total_seconds() / 3600
>this section tracks how long since they played their last match and if they're on a streak as defined by the company
def hours_since_last_match(self):
if not self.matches: return float('inf')
return (datetime.datetime.now() - self.matches[-1].timestamp).total_seconds() / 3600
def last_streaks(self, n=5):
streaks, current = [], {'r': None, 'len': 0}
for m in self.matches:
if m.result == current['r']: current['len'] += 1
else:
if current['len']: streaks.append(current.copy())
current = {'r': m.result, 'len': 1}
if current['len']: streaks.append(current)
return streaks[-n:]
>if the player quits after a certain amount of losses or variable wins that are insufficient to keep them playing past the retention threshold, they are likely to quit the game
def churn_risk(self):
hours = self.hours_since_last_match()
streaks = self.last_streaks()
balance = sum(1 if s['r'] == 'W' else -1 for s in streaks)
if hours > 72: return True
if any(s['r'] == 'L' and s['len'] >= 3 for s in streaks) and hours > 24: return True
if balance >= 4 or balance <= -3: return True
return False
Page 1