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.
 
 
 
 

98 lines
2.2 KiB

var BuoyAnalysisData = {
mapW: 500,
mapH: 600,
mapJson: {},
stationJson: {},
property: 'wt',
years: {
start: 1982,
end: 2015
},
/**
*
*/
populateMapData: function() {
return new Promise(function(resolve) {
d3.json('data/map.json', function(error, json) {
BuoyAnalysisData.mapJson = json;
resolve();
});
});
},
/**
*
*/
populateSrcFile: function() {
return new Promise(function(resolve) {
d3.json('data/stations.json', function(error, json) {
BuoyAnalysisData.stationJson = json;
resolve();
});
});
},
/**
*
*/
calculateYearlyAverages: function(stations) {
var sum, count, avg;
var years = [];
for (var year = BuoyAnalysisData.years.start; year <= BuoyAnalysisData.years.end; year++) {
sum = 0;
count = 0;
stations.forEach(function(id) {
data = BuoyAnalysisData.stationJson[id]['a' + year][BuoyAnalysisData.property];
if (data === undefined || data.y === 0) {
return;
}
sum += data.y;
count++;
});
years.push({ average: (sum / count) || 0, year: year });
}
return years;
},
/**
*
*/
calculateMonthlyAverages: function(stations) {
var sum, count, data;
var months = [];
for (var year = BuoyAnalysisData.years.start; year <= BuoyAnalysisData.years.end; year++) {
for (var month = 0; month < 12; month++) {
sum = 0;
count = 0;
stations.forEach(function(id) {
data = BuoyAnalysisData.stationJson[id]['a' + year][BuoyAnalysisData.property];
if (data === undefined || data.m[month] === 0) {
return;
}
sum += data.m[month];
count++;
});
months.push({ average: (sum / count) || 0, month: month, year: year });
}
};
return months;
}
};