Skip to content

Add example dataset to new projects #181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions cesium_app/handlers/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from cesium import data_management, time_series
from cesium.util import shorten_fname
from ..tests.fixtures import create_test_dataset

import os
from os.path import join as pjoin
Expand All @@ -24,6 +25,12 @@ def _get_dataset(self, dataset_id):
return d

def post(self):
if self.get_argument('create_example') == 'true':
project_id = self.get_argument('projectID')
p = Project.get(Project.id == project_id)
with create_test_dataset(p, delete_after=False) as d:
return self.success(d, 'cesium/FETCH_DATASETS')

if not 'tarFile' in self.request.files:
return self.error('No tar file uploaded')

Expand Down
10 changes: 7 additions & 3 deletions cesium_app/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def create_test_project():


@contextmanager
def create_test_dataset(project, label_type='class'):
def create_test_dataset(project, label_type='class', delete_after=True):
"""Create and yield test labeled dataset, then delete.

Params
Expand Down Expand Up @@ -57,12 +57,16 @@ def create_test_dataset(project, label_type='class'):
tarball = shutil.copy2(tarball, cfg['paths']['upload_folder'])
ts_paths = data_management.parse_and_store_ts_data(
tarball, cfg['paths']['ts_data_folder'], header)
d = m.Dataset.add(name='test_ds', project=project, file_uris=ts_paths)

name = 'Example Dataset'
d = m.Dataset.add(name=name, project=project, file_uris=ts_paths)
d.save()

try:
yield d
finally:
d.delete_instance()
if delete_after:
d.delete_instance()


@contextmanager
Expand Down
8 changes: 7 additions & 1 deletion public/scripts/Datasets.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ let DatasetForm = (props) => {

<SubmitButton label="Upload Dataset" disabled={submitting} />
</Form>
<button
onClick={props.createExampleDataset}
>
Use Example Dataset
</button>

<CesiumTooltip
id="headerfileTooltip"
Expand Down Expand Up @@ -101,7 +106,8 @@ const dsMapDispatchToProps = (dispatch, ownProps) => (
{
onSubmit: form => (
dispatch(Action.uploadDataset(form))
)
),
createExampleDataset: () => dispatch(Action.createExampleDataset(ownProps.selectedProject.id))
}
);

Expand Down
27 changes: 27 additions & 0 deletions public/scripts/actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const FETCH_DATASETS = 'cesium/FETCH_DATASETS';
export const RECEIVE_DATASETS = 'cesium/RECEIVE_DATASETS';
export const UPLOAD_DATASET = 'cesium/UPLOAD_DATASET';
export const DELETE_DATASET = 'cesium/DELETE_DATASET';
export const CREATE_EXAMPLE_DATASET = 'cesium/CREATE_EXAMPLE_DATASET';

export const FETCH_FEATURES = 'cesium/FETCH_FEATURES';
export const FETCH_FEATURESETS = 'cesium/FETCH_FEATURESETS';
Expand Down Expand Up @@ -174,6 +175,7 @@ export function deleteProject(id) {

export function uploadDataset(form) {
const formData = new FormData();
formData.append('create_example', false);

for (const key in form) {
if (form[key] && objectType(form[key][0]) === 'File') {
Expand Down Expand Up @@ -228,6 +230,31 @@ function receiveDatasets(datasets) {
}


// Create example dataset
export function createExampleDataset(projectID) {
var form_data = new FormData();
form_data.append('projectID', projectID);
form_data.append('create_example', true);

return dispatch =>
promiseAction(
dispatch,
CREATE_EXAMPLE_DATASET,

fetch('/dataset', {
method: 'POST',
body: form_data,
})
.then(response => response.json())
.then((json) => {
dispatch(fetchDatasets());
dispatch(hideExpander('newDatasetExpander'));
dispatch(resetForm('newDataset'));
}).catch(ex => console.log('createExampleDataset', ex))
);
}


// Download featuresets
export function fetchFeaturesets() {
return dispatch =>
Expand Down