summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2018-06-04 03:13:46 +0200
committerJules Laplace <julescarbon@gmail.com>2018-06-04 03:13:46 +0200
commit94f083788d58bccb09f775ef731827d29d719d43 (patch)
tree0bc188ef302ddfc69365521d743cb9f6293ab327 /app
parent2f22fd5e4a558ed9b2379565be88b9d1e1b9b7c5 (diff)
promises progress
Diffstat (limited to 'app')
-rw-r--r--app/client/modules/samplernn/index.js2
-rw-r--r--app/client/modules/samplernn/samplernn.actions.js8
-rw-r--r--app/client/modules/samplernn/samplernn.datasets.js5
-rw-r--r--app/client/modules/samplernn/samplernn.show.js6
-rw-r--r--app/client/util/index.js13
5 files changed, 25 insertions, 9 deletions
diff --git a/app/client/modules/samplernn/index.js b/app/client/modules/samplernn/index.js
index d8ea9f8..9efb6de 100644
--- a/app/client/modules/samplernn/index.js
+++ b/app/client/modules/samplernn/index.js
@@ -15,7 +15,7 @@ function router () {
<Route exact path='/samplernn/graph/' component={SampleRNNLoss} />
<Route exact path='/samplernn/inspect/' component={SampleRNNInspect} />
<Route exact path='/samplernn/import/' component={SampleRNNImport} />
- <Route exact path='/samplernn/datasets/' component={SampleRNNDatasets} />
+ <Route exact path='/samplernn/datasets/' component={SampleRNNShow} />
<Route exact path='/samplernn/datasets/:id/' component={SampleRNNShow} />
<Route exact path='/samplernn/results/' component={SampleRNNResults} />
</section>
diff --git a/app/client/modules/samplernn/samplernn.actions.js b/app/client/modules/samplernn/samplernn.actions.js
index 30620a7..343550e 100644
--- a/app/client/modules/samplernn/samplernn.actions.js
+++ b/app/client/modules/samplernn/samplernn.actions.js
@@ -3,9 +3,11 @@ import types from '../../types'
import actions from '../../actions'
+import { allProgress } from '../../util'
+
export const load_directories = (id) => (dispatch) => {
// console.log(actions)
- Promise.all([
+ allProgress([
actions.folder.index({ module: 'samplernn' }),
actions.file.index({ module: 'samplernn' }),
actions.task.index({ module: 'samplernn' }),
@@ -13,7 +15,9 @@ export const load_directories = (id) => (dispatch) => {
actions.socket.list_directory({ module: 'samplernn', dir: 'results' }),
actions.socket.list_directory({ module: 'samplernn', dir: 'output' }),
load_loss()(dispatch),
- ]).then(res => {
+ ], (percent, i, n) => {
+ console.log(percent + "%")
+ }).then(res => {
// console.log(res)
const [folders, files, tasks, datasets, results, output, lossReport] = res
diff --git a/app/client/modules/samplernn/samplernn.datasets.js b/app/client/modules/samplernn/samplernn.datasets.js
index 0b7ccb8..683d44a 100644
--- a/app/client/modules/samplernn/samplernn.datasets.js
+++ b/app/client/modules/samplernn/samplernn.datasets.js
@@ -21,8 +21,8 @@ class SampleRNNDatasets extends Component {
this.pickFile = this.pickFile.bind(this)
}
componentWillMount(){
- const id = this.props.id || this.props.match.params.id || localStorage.getItem('samplernn.last_id')
- console.log('load dataset:', id)
+ const id = this.props.id
+ console.log('load dataset:', id, this.props.id)
const { match, samplernn, actions } = this.props
if (id === 'new') return
if (id) {
@@ -60,7 +60,6 @@ class SampleRNNDatasets extends Component {
}
render(){
const { samplernn, match, history } = this.props
- const id = this.props.id || localStorage.getItem('samplernn.last_id')
if (samplernn.loading) {
// console.log('loading')
return <span>Loading</span>
diff --git a/app/client/modules/samplernn/samplernn.show.js b/app/client/modules/samplernn/samplernn.show.js
index f16758a..8e271fc 100644
--- a/app/client/modules/samplernn/samplernn.show.js
+++ b/app/client/modules/samplernn/samplernn.show.js
@@ -20,13 +20,12 @@ class SampleRNNShow extends Component {
render(){
const { samplernn, match, history } = this.props
const { folder } = samplernn || {}
- console.log(folder)
return (
<div className='app'>
<div class='heading'>
<h1>{folder ? folder.name : 'Loading...'}</h1>
</div>
- {folder && folder.name !== 'unsorted' &&
+ {folder && folder.name && folder.name !== 'unsorted' &&
<DatasetForm
title='Add Files'
module={samplernnModule}
@@ -35,7 +34,7 @@ class SampleRNNShow extends Component {
/>
}
<SampleRNNDatasets
- id={this.props.match.params.id}
+ id={this.props.match.params.id || localStorage.getItem('samplernn.last_id')}
/>
</div>
)
@@ -44,6 +43,7 @@ class SampleRNNShow extends Component {
const mapStateToProps = state => ({
samplernn: state.module.samplernn,
+ dataset: state.dataset,
})
const mapDispatchToProps = (dispatch, ownProps) => ({
diff --git a/app/client/util/index.js b/app/client/util/index.js
index 6ae1f64..75992d9 100644
--- a/app/client/util/index.js
+++ b/app/client/util/index.js
@@ -25,6 +25,19 @@ export function randrange(a,b){ return Math.random() * (b-a) + a }
document.body.style.backgroundImage = 'linear-gradient(' + (randint(40)+40) + 'deg, #fde, #ffe)'
+export const allProgress = (promises, progress_cb) => {
+ let d = 0;
+ progress_cb(0);
+ promises.forEach((p) => {
+ p.then((s) => {
+ d += 1
+ progress_cb((d * 100) / promises.length, d, promises.length)
+ return s
+ })
+ })
+ return Promise.all(promises)
+}
+
export function timeInSeconds(n){
return (n / 10).toFixed(1) + ' s.'
}