mirror of
https://github.com/apache/superset.git
synced 2024-09-12 08:39:45 -04:00
Add hour grain to Sqlite (#4333)
This commit is contained in:
parent
31a0b6e5b0
commit
f14c1bb593
@ -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()
|
||||
|
@ -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')"),
|
||||
|
Loading…
Reference in New Issue
Block a user