Skip to content

Commit

Permalink
Fix chart server error for other locales.
Browse files Browse the repository at this point in the history
  • Loading branch information
guydavis committed Jun 14, 2022
1 parent 03dcd28 commit 1fa4d51
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 8 additions & 0 deletions common/utils/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ def gib_to_fmt(gibs, target_unit=None):
else:
return sizeof_fmt(gibs * 1024 * 1024 * 1024)

def gib_to_float(gibs, target_unit):
num = gibs * 1024 * 1024 * 1024
for unit in ['B','KiB','MiB','GiB','TiB','PiB','EiB','ZiB', 'YiB']:
if target_unit == unit:
return float(num)
num /= 1024.0
raise Exception("Unsupported unit size of {0} for conversion from GiB.".format(target_unit))

def str_to_gibs(str):
if str == "Unknown":
return 0.0
Expand Down
8 changes: 2 additions & 6 deletions web/actions/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,14 +444,12 @@ def load_netspace_size(blockchain):
if (i == 0) or (i % 24 == 0) or (i == len(result) - 1):
dates.append(converted_date)
values.append(s.value)
#app.logger.info(dates)
if len(values) > 0:
unit = converters.gib_to_fmt(max(values)).split()[1]
converted_values = list(map(lambda x: float(converters.gib_to_fmt(x, target_unit=unit).split()[0]), values))
converted_values = list(map(lambda x: converters.gib_to_float(x, unit), values))
else:
unit = 'B'
converted_values = []
#app.logger.info(converted_values)
return { 'title': blockchain.capitalize() + ' - ' + _('Netspace Size'), 'dates': dates, 'vals': converted_values,
'y_axis_title': _('Size') + ' (' + unit + ')'}

Expand Down Expand Up @@ -506,14 +504,12 @@ def load_plots_size(blockchain):
dates.append(converted_date)
values.append(s.value)
last_value = s.value
#app.logger.info(dates)
if len(values) > 0:
unit = converters.gib_to_fmt(max(values)).split()[1]
converted_values = list(map(lambda x: float(converters.gib_to_fmt(x, target_unit=unit).split()[0]), values))
converted_values = list(map(lambda x: converters.gib_to_float(x, unit), values))
else:
unit = 'B'
converted_values = []
#app.logger.info(converted_values)
return { 'title': blockchain.capitalize() + ' - ' + _('Plots Size'), 'dates': dates, 'vals': converted_values,
'y_axis_title': _('Size') + ' (' + unit + ')'}

Expand Down

0 comments on commit 1fa4d51

Please sign in to comment.