def value_unit_to_number(self, param, value):
     # string is of the form "32.3L"
     unit = value[-1]
     #v = float(value[:-1])
     v = self.str_to_float(param, value[:-1])
     if (Unit.get(param) != unit):
         v = Unit.convert(unit, Unit.get(param), v)
     return round(v, self.precision)
Example #2
0
 def __init__(self, sport, xparam, yparam, xvals = None, yvals = None):
     self.xparam = xparam
     self.yparam = yparam
     self.sport = sport
     if (xvals is None):
         xvals = []
     if (yvals is None):
         yvals = []
     self.xvals = xvals
     self.yvals = yvals
     self.xlabel = self.xparam + " (%s)"%(Unit.get(self.xparam))
     self.ylabel = self.yparam + " (%s)"%(Unit.get(self.yparam))
 def value_space_unit_to_number(self, param, value):
     # default format is "<value> <unit>"
     if (value == "-"):
         raise InvalidValueException(param, value)
     parts = value.split()
     unit = parts[1]
     if (unit == "min/mi" and (":" in parts[0])):
         v_parts = parts[0].split(":")
         #v = float(v_parts[0]) + float(v_parts[1])/60.0  # convert to float minutes value
         v = self.str_to_float(param, v_parts[0]) + self.str_to_float(param, v_parts[1])/60.0  # convert to float minutes value
     else:
         #v = float(parts[0])
         v = self.str_to_float(param, parts[0])
     if (Unit.get(param) != unit):
         v = Unit.convert(unit, Unit.get(param), v)
     return round(v, self.precision)
 def duration_to_number(self, param, value):
     # the value is of the form 16m:31s
     parts = value.split(":")
     v = 0
     assert(param == "Duration")
     assert(Unit.get("Duration") == "s")  # following code assumes the unit is seconds
     for p in parts:
         #p_value = int(p[0:len(p) - 1])
         p_value = self.str_to_float(param, p[0:len(p) - 1])
         p_unit = p[len(p) - 1]
         if (p_unit == "s"):
             v += p_value
         elif(p_unit == "m"):
             v += p_value * 60
         elif(p_unit == "h"):
             v += p_value * 3600
         elif(p_unit == "d"):
             v += p_value * 86400
         else:
             raise Exception("Invalid time unit.. param = %s, value = %s" % (param, value))
     return v