You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2019/09/21 14:38:18 UTC

[GitHub] [incubator-superset] benvdh opened a new issue #8274: Intuitive display of negative timedeltas

benvdh opened a new issue #8274: Intuitive display of negative timedeltas
URL: https://github.com/apache/incubator-superset/issues/8274
 
 
   **Is your feature request related to a problem? Please describe.**
   At the moment I'm working on a dashboard for a customer of ours that has to display averages of timedeltas. Luckily PostgreSQL has a native datatype called interval to save such data, and that makes it possible to calculate averages over them too. Superset is currently able to show the results of such aggregations in its table visualisation by converting the postgres interval data to python's timedelta type. However, this has one disadvantage, a negative interval of -6 minutes becomes:
   
   ```python
   >>> from datetime import timedelta
   >>> a = timedelta(minutes=-6)
   >>> str(a)
   '-1 day, 23:54:00
   ```
   The main rationale behind the above result is that the string representation matches the timedelta object's internal representation[1]. The above displayed value relates to the -6 minutes by interpreting -1 day as -24 hours and the hours and minutes part as +23 hours + 54 minutes. If we sum those values we end up with -6 minutes. 
   
   However, for a customer having to interpret a whole column with tens of values like this, this quickly becomes a hassle and makes it hard to compare the values, not to speak of the cognitive load it brings to interpret the data.
   
   A similar discussion is currently going on in the pandas community: https://github.com/pandas-dev/pandas/issues/17232
   
   **Describe the solution you'd like**
   Personally I would like -6 minutes to be displayed as `-0 days, 00:06:00` or something similar. This makes it much more intuitive for the user of the dashboard. I already have a pull request available which does exactly that, it's based on a solution to this problem suggested on SO[2].
   
   **Describe alternatives you've considered**
   1. I have considered storing the intervals as strings, but that would make aggregating impossible. 
   2. Another solution would be to store the intervals in absolute terms (e.g. -360 seconds), and then formatting that number with fairly complex SQL (i.e. applying modulus operators for seconds, minutes, hours, days... etc.) into a human-readable string, That would be the workaround at the database level applicable for MySQL/MariaDB databases, as its time datatype cannot store intervals longer than ~35 days.
   3. A more generic solution to these kinds of problems might be to allow columns in Table data sources to be formatted with an arbitrary python function, which you could define on a per column basis.
   4. To solve many other issues with the postgres Interval type, it would be nice if superset would support TimeDelta's as a native datatype (like String, Numeric, and Datetime), formatting negative values could then be one small problem solved by this more generic solution.
   
   Solution 2 would require more effort from the user when building a dasboard, solution 3 has a much larger scope, and 4 would likely be the size of a SIP.
   
   **Additional context**
   Add any other context or screenshots about the feature request here.
   [1] https://github.com/pandas-dev/pandas/issues/17232#issuecomment-353548646
   [2] https://stackoverflow.com/a/8408947/10243474

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org