You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

90 lines
1.8 KiB

var BuoyAnalysisData = {
mapW: 450,
mapH: 450,
mapJson: {},
stationJson: {},
/**
*
*/
populateMapData: function() {
return new Promise(function(resolve) {
d3.json('client/_map.json', function(error, json) {
BuoyAnalysisData.mapJson = json;
resolve();
});
});
},
/**
*
*/
populateSrcFile: function() {
return new Promise(function(resolve) {
d3.json('client/_stations.json', function(error, json) {
BuoyAnalysisData.stationJson = json;
resolve();
});
});
},
/**
*
*/
calculateYearlyAverages: function(stations) {
var sum, count, avg;
var years = {};
for (var i = 1982; i < 2016; i++) {
sum = 0;
count = 0;
stations.forEach(function(id) {
avg = BuoyAnalysisData.stationJson[id]['avgs' + i];
if (avg === undefined || avg.y === 0) {
return;
}
sum += avg.y;
count++;
});
years['y' + i] = (sum / count) || 0;
}
return years;
},
/**
*
*/
calculateMonthlyAverages: function(stations, year) {
var sum, count, avg;
var months = {};
for (var i = 0; i < 12; i++) {
sum = 0;
count = 0;
stations.forEach(function(id) {
avg = BuoyAnalysisData.stationJson[id]['avgs' + year];
if (avg === undefined || avg.m[i] === 0) {
return;
}
sum += avg.m[i];
count++;
});
months['m' + i] = (sum / count) || 0;
}
return months;
}
};