Page MenuHomePhabricator

'Current Day' reporting in Superset
Closed, ResolvedPublic

Description

The default time grain for reporting in Superset appears to be 'Last X [days/weeks/etc]'. Is there a way to get a default 'Current [day/week/month] time grain for live dashboards?

Event Timeline

EYener created this task.May 7 2020, 12:15 PM
Jgreen removed Jgreen as the assignee of this task.May 7 2020, 1:17 PM
Jgreen moved this task from Triage to Watching on the fundraising-tech-ops board.
DStrine moved this task from Triage to FR-Ops on the Fundraising-Backlog board.May 11 2020, 8:16 PM
Jgreen added a comment.EditedMay 27 2020, 7:52 PM

Spelunking code since I can't find any documentation...time grains appear to be backend-specific, so for mysql I think the list is in /srv/superset/venv/lib/python3.7/site-packages/superset/db_engine_specs/mysql.py:

_time_grain_functions = {
    None: "{col}",
    "PT1S": "DATE_ADD(DATE({col}), "
    "INTERVAL (HOUR({col})*60*60 + MINUTE({col})*60"
    " + SECOND({col})) SECOND)",
    "PT1M": "DATE_ADD(DATE({col}), "
    "INTERVAL (HOUR({col})*60 + MINUTE({col})) MINUTE)",
    "PT1H": "DATE_ADD(DATE({col}), " "INTERVAL HOUR({col}) HOUR)",
    "P1D": "DATE({col})",
    "P1W": "DATE(DATE_SUB({col}, " "INTERVAL DAYOFWEEK({col}) - 1 DAY))",
    "P1M": "DATE(DATE_SUB({col}, " "INTERVAL DAYOFMONTH({col}) - 1 DAY))",
    "P0.25Y": "MAKEDATE(YEAR({col}), 1) "
    "+ INTERVAL QUARTER({col}) QUARTER - INTERVAL 1 QUARTER",
    "P1Y": "DATE(DATE_SUB({col}, " "INTERVAL DAYOFYEAR({col}) - 1 DAY))",
    "1969-12-29T00:00:00Z/P1W": "DATE(DATE_SUB({col}, "
    "INTERVAL DAYOFWEEK(DATE_SUB({col}, "
    "INTERVAL 1 DAY)) - 1 DAY))",
}

There are some related configuration options in /srv/superset/venv/lib/python3.7/site-packages/superset/config.py:

# ---------------------------------------------------
# Time grain configurations
# ---------------------------------------------------
# List of time grains to disable in the application (see list of builtin
# time grains in superset/db_engine_specs.builtin_time_grains).
# For example: to disable 1 second time grain:
# TIME_GRAIN_BLACKLIST = ['PT1S']
TIME_GRAIN_BLACKLIST: List[str] = []

# Additional time grains to be supported using similar definitions as in
# superset/db_engine_specs.builtin_time_grains.
# For example: To add a new 2 second time grain:
# TIME_GRAIN_ADDONS = {'PT2S': '2 second'}
TIME_GRAIN_ADDONS: Dict[str, str] = {}

# Implementation of additional time grains per engine.
# For example: To implement 2 second time grain on clickhouse engine:
# TIME_GRAIN_ADDON_FUNCTIONS = {
#     'clickhouse': {
#         'PT2S': 'toDateTime(intDiv(toUInt32(toDateTime({col})), 2)*2)'
#     }
# }
TIME_GRAIN_ADDON_FUNCTIONS: Dict[str, Dict[str, str]] = {}

I can see how TIME_GRAIN_BLACKLIST would be used, but am unclear how a unified configuration option would relate to the per-backend built-in ones above, i.e. how can one addon work for all the different possible backends.

Hi @Jgreen I actually found a hack for current day (within the UI) by searching Stack Overflow. The time grain supports selecting "today:tomorrow" for current day reporting and I believe there are other work-arounds within the UI for month to date and year to date. It's not intuitive based on their selections but I don't believe this requires a code-level change - just more self-education!

Jgreen closed this task as Resolved.May 27 2020, 8:17 PM
Jgreen claimed this task.
Jgreen triaged this task as Medium priority.
Jgreen moved this task from Watching to Done on the fundraising-tech-ops board.

Hi @Jgreen I actually found a hack for current day (within the UI) by searching Stack Overflow. The time grain supports selecting "today:tomorrow" for current day reporting and I believe there are other work-arounds within the UI for month to date and year to date. It's not intuitive based on their selections but I don't believe this requires a code-level change - just more self-education!

Ok great, then I'll close the task.