Beispiel #1
0
def dashboard_summary():
    """
    Amalgamates all useful data for a live dashboard to reduce number of http calls
    """
    return _wrap_result(
        dict(
            yesterday=DaySummary(DateUtil.yesterday().date()).stats_json(),
            month=MonthSummary.for_this_month().stats(),
            year=YearSummary.for_this_year().stats(),
            astronomy=get_all_times_rwc(),
        ))
Beispiel #2
0
def _var_avg_exts_from_request(var: str, typ: str) -> List[AvgExt]:
    if "year" in request.args:
        year = int(request.args.get("year", DateUtil.now().year))
        avg_ext = AvgExtQ.for_var_and_year(var, typ, year)
    else:
        if "start" in request.args:
            start = DateStampConverter.from_str(request.args["start"])
        else:
            n = int(request.args.get("n", "31"))
            start = DateUtil.now() - timedelta(days=n)

        if "end" in request.args:
            end = DateStampConverter.from_str(request.args["end"])
        elif "include_today" in request.args or DateUtil.now().hour >= 21:
            end = None
        else:
            end = DateUtil.yesterday()

        avg_ext = AvgExtQ.for_var_between_dates(var, typ, start, end)

    return avg_ext