From fb7c11f65f1ef152aeea9992f68a6e8b4cf872e4 Mon Sep 17 00:00:00 2001 From: Prithvi Prabhu Date: Thu, 15 Jan 2015 17:47:33 -0800 Subject: [PATCH] Bump version --- bower.json | 2 +- build/js/flow.js | 8123 +++++++++++++++--------------- src/core/components/about.coffee | 2 +- 3 files changed, 4064 insertions(+), 4063 deletions(-) diff --git a/bower.json b/bower.json index 465546183..f2db91e3c 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "h2o-flow", - "version": "0.2.26", + "version": "0.2.27", "homepage": "https://github.com/h2oai/h2o-flow", "authors": [ "Prithvi Prabhu " diff --git a/build/js/flow.js b/build/js/flow.js index c5990e916..4f7b1c9eb 100755 --- a/build/js/flow.js +++ b/build/js/flow.js @@ -12,7 +12,7 @@ }.call(this)); (function () { var FLOW_VERSION; - FLOW_VERSION = '0.2.26'; + FLOW_VERSION = '0.2.27'; Flow.About = function (_) { var _properties; _properties = Flow.Dataflow.signals([]); @@ -1086,6 +1086,7 @@ createMenu('Admin', [ createMenuItem('Jobs', executeCommand('getJobs')), createMenuItem('Cluster Status', executeCommand('getCloud')), + createMenuItem('Performance Monitor', goToUrl('/perfbar.html')), createMenuItem('Inspect Log', executeCommand('getLogFile 0')), createMenuItem('Download Log', goToUrl('/Logs/download')), createMenuItem('Profiler', executeCommand('getProfile depth: 10')), @@ -4067,2340 +4068,2437 @@ }; }.call(this)); (function () { - H2O.ApplicationContext = function (_) { - _.requestGet = Flow.Dataflow.slot(); - _.requestPost = Flow.Dataflow.slot(); - _.requestFileGlob = Flow.Dataflow.slot(); - _.requestCreateFrame = Flow.Dataflow.slot(); - _.requestImportFile = Flow.Dataflow.slot(); - _.requestImportFiles = Flow.Dataflow.slot(); - _.requestParseFiles = Flow.Dataflow.slot(); - _.requestInspect = Flow.Dataflow.slot(); - _.requestParseSetup = Flow.Dataflow.slot(); - _.requestFrames = Flow.Dataflow.slot(); - _.requestFrame = Flow.Dataflow.slot(); - _.requestColumnSummary = Flow.Dataflow.slot(); - _.requestModelBuilder = Flow.Dataflow.slot(); - _.requestModelBuilders = Flow.Dataflow.slot(); - _.requestModelBuild = Flow.Dataflow.slot(); - _.requestModelInputValidation = Flow.Dataflow.slot(); - _.requestPredict = Flow.Dataflow.slot(); - _.requestPrediction = Flow.Dataflow.slot(); - _.requestPredictions = Flow.Dataflow.slot(); - _.requestModels = Flow.Dataflow.slot(); - _.requestModel = Flow.Dataflow.slot(); - _.requestJobs = Flow.Dataflow.slot(); - _.requestJob = Flow.Dataflow.slot(); - _.requestObjects = Flow.Dataflow.slot(); - _.requestObject = Flow.Dataflow.slot(); - _.requestDeleteObject = Flow.Dataflow.slot(); - _.requestPutObject = Flow.Dataflow.slot(); - _.requestCloud = Flow.Dataflow.slot(); - _.requestTimeline = Flow.Dataflow.slot(); - _.requestProfile = Flow.Dataflow.slot(); - _.requestStackTrace = Flow.Dataflow.slot(); - _.requestRemoveAll = Flow.Dataflow.slot(); - _.requestLogFile = Flow.Dataflow.slot(); - _.requestAbout = Flow.Dataflow.slot(); - _.inspect = Flow.Dataflow.slot(); - return _.plot = Flow.Dataflow.slot(); - }; -}.call(this)); -(function () { - H2O.Application = function (_) { - H2O.ApplicationContext(_); - return H2O.Proxy(_); + H2O.Assist = function (_, _items) { + var createAssistItem, item, name; + createAssistItem = function (name, item) { + return { + name: name, + description: item.description, + icon: 'fa fa-' + item.icon + ' flow-icon', + execute: function () { + return _.insertAndExecuteCell('cs', name); + } + }; + }; + return { + routines: function () { + var _results; + _results = []; + for (name in _items) { + item = _items[name]; + _results.push(createAssistItem(name, item)); + } + return _results; + }(), + template: 'flow-assist' + }; }; }.call(this)); (function () { - H2O.Proxy = function (_) { - var composePath, doGet, doPost, encodeArray, encodeObject, http, mapWithKey, patchUpModels, requestAbout, requestCloud, requestColumnSummary, requestCreateFrame, requestDeleteObject, requestFileGlob, requestFrame, requestFrames, requestImportFile, requestImportFiles, requestInspect, requestJob, requestJobs, requestLogFile, requestModel, requestModelBuild, requestModelBuilder, requestModelBuilders, requestModelInputValidation, requestModels, requestObject, requestObjects, requestParseFiles, requestParseSetup, requestPredict, requestPrediction, requestPredictions, requestProfile, requestPutObject, requestRemoveAll, requestStackTrace, requestTimeline, requestWithOpts; - http = function (path, opts, go) { - var req; - _.status('server', 'request', path); - req = opts ? $.post(path, opts) : $.getJSON(path); - req.done(function (data, status, xhr) { - var error; - _.status('server', 'response', path); - try { - return go(null, data); - } catch (_error) { - error = _error; - return go(new Flow.Error(opts ? 'Error processing POST ' + path : 'Error processing GET ' + path, error)); - } - }); - return req.fail(function (xhr, status, error) { - var message, _ref; - _.status('server', 'error', path); - message = ((_ref = xhr.responseJSON) != null ? _ref.errmsg : void 0) ? xhr.responseJSON.errmsg : (error != null ? error.message : void 0) ? error.message : status === 0 ? 'Could not connect to H2O' : 'Unknown error'; - return go(new Flow.Error(message, new Flow.Error(opts ? 'Error calling POST ' + path + ' with opts ' + JSON.stringify(opts) : 'Error calling GET ' + path))); - }); - }; - doGet = function (path, go) { - return http(path, null, go); + H2O.CloudOutput = function (_, _cloud) { + var avg, createGrid, createNodeRow, createTotalRow, format3f, formatMilliseconds, formatThreads, prettyPrintBytes, refresh, sum, toggleExpansion, toggleRefresh, updateCloud, _exception, _hasConsensus, _headers, _isBusy, _isExpanded, _isHealthy, _isLive, _isLocked, _name, _nodeCounts, _nodes, _size, _sizes, _uptime, _version; + _exception = Flow.Dataflow.signal(null); + _isLive = Flow.Dataflow.signal(false); + _isBusy = Flow.Dataflow.signal(false); + _isExpanded = Flow.Dataflow.signal(false); + _name = Flow.Dataflow.signal(); + _size = Flow.Dataflow.signal(); + _uptime = Flow.Dataflow.signal(); + _version = Flow.Dataflow.signal(); + _nodeCounts = Flow.Dataflow.signal(); + _hasConsensus = Flow.Dataflow.signal(); + _isLocked = Flow.Dataflow.signal(); + _isHealthy = Flow.Dataflow.signal(); + _nodes = Flow.Dataflow.signals(); + formatMilliseconds = function (ms) { + return Flow.Util.fromNow(new Date(new Date().getTime() - ms)); }; - doPost = http; - mapWithKey = function (obj, f) { - var key, result, value; - result = []; - for (key in obj) { - value = obj[key]; - result.push(f(value, key)); + format3f = d3.format('.3f'); + _sizes = [ + 'B', + 'KB', + 'MB', + 'GB', + 'TB', + 'PB', + 'EB', + 'ZB', + 'YB' + ]; + prettyPrintBytes = function (bytes) { + var i; + if (bytes === 0) { + return '-'; } - return result; + i = Math.floor(Math.log(bytes) / Math.log(1024)); + return (bytes / Math.pow(1024, i)).toFixed(2) + ' ' + _sizes[i]; }; - composePath = function (path, opts) { - var params; - if (opts) { - params = mapWithKey(opts, function (v, k) { - return '' + k + '=' + v; - }); - return path + '?' + params.join('&'); - } else { - return path; + formatThreads = function (fjs) { + var i, max_lo, s, _i, _j, _k, _ref; + for (max_lo = _i = 120; _i > 0; max_lo = --_i) { + if (fjs[max_lo - 1] !== -1) { + break; + } } - }; - requestWithOpts = function (path, opts, go) { - return doGet(composePath(path, opts), go); - }; - encodeArray = function (array) { - return '[' + lodash.map(array, encodeURIComponent).join(',') + ']'; - }; - encodeObject = function (source) { - var k, target, v; - target = {}; - for (k in source) { - v = source[k]; - target[k] = encodeURIComponent(v); + s = '['; + for (i = _j = 0; 0 <= max_lo ? _j < max_lo : _j > max_lo; i = 0 <= max_lo ? ++_j : --_j) { + s += Math.max(fjs[i], 0); + s += '/'; } - return target; - }; - requestInspect = function (key, go) { - var opts; - opts = { key: encodeURIComponent(key) }; - return requestWithOpts('/Inspect.json', opts, go); - }; - requestCreateFrame = function (opts, go) { - return requestWithOpts('/2/CreateFrame.json', encodeObject(opts), go); - }; - requestFrames = function (go) { - return doGet('/3/Frames.json', function (error, result) { - if (error) { - return go(error); - } else { - return go(null, result.frames); - } - }); - }; - requestFrame = function (key, go) { - return doGet('/3/Frames.json/' + encodeURIComponent(key), function (error, result) { - if (error) { - return go(error); - } else { - return go(null, lodash.head(result.frames)); - } - }); - }; - requestColumnSummary = function (key, column, go) { - return doGet('/3/Frames.json/' + encodeURIComponent(key) + '/columns/' + encodeURIComponent(column) + '/summary', function (error, result) { - if (error) { - return go(error); - } else { - return go(null, lodash.head(result.frames)); - } - }); - }; - requestJobs = function (go) { - return doGet('/3/Jobs.json', function (error, result) { - if (error) { - return go(new Flow.Error('Error fetching jobs', error)); - } else { - return go(null, result.jobs); - } - }); - }; - requestJob = function (key, go) { - return doGet('/3/Jobs.json/' + encodeURIComponent(key), function (error, result) { - if (error) { - return go(new Flow.Error('Error fetching job \'' + key + '\'', error)); - } else { - return go(null, lodash.head(result.jobs)); - } - }); + s += '.../'; + for (i = _k = 120, _ref = fjs.length - 1; 120 <= _ref ? _k < _ref : _k > _ref; i = 120 <= _ref ? ++_k : --_k) { + s += fjs[i]; + s += '/'; + } + s += fjs[fjs.length - 1]; + s += ']'; + return s; }; - requestFileGlob = function (path, limit, go) { - var opts; - opts = { - src: encodeURIComponent(path), - limit: limit - }; - return requestWithOpts('/Typeahead.json/files', opts, go); + sum = function (nodes, attrOf) { + var node, total, _i, _len; + total = 0; + for (_i = 0, _len = nodes.length; _i < _len; _i++) { + node = nodes[_i]; + total += attrOf(node); + } + return total; }; - requestImportFiles = function (paths, go) { - var tasks; - tasks = lodash.map(paths, function (path) { - return function (go) { - return requestImportFile(path, go); - }; - }); - return Flow.Async.iterate(tasks)(go); + avg = function (nodes, attrOf) { + return sum(nodes, attrOf) / nodes.length; }; - requestImportFile = function (path, go) { - var opts; - opts = { path: encodeURIComponent(path) }; - return requestWithOpts('/ImportFiles.json', opts, go); - }; - requestParseSetup = function (sources, go) { - var encodedPaths, opts; - encodedPaths = lodash.map(sources, encodeURIComponent); - opts = { srcs: '[' + encodedPaths.join(',') + ']' }; - return requestWithOpts('/ParseSetup.json', opts, go); + _headers = [ + [ + ' ', + true + ], + [ + 'Name', + true + ], + [ + 'Ping', + true + ], + [ + 'Cores', + true + ], + [ + 'Load', + true + ], + [ + 'Data (Used/Total)', + true + ], + [ + 'Data (% Cached)', + true + ], + [ + 'GC (Free / Total / Max)', + true + ], + [ + 'Disk (Free / Max)', + true + ], + [ + 'Disk (% Free)', + true + ], + [ + 'PID', + false + ], + [ + 'Keys', + false + ], + [ + 'TCP', + false + ], + [ + 'FD', + false + ], + [ + 'RPCs', + false + ], + [ + 'Threads', + false + ], + [ + 'Tasks', + false + ] + ]; + createNodeRow = function (node) { + return [ + node.healthy, + node.h2o.node, + moment(new Date(node.last_ping)).fromNow(), + node.num_cpus, + format3f(node.sys_load), + '' + prettyPrintBytes(node.mem_value_size) + ' / ' + prettyPrintBytes(node.total_value_size), + '' + Math.floor(node.mem_value_size * 100 / node.total_value_size) + '%', + '' + prettyPrintBytes(node.free_mem) + ' / ' + prettyPrintBytes(node.tot_mem) + ' / ' + prettyPrintBytes(node.max_mem), + '' + prettyPrintBytes(node.free_disk) + ' / ' + prettyPrintBytes(node.max_disk), + '' + Math.floor(node.free_disk * 100 / node.max_disk) + '%', + node.pid, + node.num_keys, + node.tcps_active, + node.open_fds, + node.rpcs_active, + formatThreads(node.fjthrds), + formatThreads(node.fjqueue) + ]; }; - requestParseFiles = function (sourceKeys, destinationKey, parserType, separator, columnCount, useSingleQuotes, columnNames, deleteOnDone, checkHeader, go) { - var opts; - opts = { - hex: encodeURIComponent(destinationKey), - srcs: encodeArray(sourceKeys), - pType: parserType, - sep: separator, - ncols: columnCount, - singleQuotes: useSingleQuotes, - columnNames: encodeArray(columnNames), - checkHeader: checkHeader, - delete_on_done: deleteOnDone - }; - return requestWithOpts('/Parse.json', opts, go); + createTotalRow = function (cloud) { + var nodes; + nodes = cloud.nodes; + return [ + cloud.cloud_healthy, + 'TOTAL', + '-', + sum(nodes, function (node) { + return node.num_cpus; + }), + format3f(sum(nodes, function (node) { + return node.sys_load; + })), + '' + prettyPrintBytes(sum(nodes, function (node) { + return node.mem_value_size; + })) + ' / ' + prettyPrintBytes(sum(nodes, function (node) { + return node.total_value_size; + })), + '' + Math.floor(avg(nodes, function (node) { + return node.mem_value_size * 100 / node.total_value_size; + })) + '%', + '' + prettyPrintBytes(sum(nodes, function (node) { + return node.free_mem; + })) + ' / ' + prettyPrintBytes(sum(nodes, function (node) { + return node.tot_mem; + })) + ' / ' + prettyPrintBytes(sum(nodes, function (node) { + return node.max_mem; + })), + '' + prettyPrintBytes(sum(nodes, function (node) { + return node.free_disk; + })) + ' / ' + prettyPrintBytes(sum(nodes, function (node) { + return node.max_disk; + })), + '' + Math.floor(avg(nodes, function (node) { + return node.free_disk * 100 / node.max_disk; + })) + '%', + '-', + sum(nodes, function (node) { + return node.num_keys; + }), + sum(nodes, function (node) { + return node.tcps_active; + }), + sum(nodes, function (node) { + return node.open_fds; + }), + sum(nodes, function (node) { + return node.rpcs_active; + }), + '-', + '-' + ]; }; - patchUpModels = function (models) { - var model, parameter, parseError, _i, _j, _len, _len1, _ref; - for (_i = 0, _len = models.length; _i < _len; _i++) { - model = models[_i]; - _ref = model.parameters; - for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { - parameter = _ref[_j]; - switch (parameter.type) { - case 'Key': - case 'Key': - case 'VecSpecifier': - if (lodash.isString(parameter.actual_value)) { - try { - parameter.actual_value = JSON.parse(parameter.actual_value); - } catch (_error) { - parseError = _error; + createGrid = function (cloud, isExpanded) { + var caption, cell, danger, grid, i, nodeRows, row, showAlways, success, table, tbody, td, tds, th, thead, ths, tr, trs, _ref; + _ref = Flow.HTML.template('.grid', 'table', '=thead', 'tbody', 'tr', '=th', '=td', '=i.fa.fa-check-circle.text-success', '=i.fa.fa-exclamation-circle.text-danger'), grid = _ref[0], table = _ref[1], thead = _ref[2], tbody = _ref[3], tr = _ref[4], th = _ref[5], td = _ref[6], success = _ref[7], danger = _ref[8]; + nodeRows = lodash.map(cloud.nodes, createNodeRow); + nodeRows.push(createTotalRow(cloud)); + ths = function () { + var _i, _len, _ref1, _results; + _results = []; + for (_i = 0, _len = _headers.length; _i < _len; _i++) { + _ref1 = _headers[_i], caption = _ref1[0], showAlways = _ref1[1]; + if (showAlways || isExpanded) { + _results.push(th(caption)); + } + } + return _results; + }(); + trs = function () { + var _i, _len, _results; + _results = []; + for (_i = 0, _len = nodeRows.length; _i < _len; _i++) { + row = nodeRows[_i]; + tds = function () { + var _j, _len1, _results1; + _results1 = []; + for (i = _j = 0, _len1 = row.length; _j < _len1; i = ++_j) { + cell = row[i]; + if (_headers[i][1] || isExpanded) { + if (i === 0) { + _results1.push(td(cell ? success() : danger())); + } else { + _results1.push(td(cell)); + } } } - } + return _results1; + }(); + _results.push(tr(tds)); } - } - return models; + return _results; + }(); + return Flow.HTML.render('div', grid([table([ + thead(tr(ths)), + tbody(trs) + ])])); }; - requestModels = function (go, opts) { - return requestWithOpts('/3/Models.json', opts, function (error, result) { + updateCloud = function (cloud, isExpanded) { + _name(cloud.cloud_name); + _version(cloud.version); + _hasConsensus(cloud.consensus); + _uptime(formatMilliseconds(cloud.cloud_uptime_millis)); + _nodeCounts('' + (cloud.cloud_size - cloud.bad_nodes) + ' / ' + cloud.cloud_size); + _isLocked(cloud.locked); + _isHealthy(cloud.cloud_healthy); + return _nodes(createGrid(cloud, isExpanded)); + }; + toggleRefresh = function () { + return _isLive(!_isLive()); + }; + refresh = function () { + _isBusy(true); + return _.requestCloud(function (error, cloud) { + _isBusy(false); if (error) { - return go(error, result); + _exception(Flow.Failure(new Flow.Error('Error fetching cloud status', error))); + return _isLive(false); } else { - return go(error, patchUpModels(result.models)); + updateCloud(_cloud = cloud, _isExpanded()); + if (_isLive()) { + return lodash.delay(refresh, 2000); + } } }); }; - requestModel = function (key, go) { - return doGet('/3/Models.json/' + encodeURIComponent(key), function (error, result) { - if (error) { - return go(error, result); - } else { - return go(error, lodash.head(patchUpModels(result.models))); - } - }); + Flow.Dataflow.act(_isLive, function (isLive) { + if (isLive) { + return refresh(); + } + }); + toggleExpansion = function () { + return _isExpanded(!_isExpanded()); }; - requestModelBuilders = function (go) { - return doGet('/2/ModelBuilders.json', go); + Flow.Dataflow.act(_isExpanded, function (isExpanded) { + return updateCloud(_cloud, isExpanded); + }); + updateCloud(_cloud, _isExpanded()); + return { + name: _name, + size: _size, + uptime: _uptime, + version: _version, + nodeCounts: _nodeCounts, + hasConsensus: _hasConsensus, + isLocked: _isLocked, + isHealthy: _isHealthy, + nodes: _nodes, + isLive: _isLive, + isBusy: _isBusy, + toggleRefresh: toggleRefresh, + refresh: refresh, + isExpanded: _isExpanded, + toggleExpansion: toggleExpansion, + template: 'flow-cloud-output' }; - requestModelBuilder = function (algo, go) { - return doGet('/2/ModelBuilders.json/' + algo, go); + }; +}.call(this)); +(function () { + H2O.ColumnSummaryOutput = function (_, frameKey, frame, columnName) { + var column, inspect, _characteristicsPlot, _characteristicsPlotConfig, _characteristicsTable; + column = lodash.head(frame.columns); + _characteristicsPlot = Flow.Dataflow.signal(null); + _characteristicsTable = _.inspect('characteristics', frame); + _characteristicsPlotConfig = { + data: _characteristicsTable, + type: 'interval', + x: Flow.Plot.stack('count'), + y: 'label' }; - requestModelInputValidation = function (algo, parameters, go) { - return doPost('/2/ModelBuilders.json/' + algo + '/parameters', parameters, go); + Flow.Plot(_characteristicsPlotConfig, function (error, plot) { + if (!error) { + return _characteristicsPlot(plot); + } + }); + inspect = function () { + return _.insertAndExecuteCell('cs', 'inspect getColumnSummary ' + Flow.Prelude.stringify(frameKey) + ', ' + Flow.Prelude.stringify(columnName)); }; - requestModelBuild = function (algo, parameters, go) { - return doPost('/2/ModelBuilders.json/' + algo, parameters, go); + return { + label: column.label, + characteristicsPlot: _characteristicsPlot, + inspect: inspect, + template: 'flow-column-summary-output' }; - requestPredict = function (modelKey, frameKey, go) { - return doPost('/3/Predictions.json/models/' + encodeURIComponent(modelKey) + '/frames/' + encodeURIComponent(frameKey), {}, function (error, result) { - if (error) { - return go(error); - } else { - return go(null, lodash.head(result.model_metrics)); - } - }); + }; +}.call(this)); +(function () { + H2O.CreateFrameInput = function (_) { + var createFrame, _binaryFraction, _categoricalFraction, _columns, _factors, _integerFraction, _integerRange, _key, _missingFraction, _randomize, _realRange, _responseFactors, _rows, _seed, _value; + _key = Flow.Dataflow.signal(''); + _rows = Flow.Dataflow.signal(10000); + _columns = Flow.Dataflow.signal(100); + _seed = Flow.Dataflow.signal(7595850248774472000); + _randomize = Flow.Dataflow.signal(true); + _value = Flow.Dataflow.signal(0); + _realRange = Flow.Dataflow.signal(100); + _categoricalFraction = Flow.Dataflow.signal(0.1); + _factors = Flow.Dataflow.signal(5); + _integerFraction = Flow.Dataflow.signal(0.5); + _binaryFraction = Flow.Dataflow.signal(0.1); + _integerRange = Flow.Dataflow.signal(1); + _missingFraction = Flow.Dataflow.signal(0.01); + _responseFactors = Flow.Dataflow.signal(2); + createFrame = function () { + var opts; + opts = { + dest: _key(), + rows: _rows(), + cols: _columns(), + seed: _seed(), + randomize: _randomize(), + value: _value(), + real_range: _realRange(), + categorical_fraction: _categoricalFraction(), + factors: _factors(), + integer_fraction: _integerFraction(), + binary_fraction: _binaryFraction(), + integer_range: _integerRange(), + missing_fraction: _missingFraction(), + response_factors: _responseFactors() + }; + return _.insertAndExecuteCell('cs', 'createFrame ' + Flow.Prelude.stringify(opts)); }; - requestPrediction = function (modelKey, frameKey, go) { - return doPost('/3/Predictions.json/models/' + encodeURIComponent(modelKey) + '/frames/' + encodeURIComponent(frameKey), {}, function (error, result) { - if (error) { - return go(error); - } else { - return go(null, lodash.head(result.model_metrics)); - } - }); + return { + key: _key, + rows: _rows, + columns: _columns, + seed: _seed, + randomize: _randomize, + value: _value, + realRange: _realRange, + categoricalFraction: _categoricalFraction, + factors: _factors, + integerFraction: _integerFraction, + binaryFraction: _binaryFraction, + integerRange: _integerRange, + missingFraction: _missingFraction, + responseFactors: _responseFactors, + createFrame: createFrame, + template: 'flow-create-frame-input' }; - requestPredictions = function (modelKey, frameKey, _go) { - var go; - go = function (error, result) { - var prediction, predictions; - if (error) { - return _go(error); - } else { - predictions = function () { - var _i, _len, _ref, _results; - _ref = result.model_metrics; - _results = []; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - prediction = _ref[_i]; - if (modelKey && prediction.model.key !== modelKey) { - _results.push(null); - } else if (frameKey && prediction.frame.key.name !== frameKey) { - _results.push(null); - } else { - _results.push(prediction); + }; +}.call(this)); +(function () { + H2O.FrameOutput = function (_, _frame) { + var createGrid, createModel, download, inspect, inspectData, predict, _grid; + createGrid = function (data) { + var action, el, grid, row, rowIndex, table, tbody, td, tdr, tds, th, thead, thr, ths, tr, trs, value, variable, _ref; + _ref = Flow.HTML.template('.grid', 'table', '=thead', 'tbody', 'tr', '=th', '=th.rt', '=td', '=td.rt', '+a data-action=\'summary\' data-index=\'{0}\' class=\'action\' href=\'#\''), grid = _ref[0], table = _ref[1], thead = _ref[2], tbody = _ref[3], tr = _ref[4], th = _ref[5], thr = _ref[6], td = _ref[7], tdr = _ref[8], action = _ref[9]; + ths = function () { + var _i, _len, _ref1, _results; + _ref1 = data.variables; + _results = []; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + variable = _ref1[_i]; + switch (variable.type) { + case Flow.TNumber: + _results.push(thr(lodash.escape(variable.label))); + break; + default: + _results.push(th(lodash.escape(variable.label))); + } + } + return _results; + }(); + ths.push(th('Actions')); + trs = function () { + var _i, _len, _ref1, _results; + _ref1 = data.rows; + _results = []; + for (rowIndex = _i = 0, _len = _ref1.length; _i < _len; rowIndex = ++_i) { + row = _ref1[rowIndex]; + tds = function () { + var _j, _len1, _ref2, _results1; + _ref2 = data.variables; + _results1 = []; + for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { + variable = _ref2[_j]; + value = row[variable.label]; + switch (variable.type) { + case Flow.TFactor: + _results1.push(td(value === null ? '-' : lodash.escape(variable.domain[value]))); + break; + case Flow.TNumber: + _results1.push(tdr(value === null ? '-' : value)); + break; + case Flow.TArray: + _results1.push(td(value === null ? '-' : value.join(', '))); + break; + default: + _results1.push(td(value === null ? '-' : value)); } } - return _results; + return _results1; }(); - return _go(null, function () { - var _i, _len, _results; - _results = []; - for (_i = 0, _len = predictions.length; _i < _len; _i++) { - prediction = predictions[_i]; - if (prediction) { - _results.push(prediction); - } + tds.push(td(action('Summary...', rowIndex))); + _results.push(tr(tds)); + } + return _results; + }(); + el = Flow.HTML.render('div', grid([table([ + thead(tr(ths)), + tbody(trs) + ])])); + $('a.action', el).click(function (e) { + var $link, index; + e.preventDefault(); + $link = $(this); + action = $link.attr('data-action'); + index = parseInt($link.attr('data-index'), 10); + switch (action) { + case 'summary': + if (index >= 0) { + row = data.rows[index]; + if (row) { + return _.insertAndExecuteCell('cs', 'inspect getColumnSummary ' + Flow.Prelude.stringify(_frame.key.name) + ', ' + Flow.Prelude.stringify(row.label)); } - return _results; - }()); + } } - }; - if (modelKey && frameKey) { - return doPost('/3/Predictions.json/models/' + encodeURIComponent(modelKey) + '/frames/' + encodeURIComponent(frameKey), {}, go); - } else if (modelKey) { - return doGet('/3/ModelMetrics.json/models/' + encodeURIComponent(modelKey), go); - } else if (frameKey) { - return doGet('/3/ModelMetrics.json/frames/' + encodeURIComponent(frameKey), go); - } else { - return doGet('/3/ModelMetrics.json', go); - } + }); + return el; }; - requestObjects = function (type, go) { - return go(null, Flow.LocalStorage.list(type)); + createModel = function () { + return _.insertAndExecuteCell('cs', 'assist buildModel, null, training_frame: ' + Flow.Prelude.stringify(_frame.key.name)); }; - requestObject = function (type, id, go) { - return go(null, Flow.LocalStorage.read(type, id)); - }; - requestDeleteObject = function (type, id, go) { - return go(null, Flow.LocalStorage.purge(type, id)); - }; - requestPutObject = function (type, id, obj, go) { - return go(null, Flow.LocalStorage.write(type, id, obj)); - }; - requestCloud = function (go) { - return doGet('/3/Cloud.json', go); - }; - requestTimeline = function (go) { - return doGet('/3/Timeline.json', go); - }; - requestProfile = function (depth, go) { - return doGet('/3/Profiler.json?depth=' + depth, go); + inspect = function () { + return _.insertAndExecuteCell('cs', 'inspect getFrame ' + Flow.Prelude.stringify(_frame.key.name)); }; - requestStackTrace = function (go) { - return doGet('/3/JStack.json', go); + inspectData = function () { + return _.insertAndExecuteCell('cs', 'grid inspect \'data\', getFrame ' + Flow.Prelude.stringify(_frame.key.name)); }; - requestRemoveAll = function (go) { - return doGet('/3/RemoveAll.json', go); + predict = function () { + return _.insertAndExecuteCell('cs', 'predict null, ' + Flow.Prelude.stringify(_frame.key.name)); }; - requestLogFile = function (nodeIndex, go) { - return doGet('/3/Logs.json/nodes/' + nodeIndex + '/files/default', go); + download = function () { + return window.open('/3/DownloadDataset?key=' + encodeURIComponent(_frame.key.name), '_blank'); }; - requestAbout = function (go) { - return doGet('/3/About.json', go); + _grid = createGrid(_.inspect('columns', _frame)); + return { + key: _frame.key.name, + grid: _grid, + inspect: inspect, + createModel: createModel, + inspectData: inspectData, + predict: predict, + download: download, + template: 'flow-frame-output' }; - Flow.Dataflow.link(_.requestGet, doGet); - Flow.Dataflow.link(_.requestPost, doPost); - Flow.Dataflow.link(_.requestInspect, requestInspect); - Flow.Dataflow.link(_.requestCreateFrame, requestCreateFrame); - Flow.Dataflow.link(_.requestFrames, requestFrames); - Flow.Dataflow.link(_.requestFrame, requestFrame); - Flow.Dataflow.link(_.requestColumnSummary, requestColumnSummary); - Flow.Dataflow.link(_.requestJobs, requestJobs); - Flow.Dataflow.link(_.requestJob, requestJob); - Flow.Dataflow.link(_.requestFileGlob, requestFileGlob); - Flow.Dataflow.link(_.requestImportFiles, requestImportFiles); - Flow.Dataflow.link(_.requestImportFile, requestImportFile); - Flow.Dataflow.link(_.requestParseSetup, requestParseSetup); - Flow.Dataflow.link(_.requestParseFiles, requestParseFiles); - Flow.Dataflow.link(_.requestModels, requestModels); - Flow.Dataflow.link(_.requestModel, requestModel); - Flow.Dataflow.link(_.requestModelBuilder, requestModelBuilder); - Flow.Dataflow.link(_.requestModelBuilders, requestModelBuilders); - Flow.Dataflow.link(_.requestModelBuild, requestModelBuild); - Flow.Dataflow.link(_.requestModelInputValidation, requestModelInputValidation); - Flow.Dataflow.link(_.requestPredict, requestPredict); - Flow.Dataflow.link(_.requestPrediction, requestPrediction); - Flow.Dataflow.link(_.requestPredictions, requestPredictions); - Flow.Dataflow.link(_.requestObjects, requestObjects); - Flow.Dataflow.link(_.requestObject, requestObject); - Flow.Dataflow.link(_.requestDeleteObject, requestDeleteObject); - Flow.Dataflow.link(_.requestPutObject, requestPutObject); - Flow.Dataflow.link(_.requestCloud, requestCloud); - Flow.Dataflow.link(_.requestTimeline, requestTimeline); - Flow.Dataflow.link(_.requestProfile, requestProfile); - Flow.Dataflow.link(_.requestStackTrace, requestStackTrace); - Flow.Dataflow.link(_.requestRemoveAll, requestRemoveAll); - Flow.Dataflow.link(_.requestLogFile, requestLogFile); - return Flow.Dataflow.link(_.requestAbout, requestAbout); }; }.call(this)); (function () { - var computeFalsePositiveRate, computeTruePositiveRate, formatConfusionMatrix, formulateGetPredictionsOrigin, _assistance, __slice = [].slice; - _assistance = { - importFiles: { - description: 'Import file(s) into H2O', - icon: 'files-o' - }, - getFrames: { - description: 'Get a list of frames in H2O', - icon: 'database' - }, - getModels: { - description: 'Get a list of models in H2O', - icon: 'cubes' - }, - getPredictions: { - description: 'Get a list of predictions in H2O', - icon: 'bolt' - }, - getJobs: { - description: 'Get a list of jobs running in H2O', - icon: 'tasks' - }, - buildModel: { - description: 'Build a model', - icon: 'cube' - }, - predict: { - description: 'Make a prediction', - icon: 'bolt' + var toSize; + toSize = function (bytes) { + var i, sizes; + sizes = [ + 'Bytes', + 'KB', + 'MB', + 'GB', + 'TB' + ]; + if (bytes === 0) { + return '0 Byte'; } + i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); + return Math.round(bytes / Math.pow(1024, i), 2) + sizes[i]; }; - computeTruePositiveRate = function (cm) { - var fn, fp, tn, tp, _ref, _ref1; - (_ref = cm[0], tn = _ref[0], fp = _ref[1]), (_ref1 = cm[1], fn = _ref1[0], tp = _ref1[1]); - return tp / (tp + fn); - }; - computeFalsePositiveRate = function (cm) { - var fn, fp, tn, tp, _ref, _ref1; - (_ref = cm[0], tn = _ref[0], fp = _ref[1]), (_ref1 = cm[1], fn = _ref1[0], tp = _ref1[1]); - return fp / (fp + tn); - }; - formatConfusionMatrix = function (cm) { - var fn, fp, table, tbody, td, tn, tp, tr, _ref, _ref1, _ref2; - (_ref = cm[0], tn = _ref[0], fp = _ref[1]), (_ref1 = cm[1], fn = _ref1[0], tp = _ref1[1]); - _ref2 = Flow.HTML.template('table.flow-matrix', 'tbody', 'tr', '=td'), table = _ref2[0], tbody = _ref2[1], tr = _ref2[2], td = _ref2[3]; - return table([tbody([ - tr([ - td(tn), - td(fp) - ]), - tr([ - td(fn), - td(tp) - ]) - ])]); - }; - formulateGetPredictionsOrigin = function (opts) { - var frameKey, modelKey, opt, sanitizedOpt, sanitizedOpts; - if (lodash.isArray(opts)) { - sanitizedOpts = function () { - var _i, _len, _results; - _results = []; - for (_i = 0, _len = opts.length; _i < _len; _i++) { - opt = opts[_i]; - sanitizedOpt = {}; - if (opt.model) { - sanitizedOpt.model = opt.model; + H2O.FramesOutput = function (_, _frames) { + var createFrameView, importFiles, predictOnFrames, _canCompareFrames, _checkAllFrames, _frameViews, _isCheckingAll; + _frameViews = Flow.Dataflow.signal([]); + _checkAllFrames = Flow.Dataflow.signal(false); + _canCompareFrames = Flow.Dataflow.signal(false); + _isCheckingAll = false; + Flow.Dataflow.react(_checkAllFrames, function (checkAll) { + var view, _i, _len, _ref; + _isCheckingAll = true; + _ref = _frameViews(); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + view = _ref[_i]; + view.isChecked(checkAll); + } + _canCompareFrames(checkAll); + _isCheckingAll = false; + }); + createFrameView = function (frame) { + var columnLabels, createModel, description, inspect, predict, view, _isChecked; + _isChecked = Flow.Dataflow.signal(false); + Flow.Dataflow.react(_isChecked, function () { + var checkedViews, view; + if (_isCheckingAll) { + return; + } + checkedViews = function () { + var _i, _len, _ref, _results; + _ref = _frameViews(); + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + view = _ref[_i]; + if (view.isChecked()) { + _results.push(view); + } } - if (opt.frame) { - sanitizedOpt.frame = opt.frame; + return _results; + }(); + return _canCompareFrames(checkedViews.length > 0); + }); + columnLabels = lodash.head(lodash.map(frame.columns, function (column) { + return column.label; + }), 15); + description = 'Columns: ' + columnLabels.join(', ') + (frame.columns.length > columnLabels.length ? '... (' + (frame.columns.length - columnLabels.length) + ' more columns)' : ''); + view = function () { + if (frame.isText) { + return _.insertAndExecuteCell('cs', 'setupParse [ ' + Flow.Prelude.stringify(frame.key.name) + ' ]'); + } else { + return _.insertAndExecuteCell('cs', 'getFrame ' + Flow.Prelude.stringify(frame.key.name)); + } + }; + predict = function () { + return _.insertAndExecuteCell('cs', 'predict null, ' + Flow.Prelude.stringify(frame.key.name)); + }; + inspect = function () { + return _.insertAndExecuteCell('cs', 'inspect getFrame ' + Flow.Prelude.stringify(frame.key.name)); + }; + createModel = function () { + return _.insertAndExecuteCell('cs', 'assist buildModel, null, training_frame: ' + Flow.Prelude.stringify(frame.key.name)); + }; + return { + key: frame.key.name, + isChecked: _isChecked, + description: description, + size: toSize(frame.byteSize), + rowCount: frame.rows, + columnCount: frame.columns.length, + isText: frame.isText, + view: view, + predict: predict, + inspect: inspect, + createModel: createModel + }; + }; + importFiles = function () { + return _.insertAndExecuteCell('cs', 'importFiles'); + }; + predictOnFrames = function () { + var selectedKeys, view; + selectedKeys = function () { + var _i, _len, _ref, _results; + _ref = _frameViews(); + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + view = _ref[_i]; + if (view.isChecked()) { + _results.push(view.key); } - _results.push(sanitizedOpt); } return _results; }(); - return 'getPredictions ' + Flow.Prelude.stringify(sanitizedOpts); - } else { - modelKey = opts.model, frameKey = opts.frame; - if (modelKey && frameKey) { - return 'getPredictions model: ' + Flow.Prelude.stringify(modelKey) + ', frame: ' + Flow.Prelude.stringify(frameKey); - } else if (modelKey) { - return 'getPredictions model: ' + Flow.Prelude.stringify(modelKey); - } else if (frameKey) { - return 'getPredictions frame: ' + Flow.Prelude.stringify(frameKey); - } else { - return 'getPredictions()'; - } - } - }; - H2O.Routines = function (_) { - var assist, buildModel, createFrame, dump, dumpFuture, extendCloud, extendColumnSummary, extendDeepLearningModel, extendFrame, extendFrames, extendGBMModel, extendGLMModel, extendKMeansModel, extendLogFile, extendModel, extendModels, extendPrediction, extendPredictions, extendProfile, extendStackTrace, extendTimeline, f, flow_, form, getCloud, getColumnSummary, getFrame, getFrames, getJob, getJobs, getLogFile, getModel, getModels, getPrediction, getPredictions, getProfile, getStackTrace, getTimeline, grid, gui, importFiles, inspect, inspect$1, inspect$2, inspectBinomialMetrics, inspectBinomialPrediction, inspectBinomialPredictions, inspectBinomialScores, inspectFrameColumns, inspectFrameData, inspectGBMModelOutput, inspectKMeansModelClusterDetails, inspectKMeansModelClusters, inspectKMeansModelOutput, inspectModelParameters, inspectMultimodelParameters, inspectRegressionPrediction, inspect_, loadScript, name, parseRaw, plot, predict, proceed, read, render_, renderable, requestCloud, requestColumnSummary, requestCreateFrame, requestFrame, requestFrames, requestLogFile, requestModel, requestModels, requestModelsByKeys, requestPredict, requestPrediction, requestPredictions, requestPredicts, requestProfile, requestStackTrace, requestTimeline, setupParse, __plot, _apply, _async, _call, _fork, _get, _isFuture, _join, _plot, _plotInput, _ref; - _fork = function () { - var args, f; - f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; - return Flow.Async.fork(f, args); - }; - _join = function () { - var args, go, _i; - args = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), go = arguments[_i++]; - return Flow.Async.join(args, Flow.Async.applicate(go)); - }; - _call = function () { - var args, go; - go = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; - return Flow.Async.join(args, Flow.Async.applicate(go)); - }; - _apply = function (go, args) { - return Flow.Async.join(args, go); - }; - _isFuture = Flow.Async.isFuture; - _async = Flow.Async.async; - _get = Flow.Async.get; - proceed = function (func, args, go) { - return go(null, render_({}, function () { - return func.apply(null, [_].concat(args || [])); - })); + return _.insertAndExecuteCell('cs', 'predict null, ' + Flow.Prelude.stringify(selectedKeys)); }; - renderable = Flow.Async.renderable; - form = function (controls, go) { - return go(null, Flow.Dataflow.signals(controls || [])); + _frameViews(lodash.map(_frames, createFrameView)); + return { + frameViews: _frameViews, + hasFrames: _frames.length > 0, + importFiles: importFiles, + predictOnFrames: predictOnFrames, + canCompareFrames: _canCompareFrames, + checkAllFrames: _checkAllFrames, + template: 'flow-frames-output' }; - gui = function (controls) { - return Flow.Async.renderable(form, controls, function (form, go) { - return go(null, Flow.Form(_, form)); + }; +}.call(this)); +(function () { + H2O.ImportFilesInput = function (_) { + var createFileItem, createFileItems, createSelectedFileItem, deselectAllFiles, importFiles, importSelectedFiles, listPathHints, processImportResult, selectAllFiles, tryImportFiles, _exception, _hasErrorMessage, _hasImportedFiles, _hasSelectedFiles, _hasUnselectedFiles, _importedFileCount, _importedFiles, _selectedFileCount, _selectedFiles, _selectedFilesDictionary, _specifiedPath; + _specifiedPath = Flow.Dataflow.signal(''); + _exception = Flow.Dataflow.signal(''); + _hasErrorMessage = Flow.Dataflow.lift(_exception, function (exception) { + if (exception) { + return true; + } else { + return false; + } + }); + tryImportFiles = function () { + var specifiedPath; + specifiedPath = _specifiedPath(); + return _.requestFileGlob(specifiedPath, 0, function (error, result) { + if (error) { + return _exception(error.data.errmsg); + } else { + _exception(''); + return processImportResult(result); + } }); }; - _ref = Flow.Gui; - for (name in _ref) { - f = _ref[name]; - gui[name] = f; - } - flow_ = function (raw) { - return raw._flow_ || (raw._flow_ = { _cache_: {} }); - }; - render_ = function (raw, render) { - flow_(raw).render = render; - return raw; - }; - inspect_ = function (raw, inspectors) { - var attr, root; - root = flow_(raw); - if (root.inspect == null) { - root.inspect = {}; + _importedFiles = Flow.Dataflow.signals([]); + _importedFileCount = Flow.Dataflow.lift(_importedFiles, function (files) { + if (files.length) { + return 'Found ' + Flow.Util.describeCount(files.length, 'file') + ':'; + } else { + return ''; } - for (attr in inspectors) { - f = inspectors[attr]; - root.inspect[attr] = f; + }); + _hasImportedFiles = Flow.Dataflow.lift(_importedFiles, function (files) { + return files.length > 0; + }); + _hasUnselectedFiles = Flow.Dataflow.lift(_importedFiles, function (files) { + return lodash.some(files, function (file) { + return !file.isSelected(); + }); + }); + _selectedFiles = Flow.Dataflow.signals([]); + _selectedFilesDictionary = Flow.Dataflow.lift(_selectedFiles, function (files) { + var dictionary, file, _i, _len; + dictionary = {}; + for (_i = 0, _len = files.length; _i < _len; _i++) { + file = files[_i]; + dictionary[file.path] = true; } - return raw; + return dictionary; + }); + _selectedFileCount = Flow.Dataflow.lift(_selectedFiles, function (files) { + return '' + Flow.Util.describeCount(files.length, 'file') + ' selected:'; + }); + _hasSelectedFiles = Flow.Dataflow.lift(_selectedFiles, function (files) { + return files.length > 0; + }); + importFiles = function (files) { + var paths; + paths = lodash.map(files, function (file) { + return Flow.Prelude.stringify(file.path); + }); + return _.insertAndExecuteCell('cs', 'importFiles [ ' + paths.join(',') + ' ]'); }; - inspect = function (a, b) { - if (arguments.length === 1) { - return inspect$1(a); - } else { - return inspect$2(a, b); - } + importSelectedFiles = function () { + return importFiles(_selectedFiles()); }; - inspect$1 = function (obj) { - var attr, inspections, inspectors, _ref1; - if (_isFuture(obj)) { - return _async(inspect, obj); - } else { - if (inspectors = obj != null ? (_ref1 = obj._flow_) != null ? _ref1.inspect : void 0 : void 0) { - inspections = []; - for (attr in inspectors) { - f = inspectors[attr]; - inspections.push(inspect$2(attr, obj)); + createSelectedFileItem = function (path) { + var self; + return self = { + path: path, + deselect: function () { + var file, _i, _len, _ref; + _selectedFiles.remove(self); + _ref = _importedFiles(); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + file = _ref[_i]; + if (file.path === path) { + file.isSelected(false); + } } - render_(inspections, function () { - return H2O.InspectsOutput(_, inspections); - }); - return inspections; - } else { - return {}; } - } + }; }; - inspect$2 = function (attr, obj) { - var cached, inspection, inspectors, key, root; - if (!attr) { - return; - } - if (_isFuture(obj)) { - return _async(inspect, attr, obj); - } - if (!obj) { - return; - } - if (!(root = obj._flow_)) { - return; - } - if (!(inspectors = root.inspect)) { - return; - } - if (cached = root._cache_[key = 'inspect_' + attr]) { - return cached; - } - if (!(f = inspectors[attr])) { - return; - } - if (!lodash.isFunction(f)) { - return; - } - root._cache_[key] = inspection = f(); - render_(inspection, function () { - return H2O.InspectOutput(_, inspection); + createFileItem = function (path, isSelected) { + var self; + self = { + path: path, + isSelected: Flow.Dataflow.signal(isSelected), + select: function () { + _selectedFiles.push(createSelectedFileItem(self.path)); + return self.isSelected(true); + } + }; + Flow.Dataflow.act(self.isSelected, function (isSelected) { + return _hasUnselectedFiles(lodash.some(_importedFiles(), function (file) { + return !file.isSelected(); + })); }); - return inspection; + return self; }; - __plot = function (config, go) { - return Flow.Plot(config, function (error, plot) { - if (error) { - return go(new Flow.Error('Error rendering plot.', error)); - } else { - return go(null, plot); - } + createFileItems = function (result) { + return lodash.map(result.matches, function (path) { + return createFileItem(path, _selectedFilesDictionary()[path]); }); }; - _plot = function (config, go) { - if (config.data) { - if (_isFuture(config.data)) { - return config.data(function (error, data) { - if (error) { - return go(new Flow.Error('Error evaluating data for plot().', error)); - } else { - config.data = data; - return __plot(config, go); - } - }); - } else { - return __plot(config, go); + listPathHints = function (query, process) { + return _.requestFileGlob(query, 10, function (error, result) { + if (!error) { + return process(lodash.map(result.matches, function (value) { + return { value: value }; + })); } - } else { - return go(new Flow.Error('Cannot plot(): missing \'data\'.')); + }); + }; + selectAllFiles = function () { + var file, _i, _len, _ref; + _selectedFiles(lodash.map(_importedFiles(), function (file) { + return createSelectedFileItem(file.path); + })); + _ref = _importedFiles(); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + file = _ref[_i]; + file.isSelected(true); } }; - _plotInput = function (config, go) { - if (config.data) { - if (_isFuture(config.data)) { - return config.data(function (error, data) { - if (error) { - return go(new Flow.Error('Error evaluating data for plot().', error)); - } else { - config.data = data; - return go(null, config); - } - }); - } else { - return go(null, config); - } + deselectAllFiles = function () { + var file, _i, _len, _ref; + _selectedFiles([]); + _ref = _importedFiles(); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + file = _ref[_i]; + file.isSelected(false); + } + }; + processImportResult = function (result) { + var files; + files = createFileItems(result); + return _importedFiles(files); + }; + return { + specifiedPath: _specifiedPath, + hasErrorMessage: _hasErrorMessage, + exception: _exception, + tryImportFiles: tryImportFiles, + listPathHints: lodash.throttle(listPathHints, 100), + hasImportedFiles: _hasImportedFiles, + importedFiles: _importedFiles, + importedFileCount: _importedFileCount, + selectedFiles: _selectedFiles, + selectAllFiles: selectAllFiles, + deselectAllFiles: deselectAllFiles, + hasUnselectedFiles: _hasUnselectedFiles, + hasSelectedFiles: _hasSelectedFiles, + selectedFileCount: _selectedFileCount, + importSelectedFiles: importSelectedFiles, + template: 'flow-import-files' + }; + }; +}.call(this)); +(function () { + H2O.ImportFilesOutput = function (_, _importResults) { + var buildModel, createImportView, parse, _allKeys, _canBuildModel, _canParse, _importViews, _title; + _allKeys = lodash.flatten(lodash.compact(lodash.map(_importResults, function (_arg) { + var error, result; + error = _arg[0], result = _arg[1]; + if (error) { + return null; } else { - return go(new Flow.Error('Cannot plot(): missing \'data\'.')); + return result.keys; } + }))); + _canParse = _allKeys.length > 0; + _canBuildModel = _allKeys.length === 1; + _title = '' + _allKeys.length + ' / ' + _importResults.length + ' files imported.'; + createImportView = function (result) { + return { + keys: result.keys, + template: 'flow-import-file-output' + }; }; - plot = function (config) { - var configKeys; - configKeys = lodash.keys(config); - if (configKeys.length === 1 && 'data' === lodash.head(configKeys)) { - return renderable(_plotInput, config, function (config, go) { - return go(null, H2O.PlotInput(_, config)); - }); + _importViews = lodash.map(_importResults, function (_arg) { + var error, result; + error = _arg[0], result = _arg[1]; + if (error) { + return Flow.Failure(new Flow.Error('Error importing file', error)); } else { - return renderable(_plot, config, function (plot, go) { - return go(null, H2O.PlotOutput(_, plot)); - }); + return createImportView(result); } + }); + parse = function () { + var paths; + paths = lodash.map(_allKeys, Flow.Prelude.stringify); + return _.insertAndExecuteCell('cs', 'setupParse [ ' + paths.join(',') + ' ]'); }; - plot.stack = Flow.Plot.stack; - grid = function (data) { - return plot({ - type: 'text', - data: data - }); + buildModel = function () { + return _.insertAndExecuteCell('cs', 'assist buildModel, null, training_frame: ' + Flow.Prelude.stringify(lodash.head(_allKeys))); }; - extendCloud = function (cloud) { - return render_(cloud, function () { - return H2O.CloudOutput(_, cloud); - }); + return { + title: _title, + importViews: _importViews, + canParse: _canParse, + parse: parse, + canBuildModel: _canBuildModel, + buildModel: buildModel, + template: 'flow-import-files-output', + templateOf: function (view) { + return view.template; + } }; - extendTimeline = function (timeline) { - return render_(timeline, function () { - return H2O.TimelineOutput(_, timeline); - }); + }; +}.call(this)); +(function () { + H2O.InspectOutput = function (_, _table) { + var plot, view; + view = function () { + return _.insertAndExecuteCell('cs', 'grid inspect ' + Flow.Prelude.stringify(_table.label) + ', ' + _table.meta.origin); }; - extendStackTrace = function (stackTrace) { - return render_(stackTrace, function () { - return H2O.StackTraceOutput(_, stackTrace); - }); + plot = function () { + return _.insertAndExecuteCell('cs', _table.meta.plot); }; - extendLogFile = function (nodeIndex, logFile) { - return render_(logFile, function () { - return H2O.LogFileOutput(_, nodeIndex, logFile); - }); + return { + label: _table.label, + variables: _table.variables, + view: view, + canPlot: _table.meta.plot ? true : false, + plot: plot, + template: 'flow-inspect-output' }; - extendProfile = function (profile) { - return render_(profile, function () { - return H2O.ProfileOutput(_, profile); - }); + }; +}.call(this)); +(function () { + H2O.InspectsOutput = function (_, _tables) { + var createTableView; + createTableView = function (table) { + var grid, inspect, plot; + inspect = function () { + return _.insertAndExecuteCell('cs', 'inspect ' + Flow.Prelude.stringify(table.label) + ', ' + table.meta.origin); + }; + grid = function () { + return _.insertAndExecuteCell('cs', 'grid inspect ' + Flow.Prelude.stringify(table.label) + ', ' + table.meta.origin); + }; + plot = function () { + return _.insertAndExecuteCell('cs', table.meta.plot); + }; + return { + label: table.label, + description: table.description, + variables: table.variables, + inspect: inspect, + grid: grid, + canPlot: table.meta.plot ? true : false, + plot: plot + }; }; - extendFrames = function (frames) { - render_(frames, function () { - return H2O.FramesOutput(_, frames); + return { + hasTables: _tables.length > 0, + tables: lodash.map(_tables, createTableView), + template: 'flow-inspects-output' + }; + }; +}.call(this)); +(function () { + var getJobOutputStatusColor, getJobProgressPercent, jobOutputStatusColors; + jobOutputStatusColors = { + failed: '#d9534f', + done: '#ccc', + running: '#f0ad4e' + }; + getJobOutputStatusColor = function (status) { + switch (status) { + case 'DONE': + return jobOutputStatusColors.done; + case 'CREATED': + case 'RUNNING': + return jobOutputStatusColors.running; + default: + return jobOutputStatusColors.failed; + } + }; + getJobProgressPercent = function (progress) { + return '' + Math.ceil(100 * progress) + '%'; + }; + H2O.JobOutput = function (_, _job) { + var initialize, isJobRunning, refresh, toggleRefresh, updateJob, view, _canView, _description, _destinationKey, _exception, _isBusy, _isLive, _key, _progress, _runTime, _status, _statusColor; + _isBusy = Flow.Dataflow.signal(false); + _isLive = Flow.Dataflow.signal(false); + _key = _job.key.name; + _description = _job.description; + _destinationKey = _job.dest.name; + _runTime = Flow.Dataflow.signal(null); + _progress = Flow.Dataflow.signal(null); + _status = Flow.Dataflow.signal(null); + _statusColor = Flow.Dataflow.signal(null); + _exception = Flow.Dataflow.signal(null); + _canView = Flow.Dataflow.signal(false); + isJobRunning = function (job) { + return job.status === 'CREATED' || job.status === 'RUNNING'; + }; + updateJob = function (job) { + _runTime(job.msec); + _progress(getJobProgressPercent(job.progress)); + _status(job.status); + _statusColor(getJobOutputStatusColor(job.status)); + _exception(job.exception ? Flow.Failure(new Flow.Error('Job failure.', new Error(job.exception))) : null); + return _canView(!isJobRunning(job)); + }; + toggleRefresh = function () { + return _isLive(!_isLive()); + }; + refresh = function () { + _isBusy(true); + return _.requestJob(_key, function (error, job) { + _isBusy(false); + if (error) { + _exception(Flow.Failure(new Flow.Error('Error fetching jobs', error))); + return _isLive(false); + } else { + updateJob(job); + if (isJobRunning(job)) { + if (_isLive()) { + return lodash.delay(refresh, 1000); + } + } else { + return toggleRefresh(); + } + } }); - return frames; }; - inspectMultimodelParameters = function (models) { - return function () { - var Record, i, j, leader, model, modelKeys, parameter, parameters, row, rows, variable, variables, _i, _j, _len, _len1, _ref1; - leader = lodash.head(models); - parameters = leader.parameters; - variables = function () { - var _i, _len, _results; - _results = []; - for (_i = 0, _len = parameters.length; _i < _len; _i++) { - parameter = parameters[_i]; - switch (parameter.type) { - case 'enum': - case 'Frame': - case 'string': - case 'byte[]': - case 'short[]': - case 'int[]': - case 'long[]': - case 'float[]': - case 'double[]': - _results.push(Flow.Data.Variable(parameter.label, Flow.TString)); - break; - case 'byte': - case 'short': - case 'int': - case 'long': - case 'float': - case 'double': - _results.push(Flow.Data.Variable(parameter.label, Flow.TNumber)); - break; - case 'string[]': - _results.push(Flow.Data.Variable(parameter.label, Flow.TString)); - break; - case 'boolean': - _results.push(Flow.Data.Variable(parameter.label, Flow.TBoolean)); - break; - default: - _results.push(Flow.Data.Variable(parameter.label, Flow.TObject)); - } - } - return _results; - }(); - Record = Flow.Data.Record(variables); - rows = new Array(models.length); - for (i = _i = 0, _len = models.length; _i < _len; i = ++_i) { - model = models[i]; - rows[i] = row = new Record(); - _ref1 = model.parameters; - for (j = _j = 0, _len1 = _ref1.length; _j < _len1; j = ++_j) { - parameter = _ref1[j]; - variable = variables[j]; - row[variable.label] = parameter.actual_value; + Flow.Dataflow.act(_isLive, function (isLive) { + if (isLive) { + return refresh(); + } + }); + view = function () { + if (!_canView()) { + return; + } + return _.requestInspect(_destinationKey, function (error, result) { + if (error) { + return _exception(Flow.Failure(new Flow.Error('Error inspecting job target.', error))); + } else { + switch (result.kind) { + case 'frame': + return _.insertAndExecuteCell('cs', 'getFrame ' + Flow.Prelude.stringify(_destinationKey)); + case 'model': + return _.insertAndExecuteCell('cs', 'getModel ' + Flow.Prelude.stringify(_destinationKey)); } } - modelKeys = function () { - var _k, _len2, _results; - _results = []; - for (_k = 0, _len2 = models.length; _k < _len2; _k++) { - model = models[_k]; - _results.push(model.key); - } - return _results; - }(); - return Flow.Data.Table({ - label: 'parameters', - description: 'Parameters for models ' + modelKeys.join(', '), - variables: variables, - rows: rows, - meta: { origin: 'getModels ' + Flow.Prelude.stringify(modelKeys) } - }); - }; + }); }; - inspectModelParameters = function (model) { - return function () { - var Record, i, parameter, parameters, row, rows, variable, variables, _i, _j, _len, _len1; - parameters = model.parameters; - variables = [ - Flow.Data.Variable('label', Flow.TString), - Flow.Data.Variable('type', Flow.TString), - Flow.Data.Variable('level', Flow.TString), - Flow.Data.Variable('actual_value', Flow.TObject), - Flow.Data.Variable('default_value', Flow.TObject) - ]; - Record = Flow.Data.Record(variables); - rows = new Array(parameters.length); - for (i = _i = 0, _len = parameters.length; _i < _len; i = ++_i) { - parameter = parameters[i]; - rows[i] = row = new Record(); - for (_j = 0, _len1 = variables.length; _j < _len1; _j++) { - variable = variables[_j]; - row[variable.label] = parameter[variable.label]; - } - } - return Flow.Data.Table({ - label: 'parameters', - description: 'Parameters for model \'' + model.key.name + '\'', - variables: variables, - rows: rows, - meta: { origin: 'getModel ' + Flow.Prelude.stringify(model.key.name) } - }); - }; + initialize = function (job) { + updateJob(job); + if (isJobRunning(job)) { + return toggleRefresh(); + } }; - inspectGBMModelOutput = function (model) { - return function () { - var Record, i, mse_train, output, rows, variables, _i, _len, _ref1; - output = model.output; - variables = [ - Flow.Data.Variable('tree', Flow.TNumber), - Flow.Data.Variable('mse_train', Flow.TObject), - Flow.Data.Variable('mse_valid', Flow.TObject) - ]; - Record = Flow.Data.Record(variables); - rows = new Array(output.mse_train.length); - _ref1 = output.mse_train; - for (i = _i = 0, _len = _ref1.length; _i < _len; i = ++_i) { - mse_train = _ref1[i]; - rows[i] = new Record(i, mse_train, output.mse_valid[i]); - } - return Flow.Data.Table({ - label: 'output', - description: 'Output for GBM model \'' + model.key.name + '\'', - variables: variables, - rows: rows, - meta: { origin: 'getModel ' + Flow.Prelude.stringify(model.key.name) } - }); - }; + initialize(_job); + return { + key: _key, + description: _description, + destinationKey: _destinationKey, + runTime: _runTime, + progress: _progress, + status: _status, + statusColor: _statusColor, + exception: _exception, + isLive: _isLive, + toggleRefresh: toggleRefresh, + canView: _canView, + view: view, + template: 'flow-job-output' }; - inspectKMeansModelOutput = function (model) { - return function () { - var Record, attr, attrs, i, output, rows, variables, _i, _len; - output = model.output; - variables = [ - Flow.Data.Variable('parameter', Flow.TString), - Flow.Data.Variable('value', Flow.TObject) - ]; - Record = Flow.Data.Record(variables); - attrs = [ - 'iters', - 'mse', - 'ncats' - ]; - rows = new Array(attrs.length); - for (i = _i = 0, _len = attrs.length; _i < _len; i = ++_i) { - attr = attrs[i]; - rows[i] = new Record(attr, output[attr]); - } - return Flow.Data.Table({ - label: 'output', - description: 'Output for k-means model \'' + model.key.name + '\'', - variables: variables, - rows: rows, - meta: { origin: 'getModel ' + Flow.Prelude.stringify(model.key.name) } - }); + }; +}.call(this)); +(function () { + H2O.JobsOutput = function (_, jobs) { + var createJobView, initialize, refresh, toggleRefresh, _exception, _hasJobViews, _isBusy, _isLive, _jobViews; + _jobViews = Flow.Dataflow.signals([]); + _hasJobViews = Flow.Dataflow.lift(_jobViews, function (jobViews) { + return jobViews.length > 0; + }); + _isLive = Flow.Dataflow.signal(false); + _isBusy = Flow.Dataflow.signal(false); + _exception = Flow.Dataflow.signal(null); + createJobView = function (job) { + var view; + view = function () { + return _.insertAndExecuteCell('cs', 'getJob ' + Flow.Prelude.stringify(job.key.name)); }; - }; - inspectKMeansModelClusterDetails = function (model) { - return function () { - var Record, cluster, i, output, rows, variables, _i, _len, _ref1; - output = model.output; - variables = [ - Flow.Data.Variable('cluster', Flow.TNumber), - Flow.Data.Variable('rows', Flow.TNumber), - Flow.Data.Variable('mses', Flow.TNumber) - ]; - Record = Flow.Data.Record(variables); - rows = new Array(output.clusters.length); - _ref1 = output.clusters; - for (i = _i = 0, _len = _ref1.length; _i < _len; i = ++_i) { - cluster = _ref1[i]; - rows[i] = new Record(i, output.rows[i], output.mses[i]); - } - return Flow.Data.Table({ - label: 'cluster_details', - description: 'Clusters for k-means model \'' + model.key.name + '\'', - variables: variables, - rows: rows, - meta: { origin: 'getModel ' + Flow.Prelude.stringify(model.key.name) } - }); + return { + job: job, + view: view }; }; - inspectKMeansModelClusters = function (model) { - return function () { - var Record, cluster, cluster0, clusters, domain, domains, i, j, names, output, row, rows, variables, _i, _j, _k, _len, _ref1, _ref2; - output = model.output; - clusters = output.clusters, domains = output.domains, names = output.names; - variables = [Flow.Data.Variable('names', Flow.TNumber)]; - for (i = _i = 0, _ref1 = clusters.length; 0 <= _ref1 ? _i < _ref1 : _i > _ref1; i = 0 <= _ref1 ? ++_i : --_i) { - variables.push(Flow.Data.Variable('' + i, Flow.TObject)); - } - Record = Flow.Data.Record(variables); - cluster0 = lodash.head(clusters); - rows = new Array(cluster0.length); - for (i = _j = 0, _ref2 = cluster0.length; 0 <= _ref2 ? _j < _ref2 : _j > _ref2; i = 0 <= _ref2 ? ++_j : --_j) { - rows[i] = row = new Record(names[i]); - for (j = _k = 0, _len = clusters.length; _k < _len; j = ++_k) { - cluster = clusters[j]; - row['' + j] = (domain = domains[i]) ? domain[cluster[i]] : cluster[i]; + toggleRefresh = function () { + return _isLive(!_isLive()); + }; + refresh = function () { + _isBusy(true); + return _.requestJobs(function (error, jobs) { + _isBusy(false); + if (error) { + _exception(Flow.Failure(new Flow.Error('Error fetching jobs', error))); + return _isLive(false); + } else { + _jobViews(lodash.map(jobs, createJobView)); + if (_isLive()) { + return lodash.delay(refresh, 2000); } } - return Flow.Data.Table({ - label: 'clusters', - description: 'Clusters for k-means model \'' + model.key.name + '\'', - variables: variables, - rows: rows, - meta: { origin: 'getModel ' + Flow.Prelude.stringify(model.key.name) } - }); - }; + }); }; - extendKMeansModel = function (model) { - return inspect_(model, { - parameters: inspectModelParameters(model), - output: inspectKMeansModelOutput(model), - clusters: inspectKMeansModelClusters(model), - cluster_details: inspectKMeansModelClusterDetails(model) - }); + Flow.Dataflow.act(_isLive, function (isLive) { + if (isLive) { + return refresh(); + } + }); + initialize = function () { + return _jobViews(lodash.map(jobs, createJobView)); }; - extendDeepLearningModel = function (model) { - return inspect_(model, { parameters: inspectModelParameters(model) }); + initialize(); + return { + jobViews: _jobViews, + hasJobViews: _hasJobViews, + isLive: _isLive, + isBusy: _isBusy, + toggleRefresh: toggleRefresh, + refresh: refresh, + exception: _exception, + template: 'flow-jobs-output' }; - extendGBMModel = function (model) { - return inspect_(model, { - parameters: inspectModelParameters(model), - output: inspectGBMModelOutput(model) + }; +}.call(this)); +(function () { + H2O.LogFileOutput = function (_, _nodeIndex, _logFile) { + var createNode, initialize, _activeNode, _contents, _exception, _nodes; + _exception = Flow.Dataflow.signal(null); + _contents = Flow.Dataflow.signal(''); + _activeNode = Flow.Dataflow.signal(null); + _nodes = Flow.Dataflow.signal([]); + createNode = function (node, index) { + return { + name: node.h2o.node, + index: index + }; + }; + initialize = function (nodeIndex, logFile) { + _contents(logFile.log); + return _.requestCloud(function (error, cloud) { + var i, node, nodes; + if (!error) { + _nodes(nodes = function () { + var _i, _len, _ref, _results; + _ref = cloud.nodes; + _results = []; + for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { + node = _ref[i]; + _results.push(createNode(node, i)); + } + return _results; + }()); + if (nodeIndex < nodes.length) { + _activeNode(nodes[nodeIndex]); + } + return Flow.Dataflow.react(_activeNode, function (node) { + if (node) { + return _.requestLogFile(node.index, function (error, logFile) { + if (error) { + return _contents('Error fetching log file: ' + error.message); + } else { + return _contents(logFile.log); + } + }); + } else { + return _contents(''); + } + }); + } }); }; - extendGLMModel = function (model) { - return inspect_(model, { parameters: inspectModelParameters(model) }); + initialize(_nodeIndex, _logFile); + return { + nodes: _nodes, + activeNode: _activeNode, + contents: _contents, + template: 'flow-log-file-output' }; - extendModel = function (model) { - switch (model.algo) { - case 'kmeans': - extendKMeansModel(model); - break; - case 'deeplearning': - extendDeepLearningModel(model); - break; - case 'gbm': - extendGBMModel(model); - break; - case 'glm': - extendGLMModel(model); + }; +}.call(this)); +(function () { + var createCheckboxControl, createControl, createControlFromParameter, createDropdownControl, createListControl, createTextboxControl; + createControl = function (kind, parameter) { + var _hasError, _hasInfo, _hasMessage, _hasWarning, _isVisible, _message; + _hasError = Flow.Dataflow.signal(false); + _hasWarning = Flow.Dataflow.signal(false); + _hasInfo = Flow.Dataflow.signal(false); + _message = Flow.Dataflow.signal(''); + _hasMessage = Flow.Dataflow.lift(_message, function (message) { + if (message) { + return true; + } else { + return false; } - return render_(model, function () { - return H2O.ModelOutput(_, model); - }); + }); + _isVisible = Flow.Dataflow.signal(true); + return { + kind: kind, + name: parameter.name, + label: parameter.label, + description: parameter.help, + isRequired: parameter.required, + hasError: _hasError, + hasWarning: _hasWarning, + hasInfo: _hasInfo, + message: _message, + hasMessage: _hasMessage, + isVisible: _isVisible }; - extendModels = function (models) { - var algos, model, _i, _len; - for (_i = 0, _len = models.length; _i < _len; _i++) { - model = models[_i]; - extendModel(model); + }; + createTextboxControl = function (parameter) { + var control, _value; + _value = Flow.Dataflow.signal(parameter.actual_value); + control = createControl('textbox', parameter); + control.value = _value; + control.defaultValue = parameter.default_value; + return control; + }; + createDropdownControl = function (parameter) { + var control, _value; + _value = Flow.Dataflow.signal(parameter.actual_value); + control = createControl('dropdown', parameter); + control.values = Flow.Dataflow.signals(parameter.values); + control.value = _value; + control.defaultValue = parameter.default_value; + return control; + }; + createListControl = function (parameter) { + var control, createValueView, excludeAll, includeAll, view, _availableSearchTerm, _availableValues, _availableValuesCaption, _i, _len, _ref, _searchAvailable, _searchSelected, _selectedSearchTerm, _selectedValues, _selectedValuesCaption, _value, _values, _views; + _availableSearchTerm = Flow.Dataflow.signal(''); + _selectedSearchTerm = Flow.Dataflow.signal(''); + createValueView = function (value) { + var exclude, include, self, _canExclude, _canInclude, _isAvailable; + _isAvailable = Flow.Dataflow.signal(true); + _canInclude = Flow.Dataflow.signal(true); + _canExclude = Flow.Dataflow.signal(true); + include = function () { + self.isAvailable(false); + return _selectedValues.push(self); + }; + exclude = function () { + self.isAvailable(true); + return _selectedValues.remove(self); + }; + return self = { + value: value, + include: include, + exclude: exclude, + canInclude: _canInclude, + canExclude: _canExclude, + isAvailable: _isAvailable + }; + }; + _values = Flow.Dataflow.signals(parameter.values); + _availableValues = Flow.Dataflow.lift(_values, function (vals) { + return lodash.map(vals, createValueView); + }); + _views = {}; + _ref = _availableValues(); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + view = _ref[_i]; + _views[view.value] = view; + } + _selectedValues = Flow.Dataflow.signals(lodash.map(parameter.actual_value, function (selectedValue) { + view = _views[selectedValue]; + view.isAvailable(false); + return view; + })); + _value = Flow.Dataflow.lift(_selectedValues, function (views) { + var _j, _len1, _results; + _results = []; + for (_j = 0, _len1 = views.length; _j < _len1; _j++) { + view = views[_j]; + _results.push(view.value); } - algos = lodash.unique(function () { - var _j, _len1, _results; - _results = []; - for (_j = 0, _len1 = models.length; _j < _len1; _j++) { - model = models[_j]; - _results.push(model.algo); + return _results; + }); + _availableValuesCaption = Flow.Dataflow.signal('0 items hidden'); + _selectedValuesCaption = Flow.Dataflow.signal('0 items hidden'); + includeAll = function () { + var _j, _len1, _ref1; + _ref1 = _availableValues(); + for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { + view = _ref1[_j]; + if (view.canInclude() && view.isAvailable()) { + view.include(); } - return _results; - }()); - if (algos.length === 1) { - inspect_(models, { parameters: inspectMultimodelParameters(models) }); } - return render_(models, function () { - return H2O.ModelsOutput(_, models); - }); }; - read = function (value) { - if (value === 'NaN') { - return null; - } else { - return value; + excludeAll = function () { + var selectedValues, _j, _len1; + selectedValues = Flow.Prelude.copy(_selectedValues()); + for (_j = 0, _len1 = selectedValues.length; _j < _len1; _j++) { + view = selectedValues[_j]; + view.exclude(); } }; - inspectRegressionPrediction = function (prediction) { - return function () { - var Record, frame, model, predictions, rows, variables; - frame = prediction.frame, model = prediction.model, predictions = prediction.predictions; - variables = [ - Flow.Data.Variable('parameter', Flow.TString), - Flow.Data.Variable('value', Flow.TObject) - ]; - Record = Flow.Data.Record(variables); - rows = []; - rows.push(new Record('key', model.name)); - rows.push(new Record('frame', frame.name)); - rows.push(new Record('model_category', prediction.model_category)); - rows.push(new Record('duration_in_ms', prediction.duration_in_ms)); - rows.push(new Record('scoring_time', prediction.scoring_time)); - return Flow.Data.Table({ - label: 'prediction', - description: 'Prediction output for model \'' + model.name + '\' on frame \'' + frame.name + '\'', - variables: variables, - rows: rows, - meta: { origin: 'getPrediction ' + Flow.Prelude.stringify(model.name) + ', ' + Flow.Prelude.stringify(frame.name) } - }); - }; - }; - inspectBinomialPrediction = function (prediction) { - return function () { - var Record, auc, frame, model, rows, variables; - frame = prediction.frame, model = prediction.model, auc = prediction.auc; - variables = [ - Flow.Data.Variable('parameter', Flow.TString), - Flow.Data.Variable('value', Flow.TObject) - ]; - Record = Flow.Data.Record(variables); - rows = []; - rows.push(new Record('key', model.name)); - rows.push(new Record('frame', frame.name)); - rows.push(new Record('model_category', prediction.model_category)); - rows.push(new Record('duration_in_ms', prediction.duration_in_ms)); - rows.push(new Record('scoring_time', prediction.scoring_time)); - rows.push(new Record('AUC', auc.AUC)); - rows.push(new Record('Gini', auc.Gini)); - rows.push(new Record('threshold_criterion', auc.threshold_criterion)); - return Flow.Data.Table({ - label: 'prediction', - description: 'Prediction output for model \'' + model.name + '\' on frame \'' + frame.name + '\'', - variables: variables, - rows: rows, - meta: { origin: 'getPrediction ' + Flow.Prelude.stringify(model.name) + ', ' + Flow.Prelude.stringify(frame.name) } - }); - }; + _searchAvailable = function () { + var hiddenCount, term, _j, _len1, _ref1; + hiddenCount = 0; + _ref1 = _availableValues(); + for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { + view = _ref1[_j]; + term = _availableSearchTerm().trim(); + if (term === '' || 0 <= view.value.toLowerCase().indexOf(term.toLowerCase())) { + view.canInclude(true); + } else { + view.canInclude(false); + hiddenCount++; + } + } + _availableValuesCaption('' + hiddenCount + ' items hidden'); }; - inspectBinomialMetrics = function (opts, predictions) { - return function () { - var Record, auc, cm, frame, i, model, prediction, rows, variables, _i, _j, _len, _ref1; - variables = [ - Flow.Data.Variable('criteria', Flow.TString), - Flow.Data.Variable('threshold', Flow.TNumber), - Flow.Data.Variable('F1', Flow.TNumber), - Flow.Data.Variable('F2', Flow.TNumber), - Flow.Data.Variable('F0point5', Flow.TNumber), - Flow.Data.Variable('accuracy', Flow.TNumber), - Flow.Data.Variable('error', Flow.TNumber), - Flow.Data.Variable('precision', Flow.TNumber), - Flow.Data.Variable('recall', Flow.TNumber), - Flow.Data.Variable('specificity', Flow.TNumber), - Flow.Data.Variable('mcc', Flow.TNumber), - Flow.Data.Variable('max_per_class_error', Flow.TNumber), - Flow.Data.Variable('confusion_matrix', Flow.TObject, null, formatConfusionMatrix), - Flow.Data.Variable('TPR', Flow.TNumber), - Flow.Data.Variable('FPR', Flow.TNumber), - Flow.Data.Variable('key', Flow.TString), - Flow.Data.Variable('model', Flow.TString), - Flow.Data.Variable('frame', Flow.TString) - ]; - Record = Flow.Data.Record(variables); - rows = []; - for (_i = 0, _len = predictions.length; _i < _len; _i++) { - prediction = predictions[_i]; - frame = prediction.frame, model = prediction.model, auc = prediction.auc; - for (i = _j = 0, _ref1 = auc.threshold_criteria.length; 0 <= _ref1 ? _j < _ref1 : _j > _ref1; i = 0 <= _ref1 ? ++_j : --_j) { - rows.push(new Record(auc.threshold_criteria[i], read(auc.threshold_for_criteria[i]), read(auc.F1_for_criteria[i]), read(auc.F2_for_criteria[i]), read(auc.F0point5_for_criteria[i]), read(auc.accuracy_for_criteria[i]), read(auc.error_for_criteria[i]), read(auc.precision_for_criteria[i]), read(auc.recall_for_criteria[i]), read(auc.specificity_for_criteria[i]), read(auc.mcc_for_criteria[i]), read(auc.max_per_class_error_for_criteria[i]), cm = auc.confusion_matrix_for_criteria[i], computeTruePositiveRate(cm), computeFalsePositiveRate(cm), model.name + ' on ' + frame.name, model.name, frame.name)); + _searchSelected = function () { + var hiddenCount, term, _j, _len1, _ref1; + hiddenCount = 0; + _ref1 = _availableValues(); + for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { + view = _ref1[_j]; + term = _selectedSearchTerm().trim(); + if (term === '' || 0 <= view.value.toLowerCase().indexOf(term.toLowerCase())) { + view.canExclude(true); + } else { + view.canExclude(false); + if (!view.isAvailable()) { + hiddenCount++; } } - return Flow.Data.Table({ - label: 'metrics', - description: 'Metrics for the selected predictions', - variables: variables, - rows: rows, - meta: { - origin: formulateGetPredictionsOrigin(opts), - plot: 'plot\n data: inspect \'metrics\', ' + formulateGetPredictionsOrigin(opts) - } - }); - }; + } + _selectedValuesCaption('' + hiddenCount + ' items hidden'); }; - inspectBinomialPredictions = function (opts, predictions) { - return function () { - var Record, auc, frame, i, model, prediction, row, rows, variables, _i, _len; - variables = [ - Flow.Data.Variable('key', Flow.TString), - Flow.Data.Variable('model', Flow.TString), - Flow.Data.Variable('frame', Flow.TString), - Flow.Data.Variable('model_category', Flow.TString), - Flow.Data.Variable('duration_in_ms', Flow.TNumber), - Flow.Data.Variable('scoring_time', Flow.TNumber) - ]; - Record = Flow.Data.Record(variables); - rows = new Array(predictions.length); - for (i = _i = 0, _len = predictions.length; _i < _len; i = ++_i) { - prediction = predictions[i]; - frame = prediction.frame, model = prediction.model, auc = prediction.auc; - rows[i] = row = new Record(model.name + ' on ' + frame.name, model.name, frame.name, prediction.model_category, prediction.duration_in_ms, prediction.scoring_time); + Flow.Dataflow.react(_availableSearchTerm, lodash.throttle(_searchAvailable, 500)); + Flow.Dataflow.react(_selectedSearchTerm, lodash.throttle(_searchSelected, 500)); + Flow.Dataflow.react(_selectedValues, lodash.throttle(_searchSelected, 500)); + control = createControl('list', parameter); + control.values = _values; + control.availableValues = _availableValues; + control.selectedValues = _selectedValues; + control.value = _value; + control.availableSearchTerm = _availableSearchTerm; + control.selectedSearchTerm = _selectedSearchTerm; + control.availableValuesCaption = _availableValuesCaption; + control.selectedValuesCaption = _selectedValuesCaption; + control.defaultValue = parameter.default_value; + control.includeAll = includeAll; + control.excludeAll = excludeAll; + return control; + }; + createCheckboxControl = function (parameter) { + var control, _value; + _value = Flow.Dataflow.signal(parameter.actual_value === 'true'); + control = createControl('checkbox', parameter); + control.clientId = lodash.uniqueId(); + control.value = _value; + control.defaultValue = parameter.default_value === 'true'; + return control; + }; + createControlFromParameter = function (parameter) { + switch (parameter.type) { + case 'enum': + case 'Key': + case 'VecSpecifier': + return createDropdownControl(parameter); + case 'string[]': + return createListControl(parameter); + case 'boolean': + return createCheckboxControl(parameter); + case 'Key': + case 'byte': + case 'short': + case 'int': + case 'long': + case 'float': + case 'double': + case 'byte[]': + case 'short[]': + case 'int[]': + case 'long[]': + case 'float[]': + case 'double[]': + return createTextboxControl(parameter); + default: + console.error('Invalid field', JSON.stringify(parameter, null, 2)); + return null; + } + }; + H2O.ModelBuilderForm = function (_, _algorithm, _parameters) { + var collectParameters, createModel, criticalControls, expertControls, findControl, findFormField, parameterTemplateOf, performValidations, secondaryControls, _controlGroups, _exception, _form, _hasValidationFailures, _parametersByLevel, _validationFailureMessage; + _exception = Flow.Dataflow.signal(null); + _validationFailureMessage = Flow.Dataflow.signal(''); + _hasValidationFailures = Flow.Dataflow.lift(_validationFailureMessage, Flow.Prelude.isTruthy); + _parametersByLevel = lodash.groupBy(_parameters, function (parameter) { + return parameter.level; + }); + _controlGroups = lodash.map([ + 'critical', + 'secondary', + 'expert' + ], function (type) { + return lodash.filter(lodash.map(_parametersByLevel[type], createControlFromParameter), function (a) { + if (a) { + return true; + } else { + return false; } - return Flow.Data.Table({ - label: 'predictions', - description: 'Prediction output for selected predictions.', - variables: variables, - rows: rows, - meta: { - origin: formulateGetPredictionsOrigin(opts), - plot: 'plot\n data: inspect \'predictions\', ' + formulateGetPredictionsOrigin(opts) + }); + }); + criticalControls = _controlGroups[0], secondaryControls = _controlGroups[1], expertControls = _controlGroups[2]; + _form = lodash.flatten([ + { + kind: 'group', + title: 'Parameters' + }, + criticalControls, + { + kind: 'group', + title: 'Advanced' + }, + secondaryControls, + { + kind: 'group', + title: 'Expert' + }, + expertControls + ]); + findControl = function (name) { + var control, controls, _i, _j, _len, _len1; + for (_i = 0, _len = _controlGroups.length; _i < _len; _i++) { + controls = _controlGroups[_i]; + for (_j = 0, _len1 = controls.length; _j < _len1; _j++) { + control = controls[_j]; + if (control.name === name) { + return control; } - }); - }; + } + } }; - extendPredictions = function (opts, predictions) { - render_(predictions, function () { - return H2O.PredictsOutput(_, opts, predictions); + parameterTemplateOf = function (control) { + return 'flow-' + control.kind + '-model-parameter'; + }; + findFormField = function (name) { + return lodash.find(_form, function (field) { + return field.name === name; }); - return inspect_(predictions, { predictions: inspectBinomialPredictions(opts, predictions) }); }; - inspectBinomialScores = function (opts, predictions) { - return function () { - var Record, auc, cm, frame, i, model, prediction, rows, variables, _i, _j, _len, _ref1; - variables = [ - Flow.Data.Variable('thresholds', Flow.TNumber), - Flow.Data.Variable('F1', Flow.TNumber), - Flow.Data.Variable('F2', Flow.TNumber), - Flow.Data.Variable('F0point5', Flow.TNumber), - Flow.Data.Variable('accuracy', Flow.TNumber), - Flow.Data.Variable('errorr', Flow.TNumber), - Flow.Data.Variable('precision', Flow.TNumber), - Flow.Data.Variable('recall', Flow.TNumber), - Flow.Data.Variable('specificity', Flow.TNumber), - Flow.Data.Variable('mcc', Flow.TNumber), - Flow.Data.Variable('max_per_class_error', Flow.TNumber), - Flow.Data.Variable('confusion_matrices', Flow.TObject, null, formatConfusionMatrix), - Flow.Data.Variable('TPR', Flow.TNumber), - Flow.Data.Variable('FPR', Flow.TNumber), - Flow.Data.Variable('key', Flow.TString), - Flow.Data.Variable('model', Flow.TString), - Flow.Data.Variable('frame', Flow.TString) - ]; - Record = Flow.Data.Record(variables); - rows = []; - for (_i = 0, _len = predictions.length; _i < _len; _i++) { - prediction = predictions[_i]; - frame = prediction.frame, model = prediction.model, auc = prediction.auc; - for (i = _j = 0, _ref1 = auc.thresholds.length; 0 <= _ref1 ? _j < _ref1 : _j > _ref1; i = 0 <= _ref1 ? ++_j : --_j) { - rows.push(new Record(read(auc.thresholds[i]), read(auc.F1[i]), read(auc.F2[i]), read(auc.F0point5[i]), read(auc.accuracy[i]), read(auc.errorr[i]), read(auc.precision[i]), read(auc.recall[i]), read(auc.specificity[i]), read(auc.mcc[i]), read(auc.max_per_class_error[i]), cm = auc.confusion_matrices[i], computeTruePositiveRate(cm), computeFalsePositiveRate(cm), model.name + ' on ' + frame.name, model.name, frame.name)); - } + (function () { + var ignoredColumnsParameter, responseColumnParameter, trainingFrameParameter, validationFrameParameter, _ref; + _ref = lodash.map([ + 'training_frame', + 'validation_frame', + 'response_column', + 'ignored_columns' + ], findFormField), trainingFrameParameter = _ref[0], validationFrameParameter = _ref[1], responseColumnParameter = _ref[2], ignoredColumnsParameter = _ref[3]; + if (trainingFrameParameter) { + if (responseColumnParameter || ignoredColumnsParameter) { + return Flow.Dataflow.act(trainingFrameParameter.value, function (frameKey) { + if (frameKey) { + _.requestFrame(frameKey, function (error, frame) { + var columnLabels; + if (!error) { + columnLabels = lodash.map(frame.columns, function (column) { + return column.label; + }); + if (responseColumnParameter) { + responseColumnParameter.values(columnLabels); + } + if (ignoredColumnsParameter) { + return ignoredColumnsParameter.values(columnLabels); + } + } + }); + } + }); } - return Flow.Data.Table({ - label: 'scores', - description: 'Scores for the selected predictions', - variables: variables, - rows: rows, - meta: { - origin: formulateGetPredictionsOrigin(opts), - plot: 'plot\n data: inspect \'scores\', ' + formulateGetPredictionsOrigin(opts) - } - }); - }; - }; - extendPrediction = function (modelKey, frameKey, prediction) { - render_(prediction, function () { - return H2O.PredictOutput(_, prediction); - }); - switch (prediction.model_category) { - case 'Regression': - case 'Multinomial': - return inspect_(prediction, { prediction: inspectRegressionPrediction(prediction) }); - default: - return inspect_(prediction, { - prediction: inspectBinomialPrediction(prediction), - scores: inspectBinomialScores({ - model: modelKey, - frame: frameKey - }, [prediction]), - metrics: inspectBinomialMetrics({ - model: modelKey, - frame: frameKey - }, [prediction]) - }); } - }; - inspectFrameColumns = function (tableLabel, frameKey, frame, frameColumns) { - return function () { - var Record, column, domain, label, row, rows, variable, variables; - variables = [ - Flow.Data.Variable('label', Flow.TString), - Flow.Data.Variable('missing', Flow.TNumber), - Flow.Data.Variable('zeros', Flow.TNumber), - Flow.Data.Variable('pinfs', Flow.TNumber), - Flow.Data.Variable('ninfs', Flow.TNumber), - Flow.Data.Variable('min', Flow.TNumber), - Flow.Data.Variable('max', Flow.TNumber), - Flow.Data.Variable('mean', Flow.TNumber), - Flow.Data.Variable('sigma', Flow.TNumber), - Flow.Data.Variable('type', Flow.TString), - Flow.Data.Variable('cardinality', Flow.TNumber) - ]; - Record = Flow.Data.Record(variables); - rows = function () { - var _i, _j, _len, _len1, _results; - _results = []; - for (_i = 0, _len = frameColumns.length; _i < _len; _i++) { - column = frameColumns[_i]; - row = new Record(); - for (_j = 0, _len1 = variables.length; _j < _len1; _j++) { - variable = variables[_j]; - label = variable.label; - switch (label) { - case 'min': - row[label] = lodash.head(column.mins); - break; - case 'max': - row[label] = lodash.head(column.maxs); - break; - case 'cardinality': - row[label] = (domain = column.domain) ? domain.length : null; - break; - default: - row[label] = column[label]; + }()); + collectParameters = function (includeUnchangedParameters) { + var control, controls, parameters, value, _i, _j, _len, _len1; + if (includeUnchangedParameters == null) { + includeUnchangedParameters = false; + } + parameters = {}; + for (_i = 0, _len = _controlGroups.length; _i < _len; _i++) { + controls = _controlGroups[_i]; + for (_j = 0, _len1 = controls.length; _j < _len1; _j++) { + control = controls[_j]; + value = control.value(); + if (includeUnchangedParameters || control.isRequired || control.defaultValue !== value) { + switch (control.kind) { + case 'dropdown': + if (value) { + parameters[control.name] = value; } - } - _results.push(row); - } - return _results; - }(); - return Flow.Data.Table({ - label: tableLabel, - description: 'A list of ' + tableLabel + ' in the H2O Frame.', - variables: variables, - rows: rows, - meta: { - origin: 'getFrame ' + Flow.Prelude.stringify(frameKey), - plot: 'plot\n data: inspect \'' + tableLabel + '\', getFrame ' + Flow.Prelude.stringify(frameKey) - } - }); - }; - }; - inspectFrameData = function (frameKey, frame) { - return function () { - var Record, column, frameColumns, i, j, row, rowCount, rows, value, variable, variables; - frameColumns = frame.columns; - variables = function () { - var _i, _len, _results; - _results = []; - for (_i = 0, _len = frameColumns.length; _i < _len; _i++) { - column = frameColumns[_i]; - switch (column.type) { - case 'int': - _results.push(Flow.Data.Variable(column.label, Flow.TNumber)); - break; - case 'real': - _results.push(Flow.Data.Variable(column.label, Flow.TNumber)); - break; - case 'enum': - _results.push(Flow.Data.Factor(column.label, column.domain)); - break; - case 'uuid': - case 'string': - _results.push(Flow.Data.Variable(column.label, Flow.TString)); break; - case 'time': - _results.push(Flow.Data.Variable(column.label, Flow.TDate)); + case 'list': + if (value.length) { + parameters[control.name] = '[' + value.join(',') + ']'; + } break; default: - _results.push(Flow.Data.Variable(column.label, Flow.TObject)); + parameters[control.name] = value; } } - return _results; - }(); - Record = Flow.Data.Record(variables); - rowCount = lodash.head(frameColumns).data.length; - rows = function () { - var _i, _j, _len, _results; - _results = []; - for (i = _i = 0; 0 <= rowCount ? _i < rowCount : _i > rowCount; i = 0 <= rowCount ? ++_i : --_i) { - row = new Record(); - for (j = _j = 0, _len = variables.length; _j < _len; j = ++_j) { - variable = variables[j]; - value = frameColumns[j].data[i]; - switch (variable.type) { - case Flow.TNumber: - case Flow.TNumber: - row[variable.label] = value === 'NaN' ? null : value; - break; - default: - row[variable.label] = value; + } + } + return parameters; + }; + performValidations = function (checkForErrors, go) { + var parameters, responseColumnParameter, trainingFrameParameter; + _exception(null); + parameters = collectParameters(true); + trainingFrameParameter = findFormField('training_frame'); + responseColumnParameter = findFormField('response_column'); + if (trainingFrameParameter && !parameters.training_frame) { + return _validationFailureMessage('Please specify a training frame.'); + } + if (responseColumnParameter && !parameters.response_column) { + return _validationFailureMessage('Please specify a response column.'); + } + _validationFailureMessage(''); + return go(); + return _.requestModelInputValidation(_algorithm, parameters, function (error, modelBuilder) { + var control, hasErrors, validation, _i, _len, _ref; + if (error) { + return _exception(Flow.Failure(new Flow.Error('Error fetching initial model builder state', error))); + } else { + hasErrors = false; + _ref = modelBuilder.validation_messages; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + validation = _ref[_i]; + control = findControl(validation.field_name); + if (control) { + if (validation.message_type === 'HIDE') { + control.isVisible(false); + } else if (!checkForErrors) { + switch (validation.message_type) { + case 'INFO': + control.isVisible(true); + control.message(validation.message); + break; + case 'WARN': + control.isVisible(true); + control.message(validation.message); + break; + case 'ERROR': + control.isVisible(true); + control.hasError(true); + control.message(validation.message); + hasErrors = true; + } } } - _results.push(row); } - return _results; - }(); - return Flow.Data.Table({ - label: 'data', - description: 'A partial list of rows in the H2O Frame.', - variables: variables, - rows: rows, - meta: { origin: 'getFrame ' + Flow.Prelude.stringify(frameKey) } - }); - }; + if (!hasErrors) { + return go(); + } + } + }); }; - extendFrame = function (frameKey, frame) { - var column, enumColumns, inspections; - inspections = { - columns: inspectFrameColumns('columns', frameKey, frame, frame.columns), - data: inspectFrameData(frameKey, frame) - }; - enumColumns = function () { - var _i, _len, _ref1, _results; - _ref1 = frame.columns; - _results = []; - for (_i = 0, _len = _ref1.length; _i < _len; _i++) { - column = _ref1[_i]; - if (column.type === 'enum') { - _results.push(column); + createModel = function () { + _exception(null); + return performValidations(false, function () { + var parameters; + parameters = collectParameters(false); + return _.insertAndExecuteCell('cs', 'buildModel \'' + _algorithm + '\', ' + Flow.Prelude.stringify(parameters)); + }); + }; + return { + form: _form, + exception: _exception, + parameterTemplateOf: parameterTemplateOf, + createModel: createModel, + hasValidationFailures: _hasValidationFailures, + validationFailureMessage: _validationFailureMessage + }; + }; + H2O.ModelInput = function (_, _algo, _opts) { + var createModel, populateFramesAndColumns, _algorithm, _algorithms, _canCreateModel, _exception, _modelForm; + _exception = Flow.Dataflow.signal(null); + _algorithms = Flow.Dataflow.signal([]); + _algorithm = Flow.Dataflow.signal(_algo); + _canCreateModel = Flow.Dataflow.lift(_algorithm, function (algorithm) { + if (algorithm) { + return true; + } else { + return false; + } + }); + _modelForm = Flow.Dataflow.signal(null); + populateFramesAndColumns = function (frameKey, algorithm, parameters, go) { + var classificationParameter; + classificationParameter = lodash.find(parameters, function (parameter) { + return parameter.name === 'do_classification'; + }); + if (classificationParameter) { + classificationParameter.actual_value = 'true'; + } + return _.requestFrames(function (error, frames) { + var frame, frameKeys, frameParameters, parameter, _i, _len; + if (error) { + } else { + frameKeys = function () { + var _i, _len, _results; + _results = []; + for (_i = 0, _len = frames.length; _i < _len; _i++) { + frame = frames[_i]; + _results.push(frame.key.name); + } + return _results; + }(); + frameParameters = lodash.filter(parameters, function (parameter) { + return parameter.type === 'Key'; + }); + for (_i = 0, _len = frameParameters.length; _i < _len; _i++) { + parameter = frameParameters[_i]; + parameter.values = frameKeys; + if (parameter.name === 'training_frame') { + if (frameKey) { + parameter.actual_value = frameKey; + } else { + frameKey = parameter.actual_value; + } + } } + return go(); } - return _results; - }(); - if (enumColumns.length > 0) { - inspections.factors = inspectFrameColumns('factors', frameKey, frame, enumColumns); - } - inspect_(frame, inspections); - return render_(frame, function () { - return H2O.FrameOutput(_, frame); }); }; - extendColumnSummary = function (frameKey, frame, columnName) { - var column, inspectCharacteristics, inspectDistribution, inspectDomain, inspectPercentiles, inspectSummary, inspections, rowCount; - column = lodash.head(frame.columns); - rowCount = frame.rows; - inspectPercentiles = function () { - var Record, i, percentile, percentileValues, percentiles, row, rows, variables; - percentiles = frame.default_pctiles; - percentileValues = column.pctiles; - variables = [ - Flow.Data.Variable('percentile', Flow.TNumber), - Flow.Data.Variable('value', Flow.TNumber) - ]; - Record = Flow.Data.Record(variables); - rows = function () { - var _i, _len, _results; + (function () { + return _.requestModelBuilders(function (error, result) { + var frameKey, key, modelBuilders; + modelBuilders = error ? [] : result.model_builders; + _algorithms(function () { + var _i, _len, _ref, _results; + _ref = lodash.keys(modelBuilders); _results = []; - for (i = _i = 0, _len = percentiles.length; _i < _len; i = ++_i) { - percentile = percentiles[i]; - row = new Record(); - row.percentile = percentile; - row.value = percentileValues[i]; - _results.push(row); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + key = _ref[_i]; + if (key !== 'example') { + _results.push(key); + } } return _results; - }(); - return Flow.Data.Table({ - label: 'percentiles', - description: 'Percentiles for column \'' + column.label + '\' in frame \'' + frameKey + '\'.', - variables: variables, - rows: rows, - meta: { origin: 'getColumnSummary ' + Flow.Prelude.stringify(frameKey) + ', ' + Flow.Prelude.stringify(columnName) } - }); - }; - inspectDistribution = function () { - var Record, base, binCount, binIndex, bins, count, i, interval, m, minBinCount, n, row, rows, stride, variables, width, _i, _j, _k, _len; - variables = [ - Flow.Data.Variable('interval', Flow.TString), - Flow.Data.Variable('width', Flow.TNumber), - Flow.Data.Variable('count', Flow.TNumber) - ]; - Record = Flow.Data.Record(variables); - minBinCount = 32; - base = column.base, stride = column.stride, bins = column.bins; - width = Math.floor(bins.length / minBinCount); - interval = stride * width; - rows = []; - if (width > 0) { - binCount = minBinCount + (bins.length % width > 0 ? 1 : 0); - for (i = _i = 0; 0 <= binCount ? _i < binCount : _i > binCount; i = 0 <= binCount ? ++_i : --_i) { - m = i * width; - n = m + width; - count = 0; - for (binIndex = _j = m; m <= n ? _j < n : _j > n; binIndex = m <= n ? ++_j : --_j) { - if (n < bins.length) { - count += bins[binIndex]; + }()); + frameKey = _opts != null ? _opts.training_frame : void 0; + return Flow.Dataflow.act(_algorithm, function (algorithm) { + if (algorithm) { + return _.requestModelBuilder(algorithm, function (error, result) { + var parameters; + if (error) { + return _exception(Flow.Failure(new Flow.Error('Error fetching model builder', error))); + } else { + parameters = result.model_builders[algorithm].parameters; + return populateFramesAndColumns(frameKey, algorithm, parameters, function () { + return _modelForm(H2O.ModelBuilderForm(_, algorithm, parameters)); + }); } - } - row = new Record(); - row.interval = base + i * interval; - row.width = interval; - row.count = count; - rows.push(row); + }); + } else { + return _modelForm(null); } - } else { - for (i = _k = 0, _len = bins.length; _k < _len; i = ++_k) { - count = bins[i]; - row = new Record(); - row.interval = base + i * stride; - row.width = stride; - row.count = count; - rows.push(row); + }); + }); + }()); + createModel = function () { + return _modelForm().createModel(); + }; + return { + parentException: _exception, + algorithms: _algorithms, + algorithm: _algorithm, + modelForm: _modelForm, + canCreateModel: _canCreateModel, + createModel: createModel, + template: 'flow-model-input' + }; + }; +}.call(this)); +(function () { + H2O.ModelOutput = function (_, _model) { + var cloneModel, inspect, predict, toggle, _inputParameters, _isExpanded; + _isExpanded = Flow.Dataflow.signal(false); + _inputParameters = lodash.map(_model.parameters, function (parameter) { + var actual_value, default_value, help, label, type, value; + type = parameter.type, default_value = parameter.default_value, actual_value = parameter.actual_value, label = parameter.label, help = parameter.help; + value = function () { + switch (type) { + case 'Key': + case 'Key': + if (actual_value) { + return actual_value.name; + } else { + return null; } - } - return Flow.Data.Table({ - label: 'distribution', - description: 'Distribution for column \'' + column.label + '\' in frame \'' + frameKey + '\'.', - variables: variables, - rows: rows, - meta: { - origin: 'getColumnSummary ' + Flow.Prelude.stringify(frameKey) + ', ' + Flow.Prelude.stringify(columnName), - plot: 'plot\n data: inspect \'distribution\', getColumnSummary ' + Flow.Prelude.stringify(frameKey) + ', ' + Flow.Prelude.stringify(columnName) + '\n type: \'interval\'\n x: \'interval\'\n y: \'count\'' + break; + case 'VecSpecifier': + if (actual_value) { + return actual_value.column_name; + } else { + return null; } - }); + break; + default: + return actual_value; + } + }(); + return { + label: label, + value: value, + help: help, + isModified: default_value === actual_value }; - inspectCharacteristics = function () { - var characteristics, count, i, missing, ninfs, other, pinfs, rows, variables, zeros; - missing = column.missing, zeros = column.zeros, pinfs = column.pinfs, ninfs = column.ninfs; - other = rowCount - missing - zeros - pinfs - ninfs; - variables = [ - { - label: 'label', - type: Flow.TString - }, - { - label: 'characteristic', - type: Flow.TString - }, - { - label: 'count', - type: Flow.TNumber, - domain: [ - 0, - rowCount - ] - }, - { - label: 'percent', - type: Flow.TNumber, - domain: [ - 0, - 100 - ] - } - ]; - characteristics = [ - 'Missing', - '-Inf', - 'Zero', - '+Inf', - 'Other' - ]; - rows = function () { - var _i, _len, _ref1, _results; - _ref1 = [ - missing, - ninfs, - zeros, - pinfs, - other - ]; + }); + toggle = function () { + return _isExpanded(!_isExpanded()); + }; + cloneModel = function () { + return alert('Not implemented'); + }; + predict = function () { + return _.insertAndExecuteCell('cs', 'predict ' + Flow.Prelude.stringify(_model.key.name)); + }; + inspect = function () { + return _.insertAndExecuteCell('cs', 'inspect getModel ' + Flow.Prelude.stringify(_model.key.name)); + }; + return { + key: _model.key, + algo: _model.algo, + inputParameters: _inputParameters, + isExpanded: _isExpanded, + toggle: toggle, + cloneModel: cloneModel, + predict: predict, + inspect: inspect, + template: 'flow-model-output' + }; + }; +}.call(this)); +(function () { + H2O.ModelsOutput = function (_, _models) { + var buildModel, compareModels, createModelView, getSelectedModelKeys, initialize, inspectAll, predictUsingModels, _canCompareModels, _checkAllModels, _isCheckingAll, _modelViews; + _modelViews = Flow.Dataflow.signal([]); + _checkAllModels = Flow.Dataflow.signal(false); + _canCompareModels = Flow.Dataflow.signal(false); + _isCheckingAll = false; + Flow.Dataflow.react(_checkAllModels, function (checkAll) { + var view, _i, _len, _ref; + _isCheckingAll = true; + _ref = _modelViews(); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + view = _ref[_i]; + view.isChecked(checkAll); + } + _canCompareModels(checkAll); + _isCheckingAll = false; + }); + createModelView = function (model) { + var cloneModel, inspect, predict, view, _isChecked; + _isChecked = Flow.Dataflow.signal(false); + Flow.Dataflow.react(_isChecked, function () { + var checkedViews, view; + if (_isCheckingAll) { + return; + } + checkedViews = function () { + var _i, _len, _ref, _results; + _ref = _modelViews(); _results = []; - for (i = _i = 0, _len = _ref1.length; _i < _len; i = ++_i) { - count = _ref1[i]; - _results.push({ - label: column.label, - characteristic: characteristics[i], - count: count, - percent: 100 * count / rowCount - }); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + view = _ref[_i]; + if (view.isChecked()) { + _results.push(view); + } } return _results; }(); - return Flow.Data.Table({ - label: 'characteristics', - description: 'Characteristics for column \'' + column.label + '\' in frame \'' + frameKey + '\'.', - variables: variables, - rows: rows, - meta: { - origin: 'getColumnSummary ' + Flow.Prelude.stringify(frameKey) + ', ' + Flow.Prelude.stringify(columnName), - plot: 'plot\n title: \'Characteristics for ' + frameKey + ' : ' + column.label + '\'\n type: \'interval\'\n data: inspect \'characteristics\', getColumnSummary ' + Flow.Prelude.stringify(frameKey) + ', ' + Flow.Prelude.stringify(columnName) + '\n x: plot.stack \'count\'\n y: \'label\'\n color: \'characteristic\'' - } - }); + return _canCompareModels(checkedViews.length > 1); + }); + predict = function () { + return _.insertAndExecuteCell('cs', 'predict ' + Flow.Prelude.stringify(model.key.name)); }; - inspectSummary = function () { - var defaultPercentiles, mean, outliers, percentiles, q1, q2, q3, row, variables; - variables = [ - { - label: 'mean', - type: Flow.TNumber - }, - { - label: 'q1', - type: Flow.TNumber - }, - { - label: 'q2', - type: Flow.TNumber - }, - { - label: 'q3', - type: Flow.TNumber - }, - { - label: 'outliers', - type: Flow.TArray - } - ]; - defaultPercentiles = frame.default_pctiles; - percentiles = column.pctiles; - mean = column.mean; - q1 = percentiles[defaultPercentiles.indexOf(0.25)]; - q2 = percentiles[defaultPercentiles.indexOf(0.5)]; - q3 = percentiles[defaultPercentiles.indexOf(0.75)]; - outliers = lodash.unique(column.mins.concat(column.maxs)); - row = { - mean: mean, - q1: q1, - q2: q2, - q3: q3, - outliers: outliers - }; - return Flow.Data.Table({ - label: 'summary', - description: 'Summary for column \'' + column.label + '\' in frame \'' + frameKey + '\'.', - variables: variables, - rows: [row], - meta: { origin: 'getColumnSummary ' + Flow.Prelude.stringify(frameKey) + ', ' + Flow.Prelude.stringify(columnName) } - }); + cloneModel = function () { + return alert('Not implemented'); + return _.insertAndExecuteCell('cs', 'cloneModel ' + Flow.Prelude.stringify(model.key.name)); }; - inspectDomain = function () { - var Record, countVariable, level, levels, row, rows, sortedLevels, variables; - levels = lodash.map(column.bins, function (count, index) { - return { - count: count, - index: index - }; - }); - sortedLevels = lodash.sortBy(levels, function (level) { - return -level.count; - }); - variables = [ - Flow.Data.Variable('label', Flow.TString), - countVariable = Flow.Data.Variable('count', Flow.TNumber), - Flow.Data.Variable('percent', Flow.TNumber, [ - 0, - 100 - ]) - ]; - Record = Flow.Data.Record(variables); - rows = function () { - var _i, _len, _results; - _results = []; - for (_i = 0, _len = sortedLevels.length; _i < _len; _i++) { - level = sortedLevels[_i]; - row = new Record(); - row.label = column.domain[level.index]; - row.count = countVariable.read(level.count); - row.percent = 100 * level.count / rowCount; - _results.push(row); - } - return _results; - }(); - return Flow.Data.Table({ - label: 'domain', - description: 'Domain for column \'' + column.label + '\' in frame \'' + frameKey + '\'.', - variables: variables, - rows: rows, - meta: { - origin: 'getColumnSummary ' + Flow.Prelude.stringify(frameKey) + ', ' + Flow.Prelude.stringify(columnName), - plot: 'plot\n title: \'Domain for ' + frameKey + ' : ' + column.label + '\'\n type: \'interval\'\n data: inspect \'domain\', getColumnSummary ' + Flow.Prelude.stringify(frameKey) + ', ' + Flow.Prelude.stringify(columnName) + '\n x: \'count\'\n y: \'label\'' - } - }); + view = function () { + return _.insertAndExecuteCell('cs', 'getModel ' + Flow.Prelude.stringify(model.key.name)); + }; + inspect = function () { + return _.insertAndExecuteCell('cs', 'inspect getModel ' + Flow.Prelude.stringify(model.key.name)); + }; + return { + key: model.key.name, + algo: model.algo, + isChecked: _isChecked, + predict: predict, + clone: cloneModel, + inspect: inspect, + view: view }; - inspections = { characteristics: inspectCharacteristics }; - if (column.type === 'int' || column.type === 'real') { - inspections.summary = inspectSummary; - inspections.distribution = inspectDistribution; - } else { - inspections.domain = inspectDomain; - } - inspect_(frame, inspections); - return render_(frame, function () { - return go(null, H2O.ColumnSummaryOutput(_, frameKey, frame, columnName)); - }); }; - requestFrame = function (frameKey, go) { - return _.requestFrame(frameKey, function (error, frame) { - if (error) { - return go(error); - } else { - return go(null, extendFrame(frameKey, frame)); - } - }); + buildModel = function () { + return _.insertAndExecuteCell('cs', 'buildModel'); }; - requestColumnSummary = function (frameKey, columnName, go) { - return _.requestColumnSummary(frameKey, columnName, function (error, frame) { - if (error) { - return go(error); - } else { - return go(null, extendColumnSummary(frameKey, frame, columnName)); + getSelectedModelKeys = function () { + var view, _i, _len, _ref, _results; + _ref = _modelViews(); + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + view = _ref[_i]; + if (view.isChecked()) { + _results.push(view.key); } - }); + } + return _results; }; - requestFrames = function (go) { - return _.requestFrames(function (error, frames) { - if (error) { - return go(error); - } else { - return go(null, extendFrames(frames)); - } - }); + compareModels = function () { + return _.insertAndExecuteCell('cs', 'inspect getModels ' + Flow.Prelude.stringify(getSelectedModelKeys())); }; - requestCreateFrame = function (opts, go) { - return _.requestCreateFrame(opts, function (error, result) { - if (error) { - return go(error); - } else { - return go(null, result); - } - }); + predictUsingModels = function () { + return _.insertAndExecuteCell('cs', 'predict ' + Flow.Prelude.stringify(getSelectedModelKeys())); }; - createFrame = function (opts) { - if (opts) { - return _fork(requestCreateFrame, opts); - } else { - return assist(createFrame); - } + inspectAll = function () { + var allKeys, view; + allKeys = function () { + var _i, _len, _ref, _results; + _ref = _modelViews(); + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + view = _ref[_i]; + _results.push(view.key); + } + return _results; + }(); + return _.insertAndExecuteCell('cs', 'inspect getModels ' + Flow.Prelude.stringify(allKeys)); }; - getFrames = function () { - return _fork(requestFrames); + initialize = function (models) { + return _modelViews(lodash.map(models, createModelView)); }; - getFrame = function (frameKey) { - switch (Flow.Prelude.typeOf(frameKey)) { - case 'String': - return _fork(requestFrame, frameKey); - default: - return assist(getFrame); - } + initialize(_models); + return { + modelViews: _modelViews, + hasModels: _models.length > 0, + buildModel: buildModel, + compareModels: compareModels, + predictUsingModels: predictUsingModels, + canCompareModels: _canCompareModels, + checkAllModels: _checkAllModels, + inspect: inspectAll, + template: 'flow-models-output' }; - getColumnSummary = function (frameKey, columnName) { - return _fork(requestColumnSummary, frameKey, columnName); + }; +}.call(this)); +(function () { + H2O.NoAssist = function (_) { + return { + showAssist: function () { + return _.insertAndExecuteCell('cs', 'assist'); + }, + template: 'flow-no-assist' }; - requestModels = function (go) { - return _.requestModels(function (error, models) { - if (error) { - return go(error); - } else { - return go(null, extendModels(models)); - } - }); + }; +}.call(this)); +(function () { + var parseDelimiters, parserTypes; + parserTypes = lodash.map([ + 'AUTO', + 'XLS', + 'CSV', + 'SVMLight' + ], function (type) { + return { + type: type, + caption: type }; - requestModelsByKeys = function (modelKeys, go) { - var futures; - futures = lodash.map(modelKeys, function (key) { - return _fork(_.requestModel, key); - }); - return Flow.Async.join(futures, function (error, models) { - if (error) { - return go(error); - } else { - return go(null, extendModels(models)); - } - }); + }); + parseDelimiters = function () { + var characterDelimiters, createDelimiter, otherDelimiters, whitespaceDelimiters, whitespaceSeparators; + whitespaceSeparators = [ + 'NULL', + 'SOH (start of heading)', + 'STX (start of text)', + 'ETX (end of text)', + 'EOT (end of transmission)', + 'ENQ (enquiry)', + 'ACK (acknowledge)', + 'BEL \'\\a\' (bell)', + 'BS \'\\b\' (backspace)', + 'HT \'\\t\' (horizontal tab)', + 'LF \'\\n\' (new line)', + 'VT \'\\v\' (vertical tab)', + 'FF \'\\f\' (form feed)', + 'CR \'\\r\' (carriage ret)', + 'SO (shift out)', + 'SI (shift in)', + 'DLE (data link escape)', + 'DC1 (device control 1) ', + 'DC2 (device control 2)', + 'DC3 (device control 3)', + 'DC4 (device control 4)', + 'NAK (negative ack.)', + 'SYN (synchronous idle)', + 'ETB (end of trans. blk)', + 'CAN (cancel)', + 'EM (end of medium)', + 'SUB (substitute)', + 'ESC (escape)', + 'FS (file separator)', + 'GS (group separator)', + 'RS (record separator)', + 'US (unit separator)', + '\' \' SPACE' + ]; + createDelimiter = function (caption, charCode) { + return { + charCode: charCode, + caption: '' + caption + ': \'' + ('00' + charCode).slice(-2) + '\'' + }; }; - getModels = function (modelKeys) { - if (lodash.isArray(modelKeys)) { - if (modelKeys.length) { - return _fork(requestModelsByKeys, modelKeys); - } else { - return _fork(requestModels); - } - } else { - return _fork(requestModels); - } + whitespaceDelimiters = lodash.map(whitespaceSeparators, createDelimiter); + characterDelimiters = lodash.times(126 - whitespaceSeparators.length, function (i) { + var charCode; + charCode = i + whitespaceSeparators.length; + return createDelimiter(String.fromCharCode(charCode), charCode); + }); + otherDelimiters = [{ + charCode: -1, + caption: 'AUTO' + }]; + return whitespaceDelimiters.concat(characterDelimiters, otherDelimiters); + }(); + H2O.SetupParseOutput = function (_, _result) { + var parseFiles, _columnCount, _columns, _deleteOnDone, _delimiter, _destinationKey, _hasColumns, _headerOption, _headerOptions, _parserType, _rows, _sourceKeys, _useSingleQuotes; + _sourceKeys = lodash.map(_result.srcs, function (src) { + return src.name; + }); + _parserType = Flow.Dataflow.signal(lodash.find(parserTypes, function (parserType) { + return parserType.type === _result.pType; + })); + _delimiter = Flow.Dataflow.signal(lodash.find(parseDelimiters, function (delimiter) { + return delimiter.charCode === _result.sep; + })); + _useSingleQuotes = Flow.Dataflow.signal(_result.singleQuotes); + _columns = lodash.map(_result.columnNames, function (name) { + return { name: Flow.Dataflow.signal(name) }; + }); + _rows = _result.data; + _columnCount = _result.ncols; + _hasColumns = _columnCount > 0; + _destinationKey = Flow.Dataflow.signal(_result.hexName); + _headerOptions = { + auto: 0, + header: 1, + data: -1 }; - requestModel = function (modelKey, go) { - return _.requestModel(modelKey, function (error, model) { - if (error) { - return go(error); - } else { - return go(null, extendModel(model)); - } + _headerOption = Flow.Dataflow.signal(_result.checkHeader === 0 ? 'auto' : _result.checkHeader === -1 ? 'data' : 'header'); + _deleteOnDone = Flow.Dataflow.signal(true); + parseFiles = function () { + var columnNames; + columnNames = lodash.map(_columns, function (column) { + return column.name(); }); + return _.insertAndExecuteCell('cs', 'parseRaw\n srcs: ' + Flow.Prelude.stringify(_sourceKeys) + '\n hex: ' + Flow.Prelude.stringify(_destinationKey()) + '\n pType: ' + Flow.Prelude.stringify(_parserType().type) + '\n sep: ' + _delimiter().charCode + '\n ncols: ' + _columnCount + '\n singleQuotes: ' + _useSingleQuotes() + '\n columnNames: ' + Flow.Prelude.stringify(columnNames) + '\n delete_on_done: ' + _deleteOnDone() + '\n checkHeader: ' + _headerOptions[_headerOption()]); }; - getModel = function (modelKey) { - switch (Flow.Prelude.typeOf(modelKey)) { - case 'String': - return _fork(requestModel, modelKey); - default: - return assist(getModel); - } - }; - getJobs = function () { - return renderable(_.requestJobs, function (jobs, go) { - return go(null, H2O.JobsOutput(_, jobs)); - }); + return { + sourceKeys: _sourceKeys, + parserTypes: parserTypes, + delimiters: parseDelimiters, + parserType: _parserType, + delimiter: _delimiter, + useSingleQuotes: _useSingleQuotes, + columns: _columns, + rows: _rows, + columnCount: _columnCount, + hasColumns: _hasColumns, + destinationKey: _destinationKey, + headerOption: _headerOption, + deleteOnDone: _deleteOnDone, + parseFiles: parseFiles, + template: 'flow-parse-raw-input' }; - getJob = function (arg) { - switch (Flow.Prelude.typeOf(arg)) { - case 'String': - return renderable(_.requestJob, arg, function (job, go) { - return go(null, H2O.JobOutput(_, job)); - }); - case 'Object': - if (arg.key != null) { - return getJob(arg.key); - } else { - return assist(getJob); - } - break; - default: - return assist(getJob); - } + }; +}.call(this)); +(function () { + H2O.ParseOutput = function (_, _result) { + var viewJob; + viewJob = function () { + return _.insertAndExecuteCell('cs', 'getJob ' + Flow.Prelude.stringify(_result.job.key.name)); }; - importFiles = function (paths) { - switch (Flow.Prelude.typeOf(paths)) { - case 'Array': - return renderable(_.requestImportFiles, paths, function (importResults, go) { - return go(null, H2O.ImportFilesOutput(_, importResults)); - }); - default: - return assist(importFiles); - } + return { + result: _result, + viewJob: viewJob, + template: 'flow-parse-output' }; - setupParse = function (sourceKeys) { - switch (Flow.Prelude.typeOf(sourceKeys)) { - case 'Array': - return renderable(_.requestParseSetup, sourceKeys, function (parseSetupResults, go) { - return go(null, H2O.SetupParseOutput(_, parseSetupResults)); - }); - default: - return assist(setupParse); + }; +}.call(this)); +(function () { + H2O.PlotInput = function (_, config) { + var plot, _canPlot, _color, _table, _type, _types, _variables, _x, _y; + _table = config.data; + _types = [ + 'point', + 'line', + 'area', + 'interval' + ]; + _variables = lodash.map(_table.variables, function (variable) { + return variable.label; + }); + _type = Flow.Dataflow.signal(null); + _x = Flow.Dataflow.signal(null); + _y = Flow.Dataflow.signal(null); + _color = Flow.Dataflow.signal(null); + _canPlot = Flow.Dataflow.lift(_type, _x, _y, function (type, x, y) { + return type && x && y; + }); + plot = function () { + var color; + if (color = _color()) { + return _.insertAndExecuteCell('cs', 'plot\n data: inspect ' + Flow.Prelude.stringify(_table.label) + ', ' + _table.meta.origin + '\n type: \'' + _type() + '\'\n x: ' + Flow.Prelude.stringify(_x()) + '\n y: ' + Flow.Prelude.stringify(_y()) + '\n color: ' + Flow.Prelude.stringify(color)); + } else { + return _.insertAndExecuteCell('cs', 'plot\n data: inspect ' + Flow.Prelude.stringify(_table.label) + ', ' + _table.meta.origin + '\n type: \'' + _type() + '\'\n x: ' + Flow.Prelude.stringify(_x()) + '\n y: ' + Flow.Prelude.stringify(_y())); } }; - parseRaw = function (opts) { - var checkHeader, columnCount, columnNames, deleteOnDone, destinationKey, parserType, separator, sourceKeys, useSingleQuotes; - sourceKeys = opts.srcs; - destinationKey = opts.hex; - parserType = opts.pType; - separator = opts.sep; - columnCount = opts.ncols; - useSingleQuotes = opts.singleQuotes; - columnNames = opts.columnNames; - deleteOnDone = opts.delete_on_done; - checkHeader = opts.checkHeader; - return renderable(_.requestParseFiles, sourceKeys, destinationKey, parserType, separator, columnCount, useSingleQuotes, columnNames, deleteOnDone, checkHeader, function (parseResult, go) { - return go(null, H2O.ParseOutput(_, parseResult)); - }); + return { + types: _types, + type: _type, + variables: _variables, + x: _x, + y: _y, + color: _color, + plot: plot, + canPlot: _canPlot, + template: 'flow-plot-input' }; - buildModel = function (algo, opts) { - if (algo && opts && lodash.keys(opts).length > 1) { - return renderable(_.requestModelBuild, algo, opts, function (result, go) { - var messages, validation; - if (result.validation_error_count > 0) { - messages = function () { - var _i, _len, _ref1, _results; - _ref1 = result.validation_messages; - _results = []; - for (_i = 0, _len = _ref1.length; _i < _len; _i++) { - validation = _ref1[_i]; - _results.push(validation.message); - } - return _results; - }(); - return go(new Flow.Error('Model build failure: ' + messages.join('; '))); - } else { - return go(null, H2O.JobOutput(_, lodash.head(result.jobs))); - } - }); - } else { - return assist(buildModel, algo, opts); - } + }; +}.call(this)); +(function () { + H2O.PlotOutput = function (_, _plot) { + return { + plot: _plot, + template: 'flow-plot-output' }; - requestPredict = function (modelKey, frameKey, go) { - return _.requestPredict(modelKey, frameKey, function (error, prediction) { + }; +}.call(this)); +(function () { + H2O.PredictInput = function (_, _modelArg, _frameArg) { + var predict, _canPredict, _exception, _frames, _hasFrames, _hasModels, _models, _selectedFrame, _selectedFrames, _selectedFramesCaption, _selectedModel, _selectedModels, _selectedModelsCaption; + _selectedModels = _modelArg ? lodash.isArray(_modelArg) ? _modelArg : [_modelArg] : []; + _selectedFrames = _frameArg ? lodash.isArray(_frameArg) ? _frameArg : [_frameArg] : []; + _selectedModelsCaption = _selectedModels.join(', '); + _selectedFramesCaption = _selectedFrames.join(', '); + _exception = Flow.Dataflow.signal(null); + _selectedFrame = Flow.Dataflow.signal(null); + _selectedModel = Flow.Dataflow.signal(null); + _hasFrames = _selectedFrames.length ? true : false; + _hasModels = _selectedModels.length ? true : false; + _canPredict = Flow.Dataflow.lift(_selectedFrame, _selectedModel, function (frame, model) { + return frame && model || _hasFrames && model || _hasModels && frame; + }); + _frames = Flow.Dataflow.signals([]); + _models = Flow.Dataflow.signals([]); + if (!_hasFrames) { + _.requestFrames(function (error, frames) { + var frame; if (error) { - return go(error); + return _exception(new Flow.Error('Error fetching frame list.', error)); } else { - return go(null, extendPrediction(modelKey, frameKey, prediction)); + return _frames(function () { + var _i, _len, _results; + _results = []; + for (_i = 0, _len = frames.length; _i < _len; _i++) { + frame = frames[_i]; + _results.push(frame.key.name); + } + return _results; + }()); } }); - }; - requestPredicts = function (opts, go) { - var futures; - futures = lodash.map(opts, function (opt) { - var frameKey, modelKey; - modelKey = opt.model, frameKey = opt.frame; - return _fork(_.requestPredict, modelKey, frameKey); - }); - return Flow.Async.join(futures, function (error, predictions) { + } + if (!_hasModels) { + _.requestModels(function (error, models) { + var model; if (error) { - return go(error); - } else { - return go(null, extendPredictions(opts, predictions)); - } - }); - }; - predict = function (model, frame) { - var frameKey, modelKey, opts, _i, _j, _len, _len1; - if (model && frame) { - if (lodash.isString(model) && lodash.isString(frame)) { - return _fork(requestPredict, model, frame); + return _exception(new Flow.Error('Error fetching model list.', error)); } else { - if (lodash.isString(model)) { - model = [model]; - } - if (lodash.isString(frame)) { - frame = [frame]; - } - opts = []; - for (_i = 0, _len = model.length; _i < _len; _i++) { - modelKey = model[_i]; - for (_j = 0, _len1 = frame.length; _j < _len1; _j++) { - frameKey = frame[_j]; - opts.push({ - model: modelKey, - frame: frameKey - }); + return _models(function () { + var _i, _len, _results; + _results = []; + for (_i = 0, _len = models.length; _i < _len; _i++) { + model = models[_i]; + _results.push(model.key.name); } - } - return _fork(requestPredicts, opts); - } - } else { - return assist(predict, model, frame); - } - }; - requestPrediction = function (modelKey, frameKey, go) { - return _.requestPrediction(modelKey, frameKey, function (error, prediction) { - if (error) { - return go(error); - } else { - return go(null, extendPrediction(modelKey, frameKey, prediction)); + return _results; + }()); } }); - }; - requestPredictions = function (opts, go) { - var frameKey, futures, modelKey; - if (lodash.isArray(opts)) { - futures = lodash.map(opts, function (opt) { - var frameKey, modelKey; - modelKey = opt.model, frameKey = opt.frame; - return _fork(_.requestPredictions, modelKey, frameKey); - }); - return Flow.Async.join(futures, function (error, predictions) { - var uniquePredictions; - if (error) { - return go(error); - } else { - uniquePredictions = lodash.values(lodash.indexBy(lodash.flatten(predictions, true), function (prediction) { - return prediction.model.key + prediction.frame.key.name; - })); - return go(null, extendPredictions(opts, uniquePredictions)); - } - }); - } else { - modelKey = opts.model, frameKey = opts.frame; - return _.requestPredictions(modelKey, frameKey, function (error, predictions) { - if (error) { - return go(error); - } else { - return go(null, extendPredictions(opts, predictions)); - } - }); - } - }; - getPrediction = function (modelKey, frameKey) { - if (modelKey && frameKey) { - return _fork(requestPrediction, modelKey, frameKey); + } + predict = function () { + var frameArg, modelArg; + if (_hasFrames) { + frameArg = _selectedFrames.length > 1 ? _selectedFrames : lodash.head(_selectedFrames); + modelArg = _selectedModel(); + } else if (_hasModels) { + modelArg = _selectedModels.length > 1 ? _selectedModels : lodash.head(_selectedModels); + frameArg = _selectedFrame(); } else { - return assist(getPrediction, modelKey, frameKey); - } - }; - getPredictions = function (opts) { - if (opts == null) { - opts = {}; + modelArg = _selectedModel(); + frameArg = _selectedFrame(); } - return _fork(requestPredictions, opts); + return _.insertAndExecuteCell('cs', 'predict ' + Flow.Prelude.stringify(modelArg) + ', ' + Flow.Prelude.stringify(frameArg)); }; - requestCloud = function (go) { - return _.requestCloud(function (error, cloud) { - if (error) { - return go(error); - } else { - return go(null, extendCloud(cloud)); - } - }); + return { + exception: _exception, + hasModels: _hasModels, + hasFrames: _hasFrames, + canPredict: _canPredict, + selectedFramesCaption: _selectedFramesCaption, + selectedModelsCaption: _selectedModelsCaption, + selectedFrame: _selectedFrame, + selectedModel: _selectedModel, + frames: _frames, + models: _models, + predict: predict, + template: 'flow-predict-input' }; - getCloud = function () { - return _fork(requestCloud); + }; +}.call(this)); +(function () { + H2O.PredictOutput = function (_, prediction) { + var frame, inspect, model, viewPredictionFrame, _predictionTable; + frame = prediction.frame, model = prediction.model; + _predictionTable = _.inspect('prediction', prediction); + inspect = function () { + return _.insertAndExecuteCell('cs', 'inspect getPrediction ' + Flow.Prelude.stringify(model.name) + ', ' + Flow.Prelude.stringify(frame.name)); }; - requestTimeline = function (go) { - return _.requestTimeline(function (error, timeline) { - if (error) { - return go(error); - } else { - return go(null, extendTimeline(timeline)); - } - }); + viewPredictionFrame = function () { + return _.insertAndExecuteCell('cs', 'getFrame ' + Flow.Prelude.stringify(prediction.predictions.key.name)); }; - getTimeline = function () { - return _fork(requestTimeline); + return { + predictionTable: _predictionTable, + inspect: inspect, + viewPredictionFrame: viewPredictionFrame, + template: 'flow-predict-output' }; - requestStackTrace = function (go) { - return _.requestStackTrace(function (error, stackTrace) { - if (error) { - return go(error); - } else { - return go(null, extendStackTrace(stackTrace)); - } + }; +}.call(this)); +(function () { + H2O.PredictsOutput = function (_, opts, _predictions) { + var arePredictionsComparable, comparePredictions, createPredictionView, initialize, inspectAll, plotMetrics, plotPredictions, plotScores, predict, _canComparePredictions, _checkAllPredictions, _isCheckingAll, _metricsTable, _predictionViews, _predictionsTable, _rocCurve, _scoresTable; + _predictionViews = Flow.Dataflow.signal([]); + _checkAllPredictions = Flow.Dataflow.signal(false); + _canComparePredictions = Flow.Dataflow.signal(false); + _rocCurve = Flow.Dataflow.signal(null); + arePredictionsComparable = function (views) { + if (views.length === 0) { + return false; + } + return lodash.every(views, function (view) { + return view.modelCategory === 'Binomial'; }); }; - getStackTrace = function () { - return _fork(requestStackTrace); - }; - requestLogFile = function (nodeIndex, go) { - return _.requestLogFile(nodeIndex, function (error, logFile) { - if (error) { - return go(error); - } else { - return go(null, extendLogFile(nodeIndex, logFile)); + _isCheckingAll = false; + Flow.Dataflow.react(_checkAllPredictions, function (checkAll) { + var view, _i, _len, _ref; + _isCheckingAll = true; + _ref = _predictionViews(); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + view = _ref[_i]; + view.isChecked(checkAll); + } + _canComparePredictions(checkAll && arePredictionsComparable(_predictionViews())); + _isCheckingAll = false; + }); + createPredictionView = function (prediction) { + var inspect, view, _frameKey, _isChecked, _modelKey; + _modelKey = prediction.model.name; + _frameKey = prediction.frame.name; + _isChecked = Flow.Dataflow.signal(false); + Flow.Dataflow.react(_isChecked, function () { + var checkedViews, view; + if (_isCheckingAll) { + return; } + checkedViews = function () { + var _i, _len, _ref, _results; + _ref = _predictionViews(); + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + view = _ref[_i]; + if (view.isChecked()) { + _results.push(view); + } + } + return _results; + }(); + return _canComparePredictions(arePredictionsComparable(checkedViews)); }); + view = function () { + return _.insertAndExecuteCell('cs', 'getPrediction ' + Flow.Prelude.stringify(_modelKey) + ', ' + Flow.Prelude.stringify(_frameKey)); + }; + inspect = function () { + return _.insertAndExecuteCell('cs', 'inspect getPrediction ' + Flow.Prelude.stringify(_modelKey) + ', ' + Flow.Prelude.stringify(_frameKey)); + }; + return { + modelKey: _modelKey, + frameKey: _frameKey, + modelCategory: prediction.model_category, + isChecked: _isChecked, + view: view, + inspect: inspect + }; }; - getLogFile = function (nodeIndex) { - if (nodeIndex == null) { - nodeIndex = 0; - } - return _fork(requestLogFile, nodeIndex); - }; - requestProfile = function (depth, go) { - return _.requestProfile(depth, function (error, profile) { - if (error) { - return go(error); - } else { - return go(null, extendProfile(profile)); + _predictionsTable = _.inspect('predictions', _predictions); + _metricsTable = _.inspect('metrics', _predictions); + _scoresTable = _.inspect('scores', _predictions); + comparePredictions = function () { + var selectedKeys, view; + selectedKeys = function () { + var _i, _len, _ref, _results; + _ref = _predictionViews(); + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + view = _ref[_i]; + if (view.isChecked()) { + _results.push({ + model: view.modelKey, + frame: view.frameKey + }); + } } - }); + return _results; + }(); + return _.insertAndExecuteCell('cs', 'getPredictions ' + Flow.Prelude.stringify(selectedKeys)); }; - getProfile = function (opts) { - if (!opts) { - opts = { depth: 10 }; - } - return _fork(requestProfile, opts.depth); + plotPredictions = function () { + return _.insertAndExecuteCell('cs', _predictionsTable.meta.plot); }; - loadScript = function (path, go) { - var onDone, onFail; - onDone = function (script, status) { - return go(null, { - script: script, - status: status - }); - }; - onFail = function (jqxhr, settings, error) { - return go(error); - }; - return $.getScript(path).done(onDone).fail(onFail); + plotScores = function () { + return _.insertAndExecuteCell('cs', _scoresTable.meta.plot); }; - dumpFuture = function (result, go) { - console.debug(result); - return go(null, render_(result || {}, function () { - return Flow.ObjectBrowser('dump', result); - })); + plotMetrics = function () { + return _.insertAndExecuteCell('cs', _metricsTable.meta.plot); }; - dump = function (f) { - if (f != null ? f.isFuture : void 0) { - return _fork(dumpFuture, f); - } else { - return Flow.Async.async(function () { - return f; - }); - } + inspectAll = function () { + return _.insertAndExecuteCell('cs', 'inspect ' + _predictionsTable.meta.origin); }; - assist = function () { - var args, func; - func = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; - if (func === void 0) { - return _fork(proceed, H2O.Assist, [_assistance]); - } else { - switch (func) { - case importFiles: - return _fork(proceed, H2O.ImportFilesInput, []); - case buildModel: - return _fork(proceed, H2O.ModelInput, args); - case predict: - case getPrediction: - return _fork(proceed, H2O.PredictInput, args); - case createFrame: - return _fork(proceed, H2O.CreateFrameInput, args); - default: - return _fork(proceed, H2O.NoAssist, []); - } - } + predict = function () { + return _.insertAndExecuteCell('cs', 'predict'); }; - Flow.Dataflow.link(_.ready, function () { - Flow.Dataflow.link(_.inspect, inspect); - return Flow.Dataflow.link(_.plot, __plot); - }); + initialize = function (predictions) { + return _predictionViews(lodash.map(predictions, createPredictionView)); + }; + initialize(_predictions); return { - fork: _fork, - join: _join, - call: _call, - apply: _apply, - isFuture: _isFuture, - signal: Flow.Dataflow.signal, - signals: Flow.Dataflow.signals, - isSignal: Flow.Dataflow.isSignal, - act: Flow.Dataflow.act, - react: Flow.Dataflow.react, - lift: Flow.Dataflow.lift, - merge: Flow.Dataflow.merge, - dump: dump, - inspect: inspect, - plot: plot, - grid: grid, - get: _get, - assist: assist, - gui: gui, - loadScript: loadScript, - getJobs: getJobs, - getJob: getJob, - importFiles: importFiles, - setupParse: setupParse, - parseRaw: parseRaw, - createFrame: createFrame, - getFrames: getFrames, - getFrame: getFrame, - getColumnSummary: getColumnSummary, - buildModel: buildModel, - getModels: getModels, - getModel: getModel, + predictionViews: _predictionViews, + hasPredictions: _predictions.length > 0, + comparePredictions: comparePredictions, + canComparePredictions: _canComparePredictions, + checkAllPredictions: _checkAllPredictions, + plotPredictions: plotPredictions, + plotScores: plotScores, + plotMetrics: plotMetrics, + inspect: inspectAll, predict: predict, - getPrediction: getPrediction, - getPredictions: getPredictions, - getCloud: getCloud, - getTimeline: getTimeline, - getProfile: getProfile, - getStackTrace: getStackTrace, - getLogFile: getLogFile + rocCurve: _rocCurve, + template: 'flow-predicts-output' }; }; }.call(this)); (function () { - H2O.Assist = function (_, _items) { - var createAssistItem, item, name; - createAssistItem = function (name, item) { - return { - name: name, - description: item.description, - icon: 'fa fa-' + item.icon + ' flow-icon', - execute: function () { - return _.insertAndExecuteCell('cs', name); - } + H2O.ProfileOutput = function (_, _profile) { + var createNode, i, node, _activeNode, _nodes; + _activeNode = Flow.Dataflow.signal(null); + createNode = function (node) { + var display, entries, entry, self; + display = function () { + return _activeNode(self); }; - }; - return { - routines: function () { - var _results; + entries = function () { + var _i, _len, _ref, _results; + _ref = node.entries; _results = []; - for (name in _items) { - item = _items[name]; - _results.push(createAssistItem(name, item)); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + entry = _ref[_i]; + _results.push({ + stacktrace: entry.stacktrace, + caption: 'Count: ' + entry.count + }); } return _results; - }(), - template: 'flow-assist' + }(); + return self = { + name: node.node_name, + caption: '' + node.node_name + ' at ' + new Date(node.timestamp), + entries: entries, + display: display + }; + }; + _nodes = function () { + var _i, _len, _ref, _results; + _ref = _profile.nodes; + _results = []; + for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { + node = _ref[i]; + _results.push(createNode(node)); + } + return _results; + }(); + _activeNode(lodash.head(_nodes)); + return { + nodes: _nodes, + activeNode: _activeNode, + template: 'flow-profile-output' }; }; }.call(this)); (function () { - H2O.CloudOutput = function (_, _cloud) { - var avg, createGrid, createNodeRow, createTotalRow, format3f, formatMilliseconds, formatThreads, prettyPrintBytes, refresh, sum, toggleExpansion, toggleRefresh, updateCloud, _exception, _hasConsensus, _headers, _isBusy, _isExpanded, _isHealthy, _isLive, _isLocked, _name, _nodeCounts, _nodes, _size, _sizes, _uptime, _version; - _exception = Flow.Dataflow.signal(null); + H2O.StackTraceOutput = function (_, _stackTrace) { + var createNode, createThread, node, _activeNode, _nodes; + _activeNode = Flow.Dataflow.signal(null); + createThread = function (thread) { + var lines; + lines = thread.split('\n'); + return { + title: lodash.head(lines), + stackTrace: lodash.tail(lines).join('\n') + }; + }; + createNode = function (node) { + var display, self, thread; + display = function () { + return _activeNode(self); + }; + return self = { + name: node._node, + timestamp: new Date(node._time), + threads: function () { + var _i, _len, _ref, _results; + _ref = node._traces; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + thread = _ref[_i]; + _results.push(createThread(thread)); + } + return _results; + }(), + display: display + }; + }; + _nodes = function () { + var _i, _len, _ref, _results; + _ref = _stackTrace.traces; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + node = _ref[_i]; + _results.push(createNode(node)); + } + return _results; + }(); + _activeNode(lodash.head(_nodes)); + return { + nodes: _nodes, + activeNode: _activeNode, + template: 'flow-stacktrace-output' + }; + }; +}.call(this)); +(function () { + H2O.TimelineOutput = function (_, _timeline) { + var createEvent, refresh, toggleRefresh, updateTimeline, _data, _headers, _isBusy, _isLive, _timestamp; _isLive = Flow.Dataflow.signal(false); _isBusy = Flow.Dataflow.signal(false); - _isExpanded = Flow.Dataflow.signal(false); - _name = Flow.Dataflow.signal(); - _size = Flow.Dataflow.signal(); - _uptime = Flow.Dataflow.signal(); - _version = Flow.Dataflow.signal(); - _nodeCounts = Flow.Dataflow.signal(); - _hasConsensus = Flow.Dataflow.signal(); - _isLocked = Flow.Dataflow.signal(); - _isHealthy = Flow.Dataflow.signal(); - _nodes = Flow.Dataflow.signals(); - formatMilliseconds = function (ms) { - return Flow.Util.fromNow(new Date(new Date().getTime() - ms)); - }; - format3f = d3.format('.3f'); - _sizes = [ - 'B', - 'KB', - 'MB', - 'GB', - 'TB', - 'PB', - 'EB', - 'ZB', - 'YB' + _headers = [ + 'HH:MM:SS:MS', + 'nanosec', + 'Who', + 'I/O Type', + 'Event', + 'Bytes' ]; - prettyPrintBytes = function (bytes) { - var i; - if (bytes === 0) { - return '-'; + _data = Flow.Dataflow.signal(null); + _timestamp = Flow.Dataflow.signal(Date.now()); + createEvent = function (event) { + switch (event.type) { + case 'io': + return [ + event.date, + event.nanos, + event.node, + event.ioFlavor || '-', + 'I/O', + event.data + ]; + case 'heartbeat': + return [ + event.date, + event.nanos, + 'many → many', + 'UDP', + 'heartbeat', + '' + event.sends + ' sent ' + event.recvs + ' received' + ]; + case 'network_msg': + return [ + event.date, + event.nanos, + '' + event.from + ' → ' + event.to, + event.protocol, + event.msgType, + event.data + ]; } - i = Math.floor(Math.log(bytes) / Math.log(1024)); - return (bytes / Math.pow(1024, i)).toFixed(2) + ' ' + _sizes[i]; }; - formatThreads = function (fjs) { - var i, max_lo, s, _i, _j, _k, _ref; - for (max_lo = _i = 120; _i > 0; max_lo = --_i) { - if (fjs[max_lo - 1] !== -1) { - break; + updateTimeline = function (timeline) { + var cell, event, grid, header, table, tbody, td, th, thead, ths, tr, trs, _ref; + _ref = Flow.HTML.template('.grid', 'table', '=thead', 'tbody', 'tr', '=th', '=td'), grid = _ref[0], table = _ref[1], thead = _ref[2], tbody = _ref[3], tr = _ref[4], th = _ref[5], td = _ref[6]; + ths = function () { + var _i, _len, _results; + _results = []; + for (_i = 0, _len = _headers.length; _i < _len; _i++) { + header = _headers[_i]; + _results.push(th(header)); } - } - s = '['; - for (i = _j = 0; 0 <= max_lo ? _j < max_lo : _j > max_lo; i = 0 <= max_lo ? ++_j : --_j) { - s += Math.max(fjs[i], 0); - s += '/'; - } - s += '.../'; - for (i = _k = 120, _ref = fjs.length - 1; 120 <= _ref ? _k < _ref : _k > _ref; i = 120 <= _ref ? ++_k : --_k) { - s += fjs[i]; - s += '/'; - } - s += fjs[fjs.length - 1]; - s += ']'; - return s; - }; - sum = function (nodes, attrOf) { - var node, total, _i, _len; - total = 0; - for (_i = 0, _len = nodes.length; _i < _len; _i++) { - node = nodes[_i]; - total += attrOf(node); - } - return total; - }; - avg = function (nodes, attrOf) { - return sum(nodes, attrOf) / nodes.length; - }; - _headers = [ - [ - ' ', - true - ], - [ - 'Name', - true - ], - [ - 'Ping', - true - ], - [ - 'Cores', - true - ], - [ - 'Load', - true - ], - [ - 'Data (Used/Total)', - true - ], - [ - 'Data (% Cached)', - true - ], - [ - 'GC (Free / Total / Max)', - true - ], - [ - 'Disk (Free / Max)', - true - ], - [ - 'Disk (% Free)', - true - ], - [ - 'PID', - false - ], - [ - 'Keys', - false - ], - [ - 'TCP', - false - ], - [ - 'FD', - false - ], - [ - 'RPCs', - false - ], - [ - 'Threads', - false - ], - [ - 'Tasks', - false - ] - ]; - createNodeRow = function (node) { - return [ - node.healthy, - node.h2o.node, - moment(new Date(node.last_ping)).fromNow(), - node.num_cpus, - format3f(node.sys_load), - '' + prettyPrintBytes(node.mem_value_size) + ' / ' + prettyPrintBytes(node.total_value_size), - '' + Math.floor(node.mem_value_size * 100 / node.total_value_size) + '%', - '' + prettyPrintBytes(node.free_mem) + ' / ' + prettyPrintBytes(node.tot_mem) + ' / ' + prettyPrintBytes(node.max_mem), - '' + prettyPrintBytes(node.free_disk) + ' / ' + prettyPrintBytes(node.max_disk), - '' + Math.floor(node.free_disk * 100 / node.max_disk) + '%', - node.pid, - node.num_keys, - node.tcps_active, - node.open_fds, - node.rpcs_active, - formatThreads(node.fjthrds), - formatThreads(node.fjqueue) - ]; - }; - createTotalRow = function (cloud) { - var nodes; - nodes = cloud.nodes; - return [ - cloud.cloud_healthy, - 'TOTAL', - '-', - sum(nodes, function (node) { - return node.num_cpus; - }), - format3f(sum(nodes, function (node) { - return node.sys_load; - })), - '' + prettyPrintBytes(sum(nodes, function (node) { - return node.mem_value_size; - })) + ' / ' + prettyPrintBytes(sum(nodes, function (node) { - return node.total_value_size; - })), - '' + Math.floor(avg(nodes, function (node) { - return node.mem_value_size * 100 / node.total_value_size; - })) + '%', - '' + prettyPrintBytes(sum(nodes, function (node) { - return node.free_mem; - })) + ' / ' + prettyPrintBytes(sum(nodes, function (node) { - return node.tot_mem; - })) + ' / ' + prettyPrintBytes(sum(nodes, function (node) { - return node.max_mem; - })), - '' + prettyPrintBytes(sum(nodes, function (node) { - return node.free_disk; - })) + ' / ' + prettyPrintBytes(sum(nodes, function (node) { - return node.max_disk; - })), - '' + Math.floor(avg(nodes, function (node) { - return node.free_disk * 100 / node.max_disk; - })) + '%', - '-', - sum(nodes, function (node) { - return node.num_keys; - }), - sum(nodes, function (node) { - return node.tcps_active; - }), - sum(nodes, function (node) { - return node.open_fds; - }), - sum(nodes, function (node) { - return node.rpcs_active; - }), - '-', - '-' - ]; - }; - createGrid = function (cloud, isExpanded) { - var caption, cell, danger, grid, i, nodeRows, row, showAlways, success, table, tbody, td, tds, th, thead, ths, tr, trs, _ref; - _ref = Flow.HTML.template('.grid', 'table', '=thead', 'tbody', 'tr', '=th', '=td', '=i.fa.fa-check-circle.text-success', '=i.fa.fa-exclamation-circle.text-danger'), grid = _ref[0], table = _ref[1], thead = _ref[2], tbody = _ref[3], tr = _ref[4], th = _ref[5], td = _ref[6], success = _ref[7], danger = _ref[8]; - nodeRows = lodash.map(cloud.nodes, createNodeRow); - nodeRows.push(createTotalRow(cloud)); - ths = function () { - var _i, _len, _ref1, _results; - _results = []; - for (_i = 0, _len = _headers.length; _i < _len; _i++) { - _ref1 = _headers[_i], caption = _ref1[0], showAlways = _ref1[1]; - if (showAlways || isExpanded) { - _results.push(th(caption)); - } - } - return _results; - }(); - trs = function () { - var _i, _len, _results; - _results = []; - for (_i = 0, _len = nodeRows.length; _i < _len; _i++) { - row = nodeRows[_i]; - tds = function () { - var _j, _len1, _results1; - _results1 = []; - for (i = _j = 0, _len1 = row.length; _j < _len1; i = ++_j) { - cell = row[i]; - if (_headers[i][1] || isExpanded) { - if (i === 0) { - _results1.push(td(cell ? success() : danger())); - } else { - _results1.push(td(cell)); - } - } - } - return _results1; - }(); - _results.push(tr(tds)); - } - return _results; - }(); - return Flow.HTML.render('div', grid([table([ - thead(tr(ths)), - tbody(trs) - ])])); - }; - updateCloud = function (cloud, isExpanded) { - _name(cloud.cloud_name); - _version(cloud.version); - _hasConsensus(cloud.consensus); - _uptime(formatMilliseconds(cloud.cloud_uptime_millis)); - _nodeCounts('' + (cloud.cloud_size - cloud.bad_nodes) + ' / ' + cloud.cloud_size); - _isLocked(cloud.locked); - _isHealthy(cloud.cloud_healthy); - return _nodes(createGrid(cloud, isExpanded)); + return _results; + }(); + trs = function () { + var _i, _len, _ref1, _results; + _ref1 = timeline.events; + _results = []; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + event = _ref1[_i]; + _results.push(tr(function () { + var _j, _len1, _ref2, _results1; + _ref2 = createEvent(event); + _results1 = []; + for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { + cell = _ref2[_j]; + _results1.push(td(cell)); + } + return _results1; + }())); + } + return _results; + }(); + return _data(Flow.HTML.render('div', grid([table([ + thead(tr(ths)), + tbody(trs) + ])]))); }; toggleRefresh = function () { return _isLive(!_isLive()); }; refresh = function () { _isBusy(true); - return _.requestCloud(function (error, cloud) { + return _.requestTimeline(function (error, timeline) { _isBusy(false); if (error) { - _exception(Flow.Failure(new Flow.Error('Error fetching cloud status', error))); + _exception(Flow.Failure(new Flow.Error('Error fetching timeline', error))); return _isLive(false); } else { - updateCloud(_cloud = cloud, _isExpanded()); + updateTimeline(timeline); if (_isLive()) { return lodash.delay(refresh, 2000); } @@ -6412,2136 +6510,2039 @@ return refresh(); } }); - toggleExpansion = function () { - return _isExpanded(!_isExpanded()); - }; - Flow.Dataflow.act(_isExpanded, function (isExpanded) { - return updateCloud(_cloud, isExpanded); - }); - updateCloud(_cloud, _isExpanded()); + updateTimeline(_timeline); return { - name: _name, - size: _size, - uptime: _uptime, - version: _version, - nodeCounts: _nodeCounts, - hasConsensus: _hasConsensus, - isLocked: _isLocked, - isHealthy: _isHealthy, - nodes: _nodes, + data: _data, isLive: _isLive, isBusy: _isBusy, toggleRefresh: toggleRefresh, refresh: refresh, - isExpanded: _isExpanded, - toggleExpansion: toggleExpansion, - template: 'flow-cloud-output' + template: 'flow-timeline-output' }; }; }.call(this)); (function () { - H2O.ColumnSummaryOutput = function (_, frameKey, frame, columnName) { - var column, inspect, _characteristicsPlot, _characteristicsPlotConfig, _characteristicsTable; - column = lodash.head(frame.columns); - _characteristicsPlot = Flow.Dataflow.signal(null); - _characteristicsTable = _.inspect('characteristics', frame); - _characteristicsPlotConfig = { - data: _characteristicsTable, - type: 'interval', - x: Flow.Plot.stack('count'), - y: 'label' - }; - Flow.Plot(_characteristicsPlotConfig, function (error, plot) { - if (!error) { - return _characteristicsPlot(plot); - } - }); - inspect = function () { - return _.insertAndExecuteCell('cs', 'inspect getColumnSummary ' + Flow.Prelude.stringify(frameKey) + ', ' + Flow.Prelude.stringify(columnName)); - }; - return { - label: column.label, - characteristicsPlot: _characteristicsPlot, - inspect: inspect, - template: 'flow-column-summary-output' - }; + H2O.ApplicationContext = function (_) { + _.requestGet = Flow.Dataflow.slot(); + _.requestPost = Flow.Dataflow.slot(); + _.requestFileGlob = Flow.Dataflow.slot(); + _.requestCreateFrame = Flow.Dataflow.slot(); + _.requestImportFile = Flow.Dataflow.slot(); + _.requestImportFiles = Flow.Dataflow.slot(); + _.requestParseFiles = Flow.Dataflow.slot(); + _.requestInspect = Flow.Dataflow.slot(); + _.requestParseSetup = Flow.Dataflow.slot(); + _.requestFrames = Flow.Dataflow.slot(); + _.requestFrame = Flow.Dataflow.slot(); + _.requestColumnSummary = Flow.Dataflow.slot(); + _.requestModelBuilder = Flow.Dataflow.slot(); + _.requestModelBuilders = Flow.Dataflow.slot(); + _.requestModelBuild = Flow.Dataflow.slot(); + _.requestModelInputValidation = Flow.Dataflow.slot(); + _.requestPredict = Flow.Dataflow.slot(); + _.requestPrediction = Flow.Dataflow.slot(); + _.requestPredictions = Flow.Dataflow.slot(); + _.requestModels = Flow.Dataflow.slot(); + _.requestModel = Flow.Dataflow.slot(); + _.requestJobs = Flow.Dataflow.slot(); + _.requestJob = Flow.Dataflow.slot(); + _.requestObjects = Flow.Dataflow.slot(); + _.requestObject = Flow.Dataflow.slot(); + _.requestDeleteObject = Flow.Dataflow.slot(); + _.requestPutObject = Flow.Dataflow.slot(); + _.requestCloud = Flow.Dataflow.slot(); + _.requestTimeline = Flow.Dataflow.slot(); + _.requestProfile = Flow.Dataflow.slot(); + _.requestStackTrace = Flow.Dataflow.slot(); + _.requestRemoveAll = Flow.Dataflow.slot(); + _.requestLogFile = Flow.Dataflow.slot(); + _.requestAbout = Flow.Dataflow.slot(); + _.inspect = Flow.Dataflow.slot(); + return _.plot = Flow.Dataflow.slot(); }; }.call(this)); (function () { - H2O.CreateFrameInput = function (_) { - var createFrame, _binaryFraction, _categoricalFraction, _columns, _factors, _integerFraction, _integerRange, _key, _missingFraction, _randomize, _realRange, _responseFactors, _rows, _seed, _value; - _key = Flow.Dataflow.signal(''); - _rows = Flow.Dataflow.signal(10000); - _columns = Flow.Dataflow.signal(100); - _seed = Flow.Dataflow.signal(7595850248774472000); - _randomize = Flow.Dataflow.signal(true); - _value = Flow.Dataflow.signal(0); - _realRange = Flow.Dataflow.signal(100); - _categoricalFraction = Flow.Dataflow.signal(0.1); - _factors = Flow.Dataflow.signal(5); - _integerFraction = Flow.Dataflow.signal(0.5); - _binaryFraction = Flow.Dataflow.signal(0.1); - _integerRange = Flow.Dataflow.signal(1); - _missingFraction = Flow.Dataflow.signal(0.01); - _responseFactors = Flow.Dataflow.signal(2); - createFrame = function () { - var opts; - opts = { - dest: _key(), - rows: _rows(), - cols: _columns(), - seed: _seed(), - randomize: _randomize(), - value: _value(), - real_range: _realRange(), - categorical_fraction: _categoricalFraction(), - factors: _factors(), - integer_fraction: _integerFraction(), - binary_fraction: _binaryFraction(), - integer_range: _integerRange(), - missing_fraction: _missingFraction(), - response_factors: _responseFactors() - }; - return _.insertAndExecuteCell('cs', 'createFrame ' + Flow.Prelude.stringify(opts)); - }; - return { - key: _key, - rows: _rows, - columns: _columns, - seed: _seed, - randomize: _randomize, - value: _value, - realRange: _realRange, - categoricalFraction: _categoricalFraction, - factors: _factors, - integerFraction: _integerFraction, - binaryFraction: _binaryFraction, - integerRange: _integerRange, - missingFraction: _missingFraction, - responseFactors: _responseFactors, - createFrame: createFrame, - template: 'flow-create-frame-input' - }; + H2O.Application = function (_) { + H2O.ApplicationContext(_); + return H2O.Proxy(_); }; }.call(this)); (function () { - H2O.FrameOutput = function (_, _frame) { - var createGrid, createModel, download, inspect, inspectData, predict, _grid; - createGrid = function (data) { - var action, el, grid, row, rowIndex, table, tbody, td, tdr, tds, th, thead, thr, ths, tr, trs, value, variable, _ref; - _ref = Flow.HTML.template('.grid', 'table', '=thead', 'tbody', 'tr', '=th', '=th.rt', '=td', '=td.rt', '+a data-action=\'summary\' data-index=\'{0}\' class=\'action\' href=\'#\''), grid = _ref[0], table = _ref[1], thead = _ref[2], tbody = _ref[3], tr = _ref[4], th = _ref[5], thr = _ref[6], td = _ref[7], tdr = _ref[8], action = _ref[9]; - ths = function () { - var _i, _len, _ref1, _results; - _ref1 = data.variables; - _results = []; - for (_i = 0, _len = _ref1.length; _i < _len; _i++) { - variable = _ref1[_i]; - switch (variable.type) { - case Flow.TNumber: - _results.push(thr(lodash.escape(variable.label))); - break; - default: - _results.push(th(lodash.escape(variable.label))); - } - } - return _results; - }(); - ths.push(th('Actions')); - trs = function () { - var _i, _len, _ref1, _results; - _ref1 = data.rows; - _results = []; - for (rowIndex = _i = 0, _len = _ref1.length; _i < _len; rowIndex = ++_i) { - row = _ref1[rowIndex]; - tds = function () { - var _j, _len1, _ref2, _results1; - _ref2 = data.variables; - _results1 = []; - for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { - variable = _ref2[_j]; - value = row[variable.label]; - switch (variable.type) { - case Flow.TFactor: - _results1.push(td(value === null ? '-' : lodash.escape(variable.domain[value]))); - break; - case Flow.TNumber: - _results1.push(tdr(value === null ? '-' : value)); - break; - case Flow.TArray: - _results1.push(td(value === null ? '-' : value.join(', '))); - break; - default: - _results1.push(td(value === null ? '-' : value)); - } - } - return _results1; - }(); - tds.push(td(action('Summary...', rowIndex))); - _results.push(tr(tds)); - } - return _results; - }(); - el = Flow.HTML.render('div', grid([table([ - thead(tr(ths)), - tbody(trs) - ])])); - $('a.action', el).click(function (e) { - var $link, index; - e.preventDefault(); - $link = $(this); - action = $link.attr('data-action'); - index = parseInt($link.attr('data-index'), 10); - switch (action) { - case 'summary': - if (index >= 0) { - row = data.rows[index]; - if (row) { - return _.insertAndExecuteCell('cs', 'inspect getColumnSummary ' + Flow.Prelude.stringify(_frame.key.name) + ', ' + Flow.Prelude.stringify(row.label)); - } - } + H2O.Proxy = function (_) { + var composePath, doGet, doPost, encodeArray, encodeObject, http, mapWithKey, patchUpModels, requestAbout, requestCloud, requestColumnSummary, requestCreateFrame, requestDeleteObject, requestFileGlob, requestFrame, requestFrames, requestImportFile, requestImportFiles, requestInspect, requestJob, requestJobs, requestLogFile, requestModel, requestModelBuild, requestModelBuilder, requestModelBuilders, requestModelInputValidation, requestModels, requestObject, requestObjects, requestParseFiles, requestParseSetup, requestPredict, requestPrediction, requestPredictions, requestProfile, requestPutObject, requestRemoveAll, requestStackTrace, requestTimeline, requestWithOpts; + http = function (path, opts, go) { + var req; + _.status('server', 'request', path); + req = opts ? $.post(path, opts) : $.getJSON(path); + req.done(function (data, status, xhr) { + var error; + _.status('server', 'response', path); + try { + return go(null, data); + } catch (_error) { + error = _error; + return go(new Flow.Error(opts ? 'Error processing POST ' + path : 'Error processing GET ' + path, error)); } }); - return el; + return req.fail(function (xhr, status, error) { + var message, _ref; + _.status('server', 'error', path); + message = ((_ref = xhr.responseJSON) != null ? _ref.errmsg : void 0) ? xhr.responseJSON.errmsg : (error != null ? error.message : void 0) ? error.message : status === 0 ? 'Could not connect to H2O' : 'Unknown error'; + return go(new Flow.Error(message, new Flow.Error(opts ? 'Error calling POST ' + path + ' with opts ' + JSON.stringify(opts) : 'Error calling GET ' + path))); + }); }; - createModel = function () { - return _.insertAndExecuteCell('cs', 'assist buildModel, null, training_frame: ' + Flow.Prelude.stringify(_frame.key.name)); + doGet = function (path, go) { + return http(path, null, go); }; - inspect = function () { - return _.insertAndExecuteCell('cs', 'inspect getFrame ' + Flow.Prelude.stringify(_frame.key.name)); + doPost = http; + mapWithKey = function (obj, f) { + var key, result, value; + result = []; + for (key in obj) { + value = obj[key]; + result.push(f(value, key)); + } + return result; }; - inspectData = function () { - return _.insertAndExecuteCell('cs', 'grid inspect \'data\', getFrame ' + Flow.Prelude.stringify(_frame.key.name)); + composePath = function (path, opts) { + var params; + if (opts) { + params = mapWithKey(opts, function (v, k) { + return '' + k + '=' + v; + }); + return path + '?' + params.join('&'); + } else { + return path; + } }; - predict = function () { - return _.insertAndExecuteCell('cs', 'predict null, ' + Flow.Prelude.stringify(_frame.key.name)); + requestWithOpts = function (path, opts, go) { + return doGet(composePath(path, opts), go); }; - download = function () { - return window.open('/3/DownloadDataset?key=' + encodeURIComponent(_frame.key.name), '_blank'); + encodeArray = function (array) { + return '[' + lodash.map(array, encodeURIComponent).join(',') + ']'; }; - _grid = createGrid(_.inspect('columns', _frame)); - return { - key: _frame.key.name, - grid: _grid, - inspect: inspect, - createModel: createModel, - inspectData: inspectData, - predict: predict, - download: download, - template: 'flow-frame-output' + encodeObject = function (source) { + var k, target, v; + target = {}; + for (k in source) { + v = source[k]; + target[k] = encodeURIComponent(v); + } + return target; }; - }; -}.call(this)); -(function () { - var toSize; - toSize = function (bytes) { - var i, sizes; - sizes = [ - 'Bytes', - 'KB', - 'MB', - 'GB', - 'TB' - ]; - if (bytes === 0) { - return '0 Byte'; - } - i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); - return Math.round(bytes / Math.pow(1024, i), 2) + sizes[i]; - }; - H2O.FramesOutput = function (_, _frames) { - var createFrameView, importFiles, predictOnFrames, _canCompareFrames, _checkAllFrames, _frameViews, _isCheckingAll; - _frameViews = Flow.Dataflow.signal([]); - _checkAllFrames = Flow.Dataflow.signal(false); - _canCompareFrames = Flow.Dataflow.signal(false); - _isCheckingAll = false; - Flow.Dataflow.react(_checkAllFrames, function (checkAll) { - var view, _i, _len, _ref; - _isCheckingAll = true; - _ref = _frameViews(); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - view = _ref[_i]; - view.isChecked(checkAll); - } - _canCompareFrames(checkAll); - _isCheckingAll = false; - }); - createFrameView = function (frame) { - var columnLabels, createModel, description, inspect, predict, view, _isChecked; - _isChecked = Flow.Dataflow.signal(false); - Flow.Dataflow.react(_isChecked, function () { - var checkedViews, view; - if (_isCheckingAll) { - return; - } - checkedViews = function () { - var _i, _len, _ref, _results; - _ref = _frameViews(); - _results = []; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - view = _ref[_i]; - if (view.isChecked()) { - _results.push(view); - } - } - return _results; - }(); - return _canCompareFrames(checkedViews.length > 0); - }); - columnLabels = lodash.head(lodash.map(frame.columns, function (column) { - return column.label; - }), 15); - description = 'Columns: ' + columnLabels.join(', ') + (frame.columns.length > columnLabels.length ? '... (' + (frame.columns.length - columnLabels.length) + ' more columns)' : ''); - view = function () { - if (frame.isText) { - return _.insertAndExecuteCell('cs', 'setupParse [ ' + Flow.Prelude.stringify(frame.key.name) + ' ]'); - } else { - return _.insertAndExecuteCell('cs', 'getFrame ' + Flow.Prelude.stringify(frame.key.name)); - } - }; - predict = function () { - return _.insertAndExecuteCell('cs', 'predict null, ' + Flow.Prelude.stringify(frame.key.name)); - }; - inspect = function () { - return _.insertAndExecuteCell('cs', 'inspect getFrame ' + Flow.Prelude.stringify(frame.key.name)); - }; - createModel = function () { - return _.insertAndExecuteCell('cs', 'assist buildModel, null, training_frame: ' + Flow.Prelude.stringify(frame.key.name)); - }; - return { - key: frame.key.name, - isChecked: _isChecked, - description: description, - size: toSize(frame.byteSize), - rowCount: frame.rows, - columnCount: frame.columns.length, - isText: frame.isText, - view: view, - predict: predict, - inspect: inspect, - createModel: createModel - }; + requestInspect = function (key, go) { + var opts; + opts = { key: encodeURIComponent(key) }; + return requestWithOpts('/Inspect.json', opts, go); }; - importFiles = function () { - return _.insertAndExecuteCell('cs', 'importFiles'); + requestCreateFrame = function (opts, go) { + return requestWithOpts('/2/CreateFrame.json', encodeObject(opts), go); }; - predictOnFrames = function () { - var selectedKeys, view; - selectedKeys = function () { - var _i, _len, _ref, _results; - _ref = _frameViews(); - _results = []; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - view = _ref[_i]; - if (view.isChecked()) { - _results.push(view.key); - } + requestFrames = function (go) { + return doGet('/3/Frames.json', function (error, result) { + if (error) { + return go(error); + } else { + return go(null, result.frames); } - return _results; - }(); - return _.insertAndExecuteCell('cs', 'predict null, ' + Flow.Prelude.stringify(selectedKeys)); - }; - _frameViews(lodash.map(_frames, createFrameView)); - return { - frameViews: _frameViews, - hasFrames: _frames.length > 0, - importFiles: importFiles, - predictOnFrames: predictOnFrames, - canCompareFrames: _canCompareFrames, - checkAllFrames: _checkAllFrames, - template: 'flow-frames-output' + }); }; - }; -}.call(this)); -(function () { - H2O.ImportFilesInput = function (_) { - var createFileItem, createFileItems, createSelectedFileItem, deselectAllFiles, importFiles, importSelectedFiles, listPathHints, processImportResult, selectAllFiles, tryImportFiles, _exception, _hasErrorMessage, _hasImportedFiles, _hasSelectedFiles, _hasUnselectedFiles, _importedFileCount, _importedFiles, _selectedFileCount, _selectedFiles, _selectedFilesDictionary, _specifiedPath; - _specifiedPath = Flow.Dataflow.signal(''); - _exception = Flow.Dataflow.signal(''); - _hasErrorMessage = Flow.Dataflow.lift(_exception, function (exception) { - if (exception) { - return true; - } else { - return false; - } - }); - tryImportFiles = function () { - var specifiedPath; - specifiedPath = _specifiedPath(); - return _.requestFileGlob(specifiedPath, 0, function (error, result) { + requestFrame = function (key, go) { + return doGet('/3/Frames.json/' + encodeURIComponent(key), function (error, result) { if (error) { - return _exception(error.data.errmsg); + return go(error); } else { - _exception(''); - return processImportResult(result); + return go(null, lodash.head(result.frames)); } }); }; - _importedFiles = Flow.Dataflow.signals([]); - _importedFileCount = Flow.Dataflow.lift(_importedFiles, function (files) { - if (files.length) { - return 'Found ' + Flow.Util.describeCount(files.length, 'file') + ':'; - } else { - return ''; - } - }); - _hasImportedFiles = Flow.Dataflow.lift(_importedFiles, function (files) { - return files.length > 0; - }); - _hasUnselectedFiles = Flow.Dataflow.lift(_importedFiles, function (files) { - return lodash.some(files, function (file) { - return !file.isSelected(); - }); - }); - _selectedFiles = Flow.Dataflow.signals([]); - _selectedFilesDictionary = Flow.Dataflow.lift(_selectedFiles, function (files) { - var dictionary, file, _i, _len; - dictionary = {}; - for (_i = 0, _len = files.length; _i < _len; _i++) { - file = files[_i]; - dictionary[file.path] = true; - } - return dictionary; - }); - _selectedFileCount = Flow.Dataflow.lift(_selectedFiles, function (files) { - return '' + Flow.Util.describeCount(files.length, 'file') + ' selected:'; - }); - _hasSelectedFiles = Flow.Dataflow.lift(_selectedFiles, function (files) { - return files.length > 0; - }); - importFiles = function (files) { - var paths; - paths = lodash.map(files, function (file) { - return Flow.Prelude.stringify(file.path); + requestColumnSummary = function (key, column, go) { + return doGet('/3/Frames.json/' + encodeURIComponent(key) + '/columns/' + encodeURIComponent(column) + '/summary', function (error, result) { + if (error) { + return go(error); + } else { + return go(null, lodash.head(result.frames)); + } }); - return _.insertAndExecuteCell('cs', 'importFiles [ ' + paths.join(',') + ' ]'); - }; - importSelectedFiles = function () { - return importFiles(_selectedFiles()); }; - createSelectedFileItem = function (path) { - var self; - return self = { - path: path, - deselect: function () { - var file, _i, _len, _ref; - _selectedFiles.remove(self); - _ref = _importedFiles(); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - file = _ref[_i]; - if (file.path === path) { - file.isSelected(false); - } - } + requestJobs = function (go) { + return doGet('/3/Jobs.json', function (error, result) { + if (error) { + return go(new Flow.Error('Error fetching jobs', error)); + } else { + return go(null, result.jobs); } - }; + }); }; - createFileItem = function (path, isSelected) { - var self; - self = { - path: path, - isSelected: Flow.Dataflow.signal(isSelected), - select: function () { - _selectedFiles.push(createSelectedFileItem(self.path)); - return self.isSelected(true); + requestJob = function (key, go) { + return doGet('/3/Jobs.json/' + encodeURIComponent(key), function (error, result) { + if (error) { + return go(new Flow.Error('Error fetching job \'' + key + '\'', error)); + } else { + return go(null, lodash.head(result.jobs)); } - }; - Flow.Dataflow.act(self.isSelected, function (isSelected) { - return _hasUnselectedFiles(lodash.some(_importedFiles(), function (file) { - return !file.isSelected(); - })); }); - return self; }; - createFileItems = function (result) { - return lodash.map(result.matches, function (path) { - return createFileItem(path, _selectedFilesDictionary()[path]); + requestFileGlob = function (path, limit, go) { + var opts; + opts = { + src: encodeURIComponent(path), + limit: limit + }; + return requestWithOpts('/Typeahead.json/files', opts, go); + }; + requestImportFiles = function (paths, go) { + var tasks; + tasks = lodash.map(paths, function (path) { + return function (go) { + return requestImportFile(path, go); + }; }); + return Flow.Async.iterate(tasks)(go); }; - listPathHints = function (query, process) { - return _.requestFileGlob(query, 10, function (error, result) { - if (!error) { - return process(lodash.map(result.matches, function (value) { - return { value: value }; - })); + requestImportFile = function (path, go) { + var opts; + opts = { path: encodeURIComponent(path) }; + return requestWithOpts('/ImportFiles.json', opts, go); + }; + requestParseSetup = function (sources, go) { + var encodedPaths, opts; + encodedPaths = lodash.map(sources, encodeURIComponent); + opts = { srcs: '[' + encodedPaths.join(',') + ']' }; + return requestWithOpts('/ParseSetup.json', opts, go); + }; + requestParseFiles = function (sourceKeys, destinationKey, parserType, separator, columnCount, useSingleQuotes, columnNames, deleteOnDone, checkHeader, go) { + var opts; + opts = { + hex: encodeURIComponent(destinationKey), + srcs: encodeArray(sourceKeys), + pType: parserType, + sep: separator, + ncols: columnCount, + singleQuotes: useSingleQuotes, + columnNames: encodeArray(columnNames), + checkHeader: checkHeader, + delete_on_done: deleteOnDone + }; + return requestWithOpts('/Parse.json', opts, go); + }; + patchUpModels = function (models) { + var model, parameter, parseError, _i, _j, _len, _len1, _ref; + for (_i = 0, _len = models.length; _i < _len; _i++) { + model = models[_i]; + _ref = model.parameters; + for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { + parameter = _ref[_j]; + switch (parameter.type) { + case 'Key': + case 'Key': + case 'VecSpecifier': + if (lodash.isString(parameter.actual_value)) { + try { + parameter.actual_value = JSON.parse(parameter.actual_value); + } catch (_error) { + parseError = _error; + } + } + } + } + } + return models; + }; + requestModels = function (go, opts) { + return requestWithOpts('/3/Models.json', opts, function (error, result) { + if (error) { + return go(error, result); + } else { + return go(error, patchUpModels(result.models)); } }); }; - selectAllFiles = function () { - var file, _i, _len, _ref; - _selectedFiles(lodash.map(_importedFiles(), function (file) { - return createSelectedFileItem(file.path); - })); - _ref = _importedFiles(); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - file = _ref[_i]; - file.isSelected(true); - } + requestModel = function (key, go) { + return doGet('/3/Models.json/' + encodeURIComponent(key), function (error, result) { + if (error) { + return go(error, result); + } else { + return go(error, lodash.head(patchUpModels(result.models))); + } + }); }; - deselectAllFiles = function () { - var file, _i, _len, _ref; - _selectedFiles([]); - _ref = _importedFiles(); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - file = _ref[_i]; - file.isSelected(false); - } + requestModelBuilders = function (go) { + return doGet('/2/ModelBuilders.json', go); }; - processImportResult = function (result) { - var files; - files = createFileItems(result); - return _importedFiles(files); + requestModelBuilder = function (algo, go) { + return doGet('/2/ModelBuilders.json/' + algo, go); }; - return { - specifiedPath: _specifiedPath, - hasErrorMessage: _hasErrorMessage, - exception: _exception, - tryImportFiles: tryImportFiles, - listPathHints: lodash.throttle(listPathHints, 100), - hasImportedFiles: _hasImportedFiles, - importedFiles: _importedFiles, - importedFileCount: _importedFileCount, - selectedFiles: _selectedFiles, - selectAllFiles: selectAllFiles, - deselectAllFiles: deselectAllFiles, - hasUnselectedFiles: _hasUnselectedFiles, - hasSelectedFiles: _hasSelectedFiles, - selectedFileCount: _selectedFileCount, - importSelectedFiles: importSelectedFiles, - template: 'flow-import-files' + requestModelInputValidation = function (algo, parameters, go) { + return doPost('/2/ModelBuilders.json/' + algo + '/parameters', parameters, go); }; - }; -}.call(this)); -(function () { - H2O.ImportFilesOutput = function (_, _importResults) { - var buildModel, createImportView, parse, _allKeys, _canBuildModel, _canParse, _importViews, _title; - _allKeys = lodash.flatten(lodash.compact(lodash.map(_importResults, function (_arg) { - var error, result; - error = _arg[0], result = _arg[1]; - if (error) { - return null; - } else { - return result.keys; - } - }))); - _canParse = _allKeys.length > 0; - _canBuildModel = _allKeys.length === 1; - _title = '' + _allKeys.length + ' / ' + _importResults.length + ' files imported.'; - createImportView = function (result) { - return { - keys: result.keys, - template: 'flow-import-file-output' - }; + requestModelBuild = function (algo, parameters, go) { + return doPost('/2/ModelBuilders.json/' + algo, parameters, go); }; - _importViews = lodash.map(_importResults, function (_arg) { - var error, result; - error = _arg[0], result = _arg[1]; - if (error) { - return Flow.Failure(new Flow.Error('Error importing file', error)); + requestPredict = function (modelKey, frameKey, go) { + return doPost('/3/Predictions.json/models/' + encodeURIComponent(modelKey) + '/frames/' + encodeURIComponent(frameKey), {}, function (error, result) { + if (error) { + return go(error); + } else { + return go(null, lodash.head(result.model_metrics)); + } + }); + }; + requestPrediction = function (modelKey, frameKey, go) { + return doPost('/3/Predictions.json/models/' + encodeURIComponent(modelKey) + '/frames/' + encodeURIComponent(frameKey), {}, function (error, result) { + if (error) { + return go(error); + } else { + return go(null, lodash.head(result.model_metrics)); + } + }); + }; + requestPredictions = function (modelKey, frameKey, _go) { + var go; + go = function (error, result) { + var prediction, predictions; + if (error) { + return _go(error); + } else { + predictions = function () { + var _i, _len, _ref, _results; + _ref = result.model_metrics; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + prediction = _ref[_i]; + if (modelKey && prediction.model.key !== modelKey) { + _results.push(null); + } else if (frameKey && prediction.frame.key.name !== frameKey) { + _results.push(null); + } else { + _results.push(prediction); + } + } + return _results; + }(); + return _go(null, function () { + var _i, _len, _results; + _results = []; + for (_i = 0, _len = predictions.length; _i < _len; _i++) { + prediction = predictions[_i]; + if (prediction) { + _results.push(prediction); + } + } + return _results; + }()); + } + }; + if (modelKey && frameKey) { + return doPost('/3/Predictions.json/models/' + encodeURIComponent(modelKey) + '/frames/' + encodeURIComponent(frameKey), {}, go); + } else if (modelKey) { + return doGet('/3/ModelMetrics.json/models/' + encodeURIComponent(modelKey), go); + } else if (frameKey) { + return doGet('/3/ModelMetrics.json/frames/' + encodeURIComponent(frameKey), go); } else { - return createImportView(result); + return doGet('/3/ModelMetrics.json', go); } - }); - parse = function () { - var paths; - paths = lodash.map(_allKeys, Flow.Prelude.stringify); - return _.insertAndExecuteCell('cs', 'setupParse [ ' + paths.join(',') + ' ]'); }; - buildModel = function () { - return _.insertAndExecuteCell('cs', 'assist buildModel, null, training_frame: ' + Flow.Prelude.stringify(lodash.head(_allKeys))); + requestObjects = function (type, go) { + return go(null, Flow.LocalStorage.list(type)); }; - return { - title: _title, - importViews: _importViews, - canParse: _canParse, - parse: parse, - canBuildModel: _canBuildModel, - buildModel: buildModel, - template: 'flow-import-files-output', - templateOf: function (view) { - return view.template; - } + requestObject = function (type, id, go) { + return go(null, Flow.LocalStorage.read(type, id)); }; - }; -}.call(this)); -(function () { - H2O.InspectOutput = function (_, _table) { - var plot, view; - view = function () { - return _.insertAndExecuteCell('cs', 'grid inspect ' + Flow.Prelude.stringify(_table.label) + ', ' + _table.meta.origin); + requestDeleteObject = function (type, id, go) { + return go(null, Flow.LocalStorage.purge(type, id)); }; - plot = function () { - return _.insertAndExecuteCell('cs', _table.meta.plot); + requestPutObject = function (type, id, obj, go) { + return go(null, Flow.LocalStorage.write(type, id, obj)); }; - return { - label: _table.label, - variables: _table.variables, - view: view, - canPlot: _table.meta.plot ? true : false, - plot: plot, - template: 'flow-inspect-output' + requestCloud = function (go) { + return doGet('/3/Cloud.json', go); }; - }; -}.call(this)); -(function () { - H2O.InspectsOutput = function (_, _tables) { - var createTableView; - createTableView = function (table) { - var grid, inspect, plot; - inspect = function () { - return _.insertAndExecuteCell('cs', 'inspect ' + Flow.Prelude.stringify(table.label) + ', ' + table.meta.origin); - }; - grid = function () { - return _.insertAndExecuteCell('cs', 'grid inspect ' + Flow.Prelude.stringify(table.label) + ', ' + table.meta.origin); - }; - plot = function () { - return _.insertAndExecuteCell('cs', table.meta.plot); - }; - return { - label: table.label, - description: table.description, - variables: table.variables, - inspect: inspect, - grid: grid, - canPlot: table.meta.plot ? true : false, - plot: plot - }; + requestTimeline = function (go) { + return doGet('/3/Timeline.json', go); }; - return { - hasTables: _tables.length > 0, - tables: lodash.map(_tables, createTableView), - template: 'flow-inspects-output' + requestProfile = function (depth, go) { + return doGet('/3/Profiler.json?depth=' + depth, go); + }; + requestStackTrace = function (go) { + return doGet('/3/JStack.json', go); + }; + requestRemoveAll = function (go) { + return doGet('/3/RemoveAll.json', go); + }; + requestLogFile = function (nodeIndex, go) { + return doGet('/3/Logs.json/nodes/' + nodeIndex + '/files/default', go); + }; + requestAbout = function (go) { + return doGet('/3/About.json', go); }; + Flow.Dataflow.link(_.requestGet, doGet); + Flow.Dataflow.link(_.requestPost, doPost); + Flow.Dataflow.link(_.requestInspect, requestInspect); + Flow.Dataflow.link(_.requestCreateFrame, requestCreateFrame); + Flow.Dataflow.link(_.requestFrames, requestFrames); + Flow.Dataflow.link(_.requestFrame, requestFrame); + Flow.Dataflow.link(_.requestColumnSummary, requestColumnSummary); + Flow.Dataflow.link(_.requestJobs, requestJobs); + Flow.Dataflow.link(_.requestJob, requestJob); + Flow.Dataflow.link(_.requestFileGlob, requestFileGlob); + Flow.Dataflow.link(_.requestImportFiles, requestImportFiles); + Flow.Dataflow.link(_.requestImportFile, requestImportFile); + Flow.Dataflow.link(_.requestParseSetup, requestParseSetup); + Flow.Dataflow.link(_.requestParseFiles, requestParseFiles); + Flow.Dataflow.link(_.requestModels, requestModels); + Flow.Dataflow.link(_.requestModel, requestModel); + Flow.Dataflow.link(_.requestModelBuilder, requestModelBuilder); + Flow.Dataflow.link(_.requestModelBuilders, requestModelBuilders); + Flow.Dataflow.link(_.requestModelBuild, requestModelBuild); + Flow.Dataflow.link(_.requestModelInputValidation, requestModelInputValidation); + Flow.Dataflow.link(_.requestPredict, requestPredict); + Flow.Dataflow.link(_.requestPrediction, requestPrediction); + Flow.Dataflow.link(_.requestPredictions, requestPredictions); + Flow.Dataflow.link(_.requestObjects, requestObjects); + Flow.Dataflow.link(_.requestObject, requestObject); + Flow.Dataflow.link(_.requestDeleteObject, requestDeleteObject); + Flow.Dataflow.link(_.requestPutObject, requestPutObject); + Flow.Dataflow.link(_.requestCloud, requestCloud); + Flow.Dataflow.link(_.requestTimeline, requestTimeline); + Flow.Dataflow.link(_.requestProfile, requestProfile); + Flow.Dataflow.link(_.requestStackTrace, requestStackTrace); + Flow.Dataflow.link(_.requestRemoveAll, requestRemoveAll); + Flow.Dataflow.link(_.requestLogFile, requestLogFile); + return Flow.Dataflow.link(_.requestAbout, requestAbout); }; }.call(this)); (function () { - var getJobOutputStatusColor, getJobProgressPercent, jobOutputStatusColors; - jobOutputStatusColors = { - failed: '#d9534f', - done: '#ccc', - running: '#f0ad4e' - }; - getJobOutputStatusColor = function (status) { - switch (status) { - case 'DONE': - return jobOutputStatusColors.done; - case 'CREATED': - case 'RUNNING': - return jobOutputStatusColors.running; - default: - return jobOutputStatusColors.failed; + var computeFalsePositiveRate, computeTruePositiveRate, formatConfusionMatrix, formulateGetPredictionsOrigin, _assistance, __slice = [].slice; + _assistance = { + importFiles: { + description: 'Import file(s) into H2O', + icon: 'files-o' + }, + getFrames: { + description: 'Get a list of frames in H2O', + icon: 'database' + }, + getModels: { + description: 'Get a list of models in H2O', + icon: 'cubes' + }, + getPredictions: { + description: 'Get a list of predictions in H2O', + icon: 'bolt' + }, + getJobs: { + description: 'Get a list of jobs running in H2O', + icon: 'tasks' + }, + buildModel: { + description: 'Build a model', + icon: 'cube' + }, + predict: { + description: 'Make a prediction', + icon: 'bolt' } }; - getJobProgressPercent = function (progress) { - return '' + Math.ceil(100 * progress) + '%'; + computeTruePositiveRate = function (cm) { + var fn, fp, tn, tp, _ref, _ref1; + (_ref = cm[0], tn = _ref[0], fp = _ref[1]), (_ref1 = cm[1], fn = _ref1[0], tp = _ref1[1]); + return tp / (tp + fn); }; - H2O.JobOutput = function (_, _job) { - var initialize, isJobRunning, refresh, toggleRefresh, updateJob, view, _canView, _description, _destinationKey, _exception, _isBusy, _isLive, _key, _progress, _runTime, _status, _statusColor; - _isBusy = Flow.Dataflow.signal(false); - _isLive = Flow.Dataflow.signal(false); - _key = _job.key.name; - _description = _job.description; - _destinationKey = _job.dest.name; - _runTime = Flow.Dataflow.signal(null); - _progress = Flow.Dataflow.signal(null); - _status = Flow.Dataflow.signal(null); - _statusColor = Flow.Dataflow.signal(null); - _exception = Flow.Dataflow.signal(null); - _canView = Flow.Dataflow.signal(false); - isJobRunning = function (job) { - return job.status === 'CREATED' || job.status === 'RUNNING'; - }; - updateJob = function (job) { - _runTime(job.msec); - _progress(getJobProgressPercent(job.progress)); - _status(job.status); - _statusColor(getJobOutputStatusColor(job.status)); - _exception(job.exception ? Flow.Failure(new Flow.Error('Job failure.', new Error(job.exception))) : null); - return _canView(!isJobRunning(job)); - }; - toggleRefresh = function () { - return _isLive(!_isLive()); - }; - refresh = function () { - _isBusy(true); - return _.requestJob(_key, function (error, job) { - _isBusy(false); - if (error) { - _exception(Flow.Failure(new Flow.Error('Error fetching jobs', error))); - return _isLive(false); - } else { - updateJob(job); - if (isJobRunning(job)) { - if (_isLive()) { - return lodash.delay(refresh, 1000); - } - } else { - return toggleRefresh(); + computeFalsePositiveRate = function (cm) { + var fn, fp, tn, tp, _ref, _ref1; + (_ref = cm[0], tn = _ref[0], fp = _ref[1]), (_ref1 = cm[1], fn = _ref1[0], tp = _ref1[1]); + return fp / (fp + tn); + }; + formatConfusionMatrix = function (cm) { + var fn, fp, table, tbody, td, tn, tp, tr, _ref, _ref1, _ref2; + (_ref = cm[0], tn = _ref[0], fp = _ref[1]), (_ref1 = cm[1], fn = _ref1[0], tp = _ref1[1]); + _ref2 = Flow.HTML.template('table.flow-matrix', 'tbody', 'tr', '=td'), table = _ref2[0], tbody = _ref2[1], tr = _ref2[2], td = _ref2[3]; + return table([tbody([ + tr([ + td(tn), + td(fp) + ]), + tr([ + td(fn), + td(tp) + ]) + ])]); + }; + formulateGetPredictionsOrigin = function (opts) { + var frameKey, modelKey, opt, sanitizedOpt, sanitizedOpts; + if (lodash.isArray(opts)) { + sanitizedOpts = function () { + var _i, _len, _results; + _results = []; + for (_i = 0, _len = opts.length; _i < _len; _i++) { + opt = opts[_i]; + sanitizedOpt = {}; + if (opt.model) { + sanitizedOpt.model = opt.model; } - } - }); - }; - Flow.Dataflow.act(_isLive, function (isLive) { - if (isLive) { - return refresh(); - } - }); - view = function () { - if (!_canView()) { - return; - } - return _.requestInspect(_destinationKey, function (error, result) { - if (error) { - return _exception(Flow.Failure(new Flow.Error('Error inspecting job target.', error))); - } else { - switch (result.kind) { - case 'frame': - return _.insertAndExecuteCell('cs', 'getFrame ' + Flow.Prelude.stringify(_destinationKey)); - case 'model': - return _.insertAndExecuteCell('cs', 'getModel ' + Flow.Prelude.stringify(_destinationKey)); + if (opt.frame) { + sanitizedOpt.frame = opt.frame; } + _results.push(sanitizedOpt); } - }); - }; - initialize = function (job) { - updateJob(job); - if (isJobRunning(job)) { - return toggleRefresh(); + return _results; + }(); + return 'getPredictions ' + Flow.Prelude.stringify(sanitizedOpts); + } else { + modelKey = opts.model, frameKey = opts.frame; + if (modelKey && frameKey) { + return 'getPredictions model: ' + Flow.Prelude.stringify(modelKey) + ', frame: ' + Flow.Prelude.stringify(frameKey); + } else if (modelKey) { + return 'getPredictions model: ' + Flow.Prelude.stringify(modelKey); + } else if (frameKey) { + return 'getPredictions frame: ' + Flow.Prelude.stringify(frameKey); + } else { + return 'getPredictions()'; } - }; - initialize(_job); - return { - key: _key, - description: _description, - destinationKey: _destinationKey, - runTime: _runTime, - progress: _progress, - status: _status, - statusColor: _statusColor, - exception: _exception, - isLive: _isLive, - toggleRefresh: toggleRefresh, - canView: _canView, - view: view, - template: 'flow-job-output' - }; + } }; -}.call(this)); -(function () { - H2O.JobsOutput = function (_, jobs) { - var createJobView, initialize, refresh, toggleRefresh, _exception, _hasJobViews, _isBusy, _isLive, _jobViews; - _jobViews = Flow.Dataflow.signals([]); - _hasJobViews = Flow.Dataflow.lift(_jobViews, function (jobViews) { - return jobViews.length > 0; - }); - _isLive = Flow.Dataflow.signal(false); - _isBusy = Flow.Dataflow.signal(false); - _exception = Flow.Dataflow.signal(null); - createJobView = function (job) { - var view; - view = function () { - return _.insertAndExecuteCell('cs', 'getJob ' + Flow.Prelude.stringify(job.key.name)); - }; - return { - job: job, - view: view - }; + H2O.Routines = function (_) { + var assist, buildModel, createFrame, dump, dumpFuture, extendCloud, extendColumnSummary, extendDeepLearningModel, extendFrame, extendFrames, extendGBMModel, extendGLMModel, extendKMeansModel, extendLogFile, extendModel, extendModels, extendPrediction, extendPredictions, extendProfile, extendStackTrace, extendTimeline, f, flow_, form, getCloud, getColumnSummary, getFrame, getFrames, getJob, getJobs, getLogFile, getModel, getModels, getPrediction, getPredictions, getProfile, getStackTrace, getTimeline, grid, gui, importFiles, inspect, inspect$1, inspect$2, inspectBinomialMetrics, inspectBinomialPrediction, inspectBinomialPredictions, inspectBinomialScores, inspectFrameColumns, inspectFrameData, inspectGBMModelOutput, inspectKMeansModelClusterDetails, inspectKMeansModelClusters, inspectKMeansModelOutput, inspectModelParameters, inspectMultimodelParameters, inspectRegressionPrediction, inspect_, loadScript, name, parseRaw, plot, predict, proceed, read, render_, renderable, requestCloud, requestColumnSummary, requestCreateFrame, requestFrame, requestFrames, requestLogFile, requestModel, requestModels, requestModelsByKeys, requestPredict, requestPrediction, requestPredictions, requestPredicts, requestProfile, requestStackTrace, requestTimeline, setupParse, __plot, _apply, _async, _call, _fork, _get, _isFuture, _join, _plot, _plotInput, _ref; + _fork = function () { + var args, f; + f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + return Flow.Async.fork(f, args); }; - toggleRefresh = function () { - return _isLive(!_isLive()); + _join = function () { + var args, go, _i; + args = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), go = arguments[_i++]; + return Flow.Async.join(args, Flow.Async.applicate(go)); }; - refresh = function () { - _isBusy(true); - return _.requestJobs(function (error, jobs) { - _isBusy(false); - if (error) { - _exception(Flow.Failure(new Flow.Error('Error fetching jobs', error))); - return _isLive(false); - } else { - _jobViews(lodash.map(jobs, createJobView)); - if (_isLive()) { - return lodash.delay(refresh, 2000); - } - } + _call = function () { + var args, go; + go = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + return Flow.Async.join(args, Flow.Async.applicate(go)); + }; + _apply = function (go, args) { + return Flow.Async.join(args, go); + }; + _isFuture = Flow.Async.isFuture; + _async = Flow.Async.async; + _get = Flow.Async.get; + proceed = function (func, args, go) { + return go(null, render_({}, function () { + return func.apply(null, [_].concat(args || [])); + })); + }; + renderable = Flow.Async.renderable; + form = function (controls, go) { + return go(null, Flow.Dataflow.signals(controls || [])); + }; + gui = function (controls) { + return Flow.Async.renderable(form, controls, function (form, go) { + return go(null, Flow.Form(_, form)); }); }; - Flow.Dataflow.act(_isLive, function (isLive) { - if (isLive) { - return refresh(); - } - }); - initialize = function () { - return _jobViews(lodash.map(jobs, createJobView)); + _ref = Flow.Gui; + for (name in _ref) { + f = _ref[name]; + gui[name] = f; + } + flow_ = function (raw) { + return raw._flow_ || (raw._flow_ = { _cache_: {} }); }; - initialize(); - return { - jobViews: _jobViews, - hasJobViews: _hasJobViews, - isLive: _isLive, - isBusy: _isBusy, - toggleRefresh: toggleRefresh, - refresh: refresh, - exception: _exception, - template: 'flow-jobs-output' + render_ = function (raw, render) { + flow_(raw).render = render; + return raw; }; - }; -}.call(this)); -(function () { - H2O.LogFileOutput = function (_, _nodeIndex, _logFile) { - var createNode, initialize, _activeNode, _contents, _exception, _nodes; - _exception = Flow.Dataflow.signal(null); - _contents = Flow.Dataflow.signal(''); - _activeNode = Flow.Dataflow.signal(null); - _nodes = Flow.Dataflow.signal([]); - createNode = function (node, index) { - return { - name: node.h2o.node, - index: index - }; + inspect_ = function (raw, inspectors) { + var attr, root; + root = flow_(raw); + if (root.inspect == null) { + root.inspect = {}; + } + for (attr in inspectors) { + f = inspectors[attr]; + root.inspect[attr] = f; + } + return raw; }; - initialize = function (nodeIndex, logFile) { - _contents(logFile.log); - return _.requestCloud(function (error, cloud) { - var i, node, nodes; - if (!error) { - _nodes(nodes = function () { - var _i, _len, _ref, _results; - _ref = cloud.nodes; - _results = []; - for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { - node = _ref[i]; - _results.push(createNode(node, i)); - } - return _results; - }()); - if (nodeIndex < nodes.length) { - _activeNode(nodes[nodeIndex]); + inspect = function (a, b) { + if (arguments.length === 1) { + return inspect$1(a); + } else { + return inspect$2(a, b); + } + }; + inspect$1 = function (obj) { + var attr, inspections, inspectors, _ref1; + if (_isFuture(obj)) { + return _async(inspect, obj); + } else { + if (inspectors = obj != null ? (_ref1 = obj._flow_) != null ? _ref1.inspect : void 0 : void 0) { + inspections = []; + for (attr in inspectors) { + f = inspectors[attr]; + inspections.push(inspect$2(attr, obj)); } - return Flow.Dataflow.react(_activeNode, function (node) { - if (node) { - return _.requestLogFile(node.index, function (error, logFile) { - if (error) { - return _contents('Error fetching log file: ' + error.message); - } else { - return _contents(logFile.log); - } - }); - } else { - return _contents(''); - } + render_(inspections, function () { + return H2O.InspectsOutput(_, inspections); }); + return inspections; + } else { + return {}; } + } + }; + inspect$2 = function (attr, obj) { + var cached, inspection, inspectors, key, root; + if (!attr) { + return; + } + if (_isFuture(obj)) { + return _async(inspect, attr, obj); + } + if (!obj) { + return; + } + if (!(root = obj._flow_)) { + return; + } + if (!(inspectors = root.inspect)) { + return; + } + if (cached = root._cache_[key = 'inspect_' + attr]) { + return cached; + } + if (!(f = inspectors[attr])) { + return; + } + if (!lodash.isFunction(f)) { + return; + } + root._cache_[key] = inspection = f(); + render_(inspection, function () { + return H2O.InspectOutput(_, inspection); }); + return inspection; }; - initialize(_nodeIndex, _logFile); - return { - nodes: _nodes, - activeNode: _activeNode, - contents: _contents, - template: 'flow-log-file-output' + __plot = function (config, go) { + return Flow.Plot(config, function (error, plot) { + if (error) { + return go(new Flow.Error('Error rendering plot.', error)); + } else { + return go(null, plot); + } + }); }; - }; -}.call(this)); -(function () { - var createCheckboxControl, createControl, createControlFromParameter, createDropdownControl, createListControl, createTextboxControl; - createControl = function (kind, parameter) { - var _hasError, _hasInfo, _hasMessage, _hasWarning, _isVisible, _message; - _hasError = Flow.Dataflow.signal(false); - _hasWarning = Flow.Dataflow.signal(false); - _hasInfo = Flow.Dataflow.signal(false); - _message = Flow.Dataflow.signal(''); - _hasMessage = Flow.Dataflow.lift(_message, function (message) { - if (message) { - return true; + _plot = function (config, go) { + if (config.data) { + if (_isFuture(config.data)) { + return config.data(function (error, data) { + if (error) { + return go(new Flow.Error('Error evaluating data for plot().', error)); + } else { + config.data = data; + return __plot(config, go); + } + }); + } else { + return __plot(config, go); + } } else { - return false; + return go(new Flow.Error('Cannot plot(): missing \'data\'.')); } - }); - _isVisible = Flow.Dataflow.signal(true); - return { - kind: kind, - name: parameter.name, - label: parameter.label, - description: parameter.help, - isRequired: parameter.required, - hasError: _hasError, - hasWarning: _hasWarning, - hasInfo: _hasInfo, - message: _message, - hasMessage: _hasMessage, - isVisible: _isVisible - }; - }; - createTextboxControl = function (parameter) { - var control, _value; - _value = Flow.Dataflow.signal(parameter.actual_value); - control = createControl('textbox', parameter); - control.value = _value; - control.defaultValue = parameter.default_value; - return control; - }; - createDropdownControl = function (parameter) { - var control, _value; - _value = Flow.Dataflow.signal(parameter.actual_value); - control = createControl('dropdown', parameter); - control.values = Flow.Dataflow.signals(parameter.values); - control.value = _value; - control.defaultValue = parameter.default_value; - return control; - }; - createListControl = function (parameter) { - var control, createValueView, excludeAll, includeAll, view, _availableSearchTerm, _availableValues, _availableValuesCaption, _i, _len, _ref, _searchAvailable, _searchSelected, _selectedSearchTerm, _selectedValues, _selectedValuesCaption, _value, _values, _views; - _availableSearchTerm = Flow.Dataflow.signal(''); - _selectedSearchTerm = Flow.Dataflow.signal(''); - createValueView = function (value) { - var exclude, include, self, _canExclude, _canInclude, _isAvailable; - _isAvailable = Flow.Dataflow.signal(true); - _canInclude = Flow.Dataflow.signal(true); - _canExclude = Flow.Dataflow.signal(true); - include = function () { - self.isAvailable(false); - return _selectedValues.push(self); - }; - exclude = function () { - self.isAvailable(true); - return _selectedValues.remove(self); - }; - return self = { - value: value, - include: include, - exclude: exclude, - canInclude: _canInclude, - canExclude: _canExclude, - isAvailable: _isAvailable - }; }; - _values = Flow.Dataflow.signals(parameter.values); - _availableValues = Flow.Dataflow.lift(_values, function (vals) { - return lodash.map(vals, createValueView); - }); - _views = {}; - _ref = _availableValues(); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - view = _ref[_i]; - _views[view.value] = view; - } - _selectedValues = Flow.Dataflow.signals(lodash.map(parameter.actual_value, function (selectedValue) { - view = _views[selectedValue]; - view.isAvailable(false); - return view; - })); - _value = Flow.Dataflow.lift(_selectedValues, function (views) { - var _j, _len1, _results; - _results = []; - for (_j = 0, _len1 = views.length; _j < _len1; _j++) { - view = views[_j]; - _results.push(view.value); - } - return _results; - }); - _availableValuesCaption = Flow.Dataflow.signal('0 items hidden'); - _selectedValuesCaption = Flow.Dataflow.signal('0 items hidden'); - includeAll = function () { - var _j, _len1, _ref1; - _ref1 = _availableValues(); - for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { - view = _ref1[_j]; - if (view.canInclude() && view.isAvailable()) { - view.include(); + _plotInput = function (config, go) { + if (config.data) { + if (_isFuture(config.data)) { + return config.data(function (error, data) { + if (error) { + return go(new Flow.Error('Error evaluating data for plot().', error)); + } else { + config.data = data; + return go(null, config); + } + }); + } else { + return go(null, config); } + } else { + return go(new Flow.Error('Cannot plot(): missing \'data\'.')); } }; - excludeAll = function () { - var selectedValues, _j, _len1; - selectedValues = Flow.Prelude.copy(_selectedValues()); - for (_j = 0, _len1 = selectedValues.length; _j < _len1; _j++) { - view = selectedValues[_j]; - view.exclude(); + plot = function (config) { + var configKeys; + configKeys = lodash.keys(config); + if (configKeys.length === 1 && 'data' === lodash.head(configKeys)) { + return renderable(_plotInput, config, function (config, go) { + return go(null, H2O.PlotInput(_, config)); + }); + } else { + return renderable(_plot, config, function (plot, go) { + return go(null, H2O.PlotOutput(_, plot)); + }); } }; - _searchAvailable = function () { - var hiddenCount, term, _j, _len1, _ref1; - hiddenCount = 0; - _ref1 = _availableValues(); - for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { - view = _ref1[_j]; - term = _availableSearchTerm().trim(); - if (term === '' || 0 <= view.value.toLowerCase().indexOf(term.toLowerCase())) { - view.canInclude(true); - } else { - view.canInclude(false); - hiddenCount++; - } - } - _availableValuesCaption('' + hiddenCount + ' items hidden'); + plot.stack = Flow.Plot.stack; + grid = function (data) { + return plot({ + type: 'text', + data: data + }); }; - _searchSelected = function () { - var hiddenCount, term, _j, _len1, _ref1; - hiddenCount = 0; - _ref1 = _availableValues(); - for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { - view = _ref1[_j]; - term = _selectedSearchTerm().trim(); - if (term === '' || 0 <= view.value.toLowerCase().indexOf(term.toLowerCase())) { - view.canExclude(true); - } else { - view.canExclude(false); - if (!view.isAvailable()) { - hiddenCount++; + extendCloud = function (cloud) { + return render_(cloud, function () { + return H2O.CloudOutput(_, cloud); + }); + }; + extendTimeline = function (timeline) { + return render_(timeline, function () { + return H2O.TimelineOutput(_, timeline); + }); + }; + extendStackTrace = function (stackTrace) { + return render_(stackTrace, function () { + return H2O.StackTraceOutput(_, stackTrace); + }); + }; + extendLogFile = function (nodeIndex, logFile) { + return render_(logFile, function () { + return H2O.LogFileOutput(_, nodeIndex, logFile); + }); + }; + extendProfile = function (profile) { + return render_(profile, function () { + return H2O.ProfileOutput(_, profile); + }); + }; + extendFrames = function (frames) { + render_(frames, function () { + return H2O.FramesOutput(_, frames); + }); + return frames; + }; + inspectMultimodelParameters = function (models) { + return function () { + var Record, i, j, leader, model, modelKeys, parameter, parameters, row, rows, variable, variables, _i, _j, _len, _len1, _ref1; + leader = lodash.head(models); + parameters = leader.parameters; + variables = function () { + var _i, _len, _results; + _results = []; + for (_i = 0, _len = parameters.length; _i < _len; _i++) { + parameter = parameters[_i]; + switch (parameter.type) { + case 'enum': + case 'Frame': + case 'string': + case 'byte[]': + case 'short[]': + case 'int[]': + case 'long[]': + case 'float[]': + case 'double[]': + _results.push(Flow.Data.Variable(parameter.label, Flow.TString)); + break; + case 'byte': + case 'short': + case 'int': + case 'long': + case 'float': + case 'double': + _results.push(Flow.Data.Variable(parameter.label, Flow.TNumber)); + break; + case 'string[]': + _results.push(Flow.Data.Variable(parameter.label, Flow.TString)); + break; + case 'boolean': + _results.push(Flow.Data.Variable(parameter.label, Flow.TBoolean)); + break; + default: + _results.push(Flow.Data.Variable(parameter.label, Flow.TObject)); + } + } + return _results; + }(); + Record = Flow.Data.Record(variables); + rows = new Array(models.length); + for (i = _i = 0, _len = models.length; _i < _len; i = ++_i) { + model = models[i]; + rows[i] = row = new Record(); + _ref1 = model.parameters; + for (j = _j = 0, _len1 = _ref1.length; _j < _len1; j = ++_j) { + parameter = _ref1[j]; + variable = variables[j]; + row[variable.label] = parameter.actual_value; } } - } - _selectedValuesCaption('' + hiddenCount + ' items hidden'); + modelKeys = function () { + var _k, _len2, _results; + _results = []; + for (_k = 0, _len2 = models.length; _k < _len2; _k++) { + model = models[_k]; + _results.push(model.key); + } + return _results; + }(); + return Flow.Data.Table({ + label: 'parameters', + description: 'Parameters for models ' + modelKeys.join(', '), + variables: variables, + rows: rows, + meta: { origin: 'getModels ' + Flow.Prelude.stringify(modelKeys) } + }); + }; }; - Flow.Dataflow.react(_availableSearchTerm, lodash.throttle(_searchAvailable, 500)); - Flow.Dataflow.react(_selectedSearchTerm, lodash.throttle(_searchSelected, 500)); - Flow.Dataflow.react(_selectedValues, lodash.throttle(_searchSelected, 500)); - control = createControl('list', parameter); - control.values = _values; - control.availableValues = _availableValues; - control.selectedValues = _selectedValues; - control.value = _value; - control.availableSearchTerm = _availableSearchTerm; - control.selectedSearchTerm = _selectedSearchTerm; - control.availableValuesCaption = _availableValuesCaption; - control.selectedValuesCaption = _selectedValuesCaption; - control.defaultValue = parameter.default_value; - control.includeAll = includeAll; - control.excludeAll = excludeAll; - return control; - }; - createCheckboxControl = function (parameter) { - var control, _value; - _value = Flow.Dataflow.signal(parameter.actual_value === 'true'); - control = createControl('checkbox', parameter); - control.clientId = lodash.uniqueId(); - control.value = _value; - control.defaultValue = parameter.default_value === 'true'; - return control; - }; - createControlFromParameter = function (parameter) { - switch (parameter.type) { - case 'enum': - case 'Key': - case 'VecSpecifier': - return createDropdownControl(parameter); - case 'string[]': - return createListControl(parameter); - case 'boolean': - return createCheckboxControl(parameter); - case 'Key': - case 'byte': - case 'short': - case 'int': - case 'long': - case 'float': - case 'double': - case 'byte[]': - case 'short[]': - case 'int[]': - case 'long[]': - case 'float[]': - case 'double[]': - return createTextboxControl(parameter); - default: - console.error('Invalid field', JSON.stringify(parameter, null, 2)); - return null; - } - }; - H2O.ModelBuilderForm = function (_, _algorithm, _parameters) { - var collectParameters, createModel, criticalControls, expertControls, findControl, findFormField, parameterTemplateOf, performValidations, secondaryControls, _controlGroups, _exception, _form, _hasValidationFailures, _parametersByLevel, _validationFailureMessage; - _exception = Flow.Dataflow.signal(null); - _validationFailureMessage = Flow.Dataflow.signal(''); - _hasValidationFailures = Flow.Dataflow.lift(_validationFailureMessage, Flow.Prelude.isTruthy); - _parametersByLevel = lodash.groupBy(_parameters, function (parameter) { - return parameter.level; - }); - _controlGroups = lodash.map([ - 'critical', - 'secondary', - 'expert' - ], function (type) { - return lodash.filter(lodash.map(_parametersByLevel[type], createControlFromParameter), function (a) { - if (a) { - return true; - } else { - return false; + inspectModelParameters = function (model) { + return function () { + var Record, i, parameter, parameters, row, rows, variable, variables, _i, _j, _len, _len1; + parameters = model.parameters; + variables = [ + Flow.Data.Variable('label', Flow.TString), + Flow.Data.Variable('type', Flow.TString), + Flow.Data.Variable('level', Flow.TString), + Flow.Data.Variable('actual_value', Flow.TObject), + Flow.Data.Variable('default_value', Flow.TObject) + ]; + Record = Flow.Data.Record(variables); + rows = new Array(parameters.length); + for (i = _i = 0, _len = parameters.length; _i < _len; i = ++_i) { + parameter = parameters[i]; + rows[i] = row = new Record(); + for (_j = 0, _len1 = variables.length; _j < _len1; _j++) { + variable = variables[_j]; + row[variable.label] = parameter[variable.label]; + } } - }); - }); - criticalControls = _controlGroups[0], secondaryControls = _controlGroups[1], expertControls = _controlGroups[2]; - _form = lodash.flatten([ - { - kind: 'group', - title: 'Parameters' - }, - criticalControls, - { - kind: 'group', - title: 'Advanced' - }, - secondaryControls, - { - kind: 'group', - title: 'Expert' - }, - expertControls - ]); - findControl = function (name) { - var control, controls, _i, _j, _len, _len1; - for (_i = 0, _len = _controlGroups.length; _i < _len; _i++) { - controls = _controlGroups[_i]; - for (_j = 0, _len1 = controls.length; _j < _len1; _j++) { - control = controls[_j]; - if (control.name === name) { - return control; + return Flow.Data.Table({ + label: 'parameters', + description: 'Parameters for model \'' + model.key.name + '\'', + variables: variables, + rows: rows, + meta: { origin: 'getModel ' + Flow.Prelude.stringify(model.key.name) } + }); + }; + }; + inspectGBMModelOutput = function (model) { + return function () { + var Record, i, mse_train, output, rows, variables, _i, _len, _ref1; + output = model.output; + variables = [ + Flow.Data.Variable('tree', Flow.TNumber), + Flow.Data.Variable('mse_train', Flow.TObject), + Flow.Data.Variable('mse_valid', Flow.TObject) + ]; + Record = Flow.Data.Record(variables); + rows = new Array(output.mse_train.length); + _ref1 = output.mse_train; + for (i = _i = 0, _len = _ref1.length; _i < _len; i = ++_i) { + mse_train = _ref1[i]; + rows[i] = new Record(i, mse_train, output.mse_valid[i]); + } + return Flow.Data.Table({ + label: 'output', + description: 'Output for GBM model \'' + model.key.name + '\'', + variables: variables, + rows: rows, + meta: { origin: 'getModel ' + Flow.Prelude.stringify(model.key.name) } + }); + }; + }; + inspectKMeansModelOutput = function (model) { + return function () { + var Record, attr, attrs, i, output, rows, variables, _i, _len; + output = model.output; + variables = [ + Flow.Data.Variable('parameter', Flow.TString), + Flow.Data.Variable('value', Flow.TObject) + ]; + Record = Flow.Data.Record(variables); + attrs = [ + 'iters', + 'mse', + 'ncats' + ]; + rows = new Array(attrs.length); + for (i = _i = 0, _len = attrs.length; _i < _len; i = ++_i) { + attr = attrs[i]; + rows[i] = new Record(attr, output[attr]); + } + return Flow.Data.Table({ + label: 'output', + description: 'Output for k-means model \'' + model.key.name + '\'', + variables: variables, + rows: rows, + meta: { origin: 'getModel ' + Flow.Prelude.stringify(model.key.name) } + }); + }; + }; + inspectKMeansModelClusterDetails = function (model) { + return function () { + var Record, cluster, i, output, rows, variables, _i, _len, _ref1; + output = model.output; + variables = [ + Flow.Data.Variable('cluster', Flow.TNumber), + Flow.Data.Variable('rows', Flow.TNumber), + Flow.Data.Variable('mses', Flow.TNumber) + ]; + Record = Flow.Data.Record(variables); + rows = new Array(output.clusters.length); + _ref1 = output.clusters; + for (i = _i = 0, _len = _ref1.length; _i < _len; i = ++_i) { + cluster = _ref1[i]; + rows[i] = new Record(i, output.rows[i], output.mses[i]); + } + return Flow.Data.Table({ + label: 'cluster_details', + description: 'Clusters for k-means model \'' + model.key.name + '\'', + variables: variables, + rows: rows, + meta: { origin: 'getModel ' + Flow.Prelude.stringify(model.key.name) } + }); + }; + }; + inspectKMeansModelClusters = function (model) { + return function () { + var Record, cluster, cluster0, clusters, domain, domains, i, j, names, output, row, rows, variables, _i, _j, _k, _len, _ref1, _ref2; + output = model.output; + clusters = output.clusters, domains = output.domains, names = output.names; + variables = [Flow.Data.Variable('names', Flow.TNumber)]; + for (i = _i = 0, _ref1 = clusters.length; 0 <= _ref1 ? _i < _ref1 : _i > _ref1; i = 0 <= _ref1 ? ++_i : --_i) { + variables.push(Flow.Data.Variable('' + i, Flow.TObject)); + } + Record = Flow.Data.Record(variables); + cluster0 = lodash.head(clusters); + rows = new Array(cluster0.length); + for (i = _j = 0, _ref2 = cluster0.length; 0 <= _ref2 ? _j < _ref2 : _j > _ref2; i = 0 <= _ref2 ? ++_j : --_j) { + rows[i] = row = new Record(names[i]); + for (j = _k = 0, _len = clusters.length; _k < _len; j = ++_k) { + cluster = clusters[j]; + row['' + j] = (domain = domains[i]) ? domain[cluster[i]] : cluster[i]; } } - } + return Flow.Data.Table({ + label: 'clusters', + description: 'Clusters for k-means model \'' + model.key.name + '\'', + variables: variables, + rows: rows, + meta: { origin: 'getModel ' + Flow.Prelude.stringify(model.key.name) } + }); + }; }; - parameterTemplateOf = function (control) { - return 'flow-' + control.kind + '-model-parameter'; + extendKMeansModel = function (model) { + return inspect_(model, { + parameters: inspectModelParameters(model), + output: inspectKMeansModelOutput(model), + clusters: inspectKMeansModelClusters(model), + cluster_details: inspectKMeansModelClusterDetails(model) + }); }; - findFormField = function (name) { - return lodash.find(_form, function (field) { - return field.name === name; + extendDeepLearningModel = function (model) { + return inspect_(model, { parameters: inspectModelParameters(model) }); + }; + extendGBMModel = function (model) { + return inspect_(model, { + parameters: inspectModelParameters(model), + output: inspectGBMModelOutput(model) }); }; - (function () { - var ignoredColumnsParameter, responseColumnParameter, trainingFrameParameter, validationFrameParameter, _ref; - _ref = lodash.map([ - 'training_frame', - 'validation_frame', - 'response_column', - 'ignored_columns' - ], findFormField), trainingFrameParameter = _ref[0], validationFrameParameter = _ref[1], responseColumnParameter = _ref[2], ignoredColumnsParameter = _ref[3]; - if (trainingFrameParameter) { - if (responseColumnParameter || ignoredColumnsParameter) { - return Flow.Dataflow.act(trainingFrameParameter.value, function (frameKey) { - if (frameKey) { - _.requestFrame(frameKey, function (error, frame) { - var columnLabels; - if (!error) { - columnLabels = lodash.map(frame.columns, function (column) { - return column.label; - }); - if (responseColumnParameter) { - responseColumnParameter.values(columnLabels); - } - if (ignoredColumnsParameter) { - return ignoredColumnsParameter.values(columnLabels); - } - } - }); - } - }); - } - } - }()); - collectParameters = function (includeUnchangedParameters) { - var control, controls, parameters, value, _i, _j, _len, _len1; - if (includeUnchangedParameters == null) { - includeUnchangedParameters = false; - } - parameters = {}; - for (_i = 0, _len = _controlGroups.length; _i < _len; _i++) { - controls = _controlGroups[_i]; - for (_j = 0, _len1 = controls.length; _j < _len1; _j++) { - control = controls[_j]; - value = control.value(); - if (includeUnchangedParameters || control.isRequired || control.defaultValue !== value) { - switch (control.kind) { - case 'dropdown': - if (value) { - parameters[control.name] = value; - } - break; - case 'list': - if (value.length) { - parameters[control.name] = '[' + value.join(',') + ']'; - } - break; - default: - parameters[control.name] = value; - } - } - } - } - return parameters; + extendGLMModel = function (model) { + return inspect_(model, { parameters: inspectModelParameters(model) }); }; - performValidations = function (checkForErrors, go) { - var parameters, responseColumnParameter, trainingFrameParameter; - _exception(null); - parameters = collectParameters(true); - trainingFrameParameter = findFormField('training_frame'); - responseColumnParameter = findFormField('response_column'); - if (trainingFrameParameter && !parameters.training_frame) { - return _validationFailureMessage('Please specify a training frame.'); - } - if (responseColumnParameter && !parameters.response_column) { - return _validationFailureMessage('Please specify a response column.'); + extendModel = function (model) { + switch (model.algo) { + case 'kmeans': + extendKMeansModel(model); + break; + case 'deeplearning': + extendDeepLearningModel(model); + break; + case 'gbm': + extendGBMModel(model); + break; + case 'glm': + extendGLMModel(model); } - _validationFailureMessage(''); - return go(); - return _.requestModelInputValidation(_algorithm, parameters, function (error, modelBuilder) { - var control, hasErrors, validation, _i, _len, _ref; - if (error) { - return _exception(Flow.Failure(new Flow.Error('Error fetching initial model builder state', error))); - } else { - hasErrors = false; - _ref = modelBuilder.validation_messages; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - validation = _ref[_i]; - control = findControl(validation.field_name); - if (control) { - if (validation.message_type === 'HIDE') { - control.isVisible(false); - } else if (!checkForErrors) { - switch (validation.message_type) { - case 'INFO': - control.isVisible(true); - control.message(validation.message); - break; - case 'WARN': - control.isVisible(true); - control.message(validation.message); - break; - case 'ERROR': - control.isVisible(true); - control.hasError(true); - control.message(validation.message); - hasErrors = true; - } - } - } - } - if (!hasErrors) { - return go(); - } - } - }); - }; - createModel = function () { - _exception(null); - return performValidations(false, function () { - var parameters; - parameters = collectParameters(false); - return _.insertAndExecuteCell('cs', 'buildModel \'' + _algorithm + '\', ' + Flow.Prelude.stringify(parameters)); + return render_(model, function () { + return H2O.ModelOutput(_, model); }); }; - return { - form: _form, - exception: _exception, - parameterTemplateOf: parameterTemplateOf, - createModel: createModel, - hasValidationFailures: _hasValidationFailures, - validationFailureMessage: _validationFailureMessage - }; - }; - H2O.ModelInput = function (_, _algo, _opts) { - var createModel, populateFramesAndColumns, _algorithm, _algorithms, _canCreateModel, _exception, _modelForm; - _exception = Flow.Dataflow.signal(null); - _algorithms = Flow.Dataflow.signal([]); - _algorithm = Flow.Dataflow.signal(_algo); - _canCreateModel = Flow.Dataflow.lift(_algorithm, function (algorithm) { - if (algorithm) { - return true; - } else { - return false; - } - }); - _modelForm = Flow.Dataflow.signal(null); - populateFramesAndColumns = function (frameKey, algorithm, parameters, go) { - var classificationParameter; - classificationParameter = lodash.find(parameters, function (parameter) { - return parameter.name === 'do_classification'; - }); - if (classificationParameter) { - classificationParameter.actual_value = 'true'; + extendModels = function (models) { + var algos, model, _i, _len; + for (_i = 0, _len = models.length; _i < _len; _i++) { + model = models[_i]; + extendModel(model); } - return _.requestFrames(function (error, frames) { - var frame, frameKeys, frameParameters, parameter, _i, _len; - if (error) { - } else { - frameKeys = function () { - var _i, _len, _results; - _results = []; - for (_i = 0, _len = frames.length; _i < _len; _i++) { - frame = frames[_i]; - _results.push(frame.key.name); - } - return _results; - }(); - frameParameters = lodash.filter(parameters, function (parameter) { - return parameter.type === 'Key'; - }); - for (_i = 0, _len = frameParameters.length; _i < _len; _i++) { - parameter = frameParameters[_i]; - parameter.values = frameKeys; - if (parameter.name === 'training_frame') { - if (frameKey) { - parameter.actual_value = frameKey; - } else { - frameKey = parameter.actual_value; - } - } - } - return go(); + algos = lodash.unique(function () { + var _j, _len1, _results; + _results = []; + for (_j = 0, _len1 = models.length; _j < _len1; _j++) { + model = models[_j]; + _results.push(model.algo); } + return _results; + }()); + if (algos.length === 1) { + inspect_(models, { parameters: inspectMultimodelParameters(models) }); + } + return render_(models, function () { + return H2O.ModelsOutput(_, models); }); }; - (function () { - return _.requestModelBuilders(function (error, result) { - var frameKey, key, modelBuilders; - modelBuilders = error ? [] : result.model_builders; - _algorithms(function () { - var _i, _len, _ref, _results; - _ref = lodash.keys(modelBuilders); - _results = []; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - key = _ref[_i]; - if (key !== 'example') { - _results.push(key); - } - } - return _results; - }()); - frameKey = _opts != null ? _opts.training_frame : void 0; - return Flow.Dataflow.act(_algorithm, function (algorithm) { - if (algorithm) { - return _.requestModelBuilder(algorithm, function (error, result) { - var parameters; - if (error) { - return _exception(Flow.Failure(new Flow.Error('Error fetching model builder', error))); - } else { - parameters = result.model_builders[algorithm].parameters; - return populateFramesAndColumns(frameKey, algorithm, parameters, function () { - return _modelForm(H2O.ModelBuilderForm(_, algorithm, parameters)); - }); - } - }); - } else { - return _modelForm(null); - } - }); - }); - }()); - createModel = function () { - return _modelForm().createModel(); - }; - return { - parentException: _exception, - algorithms: _algorithms, - algorithm: _algorithm, - modelForm: _modelForm, - canCreateModel: _canCreateModel, - createModel: createModel, - template: 'flow-model-input' + read = function (value) { + if (value === 'NaN') { + return null; + } else { + return value; + } }; - }; -}.call(this)); -(function () { - H2O.ModelOutput = function (_, _model) { - var cloneModel, inspect, predict, toggle, _inputParameters, _isExpanded; - _isExpanded = Flow.Dataflow.signal(false); - _inputParameters = lodash.map(_model.parameters, function (parameter) { - var actual_value, default_value, help, label, type, value; - type = parameter.type, default_value = parameter.default_value, actual_value = parameter.actual_value, label = parameter.label, help = parameter.help; - value = function () { - switch (type) { - case 'Key': - case 'Key': - if (actual_value) { - return actual_value.name; - } else { - return null; - } - break; - case 'VecSpecifier': - if (actual_value) { - return actual_value.column_name; - } else { - return null; - } - break; - default: - return actual_value; - } - }(); - return { - label: label, - value: value, - help: help, - isModified: default_value === actual_value + inspectRegressionPrediction = function (prediction) { + return function () { + var Record, frame, model, predictions, rows, variables; + frame = prediction.frame, model = prediction.model, predictions = prediction.predictions; + variables = [ + Flow.Data.Variable('parameter', Flow.TString), + Flow.Data.Variable('value', Flow.TObject) + ]; + Record = Flow.Data.Record(variables); + rows = []; + rows.push(new Record('key', model.name)); + rows.push(new Record('frame', frame.name)); + rows.push(new Record('model_category', prediction.model_category)); + rows.push(new Record('duration_in_ms', prediction.duration_in_ms)); + rows.push(new Record('scoring_time', prediction.scoring_time)); + return Flow.Data.Table({ + label: 'prediction', + description: 'Prediction output for model \'' + model.name + '\' on frame \'' + frame.name + '\'', + variables: variables, + rows: rows, + meta: { origin: 'getPrediction ' + Flow.Prelude.stringify(model.name) + ', ' + Flow.Prelude.stringify(frame.name) } + }); }; - }); - toggle = function () { - return _isExpanded(!_isExpanded()); - }; - cloneModel = function () { - return alert('Not implemented'); - }; - predict = function () { - return _.insertAndExecuteCell('cs', 'predict ' + Flow.Prelude.stringify(_model.key.name)); - }; - inspect = function () { - return _.insertAndExecuteCell('cs', 'inspect getModel ' + Flow.Prelude.stringify(_model.key.name)); }; - return { - key: _model.key, - algo: _model.algo, - inputParameters: _inputParameters, - isExpanded: _isExpanded, - toggle: toggle, - cloneModel: cloneModel, - predict: predict, - inspect: inspect, - template: 'flow-model-output' + inspectBinomialPrediction = function (prediction) { + return function () { + var Record, auc, frame, model, rows, variables; + frame = prediction.frame, model = prediction.model, auc = prediction.auc; + variables = [ + Flow.Data.Variable('parameter', Flow.TString), + Flow.Data.Variable('value', Flow.TObject) + ]; + Record = Flow.Data.Record(variables); + rows = []; + rows.push(new Record('key', model.name)); + rows.push(new Record('frame', frame.name)); + rows.push(new Record('model_category', prediction.model_category)); + rows.push(new Record('duration_in_ms', prediction.duration_in_ms)); + rows.push(new Record('scoring_time', prediction.scoring_time)); + rows.push(new Record('AUC', auc.AUC)); + rows.push(new Record('Gini', auc.Gini)); + rows.push(new Record('threshold_criterion', auc.threshold_criterion)); + return Flow.Data.Table({ + label: 'prediction', + description: 'Prediction output for model \'' + model.name + '\' on frame \'' + frame.name + '\'', + variables: variables, + rows: rows, + meta: { origin: 'getPrediction ' + Flow.Prelude.stringify(model.name) + ', ' + Flow.Prelude.stringify(frame.name) } + }); + }; }; - }; -}.call(this)); -(function () { - H2O.ModelsOutput = function (_, _models) { - var buildModel, compareModels, createModelView, getSelectedModelKeys, initialize, inspectAll, predictUsingModels, _canCompareModels, _checkAllModels, _isCheckingAll, _modelViews; - _modelViews = Flow.Dataflow.signal([]); - _checkAllModels = Flow.Dataflow.signal(false); - _canCompareModels = Flow.Dataflow.signal(false); - _isCheckingAll = false; - Flow.Dataflow.react(_checkAllModels, function (checkAll) { - var view, _i, _len, _ref; - _isCheckingAll = true; - _ref = _modelViews(); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - view = _ref[_i]; - view.isChecked(checkAll); - } - _canCompareModels(checkAll); - _isCheckingAll = false; - }); - createModelView = function (model) { - var cloneModel, inspect, predict, view, _isChecked; - _isChecked = Flow.Dataflow.signal(false); - Flow.Dataflow.react(_isChecked, function () { - var checkedViews, view; - if (_isCheckingAll) { - return; + inspectBinomialMetrics = function (opts, predictions) { + return function () { + var Record, auc, cm, frame, i, model, prediction, rows, variables, _i, _j, _len, _ref1; + variables = [ + Flow.Data.Variable('criteria', Flow.TString), + Flow.Data.Variable('threshold', Flow.TNumber), + Flow.Data.Variable('F1', Flow.TNumber), + Flow.Data.Variable('F2', Flow.TNumber), + Flow.Data.Variable('F0point5', Flow.TNumber), + Flow.Data.Variable('accuracy', Flow.TNumber), + Flow.Data.Variable('error', Flow.TNumber), + Flow.Data.Variable('precision', Flow.TNumber), + Flow.Data.Variable('recall', Flow.TNumber), + Flow.Data.Variable('specificity', Flow.TNumber), + Flow.Data.Variable('mcc', Flow.TNumber), + Flow.Data.Variable('max_per_class_error', Flow.TNumber), + Flow.Data.Variable('confusion_matrix', Flow.TObject, null, formatConfusionMatrix), + Flow.Data.Variable('TPR', Flow.TNumber), + Flow.Data.Variable('FPR', Flow.TNumber), + Flow.Data.Variable('key', Flow.TString), + Flow.Data.Variable('model', Flow.TString), + Flow.Data.Variable('frame', Flow.TString) + ]; + Record = Flow.Data.Record(variables); + rows = []; + for (_i = 0, _len = predictions.length; _i < _len; _i++) { + prediction = predictions[_i]; + frame = prediction.frame, model = prediction.model, auc = prediction.auc; + for (i = _j = 0, _ref1 = auc.threshold_criteria.length; 0 <= _ref1 ? _j < _ref1 : _j > _ref1; i = 0 <= _ref1 ? ++_j : --_j) { + rows.push(new Record(auc.threshold_criteria[i], read(auc.threshold_for_criteria[i]), read(auc.F1_for_criteria[i]), read(auc.F2_for_criteria[i]), read(auc.F0point5_for_criteria[i]), read(auc.accuracy_for_criteria[i]), read(auc.error_for_criteria[i]), read(auc.precision_for_criteria[i]), read(auc.recall_for_criteria[i]), read(auc.specificity_for_criteria[i]), read(auc.mcc_for_criteria[i]), read(auc.max_per_class_error_for_criteria[i]), cm = auc.confusion_matrix_for_criteria[i], computeTruePositiveRate(cm), computeFalsePositiveRate(cm), model.name + ' on ' + frame.name, model.name, frame.name)); + } } - checkedViews = function () { - var _i, _len, _ref, _results; - _ref = _modelViews(); - _results = []; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - view = _ref[_i]; - if (view.isChecked()) { - _results.push(view); - } + return Flow.Data.Table({ + label: 'metrics', + description: 'Metrics for the selected predictions', + variables: variables, + rows: rows, + meta: { + origin: formulateGetPredictionsOrigin(opts), + plot: 'plot\n data: inspect \'metrics\', ' + formulateGetPredictionsOrigin(opts) } - return _results; - }(); - return _canCompareModels(checkedViews.length > 1); - }); - predict = function () { - return _.insertAndExecuteCell('cs', 'predict ' + Flow.Prelude.stringify(model.key.name)); - }; - cloneModel = function () { - return alert('Not implemented'); - return _.insertAndExecuteCell('cs', 'cloneModel ' + Flow.Prelude.stringify(model.key.name)); - }; - view = function () { - return _.insertAndExecuteCell('cs', 'getModel ' + Flow.Prelude.stringify(model.key.name)); - }; - inspect = function () { - return _.insertAndExecuteCell('cs', 'inspect getModel ' + Flow.Prelude.stringify(model.key.name)); - }; - return { - key: model.key.name, - algo: model.algo, - isChecked: _isChecked, - predict: predict, - clone: cloneModel, - inspect: inspect, - view: view + }); }; }; - buildModel = function () { - return _.insertAndExecuteCell('cs', 'buildModel'); - }; - getSelectedModelKeys = function () { - var view, _i, _len, _ref, _results; - _ref = _modelViews(); - _results = []; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - view = _ref[_i]; - if (view.isChecked()) { - _results.push(view.key); + inspectBinomialPredictions = function (opts, predictions) { + return function () { + var Record, auc, frame, i, model, prediction, row, rows, variables, _i, _len; + variables = [ + Flow.Data.Variable('key', Flow.TString), + Flow.Data.Variable('model', Flow.TString), + Flow.Data.Variable('frame', Flow.TString), + Flow.Data.Variable('model_category', Flow.TString), + Flow.Data.Variable('duration_in_ms', Flow.TNumber), + Flow.Data.Variable('scoring_time', Flow.TNumber) + ]; + Record = Flow.Data.Record(variables); + rows = new Array(predictions.length); + for (i = _i = 0, _len = predictions.length; _i < _len; i = ++_i) { + prediction = predictions[i]; + frame = prediction.frame, model = prediction.model, auc = prediction.auc; + rows[i] = row = new Record(model.name + ' on ' + frame.name, model.name, frame.name, prediction.model_category, prediction.duration_in_ms, prediction.scoring_time); } - } - return _results; - }; - compareModels = function () { - return _.insertAndExecuteCell('cs', 'inspect getModels ' + Flow.Prelude.stringify(getSelectedModelKeys())); + return Flow.Data.Table({ + label: 'predictions', + description: 'Prediction output for selected predictions.', + variables: variables, + rows: rows, + meta: { + origin: formulateGetPredictionsOrigin(opts), + plot: 'plot\n data: inspect \'predictions\', ' + formulateGetPredictionsOrigin(opts) + } + }); + }; }; - predictUsingModels = function () { - return _.insertAndExecuteCell('cs', 'predict ' + Flow.Prelude.stringify(getSelectedModelKeys())); + extendPredictions = function (opts, predictions) { + render_(predictions, function () { + return H2O.PredictsOutput(_, opts, predictions); + }); + return inspect_(predictions, { predictions: inspectBinomialPredictions(opts, predictions) }); }; - inspectAll = function () { - var allKeys, view; - allKeys = function () { - var _i, _len, _ref, _results; - _ref = _modelViews(); - _results = []; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - view = _ref[_i]; - _results.push(view.key); + inspectBinomialScores = function (opts, predictions) { + return function () { + var Record, auc, cm, frame, i, model, prediction, rows, variables, _i, _j, _len, _ref1; + variables = [ + Flow.Data.Variable('thresholds', Flow.TNumber), + Flow.Data.Variable('F1', Flow.TNumber), + Flow.Data.Variable('F2', Flow.TNumber), + Flow.Data.Variable('F0point5', Flow.TNumber), + Flow.Data.Variable('accuracy', Flow.TNumber), + Flow.Data.Variable('errorr', Flow.TNumber), + Flow.Data.Variable('precision', Flow.TNumber), + Flow.Data.Variable('recall', Flow.TNumber), + Flow.Data.Variable('specificity', Flow.TNumber), + Flow.Data.Variable('mcc', Flow.TNumber), + Flow.Data.Variable('max_per_class_error', Flow.TNumber), + Flow.Data.Variable('confusion_matrices', Flow.TObject, null, formatConfusionMatrix), + Flow.Data.Variable('TPR', Flow.TNumber), + Flow.Data.Variable('FPR', Flow.TNumber), + Flow.Data.Variable('key', Flow.TString), + Flow.Data.Variable('model', Flow.TString), + Flow.Data.Variable('frame', Flow.TString) + ]; + Record = Flow.Data.Record(variables); + rows = []; + for (_i = 0, _len = predictions.length; _i < _len; _i++) { + prediction = predictions[_i]; + frame = prediction.frame, model = prediction.model, auc = prediction.auc; + for (i = _j = 0, _ref1 = auc.thresholds.length; 0 <= _ref1 ? _j < _ref1 : _j > _ref1; i = 0 <= _ref1 ? ++_j : --_j) { + rows.push(new Record(read(auc.thresholds[i]), read(auc.F1[i]), read(auc.F2[i]), read(auc.F0point5[i]), read(auc.accuracy[i]), read(auc.errorr[i]), read(auc.precision[i]), read(auc.recall[i]), read(auc.specificity[i]), read(auc.mcc[i]), read(auc.max_per_class_error[i]), cm = auc.confusion_matrices[i], computeTruePositiveRate(cm), computeFalsePositiveRate(cm), model.name + ' on ' + frame.name, model.name, frame.name)); + } } - return _results; - }(); - return _.insertAndExecuteCell('cs', 'inspect getModels ' + Flow.Prelude.stringify(allKeys)); - }; - initialize = function (models) { - return _modelViews(lodash.map(models, createModelView)); - }; - initialize(_models); - return { - modelViews: _modelViews, - hasModels: _models.length > 0, - buildModel: buildModel, - compareModels: compareModels, - predictUsingModels: predictUsingModels, - canCompareModels: _canCompareModels, - checkAllModels: _checkAllModels, - inspect: inspectAll, - template: 'flow-models-output' - }; - }; -}.call(this)); -(function () { - H2O.NoAssist = function (_) { - return { - showAssist: function () { - return _.insertAndExecuteCell('cs', 'assist'); - }, - template: 'flow-no-assist' - }; - }; -}.call(this)); -(function () { - var parseDelimiters, parserTypes; - parserTypes = lodash.map([ - 'AUTO', - 'XLS', - 'CSV', - 'SVMLight' - ], function (type) { - return { - type: type, - caption: type - }; - }); - parseDelimiters = function () { - var characterDelimiters, createDelimiter, otherDelimiters, whitespaceDelimiters, whitespaceSeparators; - whitespaceSeparators = [ - 'NULL', - 'SOH (start of heading)', - 'STX (start of text)', - 'ETX (end of text)', - 'EOT (end of transmission)', - 'ENQ (enquiry)', - 'ACK (acknowledge)', - 'BEL \'\\a\' (bell)', - 'BS \'\\b\' (backspace)', - 'HT \'\\t\' (horizontal tab)', - 'LF \'\\n\' (new line)', - 'VT \'\\v\' (vertical tab)', - 'FF \'\\f\' (form feed)', - 'CR \'\\r\' (carriage ret)', - 'SO (shift out)', - 'SI (shift in)', - 'DLE (data link escape)', - 'DC1 (device control 1) ', - 'DC2 (device control 2)', - 'DC3 (device control 3)', - 'DC4 (device control 4)', - 'NAK (negative ack.)', - 'SYN (synchronous idle)', - 'ETB (end of trans. blk)', - 'CAN (cancel)', - 'EM (end of medium)', - 'SUB (substitute)', - 'ESC (escape)', - 'FS (file separator)', - 'GS (group separator)', - 'RS (record separator)', - 'US (unit separator)', - '\' \' SPACE' - ]; - createDelimiter = function (caption, charCode) { - return { - charCode: charCode, - caption: '' + caption + ': \'' + ('00' + charCode).slice(-2) + '\'' + return Flow.Data.Table({ + label: 'scores', + description: 'Scores for the selected predictions', + variables: variables, + rows: rows, + meta: { + origin: formulateGetPredictionsOrigin(opts), + plot: 'plot\n data: inspect \'scores\', ' + formulateGetPredictionsOrigin(opts) + } + }); }; }; - whitespaceDelimiters = lodash.map(whitespaceSeparators, createDelimiter); - characterDelimiters = lodash.times(126 - whitespaceSeparators.length, function (i) { - var charCode; - charCode = i + whitespaceSeparators.length; - return createDelimiter(String.fromCharCode(charCode), charCode); - }); - otherDelimiters = [{ - charCode: -1, - caption: 'AUTO' - }]; - return whitespaceDelimiters.concat(characterDelimiters, otherDelimiters); - }(); - H2O.SetupParseOutput = function (_, _result) { - var parseFiles, _columnCount, _columns, _deleteOnDone, _delimiter, _destinationKey, _hasColumns, _headerOption, _headerOptions, _parserType, _rows, _sourceKeys, _useSingleQuotes; - _sourceKeys = lodash.map(_result.srcs, function (src) { - return src.name; - }); - _parserType = Flow.Dataflow.signal(lodash.find(parserTypes, function (parserType) { - return parserType.type === _result.pType; - })); - _delimiter = Flow.Dataflow.signal(lodash.find(parseDelimiters, function (delimiter) { - return delimiter.charCode === _result.sep; - })); - _useSingleQuotes = Flow.Dataflow.signal(_result.singleQuotes); - _columns = lodash.map(_result.columnNames, function (name) { - return { name: Flow.Dataflow.signal(name) }; - }); - _rows = _result.data; - _columnCount = _result.ncols; - _hasColumns = _columnCount > 0; - _destinationKey = Flow.Dataflow.signal(_result.hexName); - _headerOptions = { - auto: 0, - header: 1, - data: -1 - }; - _headerOption = Flow.Dataflow.signal(_result.checkHeader === 0 ? 'auto' : _result.checkHeader === -1 ? 'data' : 'header'); - _deleteOnDone = Flow.Dataflow.signal(true); - parseFiles = function () { - var columnNames; - columnNames = lodash.map(_columns, function (column) { - return column.name(); + extendPrediction = function (modelKey, frameKey, prediction) { + render_(prediction, function () { + return H2O.PredictOutput(_, prediction); }); - return _.insertAndExecuteCell('cs', 'parseRaw\n srcs: ' + Flow.Prelude.stringify(_sourceKeys) + '\n hex: ' + Flow.Prelude.stringify(_destinationKey()) + '\n pType: ' + Flow.Prelude.stringify(_parserType().type) + '\n sep: ' + _delimiter().charCode + '\n ncols: ' + _columnCount + '\n singleQuotes: ' + _useSingleQuotes() + '\n columnNames: ' + Flow.Prelude.stringify(columnNames) + '\n delete_on_done: ' + _deleteOnDone() + '\n checkHeader: ' + _headerOptions[_headerOption()]); - }; - return { - sourceKeys: _sourceKeys, - parserTypes: parserTypes, - delimiters: parseDelimiters, - parserType: _parserType, - delimiter: _delimiter, - useSingleQuotes: _useSingleQuotes, - columns: _columns, - rows: _rows, - columnCount: _columnCount, - hasColumns: _hasColumns, - destinationKey: _destinationKey, - headerOption: _headerOption, - deleteOnDone: _deleteOnDone, - parseFiles: parseFiles, - template: 'flow-parse-raw-input' - }; - }; -}.call(this)); -(function () { - H2O.ParseOutput = function (_, _result) { - var viewJob; - viewJob = function () { - return _.insertAndExecuteCell('cs', 'getJob ' + Flow.Prelude.stringify(_result.job.key.name)); - }; - return { - result: _result, - viewJob: viewJob, - template: 'flow-parse-output' - }; - }; -}.call(this)); -(function () { - H2O.PlotInput = function (_, config) { - var plot, _canPlot, _color, _table, _type, _types, _variables, _x, _y; - _table = config.data; - _types = [ - 'point', - 'line', - 'area', - 'interval' - ]; - _variables = lodash.map(_table.variables, function (variable) { - return variable.label; - }); - _type = Flow.Dataflow.signal(null); - _x = Flow.Dataflow.signal(null); - _y = Flow.Dataflow.signal(null); - _color = Flow.Dataflow.signal(null); - _canPlot = Flow.Dataflow.lift(_type, _x, _y, function (type, x, y) { - return type && x && y; - }); - plot = function () { - var color; - if (color = _color()) { - return _.insertAndExecuteCell('cs', 'plot\n data: inspect ' + Flow.Prelude.stringify(_table.label) + ', ' + _table.meta.origin + '\n type: \'' + _type() + '\'\n x: ' + Flow.Prelude.stringify(_x()) + '\n y: ' + Flow.Prelude.stringify(_y()) + '\n color: ' + Flow.Prelude.stringify(color)); - } else { - return _.insertAndExecuteCell('cs', 'plot\n data: inspect ' + Flow.Prelude.stringify(_table.label) + ', ' + _table.meta.origin + '\n type: \'' + _type() + '\'\n x: ' + Flow.Prelude.stringify(_x()) + '\n y: ' + Flow.Prelude.stringify(_y())); + switch (prediction.model_category) { + case 'Regression': + case 'Multinomial': + return inspect_(prediction, { prediction: inspectRegressionPrediction(prediction) }); + default: + return inspect_(prediction, { + prediction: inspectBinomialPrediction(prediction), + scores: inspectBinomialScores({ + model: modelKey, + frame: frameKey + }, [prediction]), + metrics: inspectBinomialMetrics({ + model: modelKey, + frame: frameKey + }, [prediction]) + }); } }; - return { - types: _types, - type: _type, - variables: _variables, - x: _x, - y: _y, - color: _color, - plot: plot, - canPlot: _canPlot, - template: 'flow-plot-input' + inspectFrameColumns = function (tableLabel, frameKey, frame, frameColumns) { + return function () { + var Record, column, domain, label, row, rows, variable, variables; + variables = [ + Flow.Data.Variable('label', Flow.TString), + Flow.Data.Variable('missing', Flow.TNumber), + Flow.Data.Variable('zeros', Flow.TNumber), + Flow.Data.Variable('pinfs', Flow.TNumber), + Flow.Data.Variable('ninfs', Flow.TNumber), + Flow.Data.Variable('min', Flow.TNumber), + Flow.Data.Variable('max', Flow.TNumber), + Flow.Data.Variable('mean', Flow.TNumber), + Flow.Data.Variable('sigma', Flow.TNumber), + Flow.Data.Variable('type', Flow.TString), + Flow.Data.Variable('cardinality', Flow.TNumber) + ]; + Record = Flow.Data.Record(variables); + rows = function () { + var _i, _j, _len, _len1, _results; + _results = []; + for (_i = 0, _len = frameColumns.length; _i < _len; _i++) { + column = frameColumns[_i]; + row = new Record(); + for (_j = 0, _len1 = variables.length; _j < _len1; _j++) { + variable = variables[_j]; + label = variable.label; + switch (label) { + case 'min': + row[label] = lodash.head(column.mins); + break; + case 'max': + row[label] = lodash.head(column.maxs); + break; + case 'cardinality': + row[label] = (domain = column.domain) ? domain.length : null; + break; + default: + row[label] = column[label]; + } + } + _results.push(row); + } + return _results; + }(); + return Flow.Data.Table({ + label: tableLabel, + description: 'A list of ' + tableLabel + ' in the H2O Frame.', + variables: variables, + rows: rows, + meta: { + origin: 'getFrame ' + Flow.Prelude.stringify(frameKey), + plot: 'plot\n data: inspect \'' + tableLabel + '\', getFrame ' + Flow.Prelude.stringify(frameKey) + } + }); + }; }; - }; -}.call(this)); -(function () { - H2O.PlotOutput = function (_, _plot) { - return { - plot: _plot, - template: 'flow-plot-output' + inspectFrameData = function (frameKey, frame) { + return function () { + var Record, column, frameColumns, i, j, row, rowCount, rows, value, variable, variables; + frameColumns = frame.columns; + variables = function () { + var _i, _len, _results; + _results = []; + for (_i = 0, _len = frameColumns.length; _i < _len; _i++) { + column = frameColumns[_i]; + switch (column.type) { + case 'int': + _results.push(Flow.Data.Variable(column.label, Flow.TNumber)); + break; + case 'real': + _results.push(Flow.Data.Variable(column.label, Flow.TNumber)); + break; + case 'enum': + _results.push(Flow.Data.Factor(column.label, column.domain)); + break; + case 'uuid': + case 'string': + _results.push(Flow.Data.Variable(column.label, Flow.TString)); + break; + case 'time': + _results.push(Flow.Data.Variable(column.label, Flow.TDate)); + break; + default: + _results.push(Flow.Data.Variable(column.label, Flow.TObject)); + } + } + return _results; + }(); + Record = Flow.Data.Record(variables); + rowCount = lodash.head(frameColumns).data.length; + rows = function () { + var _i, _j, _len, _results; + _results = []; + for (i = _i = 0; 0 <= rowCount ? _i < rowCount : _i > rowCount; i = 0 <= rowCount ? ++_i : --_i) { + row = new Record(); + for (j = _j = 0, _len = variables.length; _j < _len; j = ++_j) { + variable = variables[j]; + value = frameColumns[j].data[i]; + switch (variable.type) { + case Flow.TNumber: + case Flow.TNumber: + row[variable.label] = value === 'NaN' ? null : value; + break; + default: + row[variable.label] = value; + } + } + _results.push(row); + } + return _results; + }(); + return Flow.Data.Table({ + label: 'data', + description: 'A partial list of rows in the H2O Frame.', + variables: variables, + rows: rows, + meta: { origin: 'getFrame ' + Flow.Prelude.stringify(frameKey) } + }); + }; }; - }; -}.call(this)); -(function () { - H2O.PredictInput = function (_, _modelArg, _frameArg) { - var predict, _canPredict, _exception, _frames, _hasFrames, _hasModels, _models, _selectedFrame, _selectedFrames, _selectedFramesCaption, _selectedModel, _selectedModels, _selectedModelsCaption; - _selectedModels = _modelArg ? lodash.isArray(_modelArg) ? _modelArg : [_modelArg] : []; - _selectedFrames = _frameArg ? lodash.isArray(_frameArg) ? _frameArg : [_frameArg] : []; - _selectedModelsCaption = _selectedModels.join(', '); - _selectedFramesCaption = _selectedFrames.join(', '); - _exception = Flow.Dataflow.signal(null); - _selectedFrame = Flow.Dataflow.signal(null); - _selectedModel = Flow.Dataflow.signal(null); - _hasFrames = _selectedFrames.length ? true : false; - _hasModels = _selectedModels.length ? true : false; - _canPredict = Flow.Dataflow.lift(_selectedFrame, _selectedModel, function (frame, model) { - return frame && model || _hasFrames && model || _hasModels && frame; - }); - _frames = Flow.Dataflow.signals([]); - _models = Flow.Dataflow.signals([]); - if (!_hasFrames) { - _.requestFrames(function (error, frames) { - var frame; + extendFrame = function (frameKey, frame) { + var column, enumColumns, inspections; + inspections = { + columns: inspectFrameColumns('columns', frameKey, frame, frame.columns), + data: inspectFrameData(frameKey, frame) + }; + enumColumns = function () { + var _i, _len, _ref1, _results; + _ref1 = frame.columns; + _results = []; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + column = _ref1[_i]; + if (column.type === 'enum') { + _results.push(column); + } + } + return _results; + }(); + if (enumColumns.length > 0) { + inspections.factors = inspectFrameColumns('factors', frameKey, frame, enumColumns); + } + inspect_(frame, inspections); + return render_(frame, function () { + return H2O.FrameOutput(_, frame); + }); + }; + extendColumnSummary = function (frameKey, frame, columnName) { + var column, inspectCharacteristics, inspectDistribution, inspectDomain, inspectPercentiles, inspectSummary, inspections, rowCount; + column = lodash.head(frame.columns); + rowCount = frame.rows; + inspectPercentiles = function () { + var Record, i, percentile, percentileValues, percentiles, row, rows, variables; + percentiles = frame.default_pctiles; + percentileValues = column.pctiles; + variables = [ + Flow.Data.Variable('percentile', Flow.TNumber), + Flow.Data.Variable('value', Flow.TNumber) + ]; + Record = Flow.Data.Record(variables); + rows = function () { + var _i, _len, _results; + _results = []; + for (i = _i = 0, _len = percentiles.length; _i < _len; i = ++_i) { + percentile = percentiles[i]; + row = new Record(); + row.percentile = percentile; + row.value = percentileValues[i]; + _results.push(row); + } + return _results; + }(); + return Flow.Data.Table({ + label: 'percentiles', + description: 'Percentiles for column \'' + column.label + '\' in frame \'' + frameKey + '\'.', + variables: variables, + rows: rows, + meta: { origin: 'getColumnSummary ' + Flow.Prelude.stringify(frameKey) + ', ' + Flow.Prelude.stringify(columnName) } + }); + }; + inspectDistribution = function () { + var Record, base, binCount, binIndex, bins, count, i, interval, m, minBinCount, n, row, rows, stride, variables, width, _i, _j, _k, _len; + variables = [ + Flow.Data.Variable('interval', Flow.TString), + Flow.Data.Variable('width', Flow.TNumber), + Flow.Data.Variable('count', Flow.TNumber) + ]; + Record = Flow.Data.Record(variables); + minBinCount = 32; + base = column.base, stride = column.stride, bins = column.bins; + width = Math.floor(bins.length / minBinCount); + interval = stride * width; + rows = []; + if (width > 0) { + binCount = minBinCount + (bins.length % width > 0 ? 1 : 0); + for (i = _i = 0; 0 <= binCount ? _i < binCount : _i > binCount; i = 0 <= binCount ? ++_i : --_i) { + m = i * width; + n = m + width; + count = 0; + for (binIndex = _j = m; m <= n ? _j < n : _j > n; binIndex = m <= n ? ++_j : --_j) { + if (n < bins.length) { + count += bins[binIndex]; + } + } + row = new Record(); + row.interval = base + i * interval; + row.width = interval; + row.count = count; + rows.push(row); + } + } else { + for (i = _k = 0, _len = bins.length; _k < _len; i = ++_k) { + count = bins[i]; + row = new Record(); + row.interval = base + i * stride; + row.width = stride; + row.count = count; + rows.push(row); + } + } + return Flow.Data.Table({ + label: 'distribution', + description: 'Distribution for column \'' + column.label + '\' in frame \'' + frameKey + '\'.', + variables: variables, + rows: rows, + meta: { + origin: 'getColumnSummary ' + Flow.Prelude.stringify(frameKey) + ', ' + Flow.Prelude.stringify(columnName), + plot: 'plot\n data: inspect \'distribution\', getColumnSummary ' + Flow.Prelude.stringify(frameKey) + ', ' + Flow.Prelude.stringify(columnName) + '\n type: \'interval\'\n x: \'interval\'\n y: \'count\'' + } + }); + }; + inspectCharacteristics = function () { + var characteristics, count, i, missing, ninfs, other, pinfs, rows, variables, zeros; + missing = column.missing, zeros = column.zeros, pinfs = column.pinfs, ninfs = column.ninfs; + other = rowCount - missing - zeros - pinfs - ninfs; + variables = [ + { + label: 'label', + type: Flow.TString + }, + { + label: 'characteristic', + type: Flow.TString + }, + { + label: 'count', + type: Flow.TNumber, + domain: [ + 0, + rowCount + ] + }, + { + label: 'percent', + type: Flow.TNumber, + domain: [ + 0, + 100 + ] + } + ]; + characteristics = [ + 'Missing', + '-Inf', + 'Zero', + '+Inf', + 'Other' + ]; + rows = function () { + var _i, _len, _ref1, _results; + _ref1 = [ + missing, + ninfs, + zeros, + pinfs, + other + ]; + _results = []; + for (i = _i = 0, _len = _ref1.length; _i < _len; i = ++_i) { + count = _ref1[i]; + _results.push({ + label: column.label, + characteristic: characteristics[i], + count: count, + percent: 100 * count / rowCount + }); + } + return _results; + }(); + return Flow.Data.Table({ + label: 'characteristics', + description: 'Characteristics for column \'' + column.label + '\' in frame \'' + frameKey + '\'.', + variables: variables, + rows: rows, + meta: { + origin: 'getColumnSummary ' + Flow.Prelude.stringify(frameKey) + ', ' + Flow.Prelude.stringify(columnName), + plot: 'plot\n title: \'Characteristics for ' + frameKey + ' : ' + column.label + '\'\n type: \'interval\'\n data: inspect \'characteristics\', getColumnSummary ' + Flow.Prelude.stringify(frameKey) + ', ' + Flow.Prelude.stringify(columnName) + '\n x: plot.stack \'count\'\n y: \'label\'\n color: \'characteristic\'' + } + }); + }; + inspectSummary = function () { + var defaultPercentiles, mean, outliers, percentiles, q1, q2, q3, row, variables; + variables = [ + { + label: 'mean', + type: Flow.TNumber + }, + { + label: 'q1', + type: Flow.TNumber + }, + { + label: 'q2', + type: Flow.TNumber + }, + { + label: 'q3', + type: Flow.TNumber + }, + { + label: 'outliers', + type: Flow.TArray + } + ]; + defaultPercentiles = frame.default_pctiles; + percentiles = column.pctiles; + mean = column.mean; + q1 = percentiles[defaultPercentiles.indexOf(0.25)]; + q2 = percentiles[defaultPercentiles.indexOf(0.5)]; + q3 = percentiles[defaultPercentiles.indexOf(0.75)]; + outliers = lodash.unique(column.mins.concat(column.maxs)); + row = { + mean: mean, + q1: q1, + q2: q2, + q3: q3, + outliers: outliers + }; + return Flow.Data.Table({ + label: 'summary', + description: 'Summary for column \'' + column.label + '\' in frame \'' + frameKey + '\'.', + variables: variables, + rows: [row], + meta: { origin: 'getColumnSummary ' + Flow.Prelude.stringify(frameKey) + ', ' + Flow.Prelude.stringify(columnName) } + }); + }; + inspectDomain = function () { + var Record, countVariable, level, levels, row, rows, sortedLevels, variables; + levels = lodash.map(column.bins, function (count, index) { + return { + count: count, + index: index + }; + }); + sortedLevels = lodash.sortBy(levels, function (level) { + return -level.count; + }); + variables = [ + Flow.Data.Variable('label', Flow.TString), + countVariable = Flow.Data.Variable('count', Flow.TNumber), + Flow.Data.Variable('percent', Flow.TNumber, [ + 0, + 100 + ]) + ]; + Record = Flow.Data.Record(variables); + rows = function () { + var _i, _len, _results; + _results = []; + for (_i = 0, _len = sortedLevels.length; _i < _len; _i++) { + level = sortedLevels[_i]; + row = new Record(); + row.label = column.domain[level.index]; + row.count = countVariable.read(level.count); + row.percent = 100 * level.count / rowCount; + _results.push(row); + } + return _results; + }(); + return Flow.Data.Table({ + label: 'domain', + description: 'Domain for column \'' + column.label + '\' in frame \'' + frameKey + '\'.', + variables: variables, + rows: rows, + meta: { + origin: 'getColumnSummary ' + Flow.Prelude.stringify(frameKey) + ', ' + Flow.Prelude.stringify(columnName), + plot: 'plot\n title: \'Domain for ' + frameKey + ' : ' + column.label + '\'\n type: \'interval\'\n data: inspect \'domain\', getColumnSummary ' + Flow.Prelude.stringify(frameKey) + ', ' + Flow.Prelude.stringify(columnName) + '\n x: \'count\'\n y: \'label\'' + } + }); + }; + inspections = { characteristics: inspectCharacteristics }; + if (column.type === 'int' || column.type === 'real') { + inspections.summary = inspectSummary; + inspections.distribution = inspectDistribution; + } else { + inspections.domain = inspectDomain; + } + inspect_(frame, inspections); + return render_(frame, function () { + return go(null, H2O.ColumnSummaryOutput(_, frameKey, frame, columnName)); + }); + }; + requestFrame = function (frameKey, go) { + return _.requestFrame(frameKey, function (error, frame) { + if (error) { + return go(error); + } else { + return go(null, extendFrame(frameKey, frame)); + } + }); + }; + requestColumnSummary = function (frameKey, columnName, go) { + return _.requestColumnSummary(frameKey, columnName, function (error, frame) { if (error) { - return _exception(new Flow.Error('Error fetching frame list.', error)); + return go(error); } else { - return _frames(function () { - var _i, _len, _results; - _results = []; - for (_i = 0, _len = frames.length; _i < _len; _i++) { - frame = frames[_i]; - _results.push(frame.key.name); - } - return _results; - }()); + return go(null, extendColumnSummary(frameKey, frame, columnName)); } }); - } - if (!_hasModels) { - _.requestModels(function (error, models) { - var model; + }; + requestFrames = function (go) { + return _.requestFrames(function (error, frames) { if (error) { - return _exception(new Flow.Error('Error fetching model list.', error)); + return go(error); } else { - return _models(function () { - var _i, _len, _results; - _results = []; - for (_i = 0, _len = models.length; _i < _len; _i++) { - model = models[_i]; - _results.push(model.key.name); - } - return _results; - }()); + return go(null, extendFrames(frames)); } }); - } - predict = function () { - var frameArg, modelArg; - if (_hasFrames) { - frameArg = _selectedFrames.length > 1 ? _selectedFrames : lodash.head(_selectedFrames); - modelArg = _selectedModel(); - } else if (_hasModels) { - modelArg = _selectedModels.length > 1 ? _selectedModels : lodash.head(_selectedModels); - frameArg = _selectedFrame(); + }; + requestCreateFrame = function (opts, go) { + return _.requestCreateFrame(opts, function (error, result) { + if (error) { + return go(error); + } else { + return go(null, result); + } + }); + }; + createFrame = function (opts) { + if (opts) { + return _fork(requestCreateFrame, opts); } else { - modelArg = _selectedModel(); - frameArg = _selectedFrame(); + return assist(createFrame); } - return _.insertAndExecuteCell('cs', 'predict ' + Flow.Prelude.stringify(modelArg) + ', ' + Flow.Prelude.stringify(frameArg)); - }; - return { - exception: _exception, - hasModels: _hasModels, - hasFrames: _hasFrames, - canPredict: _canPredict, - selectedFramesCaption: _selectedFramesCaption, - selectedModelsCaption: _selectedModelsCaption, - selectedFrame: _selectedFrame, - selectedModel: _selectedModel, - frames: _frames, - models: _models, - predict: predict, - template: 'flow-predict-input' }; - }; -}.call(this)); -(function () { - H2O.PredictOutput = function (_, prediction) { - var frame, inspect, model, viewPredictionFrame, _predictionTable; - frame = prediction.frame, model = prediction.model; - _predictionTable = _.inspect('prediction', prediction); - inspect = function () { - return _.insertAndExecuteCell('cs', 'inspect getPrediction ' + Flow.Prelude.stringify(model.name) + ', ' + Flow.Prelude.stringify(frame.name)); + getFrames = function () { + return _fork(requestFrames); }; - viewPredictionFrame = function () { - return _.insertAndExecuteCell('cs', 'getFrame ' + Flow.Prelude.stringify(prediction.predictions.key.name)); + getFrame = function (frameKey) { + switch (Flow.Prelude.typeOf(frameKey)) { + case 'String': + return _fork(requestFrame, frameKey); + default: + return assist(getFrame); + } }; - return { - predictionTable: _predictionTable, - inspect: inspect, - viewPredictionFrame: viewPredictionFrame, - template: 'flow-predict-output' + getColumnSummary = function (frameKey, columnName) { + return _fork(requestColumnSummary, frameKey, columnName); }; - }; -}.call(this)); -(function () { - H2O.PredictsOutput = function (_, opts, _predictions) { - var arePredictionsComparable, comparePredictions, createPredictionView, initialize, inspectAll, plotMetrics, plotPredictions, plotScores, predict, _canComparePredictions, _checkAllPredictions, _isCheckingAll, _metricsTable, _predictionViews, _predictionsTable, _rocCurve, _scoresTable; - _predictionViews = Flow.Dataflow.signal([]); - _checkAllPredictions = Flow.Dataflow.signal(false); - _canComparePredictions = Flow.Dataflow.signal(false); - _rocCurve = Flow.Dataflow.signal(null); - arePredictionsComparable = function (views) { - if (views.length === 0) { - return false; - } - return lodash.every(views, function (view) { - return view.modelCategory === 'Binomial'; + requestModels = function (go) { + return _.requestModels(function (error, models) { + if (error) { + return go(error); + } else { + return go(null, extendModels(models)); + } }); }; - _isCheckingAll = false; - Flow.Dataflow.react(_checkAllPredictions, function (checkAll) { - var view, _i, _len, _ref; - _isCheckingAll = true; - _ref = _predictionViews(); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - view = _ref[_i]; - view.isChecked(checkAll); - } - _canComparePredictions(checkAll && arePredictionsComparable(_predictionViews())); - _isCheckingAll = false; - }); - createPredictionView = function (prediction) { - var inspect, view, _frameKey, _isChecked, _modelKey; - _modelKey = prediction.model.name; - _frameKey = prediction.frame.name; - _isChecked = Flow.Dataflow.signal(false); - Flow.Dataflow.react(_isChecked, function () { - var checkedViews, view; - if (_isCheckingAll) { - return; + requestModelsByKeys = function (modelKeys, go) { + var futures; + futures = lodash.map(modelKeys, function (key) { + return _fork(_.requestModel, key); + }); + return Flow.Async.join(futures, function (error, models) { + if (error) { + return go(error); + } else { + return go(null, extendModels(models)); } - checkedViews = function () { - var _i, _len, _ref, _results; - _ref = _predictionViews(); - _results = []; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - view = _ref[_i]; - if (view.isChecked()) { - _results.push(view); - } - } - return _results; - }(); - return _canComparePredictions(arePredictionsComparable(checkedViews)); }); - view = function () { - return _.insertAndExecuteCell('cs', 'getPrediction ' + Flow.Prelude.stringify(_modelKey) + ', ' + Flow.Prelude.stringify(_frameKey)); - }; - inspect = function () { - return _.insertAndExecuteCell('cs', 'inspect getPrediction ' + Flow.Prelude.stringify(_modelKey) + ', ' + Flow.Prelude.stringify(_frameKey)); - }; - return { - modelKey: _modelKey, - frameKey: _frameKey, - modelCategory: prediction.model_category, - isChecked: _isChecked, - view: view, - inspect: inspect - }; }; - _predictionsTable = _.inspect('predictions', _predictions); - _metricsTable = _.inspect('metrics', _predictions); - _scoresTable = _.inspect('scores', _predictions); - comparePredictions = function () { - var selectedKeys, view; - selectedKeys = function () { - var _i, _len, _ref, _results; - _ref = _predictionViews(); - _results = []; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - view = _ref[_i]; - if (view.isChecked()) { - _results.push({ - model: view.modelKey, - frame: view.frameKey - }); - } + getModels = function (modelKeys) { + if (lodash.isArray(modelKeys)) { + if (modelKeys.length) { + return _fork(requestModelsByKeys, modelKeys); + } else { + return _fork(requestModels); } - return _results; - }(); - return _.insertAndExecuteCell('cs', 'getPredictions ' + Flow.Prelude.stringify(selectedKeys)); - }; - plotPredictions = function () { - return _.insertAndExecuteCell('cs', _predictionsTable.meta.plot); - }; - plotScores = function () { - return _.insertAndExecuteCell('cs', _scoresTable.meta.plot); - }; - plotMetrics = function () { - return _.insertAndExecuteCell('cs', _metricsTable.meta.plot); - }; - inspectAll = function () { - return _.insertAndExecuteCell('cs', 'inspect ' + _predictionsTable.meta.origin); + } else { + return _fork(requestModels); + } }; - predict = function () { - return _.insertAndExecuteCell('cs', 'predict'); + requestModel = function (modelKey, go) { + return _.requestModel(modelKey, function (error, model) { + if (error) { + return go(error); + } else { + return go(null, extendModel(model)); + } + }); }; - initialize = function (predictions) { - return _predictionViews(lodash.map(predictions, createPredictionView)); + getModel = function (modelKey) { + switch (Flow.Prelude.typeOf(modelKey)) { + case 'String': + return _fork(requestModel, modelKey); + default: + return assist(getModel); + } }; - initialize(_predictions); - return { - predictionViews: _predictionViews, - hasPredictions: _predictions.length > 0, - comparePredictions: comparePredictions, - canComparePredictions: _canComparePredictions, - checkAllPredictions: _checkAllPredictions, - plotPredictions: plotPredictions, - plotScores: plotScores, - plotMetrics: plotMetrics, - inspect: inspectAll, - predict: predict, - rocCurve: _rocCurve, - template: 'flow-predicts-output' + getJobs = function () { + return renderable(_.requestJobs, function (jobs, go) { + return go(null, H2O.JobsOutput(_, jobs)); + }); }; - }; -}.call(this)); -(function () { - H2O.ProfileOutput = function (_, _profile) { - var createNode, i, node, _activeNode, _nodes; - _activeNode = Flow.Dataflow.signal(null); - createNode = function (node) { - var display, entries, entry, self; - display = function () { - return _activeNode(self); - }; - entries = function () { - var _i, _len, _ref, _results; - _ref = node.entries; - _results = []; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - entry = _ref[_i]; - _results.push({ - stacktrace: entry.stacktrace, - caption: 'Count: ' + entry.count - }); + getJob = function (arg) { + switch (Flow.Prelude.typeOf(arg)) { + case 'String': + return renderable(_.requestJob, arg, function (job, go) { + return go(null, H2O.JobOutput(_, job)); + }); + case 'Object': + if (arg.key != null) { + return getJob(arg.key); + } else { + return assist(getJob); } - return _results; - }(); - return self = { - name: node.node_name, - caption: '' + node.node_name + ' at ' + new Date(node.timestamp), - entries: entries, - display: display - }; + break; + default: + return assist(getJob); + } }; - _nodes = function () { - var _i, _len, _ref, _results; - _ref = _profile.nodes; - _results = []; - for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { - node = _ref[i]; - _results.push(createNode(node)); + importFiles = function (paths) { + switch (Flow.Prelude.typeOf(paths)) { + case 'Array': + return renderable(_.requestImportFiles, paths, function (importResults, go) { + return go(null, H2O.ImportFilesOutput(_, importResults)); + }); + default: + return assist(importFiles); } - return _results; - }(); - _activeNode(lodash.head(_nodes)); - return { - nodes: _nodes, - activeNode: _activeNode, - template: 'flow-profile-output' }; - }; -}.call(this)); -(function () { - H2O.StackTraceOutput = function (_, _stackTrace) { - var createNode, createThread, node, _activeNode, _nodes; - _activeNode = Flow.Dataflow.signal(null); - createThread = function (thread) { - var lines; - lines = thread.split('\n'); - return { - title: lodash.head(lines), - stackTrace: lodash.tail(lines).join('\n') - }; + setupParse = function (sourceKeys) { + switch (Flow.Prelude.typeOf(sourceKeys)) { + case 'Array': + return renderable(_.requestParseSetup, sourceKeys, function (parseSetupResults, go) { + return go(null, H2O.SetupParseOutput(_, parseSetupResults)); + }); + default: + return assist(setupParse); + } }; - createNode = function (node) { - var display, self, thread; - display = function () { - return _activeNode(self); - }; - return self = { - name: node._node, - timestamp: new Date(node._time), - threads: function () { - var _i, _len, _ref, _results; - _ref = node._traces; - _results = []; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - thread = _ref[_i]; - _results.push(createThread(thread)); - } - return _results; - }(), - display: display - }; + parseRaw = function (opts) { + var checkHeader, columnCount, columnNames, deleteOnDone, destinationKey, parserType, separator, sourceKeys, useSingleQuotes; + sourceKeys = opts.srcs; + destinationKey = opts.hex; + parserType = opts.pType; + separator = opts.sep; + columnCount = opts.ncols; + useSingleQuotes = opts.singleQuotes; + columnNames = opts.columnNames; + deleteOnDone = opts.delete_on_done; + checkHeader = opts.checkHeader; + return renderable(_.requestParseFiles, sourceKeys, destinationKey, parserType, separator, columnCount, useSingleQuotes, columnNames, deleteOnDone, checkHeader, function (parseResult, go) { + return go(null, H2O.ParseOutput(_, parseResult)); + }); }; - _nodes = function () { - var _i, _len, _ref, _results; - _ref = _stackTrace.traces; - _results = []; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - node = _ref[_i]; - _results.push(createNode(node)); + buildModel = function (algo, opts) { + if (algo && opts && lodash.keys(opts).length > 1) { + return renderable(_.requestModelBuild, algo, opts, function (result, go) { + var messages, validation; + if (result.validation_error_count > 0) { + messages = function () { + var _i, _len, _ref1, _results; + _ref1 = result.validation_messages; + _results = []; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + validation = _ref1[_i]; + _results.push(validation.message); + } + return _results; + }(); + return go(new Flow.Error('Model build failure: ' + messages.join('; '))); + } else { + return go(null, H2O.JobOutput(_, lodash.head(result.jobs))); + } + }); + } else { + return assist(buildModel, algo, opts); } - return _results; - }(); - _activeNode(lodash.head(_nodes)); - return { - nodes: _nodes, - activeNode: _activeNode, - template: 'flow-stacktrace-output' }; - }; -}.call(this)); -(function () { - H2O.TimelineOutput = function (_, _timeline) { - var createEvent, refresh, toggleRefresh, updateTimeline, _data, _headers, _isBusy, _isLive, _timestamp; - _isLive = Flow.Dataflow.signal(false); - _isBusy = Flow.Dataflow.signal(false); - _headers = [ - 'HH:MM:SS:MS', - 'nanosec', - 'Who', - 'I/O Type', - 'Event', - 'Bytes' - ]; - _data = Flow.Dataflow.signal(null); - _timestamp = Flow.Dataflow.signal(Date.now()); - createEvent = function (event) { - switch (event.type) { - case 'io': - return [ - event.date, - event.nanos, - event.node, - event.ioFlavor || '-', - 'I/O', - event.data - ]; - case 'heartbeat': - return [ - event.date, - event.nanos, - 'many → many', - 'UDP', - 'heartbeat', - '' + event.sends + ' sent ' + event.recvs + ' received' - ]; - case 'network_msg': - return [ - event.date, - event.nanos, - '' + event.from + ' → ' + event.to, - event.protocol, - event.msgType, - event.data - ]; + requestPredict = function (modelKey, frameKey, go) { + return _.requestPredict(modelKey, frameKey, function (error, prediction) { + if (error) { + return go(error); + } else { + return go(null, extendPrediction(modelKey, frameKey, prediction)); + } + }); + }; + requestPredicts = function (opts, go) { + var futures; + futures = lodash.map(opts, function (opt) { + var frameKey, modelKey; + modelKey = opt.model, frameKey = opt.frame; + return _fork(_.requestPredict, modelKey, frameKey); + }); + return Flow.Async.join(futures, function (error, predictions) { + if (error) { + return go(error); + } else { + return go(null, extendPredictions(opts, predictions)); + } + }); + }; + predict = function (model, frame) { + var frameKey, modelKey, opts, _i, _j, _len, _len1; + if (model && frame) { + if (lodash.isString(model) && lodash.isString(frame)) { + return _fork(requestPredict, model, frame); + } else { + if (lodash.isString(model)) { + model = [model]; + } + if (lodash.isString(frame)) { + frame = [frame]; + } + opts = []; + for (_i = 0, _len = model.length; _i < _len; _i++) { + modelKey = model[_i]; + for (_j = 0, _len1 = frame.length; _j < _len1; _j++) { + frameKey = frame[_j]; + opts.push({ + model: modelKey, + frame: frameKey + }); + } + } + return _fork(requestPredicts, opts); + } + } else { + return assist(predict, model, frame); } }; - updateTimeline = function (timeline) { - var cell, event, grid, header, table, tbody, td, th, thead, ths, tr, trs, _ref; - _ref = Flow.HTML.template('.grid', 'table', '=thead', 'tbody', 'tr', '=th', '=td'), grid = _ref[0], table = _ref[1], thead = _ref[2], tbody = _ref[3], tr = _ref[4], th = _ref[5], td = _ref[6]; - ths = function () { - var _i, _len, _results; - _results = []; - for (_i = 0, _len = _headers.length; _i < _len; _i++) { - header = _headers[_i]; - _results.push(th(header)); + requestPrediction = function (modelKey, frameKey, go) { + return _.requestPrediction(modelKey, frameKey, function (error, prediction) { + if (error) { + return go(error); + } else { + return go(null, extendPrediction(modelKey, frameKey, prediction)); } - return _results; - }(); - trs = function () { - var _i, _len, _ref1, _results; - _ref1 = timeline.events; - _results = []; - for (_i = 0, _len = _ref1.length; _i < _len; _i++) { - event = _ref1[_i]; - _results.push(tr(function () { - var _j, _len1, _ref2, _results1; - _ref2 = createEvent(event); - _results1 = []; - for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { - cell = _ref2[_j]; - _results1.push(td(cell)); - } - return _results1; - }())); + }); + }; + requestPredictions = function (opts, go) { + var frameKey, futures, modelKey; + if (lodash.isArray(opts)) { + futures = lodash.map(opts, function (opt) { + var frameKey, modelKey; + modelKey = opt.model, frameKey = opt.frame; + return _fork(_.requestPredictions, modelKey, frameKey); + }); + return Flow.Async.join(futures, function (error, predictions) { + var uniquePredictions; + if (error) { + return go(error); + } else { + uniquePredictions = lodash.values(lodash.indexBy(lodash.flatten(predictions, true), function (prediction) { + return prediction.model.key + prediction.frame.key.name; + })); + return go(null, extendPredictions(opts, uniquePredictions)); + } + }); + } else { + modelKey = opts.model, frameKey = opts.frame; + return _.requestPredictions(modelKey, frameKey, function (error, predictions) { + if (error) { + return go(error); + } else { + return go(null, extendPredictions(opts, predictions)); + } + }); + } + }; + getPrediction = function (modelKey, frameKey) { + if (modelKey && frameKey) { + return _fork(requestPrediction, modelKey, frameKey); + } else { + return assist(getPrediction, modelKey, frameKey); + } + }; + getPredictions = function (opts) { + if (opts == null) { + opts = {}; + } + return _fork(requestPredictions, opts); + }; + requestCloud = function (go) { + return _.requestCloud(function (error, cloud) { + if (error) { + return go(error); + } else { + return go(null, extendCloud(cloud)); } - return _results; - }(); - return _data(Flow.HTML.render('div', grid([table([ - thead(tr(ths)), - tbody(trs) - ])]))); + }); }; - toggleRefresh = function () { - return _isLive(!_isLive()); + getCloud = function () { + return _fork(requestCloud); }; - refresh = function () { - _isBusy(true); + requestTimeline = function (go) { return _.requestTimeline(function (error, timeline) { - _isBusy(false); if (error) { - _exception(Flow.Failure(new Flow.Error('Error fetching timeline', error))); - return _isLive(false); + return go(error); } else { - updateTimeline(timeline); - if (_isLive()) { - return lodash.delay(refresh, 2000); - } + return go(null, extendTimeline(timeline)); } }); }; - Flow.Dataflow.act(_isLive, function (isLive) { - if (isLive) { - return refresh(); + getTimeline = function () { + return _fork(requestTimeline); + }; + requestStackTrace = function (go) { + return _.requestStackTrace(function (error, stackTrace) { + if (error) { + return go(error); + } else { + return go(null, extendStackTrace(stackTrace)); + } + }); + }; + getStackTrace = function () { + return _fork(requestStackTrace); + }; + requestLogFile = function (nodeIndex, go) { + return _.requestLogFile(nodeIndex, function (error, logFile) { + if (error) { + return go(error); + } else { + return go(null, extendLogFile(nodeIndex, logFile)); + } + }); + }; + getLogFile = function (nodeIndex) { + if (nodeIndex == null) { + nodeIndex = 0; + } + return _fork(requestLogFile, nodeIndex); + }; + requestProfile = function (depth, go) { + return _.requestProfile(depth, function (error, profile) { + if (error) { + return go(error); + } else { + return go(null, extendProfile(profile)); + } + }); + }; + getProfile = function (opts) { + if (!opts) { + opts = { depth: 10 }; + } + return _fork(requestProfile, opts.depth); + }; + loadScript = function (path, go) { + var onDone, onFail; + onDone = function (script, status) { + return go(null, { + script: script, + status: status + }); + }; + onFail = function (jqxhr, settings, error) { + return go(error); + }; + return $.getScript(path).done(onDone).fail(onFail); + }; + dumpFuture = function (result, go) { + console.debug(result); + return go(null, render_(result || {}, function () { + return Flow.ObjectBrowser('dump', result); + })); + }; + dump = function (f) { + if (f != null ? f.isFuture : void 0) { + return _fork(dumpFuture, f); + } else { + return Flow.Async.async(function () { + return f; + }); + } + }; + assist = function () { + var args, func; + func = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + if (func === void 0) { + return _fork(proceed, H2O.Assist, [_assistance]); + } else { + switch (func) { + case importFiles: + return _fork(proceed, H2O.ImportFilesInput, []); + case buildModel: + return _fork(proceed, H2O.ModelInput, args); + case predict: + case getPrediction: + return _fork(proceed, H2O.PredictInput, args); + case createFrame: + return _fork(proceed, H2O.CreateFrameInput, args); + default: + return _fork(proceed, H2O.NoAssist, []); + } } + }; + Flow.Dataflow.link(_.ready, function () { + Flow.Dataflow.link(_.inspect, inspect); + return Flow.Dataflow.link(_.plot, __plot); }); - updateTimeline(_timeline); return { - data: _data, - isLive: _isLive, - isBusy: _isBusy, - toggleRefresh: toggleRefresh, - refresh: refresh, - template: 'flow-timeline-output' + fork: _fork, + join: _join, + call: _call, + apply: _apply, + isFuture: _isFuture, + signal: Flow.Dataflow.signal, + signals: Flow.Dataflow.signals, + isSignal: Flow.Dataflow.isSignal, + act: Flow.Dataflow.act, + react: Flow.Dataflow.react, + lift: Flow.Dataflow.lift, + merge: Flow.Dataflow.merge, + dump: dump, + inspect: inspect, + plot: plot, + grid: grid, + get: _get, + assist: assist, + gui: gui, + loadScript: loadScript, + getJobs: getJobs, + getJob: getJob, + importFiles: importFiles, + setupParse: setupParse, + parseRaw: parseRaw, + createFrame: createFrame, + getFrames: getFrames, + getFrame: getFrame, + getColumnSummary: getColumnSummary, + buildModel: buildModel, + getModels: getModels, + getModel: getModel, + predict: predict, + getPrediction: getPrediction, + getPredictions: getPredictions, + getCloud: getCloud, + getTimeline: getTimeline, + getProfile: getProfile, + getStackTrace: getStackTrace, + getLogFile: getLogFile }; }; }.call(this));}).call(this); \ No newline at end of file diff --git a/src/core/components/about.coffee b/src/core/components/about.coffee index aaa77c3e0..fdb5fcf79 100644 --- a/src/core/components/about.coffee +++ b/src/core/components/about.coffee @@ -1,4 +1,4 @@ -FLOW_VERSION = '0.2.26' +FLOW_VERSION = '0.2.27' Flow.About = (_) -> _properties = signals []