import { h, Component } from 'preact' import { bindActionCreators } from 'redux' import { connect } from 'react-redux' import * as util from '../../util' import * as samplernnActions from './samplernn.actions' import actions from '../../actions' import DatasetForm from '../../dataset/dataset.form' import NewDatasetForm from '../../dataset/dataset.new' import { FileList, FileRow } from '../../common/fileList.component' import Loading from '../../common/loading.component' const samplernnModule = { name: 'samplernn', datatype: 'audio', } class SampleRNNDatasets extends Component { constructor(props){ super(props) this.fileOptions = this.fileOptions.bind(this) this.pickFile = this.pickFile.bind(this) } componentWillMount(){ 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) { if (parseInt(id)) localStorage.setItem('samplernn.last_id', id) if (! samplernn.folder || samplernn.folder.id !== id) { actions.load_directories(id) } } } pickFile(file){ console.log('pick', file) } fileOptions(file){ if (file.activity === 'url' && !file.dataset) { if (this.props.runner.cpu.status !== 'IDLE') { return (
fetching...
) } else { return (
this.fetchURL(file.url)}> fetch
) } } return (
this.train(file)}>train
{file.epoch == 0 &&
{file.epochs} ep.
}
) } onDeleteFile(file){ const yes = confirm('Are you sure you want to delete this file?') if (yes) { actions.file.destroy(file) } } render(){ const { samplernn, folder, match, history } = this.props if (samplernn.loading) { return } if (!samplernn.data.folders.length) { console.log('no folders, redirect to /new') return history.push('/samplernn/new/') } if (!folder || !folder.name) return return (
input
status
checkpoint
output
{this.renderGroups()}
) } renderGroups(){ const { samplernn, folder, runner, onPickDataset, onPickFile, datasetActions } = this.props const { datasetLookup, fileLookup } = samplernn.data const { mapFn, sortFn } = util.sort.orderByFn('date desc') const moduleOnGPU = runner && runner.gpu.task && runner.gpu.task.module === samplernnModule.name const datasets = folder.datasets.map(name => datasetLookup[name]).map(mapFn).sort(sortFn).map(pair => { const dataset = pair[1] const isProcessing = moduleOnGPU && runner.gpu.task.dataset === dataset const status = isProcessing ? util.gerund(runner.gpu.task.activity) : '' return (
onPickDataset && onPickDataset(dataset)}> {this.props.beforeRow && this.props.beforeRow(dataset)}
{!!dataset.input.length && fileLookup[id])} className='input_files' fileListClassName='' rowClassName='input_file' fields={'name date size delete'} options={this.fileOptions} onClick={onPickFile} onDelete={(file) => this.onDeleteFile(file)} /> }
{status} {this.props.datasetActions && this.props.datasetActions(dataset)}
{!!dataset.checkpoints.length && }
{!!dataset.output.length && fileLookup[id])} orderBy='epoch desc' fields={'name date epoch size'} onPickFile={onPickFile} onDelete={(file) => this.onDeleteFile(file)} /> }
{this.props.afterRow && this.props.afterRow(dataset)}
) }) return datasets } } const mapStateToProps = state => ({ samplernn: state.module.samplernn, runner: state.system.runner, task: state.task, }) const mapDispatchToProps = (dispatch, ownProps) => ({ actions: bindActionCreators(samplernnActions, dispatch), }) export default connect(mapStateToProps, mapDispatchToProps)(SampleRNNDatasets)