You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ma...@apache.org on 2018/02/07 22:07:20 UTC
[incubator-superset] branch master updated: Add hour grain to
Sqlite (#4333)
This is an automated email from the ASF dual-hosted git repository.
maximebeauchemin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git
The following commit(s) were added to refs/heads/master by this push:
new f14c1bb Add hour grain to Sqlite (#4333)
f14c1bb is described below
commit f14c1bb593bd2fbc2aeb0c883cf2e30409cd4788
Author: Beto Dealmeida <ro...@dealmeida.net>
AuthorDate: Wed Feb 7 14:07:15 2018 -0800
Add hour grain to Sqlite (#4333)
---
superset/data/__init__.py | 11 ++++++++---
superset/db_engine_specs.py | 2 ++
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/superset/data/__init__.py b/superset/data/__init__.py
index 233550c..e1d0b67 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 c6496db..112b3ba 100644
--- a/superset/db_engine_specs.py
+++ b/superset/db_engine_specs.py
@@ -411,6 +411,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')"),
--
To stop receiving notification emails like this one, please contact
maximebeauchemin@apache.org.