Skip to content

Commit d4b84c2

Browse files
committed
Only render download link when computation is complete
Add featureset/model/prediction name & timestamp to default download file name Add project name to default download file names
1 parent 01fe865 commit d4b84c2

File tree

6 files changed

+32
-15
lines changed

6 files changed

+32
-15
lines changed

cesium_app/handlers/feature.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,19 @@ class FeatureHandler(BaseHandler):
2020
@auth_or_token
2121
def get(self, featureset_id=None, action=None):
2222
if action == 'download':
23-
fset_path = Featureset.get_if_owned_by(featureset_id,
24-
self.current_user).file_uri
23+
featureset = Featureset.get_if_owned_by(featureset_id,
24+
self.current_user)
25+
fset_path = featureset.file_uri
2526
print(fset_path)
2627
fset, data = featurize.load_featureset(fset_path)
2728
fset.index.name = 'ts_name'
2829
fset.columns = fset.columns.get_level_values(0)
2930
fset.columns.name = None
3031
self.set_header("Content-Type", 'text/csv; charset="utf-8"')
31-
self.set_header("Content-Disposition", "attachment; "
32-
"filename=cesium_featureset.csv")
32+
self.set_header(
33+
"Content-Disposition", "attachment; "
34+
f"filename=cesium_featureset_{featureset.project.name}"
35+
f"_{featureset.name}_{featureset.finished}.csv")
3336
self.write(fset.to_csv(index=True))
3437
else:
3538
if featureset_id is not None:

cesium_app/handlers/model.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,15 @@ class ModelHandler(BaseHandler):
7474
@auth_or_token
7575
def get(self, model_id=None, action=None):
7676
if action == 'download':
77-
model_path = Model.get_if_owned_by(model_id,
78-
self.current_user).file_uri
77+
model = Model.get_if_owned_by(model_id, self.current_user)
78+
model_path = model.file_uri
7979
with open(model_path, 'rb') as f:
8080
model_data = f.read()
8181
self.set_header("Content-Type", "application/octet-stream")
82-
self.set_header("Content-Disposition", "attachment; "
83-
"filename=cesium_model__joblib.pkl")
82+
self.set_header(
83+
"Content-Disposition", "attachment; "
84+
f"filename=cesium_model__joblib_{model.project.name}"
85+
f"_{model.name}_{model.finished}.pkl")
8486
self.write(model_data)
8587
else:
8688
if model_id is not None:

cesium_app/handlers/prediction.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ async def post(self):
121121
@auth_or_token
122122
def get(self, prediction_id=None, action=None):
123123
if action == 'download':
124-
pred_path = Prediction.get_if_owned_by(prediction_id,
125-
self.current_user).file_uri
124+
prediction = Prediction.get_if_owned_by(prediction_id, self.current_user)
125+
pred_path = prediction.file_uri
126126
fset, data = featurize.load_featureset(pred_path)
127127
result = pd.DataFrame(({'label': data['labels']}
128128
if len(data['labels']) > 0 else None),
@@ -133,8 +133,11 @@ def get(self, prediction_id=None, action=None):
133133
result['prediction'] = data['preds']
134134
result.index.name = 'ts_name'
135135
self.set_header("Content-Type", 'text/csv; charset="utf-8"')
136-
self.set_header("Content-Disposition", "attachment; "
137-
"filename=cesium_prediction_results.csv")
136+
self.set_header(
137+
"Content-Disposition", "attachment; "
138+
f"filename=cesium_prediction_results_{prediction.project.name}"
139+
f"_{prediction.dataset.name}"
140+
f"_{prediction.model.name}_{prediction.finished}.csv")
138141
self.write(result.to_csv(index=True))
139142
else:
140143
if prediction_id is None:

static/js/components/Features.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,10 @@ export let FeatureTable = props => (
259259
<td>{reformatDatetime(featureset.created_at)}</td>
260260
{status}
261261
<td>
262-
<Download url={`/features/${featureset.id}/download`} />
262+
{
263+
done &&
264+
<Download url={`/features/${featureset.id}/download`} />
265+
}
263266
&nbsp;&nbsp;
264267
<DeleteFeatureset ID={featureset.id} />
265268
</td>

static/js/components/Models.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,10 @@ export let ModelTable = props => (
239239
<td>{reformatDatetime(model.created_at)}</td>
240240
{status}
241241
<td>
242-
<Download url={`/models/${model.id}/download`} />
242+
{
243+
done &&
244+
<Download url={`/models/${model.id}/download`} />
245+
}
243246
&nbsp;&nbsp;
244247
<DeleteModelButton ID={model.id} />
245248
</td>

static/js/components/Predictions.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,10 @@ let PredictionsTable = props => (
135135
<td>{reformatDatetime(prediction.created_at)}</td>
136136
{status}
137137
<td>
138-
<DownloadPredCSV ID={prediction.id} />
138+
{
139+
done &&
140+
<DownloadPredCSV ID={prediction.id} />
141+
}
139142
&nbsp;&nbsp;
140143
<DeletePrediction ID={prediction.id} />
141144
</td>

0 commit comments

Comments
 (0)