Commit c29f9255 authored by Kjetil Thuen's avatar Kjetil Thuen
Browse files

Load data from Nesstar rest server.

Massage data untill usable
parent 5c362e1e
lodash = require 'lodash'
getDataDescription = () ->
{
host: "http://nesstar-dev.nsd.uib.no"
port: 80
service: "touch/hfk/restdata"
cube: "Fypr-2014-Bef_C1"
filter: {
measures: [ "Befolkning" ]
dimensions: [
{
"id": "tid"
},
{
"id": "alder"
},
{
"id": "Kjnn",
"members": ["1","2"]
},
{
"id": "Framskrivingsalternativ"
"members": ["1"]
},
{
"id": "Region"
"members": ["12"]
}
]
}
}
fetchData = (url, callback) ->
request = new XMLHttpRequest()
request.onload = callback
request.open 'GET', url, true
request.send()
assembleDataRequest = () ->
datadesc = getDataDescription()
datadesc.host + ":" +
datadesc.port + "/" +
datadesc.service + "/cube/" +
datadesc.cube + "/query?q=" +
JSON.stringify(datadesc.filter)
flattenNesstarData = (cellValue) ->
flattenedCell = lodash.object lodash.map cellValue.coordinate, (x) ->
[ x.category, x.member ]
flattenedCell.value = cellValue.value[0].value
flattenedCell
prepareFuncFactory = (callback) ->
prepareDataForTimeBar = ->
values = JSON.parse(@response).payload.values
saneValueStore = lodash.map(values, flattenNesstarData)
men = lodash.filter saneValueStore, (cell) ->
parseInt(cell.Kjnn) is 1
women = lodash.filter saneValueStore, (cell) ->
parseInt(cell.Kjnn) is 2
menByYear = lodash.groupBy men, (cell) ->
parseInt(cell.tid)
womenByYear = lodash.groupBy women, (cell) ->
parseInt(cell.tid)
restructuredData = {
men: menByYear
women: womenByYear
}
callback restructuredData
prepareDataForTimeBar
reloadData = (consumerFunc) ->
prep = prepareFuncFactory consumerFunc
fetchData assembleDataRequest(), prep
window.reloadNesstarData = reloadData
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment