Skip to content

Commit

Permalink
feat: use general _scores object
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaixhin committed Oct 14, 2015
1 parent 22d707e commit e4f58b6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -450,7 +450,7 @@ app.get("/projects/:id/optimisation", function(req, res, next) {
// Project page (experiments)
app.get("/projects/:id/experiments", function(req, res, next) {
var projP = db.projects.findByIdAsync(req.params.id);
var expP = db.experiments.find({_project_id: db.toObjectID(req.params.id)}, {"_val.score": 1, "_test.score": 1, _status: 1, _options: 1, _started: 1, _finished: 1}).toArrayAsync(); // Sort experiment scores for this project
var expP = db.experiments.find({_project_id: db.toObjectID(req.params.id)}, {_scores: 1, _status: 1, _options: 1, _started: 1, _finished: 1}).toArrayAsync();
Promise.all([projP, expP])
.then(function(results) {
res.render("experiments", {project: results[0], experiments: results[1]});
Expand Down
7 changes: 5 additions & 2 deletions views/experiment.jade
Expand Up @@ -26,15 +26,18 @@ block content
dd#experiment-finished.col-sm-9
dt.col-sm-3 Options
dd.col-sm-9= JSON.stringify(experiment._options)
if experiment._scores
each val, prop in experiment._scores
dt.col-sm-3 #{prop}
dd.col-sm-9 #{val}
- if (experiment._files.length > 0)
dt.col-sm-3 Files
dd.col-sm-9
ul.list-unstyled(style="margin-bottom: 0;")
- each file in experiment._files
li #[a(href="/files/#{file._id}") #{file.filename}]
if experiment._val
dt.col-sm-3 Val Score
dd.col-sm-9 #{experiment._val.score}

if experiment._test
dt.col-sm-3 Test Loss
dd.col-sm-9 #{experiment._test.loss}
Expand Down
23 changes: 18 additions & 5 deletions views/experiments.jade
Expand Up @@ -15,6 +15,7 @@ block scripts
script(src="/bower_components/bootstrap/dist/js/bootstrap.min.js")
script(src="/bower_components/bootstrap-table/dist/bootstrap-table.min.js")
script(src="/bower_components/bootstrap-table/dist/extensions/multiple-sort/bootstrap-table-multiple-sort.min.js")
script(src="/bower_components/lodash/lodash.min.js")
script(src="/bower_components/moment/min/moment.min.js")
script.
// Flattens JSON objects
Expand Down Expand Up @@ -65,9 +66,20 @@ block scripts
}
return "<span class='" + iconClass + "'></span>";
}},
{field: "_val.score", title: "Val Score", sortable: "true"},
{field: "_test.score", title: "Test Score", sortable: "true"}
];
// Loop over scores
var scoreLength = 0;
var scoreProps = {};
// TODO Remove "maximum props" assumption and add props as found
for (var i = 0; i < experiments.length; i++) {
if (experiments[i]._scores && _.keys(experiments[i]._scores).length > scoreLength) {
scoreLength = _.keys(experiments[i]._scores).length;
scoreProps = experiments[i]._scores;
}
}
for (var prop in scoreProps) {
columns.push({field: "_scores." + prop, title: prop, sortable: true});
}
// Utilises 2 functions to solve loop scope problem
for (var key in schema) {
columns.push({field: "_options." + key, title: key, sortable: true, formatter: function(k) {return function(val) {
Expand All @@ -79,8 +91,9 @@ block scripts
return "<span class='" + textClass + "'>" + val + "</span>";
}}(key)});
}
columns.push({field: "_started", title: "Started", sortable: "true", formatter: function(val) {return moment().format(val);}});
columns.push({field: "_finished", title: "Finished", sortable: "true", formatter: function(val) {return moment().format(val);}});
columns.push({field: "_started", title: "Started", sortable: "true", formatter: function(val) {return val ? moment().format(val) : "";}});
columns.push({field: "_finished", title: "Finished", sortable: "true", formatter: function(val) {return val ? moment().format(val) : "";}});
// TODO Loop over custom properties

// Flatten each experiment
for (var i = 0; i < experiments.length; i++) {
Expand All @@ -93,7 +106,7 @@ block scripts
classes: "table",
undefinedText: "",
striped: true,
sortName: "_test.score",
sortName: "_started",
sortOrder: "desc",
iconsPrefix: "octicon",
search: true,
Expand Down

0 comments on commit e4f58b6

Please sign in to comment.