Skip to content

Instantly share code, notes, and snippets.

@Crenshinibon
Created March 3, 2016 18:44
Show Gist options
  • Save Crenshinibon/8755ebf377b8ff01eb5e to your computer and use it in GitHub Desktop.
Save Crenshinibon/8755ebf377b8ff01eb5e to your computer and use it in GitHub Desktop.
@prepareData = (colName) ->
cur = _colCur colName
_prepareData cur
_colCur = (colName) ->
col = _col colName
cur = col.find({},{sort: {execDate: 1}})
_prepareData = (colCur) ->
res = {}
avgKey = 'Lauf. Durchschnitt'
res[avgKey] =
values: []
key: avgKey
colCur.forEach (e) ->
tester = res[e.tester]
unless tester?
tester =
values: []
key: e.tester
res[e.tester] = tester
prev = res[avgKey].values[-10..-1]
sum = prev.reduce (s, p) ->
s + p.raw
,
e.execDuration
res[avgKey].values.push {x: e.execDate, y: (sum / (prev.length + 1)), raw: e.execDuration}
tester.values.push {x: e.execDate, y: e.execDuration}
lodash.values res
Template.perfMeasure.onCreated () ->
#controlling the initial timespan to be shown
@fromDate = new ReactiveVar moment().subtract(2,'d').toDate()
data = @data
inst = @
sub = inst.subscribe data.collection, inst.fromDate.get()
Meteor.autorun () ->
col = _col data.collection
sub.stop()
sub = inst.subscribe data.collection, inst.fromDate.get()
Template.perfMeasure.onRendered () ->
data = @data
inst = @
chart = null
chartData = null
#first time init the graphs
Meteor.autorun () ->
if inst.subscriptionsReady()
nv.addGraph () ->
chart = nv.models.lineChart()
.margin({right: 50, top: 50, bottom: 50, left: 80})
.showLegend(true)
.showXAxis(true)
.showYAxis(true)
chart.yAxis
.axisLabel('Dauer (ms)')
.tickFormat (d) ->
Math.round d
chart.xAxis
.axisLabel('Ausführungszeitpunkt')
.tickFormat (d) ->
moment(d).format('HH:mm:ss')
#moment(d).format('D.MM.Y')
d = prepareData data.collection
chartData = d3.select("svg##{data.collection}").datum(d)
chartData.call(chart)
#Update the chart when window resizes.
nv.utils.windowResize () -> chart.update()
chart
#update the chart on new data
Meteor.autorun () ->
cur = _colCur data.collection
d = _prepareData cur
if chartData? and chart?
chartData.datum(d).transition().duration(100).call(chart)
Template.perfMeasure.helpers
measureId: () ->
@collection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment