Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion caravel/assets/visualizations/table.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function tableVis(slice) {
.data(function (row, i) {
return data.columns.map(function (c) {
var val = row[c];
if (c === 'timestamp') {
if (c === 'time_serial') {
val = timestampFormatter(val);
}
return {
Expand Down
14 changes: 7 additions & 7 deletions caravel/models.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def column_names(self):

@property
def main_dttm_col(self):
return "timestamp"
return "time_serial"

@property
def groupby_column_names(self):
Expand Down Expand Up @@ -651,15 +651,15 @@ def query( # sqla

if granularity:
dttm_col = cols[granularity]
dttm_expr = dttm_col.sqla_col.label('timestamp')
dttm_expr = dttm_col.sqla_col.label('time_serial')
timestamp = dttm_expr

# Transforming time grain into an expression based on configuration
time_grain_sqla = extras.get('time_grain_sqla')
if time_grain_sqla:
udf = self.database.grains_dict().get(time_grain_sqla, '{col}')
timestamp_grain = literal_column(
udf.function.format(col=dttm_expr)).label('timestamp')
udf.function.format(col=dttm_expr)).label('time_serial')
else:
timestamp_grain = timestamp

Expand Down Expand Up @@ -1352,13 +1352,13 @@ def recursive_get_fields(_conf):
if (
not is_timeseries and
granularity == "all" and
'timestamp' in df.columns):
del df['timestamp']
'time_serial' in df.columns):
del df['time_serial']

# Reordering columns
cols = []
if 'timestamp' in df.columns:
cols += ['timestamp']
if 'time_serial' in df.columns:
cols += ['time_serial']
cols += [col for col in groupby if col in df.columns]
cols += [col for col in metrics if col in df.columns]
df = df[cols]
Expand Down
34 changes: 17 additions & 17 deletions caravel/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,18 @@ def get_df(self, query_obj=None):
if df is None or df.empty:
raise Exception("No data, review your incantations!")
else:
if 'timestamp' in df.columns:
if 'time_serial' in df.columns:
if timestamp_format == "epoch_s":
df.timestamp = pd.to_datetime(
df.timestamp, utc=False, unit="s")
df.time_serial = pd.to_datetime(
df.time_serial, utc=False, unit="s")
elif timestamp_format == "epoch_ms":
df.timestamp = pd.to_datetime(
df.timestamp, utc=False, unit="ms")
df.time_serial = pd.to_datetime(
df.time_serial, utc=False, unit="ms")
else:
df.timestamp = pd.to_datetime(
df.timestamp, utc=False, format=timestamp_format)
df.time_serial = pd.to_datetime(
df.time_serial, utc=False, format=timestamp_format)
if self.datasource.offset:
df.timestamp += timedelta(hours=self.datasource.offset)
df.time_serial += timedelta(hours=self.datasource.offset)
df.replace([np.inf, -np.inf], np.nan)
df = df.fillna(0)
return df
Expand Down Expand Up @@ -407,8 +407,8 @@ def get_df(self, query_obj=None):
df = super(TableViz, self).get_df(query_obj)
if (
self.form_data.get("granularity") == "all" and
'timestamp' in df):
del df['timestamp']
'time_serial' in df):
del df['time_serial']
return df

def get_data(self):
Expand Down Expand Up @@ -465,8 +465,8 @@ def get_df(self, query_obj=None):
df = super(PivotTableViz, self).get_df(query_obj)
if (
self.form_data.get("granularity") == "all" and
'timestamp' in df):
del df['timestamp']
'time_serial' in df):
del df['time_serial']
df = df.pivot_table(
index=self.form_data.get('groupby'),
columns=self.form_data.get('columns'),
Expand Down Expand Up @@ -614,8 +614,8 @@ def get_data(self):
df = self.get_df()
form_data = self.form_data

df.columns = ["timestamp", "metric"]
timestamps = {str(obj["timestamp"].value / 10**9):
df.columns = ["time_serial", "metric"]
timestamps = {str(obj["time_serial"].value / 10**9):
obj.get("metric") for obj in df.to_dict("records")}

start = utils.parse_human_datetime(form_data.get("since"))
Expand Down Expand Up @@ -979,7 +979,7 @@ def get_df(self, query_obj=None):
raise Exception("Pick a time granularity for your time series")

df = df.pivot_table(
index="timestamp",
index="time_serial",
columns=form_data.get('groupby'),
values=form_data.get('metrics'))

Expand Down Expand Up @@ -1039,7 +1039,7 @@ def to_series(self, df, classed='', title_suffix=''):
ys = series[name]
if df[name].dtype.kind not in "biufc":
continue
df['timestamp'] = pd.to_datetime(df.index, utc=False)
df['time_serial'] = pd.to_datetime(df.index, utc=False)
if isinstance(name, string_types):
series_title = name
else:
Expand All @@ -1056,7 +1056,7 @@ def to_series(self, df, classed='', title_suffix=''):
"classed": classed,
"values": [
{'x': ds, 'y': ys[ds] if ds in ys else None}
for ds in df.timestamp
for ds in df.time_serial
],
}
chart_data.append(d)
Expand Down