-
Notifications
You must be signed in to change notification settings - Fork 14.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow multiple time shifts #5067
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,7 +86,7 @@ def __init__(self, datasource, form_data, force=False): | |
self._some_from_cache = False | ||
self._any_cache_key = None | ||
self._any_cached_dttm = None | ||
self._extra_chart_data = None | ||
self._extra_chart_data = [] | ||
|
||
self.process_metrics() | ||
|
||
|
@@ -1199,10 +1199,10 @@ def process_data(self, df, aggregate=False): | |
|
||
def run_extra_queries(self): | ||
fd = self.form_data | ||
time_compare = fd.get('time_compare') | ||
if time_compare: | ||
time_compare = fd.get('time_compare') or [] | ||
for option in time_compare: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eventually (out of scope for this PR) we could have parallelization mechanism for this kind of things, making timeouts less likely. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (y) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I looked into parallelizing this, but it's non trivial: we can't just wrap the calls here in threads or processes because the connection is already established at this point, and for some backends like SQLite it can't be shared between threads/processes. I agree that we should probably do this in a separate PR, making the logic of |
||
query_object = self.query_obj() | ||
delta = utils.parse_human_timedelta(time_compare) | ||
delta = utils.parse_human_timedelta(option) | ||
query_object['inner_from_dttm'] = query_object['from_dttm'] | ||
query_object['inner_to_dttm'] = query_object['to_dttm'] | ||
|
||
|
@@ -1215,10 +1215,11 @@ def run_extra_queries(self): | |
|
||
df2 = self.get_df_payload(query_object).get('df') | ||
if df2 is not None: | ||
label = '{} offset'. format(option) | ||
df2[DTTM_ALIAS] += delta | ||
df2 = self.process_data(df2) | ||
self._extra_chart_data = self.to_series( | ||
df2, classed='superset', title_suffix='---') | ||
self._extra_chart_data.extend(self.to_series( | ||
df2, classed='superset', title_suffix=label)) | ||
|
||
def get_data(self, df): | ||
df = self.process_data(df) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that there's an open PR that makes this backward compatible. Here: #5057 , otherwise I think it would fail for previously saved charts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I remembered that as soon as I created the PR. Cool that there's a PR addressing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merged it, so we're good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did another comment on that PR, I think the PR fixes the issue only for the explore view, not for the dashboard view. I think it requires a bit more thinking.