Created
January 4, 2015 04:58
-
-
Save reillysiemens/7e35d4c08be60a6651a5 to your computer and use it in GitHub Desktop.
Stats for your Steam!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import re | |
from collections import namedtuple | |
INTERESTING_THRESHOLD = 7.5 # Interesting threshold. | |
DISINTERESTING_THRESHOLD = 2.0 # Disinteresting threshold. | |
r = re.compile("(.*)\n(\d*.\d*) hrs on record") # Regex for name/hours | |
Game = namedtuple('Game', 'name, hours') # Namedtuple for easy record access. | |
# ---- INPUT ------------------------------------------------------------------- | |
""" | |
SAMPLE FILE INPUT: | |
The Elder Scrolls V: Skyrim | |
133 hrs on record | |
Borderlands | |
32 hrs on record | |
Dear Esther | |
2.0 hrs on record | |
System Shock 2 | |
0.1 hrs on record | |
Starbound | |
0.0 hrs on record | |
""" | |
# Read in the data set and break up according to game name and hours played. | |
with open('all_games.txt', 'r') as game_file: | |
file_string = game_file.read() | |
matches = r.findall(file_string) | |
# ---- LISTS ------------------------------------------------------------------- | |
games = list(map(Game._make, matches)) # Get the list of all games. | |
names = [game.name for game in games] # Get the list of all game names. | |
hours = [float(game.hours) for game in games] # Get the list of all game hours. | |
# Get the list of all unplayed games. | |
unplayed = list(filter(lambda g: float(g.hours) == 0.0, games)) | |
# Get the list of all games above the INTERESTING THRESHOLD. | |
interesting = list(filter(lambda g: | |
float(g.hours) >= INTERESTING_THRESHOLD, games)) | |
# Get the list of all games below the DISINTERESTING THRESHOLD that are played. | |
disinteresting = list(filter(lambda g: | |
float(g.hours) <= DISINTERESTING_THRESHOLD | |
and (g not in unplayed), games)) | |
# Get the list of all games that haven't already been categorized. | |
moderately_interesting = list(filter(lambda g: (g not in interesting) | |
and (g not in disinteresting) | |
and (g not in unplayed), games)) | |
# ---- COUNTS ------------------------------------------------------------------ | |
# Count the total number of games. | |
num_games = len(games) | |
# Count the number of unplayed games. | |
num_unplayed = len(unplayed) | |
# Count the number of interesting games. | |
num_interesting = len(interesting) | |
# Count the number of disinteresting games. | |
num_disinteresting = len(disinteresting) | |
# Count the number of moderately interesting games. | |
num_moderately_interesting = len(moderately_interesting) | |
# ---- TIME -------------------------------------------------------------------- | |
# Get the total number of hours played. | |
total_game_hours = sum(hours) | |
# Get the total number of days played. | |
days_played = (total_game_hours / 24.0) | |
# Get the number of hours spent playing interesting games. | |
interesting_hours = sum([float(i.hours) for i in interesting]) | |
# Get the number of hours spent playing disinteresting games. | |
disinteresting_hours = sum([float(d.hours) for d in disinteresting]) | |
# Get the number of hours spent playing moderately interesting games. | |
moderately_interesting_hours = sum([float(m.hours) for m in | |
moderately_interesting]) | |
# ---- GAME PERCENTAGES -------------------------------------------------------- | |
# Get the percentage of games categorized as interesting. | |
interesting_game_percentage = (100 * (len(interesting) / num_games)) | |
# Get the percentage of games categorized as disinteresting. | |
disinteresting_game_percentage = (100 * (len(disinteresting) / num_games)) | |
# Get the percentage of games categorized as moderately interesting. | |
moderately_interesting_game_percentage = (100 * (len(moderately_interesting) / | |
num_games)) | |
# Get the percentage of games categorized as unplayed. | |
unplayed_game_percentage = (100 * (len(unplayed) / num_games)) | |
# ---- TIME PERCENTAGES -------------------------------------------------------- | |
# Get the percentage of hours spent playing interesting games. | |
interesting_hour_percentage = (100 * (interesting_hours / total_game_hours)) | |
# Get the percentage of hours spent playing disinteresting games. | |
disinteresting_hour_percentage = (100 * (disinteresting_hours / | |
total_game_hours)) | |
# Get the percentage of hours spent playing moderately interesting games. | |
moderately_interesting_hour_percentage = (100 * (moderately_interesting_hours / | |
total_game_hours)) | |
# ---- AVERAGES ---------------------------------------------------------------- | |
# Get the average number of hours spent playing all games. | |
average_hours_per_game = (total_game_hours / num_games) | |
# Get the average number of hours spent playing interesting games. | |
average_interesting_hours = (interesting_hours / len(interesting)) | |
# Get the average number of hours pent playing disinteresting games. | |
average_disinteresting_hours = (disinteresting_hours / len(disinteresting)) | |
# Get the average number of hours spent playing moderately interesting games. | |
average_moderately_interesting_hours = (moderately_interesting_hours / | |
len(moderately_interesting)) | |
# ---- OUPUT ------------------------------------------------------------------- | |
if __name__ == '__main__': | |
# Print a banner. | |
print((" ____ _ ____ _ _\n" | |
"/ ___|| |_ ___ __ _ _ __ ___ / ___|| |_ __ _| |_ ___\n" | |
"\___ \| __/ _ \/ _` | '_ ` _ \ \___ \| __/ _` | __/ __|\n" | |
" ___) | || __/ (_| | | | | | | ___) | || (_| | |_\__ \\\n" | |
"|____/ \__\___|\__,_|_| |_| |_| |____/ \__\__,_|\__|___/\n")) | |
# Print game percentage stats. | |
print("You own {0} games. Of those games...\n\n{1} ({2:.2f}%) are " | |
"interesting to you.\n{3} ({4:.2f}%) are moderately interesting to " | |
"you.\n{5} ({6:.2f}%) are disinteresting to you.\n{7} ({8:.2f}%) are " | |
"unplayed.\n".format(num_games, num_interesting, | |
interesting_game_percentage, | |
num_moderately_interesting, | |
moderately_interesting_game_percentage, | |
num_disinteresting, | |
disinteresting_game_percentage, num_unplayed, | |
unplayed_game_percentage)) | |
# Print time stats. | |
print("You spent {0:.2f} hours playing games. Of those hours...\n{1:.2f} " | |
"({2:.2f}%) were spent playing interesting games.\n{3:.2f} " | |
"({4:.2f}%) were spent playing moderately interesting games.\n" | |
"{5:.2f} ({6:.2f}%) were spent playing disinteresting " | |
"games.".format(total_game_hours, interesting_hours, | |
interesting_hour_percentage, | |
moderately_interesting_hours, | |
moderately_interesting_hour_percentage, | |
disinteresting_hours, disinteresting_hour_percentage)) | |
# Print average stats. | |
print("\nOn average you spend...\n{0:.2f} hours playing any given " | |
"game.\n{1:.2f} hours playing an interesting game.\n{2:.2f} hours " | |
"playing a moderately interesting game.\n{3:.2f} hours playing a " | |
"disinteresting game.\n".format(average_hours_per_game, | |
average_interesting_hours, | |
average_moderately_interesting_hours, | |
average_disinteresting_hours)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment