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.
162 lines
5.0 KiB
162 lines
5.0 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();
|
|
});
|
|
});
|
|
},
|
|
|
|
/**
|
|
*
|
|
*/
|
|
setAxisProperties: function() {
|
|
var json = BuoyAnalysisData.stationJson;
|
|
var property = BuoyAnalysisData.property;
|
|
var tickValues = BuoyAnalysisChart.bars.tickValues;
|
|
|
|
BuoyAnalysisChart.axis.min = 100;
|
|
BuoyAnalysisChart.axis.max = 0;
|
|
|
|
for (var id in json) {
|
|
for (var year = BuoyAnalysisData.years.start; year <= BuoyAnalysisData.years.end; year++) {
|
|
for (var i = 0; i < 12; i++) {
|
|
if (json[id]['a' + year][property]['m'][i] <= 0) {
|
|
continue;
|
|
}
|
|
|
|
if (json[id]['a' + year][property]['m'][i] < BuoyAnalysisChart.axis.min) {
|
|
BuoyAnalysisChart.axis.min = json[id]['a' + year][property]['m'][i];
|
|
}
|
|
|
|
if (json[id]['a' + year][property]['m'][i] > BuoyAnalysisChart.axis.max) {
|
|
BuoyAnalysisChart.axis.max = json[id]['a' + year][property]['m'][i];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
BuoyAnalysisChart.axis.scale = d3.scale.linear().domain([0, BuoyAnalysisChart.axis.max])
|
|
.range([0, BuoyAnalysisChart.bars.height]);
|
|
|
|
BuoyAnalysisChart.axis.imperial = d3.svg.axis()
|
|
.scale(BuoyAnalysisChart.axis.scale)
|
|
.orient("right")
|
|
.tickFormat(function(d) {
|
|
var val;
|
|
|
|
switch(BuoyAnalysisData.property) {
|
|
case 'at':
|
|
case 'wt':
|
|
val = Math.round(d * 9 / 5 + 32);
|
|
break;
|
|
|
|
case 'wh':
|
|
case 'ws':
|
|
val = Math.round(d * 3.28 * 10) / 10;
|
|
break;
|
|
|
|
case 'wp':
|
|
val = d;
|
|
break;
|
|
};
|
|
|
|
return val;
|
|
})
|
|
.tickValues(tickValues);
|
|
|
|
BuoyAnalysisChart.axis.metric = d3.svg.axis()
|
|
.scale(BuoyAnalysisChart.axis.scale)
|
|
.orient("right")
|
|
.tickValues(tickValues);
|
|
},
|
|
|
|
/**
|
|
*
|
|
*/
|
|
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;
|
|
}
|
|
};
|
|
|