def __new__(cls, value=None, **kwargs): output = object.__new__(cls) if value == None: if kwargs: output.milli = datetime.timedelta( **kwargs).total_seconds() * 1000 output.month = 0 return output else: return None if is_number(value): output._milli = float(value) * 1000 output.month = 0 return output elif is_text(value): return parse(value) elif isinstance(value, Duration): output.milli = value.milli output.month = value.month return output elif isinstance(value, float) and is_nan(value): return None else: from mo_logs import Log Log.error("Do not know type of object (" + get_module("mo_json").value2json(value) + ")of to make a Duration")
def __new__(cls, value=None, **kwargs): output = object.__new__(cls) if value == None: if kwargs: output.milli = datetime.timedelta(**kwargs).total_seconds() * 1000 output.month = 0 return output else: return None if is_number(value): output._milli = float(value) * 1000 output.month = 0 return output elif is_text(value): return parse(value) elif isinstance(value, Duration): output.milli = value.milli output.month = value.month return output elif isinstance(value, float) and is_nan(value): return None else: from mo_logs import Log Log.error("Do not know type of object (" + get_module("mo_json").value2json(value) + ")of to make a Duration")
def average_weekly(y, year): # RETURN AVERAGE OVER YEAR ENDING JULY 1 min = Date(year).floor(YEAR) - 6 * MONTH max = min + YEAR max_seen = min acc = 0 for value, (start, stop) in zip(deaths[y], _death_dates): if is_nan(value): continue if min < stop < max: max_seen = stop if min < start < max: acc += value else: ratio = (stop - min) / WEEK acc += value * ratio elif min < start < max: max_seen = max ratio = (max - start) / WEEK acc += value * ratio if is_nan(acc): Log.error("not expected") return acc * WEEK / (max_seen - min)