From 5dece5cd3e1271b3af6efb5e0179a571ebdef4ef Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 4 Jun 2018 01:11:58 +0200 Subject: actually importing stuff --- app/client/modules/samplernn/samplernn.actions.js | 56 +++++++++++++- app/client/modules/samplernn/samplernn.datasets.js | 8 +- app/client/modules/samplernn/samplernn.import.js | 87 ++++++++++++++++------ app/client/modules/samplernn/samplernn.reducer.js | 2 +- 4 files changed, 126 insertions(+), 27 deletions(-) (limited to 'app/client/modules') diff --git a/app/client/modules/samplernn/samplernn.actions.js b/app/client/modules/samplernn/samplernn.actions.js index 70a8a30..f0e835e 100644 --- a/app/client/modules/samplernn/samplernn.actions.js +++ b/app/client/modules/samplernn/samplernn.actions.js @@ -76,6 +76,7 @@ export const load_directories = (id) => (dispatch) => { file.epoch = file.epoch || pair[1] }) + // also show the various flat audio files we have, in the input area.. const flatDatasets = datasets.filter(s => s.name.match(/(wav|aiff?|flac|mp3)$/) && !s.dir) const builtDatasets = datasets.filter(s => s.dir) builtDatasets.forEach(dir => { @@ -117,13 +118,25 @@ export const load_directories = (id) => (dispatch) => { file.persisted = false file.epoch = parseInt(file.epoch || pair[1].replace(/^\D+/, '')) || 0 dataset.epoch = Math.max(file.epoch, dataset.epoch || 0) - dataset.output.push(file) + // here check if the file exists in dataset, if so just check that it's persisted + const found = dataset.output.some(f => { + // if (f.name === + if (f.name === file.name) { + f.persisted = true + return true + } + return false + }) + if (! found) { + dataset.output.push(file) + } }) dispatch({ type: types.samplernn.init, data: { folderLookup, + datasetLookup, folders, files, checkpoints, builtDatasets, @@ -167,6 +180,47 @@ export const load_loss = () => dispatch => { }) } +export const import_files = (state, datasetLookup) => (dispatch) => { + const { selected, folder, url_base, import_action } = state + const names = Object.keys(selected).filter(k => selected[k]) + let promises + switch (import_action) { + case 'Hotlink': + // in this case, create a new file for each file we see. + promises = names.reduce((a,name) => { + return datasetLookup[name].output.map(file => { + const partz = file.name.split('.') + const ext = partz.pop() + return actions.file.create({ + folder_id: folder, + name: file.name, + url: url_base + file.name, + mime: 'audio/' + ext, + epoch: file.epoch, + size: file.size, + module: 'samplernn', + dataset: name, + activity: 'train', + datatype: 'audio', + generated: true, + created_at: new Date(file.date), + updated_at: new Date(file.date), + }) + }).concat(a) + }, []) + break + case 'Upload': + break + default: + break + } + Promise.all(promises).then(data => { + console.log(data) + }).catch(e => { + console.error(e) + }) +} + export const set_folder = (folder) => { types.samplernn.set_folder, folder } export const fetch_url = (url) => (dispatch) => { diff --git a/app/client/modules/samplernn/samplernn.datasets.js b/app/client/modules/samplernn/samplernn.datasets.js index c4cebc7..0b7ccb8 100644 --- a/app/client/modules/samplernn/samplernn.datasets.js +++ b/app/client/modules/samplernn/samplernn.datasets.js @@ -61,9 +61,8 @@ class SampleRNNDatasets extends Component { render(){ const { samplernn, match, history } = this.props const id = this.props.id || localStorage.getItem('samplernn.last_id') - console.log(this.props.id) if (samplernn.loading) { - console.log('loading') + // console.log('loading') return Loading } if (!samplernn.data.folders.length) { @@ -85,13 +84,13 @@ class SampleRNNDatasets extends Component { ) } renderGroups(){ - const { samplernn } = this.props + const { samplernn, onPickDataset } = this.props const folder = samplernn.folder const { mapFn, sortFn } = util.sort.orderByFn('date desc') const datasets = folder.datasets.map(mapFn).sort(sortFn).map(pair => { const dataset = pair[1] return ( -
+
onPickDataset(dataset)}> {this.props.beforeRow && this.props.beforeRow(dataset)}
{!!dataset.input.length && @@ -125,6 +124,7 @@ class SampleRNNDatasets extends Component { /> }
+ {this.props.afterRow && this.props.afterRow(dataset)}
) }) diff --git a/app/client/modules/samplernn/samplernn.import.js b/app/client/modules/samplernn/samplernn.import.js index 62a210d..d335782 100644 --- a/app/client/modules/samplernn/samplernn.import.js +++ b/app/client/modules/samplernn/samplernn.import.js @@ -7,6 +7,7 @@ import * as samplernnActions from './samplernn.actions' import Select from '../../common/select.component' import TextInput from '../../common/textInput.component' +import Button from '../../common/button.component' import SampleRNNDatasets from './samplernn.datasets' @@ -20,56 +21,100 @@ class SampleRNNImport extends Component { super() this.state = { folder: 1, - url_base: '' + import_action: 'Hotlink', + url_base: 'https://s3.amazonaws.com/i.asdf.us/bucky/data/4279/', + selected: {}, } } render(){ let datasets = []; if (this.props.samplernn.data) { datasets = (this.props.samplernn.data.folders || []).map(folder => { - console.log(folder.id, folder.name) return [folder.name, folder.id] }) - console.log(datasets) } return (

Import

-
-
-

Import to dataset

- this.setState({ folder: value })} + /> + +
+ ) + } + doImport(){ + const { samplernn } = this.props + console.log(this.state) + this.props.actions.import_files(this.state, samplernn.data.datasetLookup) } } diff --git a/app/client/modules/samplernn/samplernn.reducer.js b/app/client/modules/samplernn/samplernn.reducer.js index 65d9e3d..b294c2f 100644 --- a/app/client/modules/samplernn/samplernn.reducer.js +++ b/app/client/modules/samplernn/samplernn.reducer.js @@ -10,7 +10,7 @@ const samplernnInitialState = { } const samplernnReducer = (state = samplernnInitialState, action) => { - console.log(action.type) + // console.log(action.type) switch(action.type) { case types.samplernn.init: return { -- cgit v1.2.3-70-g09d2