{
- "id": "ohai",
- "name": "ohai",
- "slug": "ohai",
- "desc": "",
- "dataset": "/data/datasources/rc/rc_new_article_count.csv",
+ "id": "ohai",
+ "slug": "ohai",
+
+ "name": "ohai~",
+ "desc": "A graph for the testing of great justice.",
+
+ "dataset": "/data/datasources/rc/rc_page_requests.csv",
+ "data" : {
+ "metrics" : {
+ "defaults" : {
+ "source_id" : "rc_page_requests"
+ },
+ "columns" : [
+ {
+ "source_col" : 1,
+ "label" : "All Wikipedias (+Mobile)",
+ "color" : "#E62F74"
+ }, {
+ "source_col" : 2,
+ "label" : "English",
+ "color" : "#244792"
+ }
+ ]
+ }
+ },
+
"width": "auto",
- "height": 320,
+ "height": 600,
+
"parents": [
"root"
- ],
- "chartType": "dygraphs",
+ ],
+
+ "chartType": "dygraphs",
"options": {
- "animatedZooms": true,
- "avoidMinZero": false,
- "axis": null,
- "axisLabelColor": "#666666",
- "axisLabelFontSize": 14,
- "axisLabelFormatter": null,
- "axisLabelWidth": 50,
- "axisLineColor": "#AAAAAA",
- "axisLineWidth": 0.3,
- "axisTickSize": 3,
- "colorSaturation": 1,
- "colorValue": 0.5,
- "colors": [
- "#FF0097",
- "#EF8158",
- "#83BB32",
- "#182B53",
- "#4596FF",
- "#553DC9",
- "#AD3238",
- "#00FFBC",
- "#F1D950"
- ],
- "connectSeparatedPoints": false,
- "customBars": false,
- "dateWindow": null,
- "delimiter": ",",
- "digitsAfterDecimal": 2,
- "displayAnnotations": false,
- "drawPoints": true,
- "drawXAxis": true,
- "drawXGrid": true,
- "drawYAxis": true,
- "drawYGrid": true,
- "errorBars": false,
- "file": null,
- "fillAlpha": 0.15,
- "fillGraph": false,
- "fractions": false,
- "gridLineColor": "#D8D8D8",
- "gridLineWidth": 0.3,
- "hideOverlayOnMouseOut": true,
- "highlightCircleSize": 4,
- "includeZero": false,
- "interactionModel": null,
- "isZoomedIgnoreProgrammaticZoom": false,
- "labels": null,
- "labelsDiv": null,
- "labelsDivStyles": null,
- "labelsDivWidth": 250,
- "labelsKMB": true,
- "labelsKMG2": false,
- "labelsSeparateLines": true,
- "labelsShowZeroValues": true,
- "legend": "always",
- "logscale": true,
- "maxNumberWidth": 30,
- "panEdgeFraction": null,
- "pixelsPerLabel": null,
- "pixelsPerXLabel": null,
- "pixelsPerYLabel": null,
- "pointSize": 1,
- "rangeSelectorHeight": 40,
- "rangeSelectorPlotFillColor": "#A7B1C4",
- "rangeSelectorPlotStrokeColor": "#808FAB",
- "rightGap": 20,
- "rollPeriod": 1,
- "showLabelsOnHighlight": true,
- "showRangeSelector": false,
- "showRoller": false,
- "sigFigs": null,
- "sigma": 2,
- "stackedGraph": false,
- "stepPlot": false,
- "strokePattern": null,
- "strokeWidth": 4,
- "ticker": null,
- "title": null,
- "titleHeight": 18,
- "valueFormatter": null,
- "valueRange": null,
- "visibility": null,
- "wilsonInterval": true,
- "xAxisHeight": null,
- "xAxisLabelFormatter": null,
- "xAxisLabelWidth": 55,
- "xLabelHeight": 18,
- "xValueFormatter": null,
- "xValueParser": null,
- "xlabel": null,
- "y2label": null,
- "yAxisLabelFormatter": null,
- "yAxisLabelWidth": 50,
- "yLabelWidth": 18,
- "yValueFormatter": null,
+ "animatedZooms": true,
+ "avoidMinZero": false,
+ "axis": null,
+ "axisLabelColor": "#666666",
+ "axisLabelFontSize": 14,
+ "axisLabelFormatter": null,
+ "axisLabelWidth": 50,
+ "axisLineColor": "#AAAAAA",
+ "axisLineWidth": 0.3,
+ "axisTickSize": 3,
+ "colorSaturation": 1,
+ "colorValue": 0.5,
+ "colors": [ "#FF0097", "#EF8158", "#83BB32", "#182B53", "#4596FF", "#553DC9", "#AD3238", "#00FFBC", "#F1D950" ],
+ "connectSeparatedPoints": false,
+ "customBars": false,
+ "dateWindow": null,
+ "delimiter": ",",
+ "digitsAfterDecimal": 2,
+ "displayAnnotations": false,
+ "drawPoints": true,
+ "drawXAxis": true,
+ "drawXGrid": true,
+ "drawYAxis": true,
+ "drawYGrid": true,
+ "errorBars": false,
+ "file": null,
+ "fillAlpha": 0.15,
+ "fillGraph": false,
+ "fractions": false,
+ "gridLineColor": "#D8D8D8",
+ "gridLineWidth": 0.3,
+ "hideOverlayOnMouseOut": true,
+ "highlightCircleSize": 4,
+ "includeZero": false,
+ "interactionModel": null,
+ "isZoomedIgnoreProgrammaticZoom": false,
+ "labels": null,
+ "labelsDiv": null,
+ "labelsDivStyles": null,
+ "labelsDivWidth": 250,
+ "labelsKMB": true,
+ "labelsKMG2": false,
+ "labelsSeparateLines": true,
+ "labelsShowZeroValues": true,
+ "legend": "always",
+ "logscale": true,
+ "maxNumberWidth": 30,
+ "panEdgeFraction": null,
+ "pixelsPerLabel": null,
+ "pixelsPerXLabel": null,
+ "pixelsPerYLabel": null,
+ "pointSize": 1,
+ "rangeSelectorHeight": 40,
+ "rangeSelectorPlotFillColor": "#A7B1C4",
+ "rangeSelectorPlotStrokeColor": "#808FAB",
+ "rightGap": 20,
+ "rollPeriod": 1,
+ "showLabelsOnHighlight": true,
+ "showRangeSelector": false,
+ "showRoller": false,
+ "sigFigs": null,
+ "sigma": 2,
+ "stackedGraph": false,
+ "stepPlot": false,
+ "strokePattern": null,
+ "strokeWidth": 4,
+ "ticker": null,
+ "title": null,
+ "titleHeight": 18,
+ "valueFormatter": null,
+ "valueRange": null,
+ "visibility": null,
+ "wilsonInterval": true,
+ "xAxisHeight": null,
+ "xAxisLabelFormatter": null,
+ "xAxisLabelWidth": 55,
+ "xLabelHeight": 18,
+ "xValueFormatter": null,
+ "xValueParser": null,
+ "xlabel": null,
+ "y2label": null,
+ "yAxisLabelFormatter": null,
+ "yAxisLabelWidth": 50,
+ "yLabelWidth": 18,
+ "yValueFormatter": null,
"ylabel": null
}
}
fs = require 'fs'
-Seq = require 'seq'
+path = require 'path'
+{existsSync:exists} = path
+
+_ = require 'underscore'
+yaml = require 'js-yaml'
findit = require 'findit'
-Controller = require '../controller'
+Seq = require 'seq'
-YAML_EXT_PAT = /\.ya?ml$/i
+Controller = require '../controller'
+EXT_PAT = /\.[^\.]*$/i
+YAML_EXT_PAT = /\.ya?ml$/i
+YAML_OR_JSON_PAT = /\.(json|ya?ml)$/i
/**
-> super ...
+
+ toFile: (id) -> "#{@dataDir}/#id.json"
+
/**
- * Returns a JSON listing of the datasource metadata files.
+ * Auto-load :id for related requests.
+ */
+ autoload: (id, cb) ->
+ file = @toFile id
+ parser = JSON.parse
+
+ yamlFile = file.replace /\.json$/i, '.yaml'
+ if exists yamlFile
+ file = yamlFile
+ parser = yaml.load
+
+ err, data <- fs.readFile file, 'utf8'
+ if 'ENOENT' is err?.code
+ return cb null, {}
+ if err
+ console.error "DataSourceController.autoload(#id, #{typeof cb}) -->\nerr"
+ return cb err
+ try
+ cb null, parser data
+ catch err
+ console.error "DataSourceController.autoload(#id, #{typeof cb}) -->\nerr"
+ cb err
+
+ /**
+ * GET /datasources
+ * @returns {Object} JSON listing of the datasource metadata files.
*/
index : (req, res, next) ->
files = findit.sync @dataDir
# fs.readdir @dataDir, (err, files) ->
res.send do
- files.filter -> /\.(json|ya?ml)$/i.test it
+ files.filter -> YAML_OR_JSON_PAT.test it
.map -> "#it".replace YAML_EXT_PAT, '.json'
/**
+ * GET /datasources/:datasource
+ */
+ show: (req, res) ->
+ res.send req.datasource
+ # if req.format is 'json'
+ # res.send req.datasource
+ # else
+ # res.render 'datasource/view'
+
+ /**
* Returns the aggregated JSON content of the datasource metadata files.
*/
allData : (req, res, next) ->
Seq(findit.sync @dataDir)
# .seq ~> @ok findit.sync @dataDir
# .flatten()
- .filter -> /\.(json|ya?ml)$/.test it
+ .filter -> YAML_OR_JSON_PAT.test it
.seq ->
files := @stack.slice()
# console.log 'files:', files
# console.log "#f ok!", data
@ok v
catch err
- console.error "[/data/all] catch! #err"
+ console.error "[/datasources] catch! #err"
console.error err
console.error that if err.stack
res.send { error:String(err), partial_data:data }
.seq -> res.send data
.catch (err) ->
- console.error '[/data/all] catch!'
+ console.error '[/datasources] catch!'
console.error err
console.error that if err.stack
res.send { error:String(err), partial_data:data }