Skip to content

Commit

Permalink
add + prefix if percent change is positive
Browse files Browse the repository at this point in the history
  • Loading branch information
philshem committed Sep 3, 2020
1 parent 9db6014 commit b9f8d36
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions assets/py/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@ def write_data(p, d, html, birth_value, latest, R=2):
html = html.replace('{{birthvalue}}',str(birth_value))

# {{currentvalue}}
#print(latest.values())
current_value = list(latest.values())[0]
current_value = round(current_value,R)
html = html.replace('{{currentvalue}}',str(current_value))

# {{percentchange}}
percent_change = 100.0 * (current_value - birth_value) / birth_value
percent_change = round(percent_change,1)
html = html.replace('{{percentchange}}',str(percent_change))
prefix = ''
if percent_change > 0:
prefix = '+'

html = html.replace('{{percentchange}}',prefix+str(percent_change))

with open(p+os.sep+'index.html', 'w') as fp:
fp.write(html)
Expand Down

0 comments on commit b9f8d36

Please sign in to comment.