You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@superset.apache.org by GitBox <gi...@apache.org> on 2018/02/07 22:07:20 UTC

[GitHub] mistercrunch closed pull request #4333: Add hour grain to SQLite

mistercrunch closed pull request #4333: Add hour grain to SQLite
URL: https://github.com/apache/incubator-superset/pull/4333
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/superset/data/__init__.py b/superset/data/__init__.py
index 233550cb63..e1d0b67558 100644
--- a/superset/data/__init__.py
+++ b/superset/data/__init__.py
@@ -1016,7 +1016,12 @@ def load_long_lat_data():
     """Loading lat/long data from a csv file in the repo"""
     with gzip.open(os.path.join(DATA_FOLDER, 'san_francisco.csv.gz')) as f:
         pdf = pd.read_csv(f, encoding="utf-8")
-    pdf['date'] = datetime.datetime.now().date()
+    start = datetime.datetime.now().replace(
+        hour=0, minute=0, second=0, microsecond=0)
+    pdf['datetime'] = [
+        start + datetime.timedelta(hours=i * 24 / (len(pdf) - 1))
+        for i in range(len(pdf))
+    ]
     pdf['occupancy'] = [random.randint(1, 6) for _ in range(len(pdf))]
     pdf['radius_miles'] = [random.uniform(1, 3) for _ in range(len(pdf))]
     pdf['geohash'] = pdf[['LAT', 'LON']].apply(
@@ -1038,7 +1043,7 @@ def load_long_lat_data():
             'region': String(50),
             'postcode': Float(),
             'id': String(100),
-            'date': Date(),
+            'datetime': DateTime(),
             'occupancy': Float(),
             'radius_miles': Float(),
             'geohash': String(12),
@@ -1052,7 +1057,7 @@ def load_long_lat_data():
     obj = db.session.query(TBL).filter_by(table_name='long_lat').first()
     if not obj:
         obj = TBL(table_name='long_lat')
-    obj.main_dttm_col = 'date'
+    obj.main_dttm_col = 'datetime'
     obj.database = get_or_create_main_db()
     db.session.merge(obj)
     db.session.commit()
diff --git a/superset/db_engine_specs.py b/superset/db_engine_specs.py
index d26f633bbd..8649d4fc51 100644
--- a/superset/db_engine_specs.py
+++ b/superset/db_engine_specs.py
@@ -367,6 +367,8 @@ class SqliteEngineSpec(BaseEngineSpec):
     engine = 'sqlite'
     time_grains = (
         Grain('Time Column', _('Time Column'), '{col}'),
+        Grain('hour', _('hour'),
+              "DATETIME(STRFTIME('%Y-%m-%dT%H:00:00', {col}))"),
         Grain('day', _('day'), 'DATE({col})'),
         Grain('week', _('week'),
               "DATE({col}, -strftime('%w', {col}) || ' days')"),


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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