summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2018-06-03 00:13:02 +0200
committerJules Laplace <julescarbon@gmail.com>2018-06-03 00:13:02 +0200
commit2149eb581c35a93d41dbad6e3409c498b4bed804 (patch)
treea4d489ca73b2309654faece1322ea15045c0a8af /app
parentcf6f1c58a7298b0af1c13bb701032017563a6ed8 (diff)
sort files
Diffstat (limited to 'app')
-rw-r--r--app/client/common/fileList.component.js95
-rw-r--r--app/client/modules/samplernn/samplernn.actions.js18
-rw-r--r--app/client/modules/samplernn/samplernn.datasets.js4
-rw-r--r--app/client/util.js153
4 files changed, 95 insertions, 175 deletions
diff --git a/app/client/common/fileList.component.js b/app/client/common/fileList.component.js
index 0b69b62..13eb300 100644
--- a/app/client/common/fileList.component.js
+++ b/app/client/common/fileList.component.js
@@ -7,16 +7,29 @@ import * as util from '../util'
const defaultFields = new Set(['date', 'size'])
-export const FileList = (props) => {
- const { files, fields, linkFiles, title, onClick, className="" } = props
- const fileList = (files || []).map(file =>
- <FileRow
- file={file}
- fields={fields || defaultFields}
- linkFiles
- onClick
- />
- )
+export const FileList = props => {
+ const {
+ files,
+ fields, sort, title,
+ linkFiles, onClick,
+ orderBy='name asc',
+ className='',
+ fileListClassName='filelist',
+ rowClassName='row file'
+ } = props
+ const { mapFn, sortFn } = orderByFn(orderBy)
+ const fileList = (files || [])
+ .map(mapFn)
+ .sort(sortFn)
+ .map(pair =>
+ <FileRow
+ file={pair[1]}
+ fields={fieldSet(fields)}
+ className={rowClassName}
+ linkFiles
+ onClick
+ />
+ )
return (
<div className={'rows ' + className}>
<div class='row heading'>
@@ -25,23 +38,69 @@ export const FileList = (props) => {
: <h4>No files</h4>}
</div>
- <div className={'filelist rows'}>
+ <div className={'rows ' + fileListClassName}>
{fileList}
</div>
</div>
)
}
-export const FileRow = (props) => {
- const { file, linkFiles, onClick } = props
- const fields = props.fields || defaultFields
+const numericSort = {
+ asc: (a,b) => a[0] - b[0],
+ desc: (a,b) => b[0] - a[0],
+}
+const stringSort = {
+ asc: (a,b) => a[0].localeCompare(b[0]),
+ desc: (a,b) => b[0].localeCompare(a[0]),
+}
+export const orderByFn = (s='name asc') => {
+ const [field='name', direction='asc'] = s.split(' ')
+ let mapFn, sortFn
+ switch (field) {
+ case 'epoch':
+ mapFn = a => [a.epoch || a.epochs, a]
+ sortFn = numericSort[direction]
+ break
+ case 'size':
+ mapFn = a => [a.size, a]
+ sortFn = numericSort[direction]
+ break
+ case 'date':
+ mapFn = a => [+new Date(a.date || a.created_at), a]
+ sortFn = numericSort[direction]
+ break
+ case 'name':
+ default:
+ mapFn = a => [a.id || a.name, a]
+ sortFn = stringSort[direction]
+ break
+ }
+ return { mapFn, sortFn }
+}
+
+export const fieldSet = fields => {
+ if (fields) {
+ if (fields instanceof Set) {
+ return fields
+ }
+ return new Set(fields.split(' '))
+ }
+ return defaultFields
+}
+
+export const FileRow = props => {
+ const { file, linkFiles, onClick, className='row file', username='' } = props
+ const fields = fieldSet(props.fields)
+
const size = util.hush_size(file.size)
- const date = file.created_at
- const username = file.username || ""
+ const date = file.date || file.created_at
+
return (
- <div class='row file' key={file.name}>
+ <div class={className} key={file.name}>
<div className="filename" title={file.name || file.url}>
- {(linkFiles && file.url)
+ {file.persisted === false
+ ? <span>{file.name || file.url}</span>
+ : (linkFiles && file.url)
? <a target='_blank' href={file.url}>{file.name || file.url}</a>
: <span class='link' onClick={() => onClick(file)}>{file.name || file.url}</span>
}
diff --git a/app/client/modules/samplernn/samplernn.actions.js b/app/client/modules/samplernn/samplernn.actions.js
index cb8b47b..1a60719 100644
--- a/app/client/modules/samplernn/samplernn.actions.js
+++ b/app/client/modules/samplernn/samplernn.actions.js
@@ -76,7 +76,7 @@ export const load_directories = (id) => (dispatch) => {
})
// console.log(datasets)
- // const flatDatasets = datasets.filter(s => s.name.match(/(wav|aiff?|flac|mp3)$/) && !s.dir)
+ const flatDatasets = datasets.filter(s => s.name.match(/(wav|aiff?|flac|mp3)$/) && !s.dir)
const builtDatasets = datasets.filter(s => s.dir)
builtDatasets.forEach(dir => {
let dataset = datasetLookup[dir.name]
@@ -88,6 +88,18 @@ export const load_directories = (id) => (dispatch) => {
dataset.isBuilt = true
})
+ flatDatasets.forEach(file => {
+ const name = file.name.split('.')[0]
+ let dataset = datasetLookup[name]
+ if (! dataset) {
+ dataset = empty_dataset(name)
+ datasetLookup[dataset.name] = dataset
+ folderLookup.unsorted.datasets.push(dataset)
+ }
+ file.persisted = false
+ dataset.input.push(file)
+ })
+
// exp:coccokit_3-frame_sizes:8,2-n_rnn:2-dataset:coccokit_3
const checkpoints = results.filter(s => s.dir).map(s => {
const checkpoint = s.name
@@ -96,6 +108,7 @@ export const load_directories = (id) => (dispatch) => {
.filter(b => b.length && b[1])
.reduce((a,b) => (a[b[0]] = b[1]) && a, {})
checkpoint.name = checkpoint.dataset || checkpoint.exp
+ checkpoint.date = s.date
checkpoint.dir = s
let dataset = datasetLookup[checkpoint.dataset]
if (! dataset) {
@@ -115,8 +128,9 @@ export const load_directories = (id) => (dispatch) => {
datasetLookup[dataset.name] = dataset
folderLookup.unsorted.datasets.push(dataset)
}
+ file.persisted = false
+ file.epoch = file.epoch || pair[1].replace(/^\D+/, '')
dataset.output.push(file)
- file.epoch = file.epoch || pair[1]
})
dispatch({
diff --git a/app/client/modules/samplernn/samplernn.datasets.js b/app/client/modules/samplernn/samplernn.datasets.js
index 8b86007..b6a12cc 100644
--- a/app/client/modules/samplernn/samplernn.datasets.js
+++ b/app/client/modules/samplernn/samplernn.datasets.js
@@ -62,7 +62,7 @@ class SampleRNNDatasets extends Component {
return (
<div className='row dataset'>
<div className='col'>
- {!!dataset.input.length && <FileList files={dataset.input} />}
+ {!!dataset.input.length && <FileList files={dataset.input} className='input_files' fileListClassName='' rowClassName='input_file' />}
</div>
<div className='col quiet'>
<div>{dataset.isBuilt ? 'has dataset' : 'not built'}</div>
@@ -71,7 +71,7 @@ class SampleRNNDatasets extends Component {
{!!dataset.checkpoints.length && <FileRow file={dataset.checkpoints[0]} />}
</div>
<div className='col'>
- {!!dataset.output.length && <FileList files={dataset.output} />}
+ {!!dataset.output.length && <FileList files={dataset.output} orderBy='epoch desc' />}
</div>
</div>
)
diff --git a/app/client/util.js b/app/client/util.js
deleted file mode 100644
index 34fa023..0000000
--- a/app/client/util.js
+++ /dev/null
@@ -1,153 +0,0 @@
-export const is_iphone = !!((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)))
-export const is_ipad = !!(navigator.userAgent.match(/iPad/i))
-export const is_android = !!(navigator.userAgent.match(/Android/i))
-export const is_mobile = is_iphone || is_ipad || is_android
-export const is_desktop = ! is_mobile;
-
-const htmlClassList = document.body.parentNode.classList
-htmlClassList.add(is_desktop ? 'desktop' : 'mobile')
-htmlClassList.remove('loading')
-
-// window.debug = false
-
-export function clamp(n,a,b) { return n<a?a:n<b?n:b }
-export function norm(n,a,b) { return (n-a) / (b-a) }
-export function lerp(n,a,b) { return (b-a)*n+a }
-export function mix(n,a,b) { return a*(1-n)+b*n }
-export function randint(n) { return Math.floor(Math.random()*n) }
-export function randrange(a,b){ return Math.random() * (b-a) + a }
-
-document.body.style.backgroundImage = 'linear-gradient(' + (randint(40)+40) + 'deg, #fde, #ffe)'
-
-export function timeInSeconds(n){
- return (n / 10).toFixed(1) + ' s.'
-}
-export function gerund(s){
- return s.replace(/e?$/, 'ing')
-}
-export function commatize (n, radix) {
- radix = radix || 1024
- var nums = [], i, counter = 0, r = Math.floor
- if (n > radix) {
- n /= radix
- nums.unshift(r((n * 10) % 10))
- nums.unshift(".")
- }
- do {
- i = n % 10
- n = r(n / 10)
- if (n && ! (++counter % 3))
- { i = ' ' + r(i) }
- nums.unshift(r(i))
- }
- while (n)
- return nums.join("")
-}
-export function carbon_date (date, no_bold) {
- var span = (+new Date() - new Date(date)) / 1000, color
- if (! no_bold && span < 86400) // modified today
- { color = "new" }
- else if (span < 604800) // modifed this week
- { color = "recent" }
- else if (span < 1209600) // modifed 2 weeks ago
- { color = "med" }
- else if (span < 3024000) // modifed 5 weeks ago
- { color = "old" }
- else if (span < 12315200) // modifed 6 months ago
- { color = "older" }
- else
- { color = "quiet" }
- return color
-}
-export function hush_views (n, bias, no_bold) {
- var txt = commatize(n, 1000)
- bias = bias || 1
- n = n || 0
- if (n < 30) { return["quiet", n + " v."] }
- if (n < 200) { return ["quiet", txt + " v."] }
- else if (n < 500) { return ["quiet", txt + " v."] }
- else if (n < 1000) { return ["old", txt + " v."] }
- else if (n < 5000) { return ["med", txt + " kv."] }
- else if (no_bold || n < 10000) { return ["recent", txt + " kv."] }
- else { return ["new", txt + " kv."] }
-}
-export function hush_threads (n, bias, no_bold) {
- var txt = commatize(n, 1000)
- bias = bias || 1
- n = n || 0
- if (n < 10) { return["quiet", n + " t."] }
- else if (n < 25) { return ["old", txt + " t."] }
- else if (n < 50) { return ["med", txt + " t."] }
- else if (no_bold || n < 100) { return ["recent", txt + " t."] }
- else { return ["new", txt + " t."] }
-}
-export function hush_size (n, bias, no_bold) {
- var txt = commatize(Math.floor(n / 1024))
- bias = 1 || bias
- n = n || 0
- if (! n) { return ['', ''] }
- if (n < 1024) {
- return ["quiet", n + " b."]
- }
- if (n < 1024*1024) {
- return ["quiet", txt + " kb."]
- }
- else if (n < (20000000/bias)) {
- return ["quiet", txt + " mb."]
- }
- else if (n < (50000000/bias)) {
- return ["old", txt + " mb."]
- }
- else if (n < (80000000/bias)) {
- return ["med", txt + " mb."]
- }
- else if (no_bold || n < (170000000/bias)) {
- return ["recent", txt + " mb."]
- }
- else {
- return ["new", txt + " mb."]
- }
-}
-export function hush_null (n, unit, no_bold) {
- var s = unit ? n + " " + unit + "." : n
- if (n < 3) {
- return ["quiet", s]
- }
- else if (n < 6) {
- return ["older", s]
- }
- else if (n < 10) {
- return ["old", s]
- }
- else if (n < 16) {
- return ["med", s]
- }
- else if (no_bold || n < 21) {
- return ["recent", s]
- }
- else {
- return ["new", s]
- }
-}
-export function get_age (t) {
- var age = Math.abs(+Date.now() - new Date(t))/1000
- var r = Math.floor
- var m
- if (age < 5) { return "now" }
- if (age < 60) { return r(age) + "s" }
- age /= 60
- if (age < 60) { return r(age) + "m" }
- m = r(age % 60)
- age /= 60
- if (m > 0 && age < 2) { return r(age) + "h" + m + "m" }
- if (age < 24) { return r(age) + "h" }
- age /= 24
- if (age < 7) { return r(age) + "d" }
- age /= 7
- if (age < 12) { return r(age) + "w" }
- age /= 4
- if (age < 12) { return r(age) + "m" }
- age /= 12
- return r(age) + "y"
-}
-export function courtesy_s (n, s) { return n == 1 ? "" : (s || "s") }