Those uppercase dict keys were annoying the hell out of me
This commit is contained in:
parent
63cf1f0514
commit
8ebf1e24ee
1 changed files with 7 additions and 7 deletions
|
@ -17,7 +17,7 @@ def is_number(s):
|
||||||
def unicode_dictreader(utf8_data, **kwargs):
|
def unicode_dictreader(utf8_data, **kwargs):
|
||||||
csv_reader = csv.DictReader(utf8_data, **kwargs)
|
csv_reader = csv.DictReader(utf8_data, **kwargs)
|
||||||
for row in csv_reader:
|
for row in csv_reader:
|
||||||
yield dict([(key, unicode(value, 'utf-8')) for key, value in row.iteritems()])
|
yield dict([(key.lower(), unicode(value, 'utf-8')) for key, value in row.iteritems()])
|
||||||
|
|
||||||
|
|
||||||
@hook.command('sc')
|
@hook.command('sc')
|
||||||
|
@ -51,27 +51,27 @@ def steamcalc(inp):
|
||||||
data["state"] = online_state # will make this pretty later
|
data["state"] = online_state # will make this pretty later
|
||||||
|
|
||||||
# work out the average metascore for all games
|
# work out the average metascore for all games
|
||||||
ms = [float(game["Metascore"]) for game in games if is_number(game["Metascore"])]
|
ms = [float(game["metascore"]) for game in games if is_number(game["metascore"])]
|
||||||
metascore = float(sum(ms))/len(ms) if len(ms) > 0 else float('nan')
|
metascore = float(sum(ms))/len(ms) if len(ms) > 0 else float('nan')
|
||||||
data["average_metascore"] = "{0:.1f}".format(metascore)
|
data["average_metascore"] = "{0:.1f}".format(metascore)
|
||||||
|
|
||||||
# work out the totals
|
# work out the totals
|
||||||
data["games"] = len(games)
|
data["games"] = len(games)
|
||||||
|
|
||||||
total_value = sum([float(game["Value"]) for game in games if is_number(game["Value"])])
|
total_value = sum([float(game["value"]) for game in games if is_number(game["value"])])
|
||||||
data["value"] = str(int(round(total_value)))
|
data["value"] = str(int(round(total_value)))
|
||||||
|
|
||||||
# work out the total size
|
# work out the total size
|
||||||
total_size = 0.0
|
total_size = 0.0
|
||||||
|
|
||||||
for game in games:
|
for game in games:
|
||||||
if not is_number(game["Size"]):
|
if not is_number(game["size"]):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if game["Unit"] == "GB":
|
if game["unit"] == "GB":
|
||||||
total_size += float(game["Size"])
|
total_size += float(game["size"])
|
||||||
else:
|
else:
|
||||||
total_size += float(game["Size"])/1024
|
total_size += float(game["size"])/1024
|
||||||
|
|
||||||
data["size"] = "{0:.1f}".format(total_size)
|
data["size"] = "{0:.1f}".format(total_size)
|
||||||
|
|
||||||
|
|
Reference in a new issue