Merge branch 'master' of git.curoverse.com:arvados into 2638-add-cache-age-disk-usage...
[arvados.git] / apps / workbench / app / assets / javascripts / keep_disks.js.coffee
1 # Place all the behaviors and hooks related to the matching controller here.
2 # All this logic will automatically be available in application.js.
3 # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
4
5 cache_age_in_days = (milliseconds_age) ->
6   ONE_DAY = 1000 * 60 * 60 * 24
7   milliseconds_age / ONE_DAY
8
9 cache_age_hover = (milliseconds_age) ->
10   'Cache age ' + cache_age_in_days(milliseconds_age).toFixed(1) + ' days.'
11
12 cache_age_axis_label = (milliseconds_age) ->
13   cache_age_in_days(milliseconds_age).toFixed(0) + ' days'
14
15 float_as_percentage = (proportion) ->
16   (proportion.toFixed(4) * 100) + '%'
17
18 $.renderHistogram = (histogram_data) ->
19   Morris.Area({
20     element: 'cache-age-vs-disk-histogram',
21     pointSize: 0,
22     lineWidth: 0,
23     data: histogram_data,
24     xkey: 'age',
25     ykeys: ['persisted', 'cache'],
26     labels: ['Persisted Storage Disk Utilization', 'Cached Storage Disk Utilization'],
27     ymax: 1,
28     ymin: 0,
29     xLabelFormat: cache_age_axis_label,
30     yLabelFormat: float_as_percentage,
31     dateFormat: cache_age_hover
32   })