Starting final UI behaviors, styling, presentation.

master
ben-burlingham 10 years ago
parent 080a4251a9
commit df595d6c5e
  1. 19
      client/_init.js
  2. 2
      client/_stations.json
  3. 60
      client/behaviors.js
  4. 128
      client/chart.js
  5. 116
      client/data.js
  6. 20
      client/init.js
  7. 102
      client/map.js
  8. 70
      client/svg-map.js
  9. 67
      client/ui-dom.js
  10. 210
      index.html
  11. 2
      server.js
  12. 11
      server/assemble.js
  13. 23
      server/noaa.js
  14. 1
      server/stations.js

@ -1,19 +0,0 @@
//=============================
//
// IIFE ENTRY POINT
//
//=============================
(function() {
Promise.resolve()
.then(BuoyAnalysisData.populateMapData)
.then(BuoyAnalysisData.populateSrcFile)
.then(BuoyAnalysisSvgMap.drawMap)
.then(BuoyAnalysisSvgMap.drawStations)
.then(BuoyAnalysisSvgMap.drawReticle)
.then(BuoyAnalysisUiDom.populateMonths)
.then(BuoyAnalysisUiDom.populateStationDetail)
.then(BuoyAnalysisUiBehaviors.attachBehaviors)
})();

File diff suppressed because one or more lines are too long

@ -1,6 +1,6 @@
'use strict'; 'use strict';
var BuoyAnalysisUiBehaviors = { var BuoyAnalysisBehaviors = {
stationClick: function() { stationClick: function() {
}, },
@ -10,32 +10,33 @@ var BuoyAnalysisUiBehaviors = {
}, },
reticleDrag: function(d) { reticleDrag: function(d) {
d.x += d3.event.dx
d.y += d3.event.dy
d3.select(this).attr('transform', 'translate(' + [ d.x, d.y ] + ')');
}, },
reticleDragEnd: function(d) { reticleDragEnd: function() {
var dX, dY, squares, distance, station; var x = d3.mouse(this)[0];
var stations = []; var y = d3.mouse(this)[1];
for (var s in BuoyAnalysisData.stationJson) { if (x < 200) {
station = BuoyAnalysisData.stationJson[s]; x = 200;
}
dX = d.x - station.x; if (x > 800) {
dY = d.y - station.y; x = 800;
}
squares = Math.pow(dX, 2) + Math.pow(dY, 2)
distance = Math.pow(squares, 0.5);
if (distance < 50) { var d = d3.select('.reticle').data()[0];
stations.push(s); d.x = x;
} d.y = y;
};
BuoyAnalysisData.calculateYearlyAverages(stations); d3.select('.reticle')
BuoyAnalysisData.calculateMonthlyAverages(stations, 1982); .transition()
.duration(300)
.attr('transform', 'translate(' + [ d.x, d.y ] + ')')
BuoyAnalysisMap.findStationsUnderReticle();
BuoyAnalysisChart.draw();
}, },
reticleResize: function() { reticleResize: function() {
@ -43,21 +44,18 @@ var BuoyAnalysisUiBehaviors = {
}, },
attachBehaviors: function() { attachBehaviors: function() {
// d3.selectAll('.detail') d3.select('#map')
// .on('mouseover', startAnimateStation) .on('click', BuoyAnalysisBehaviors.reticleDragEnd)
// .on('mouseout', stopAnimateStation); // .call(d3.behavior.drag()
// .on('drag', BuoyAnalysisBehaviors.reticleDrag)
d3.select('.reticle') // .on('dragend', BuoyAnalysisBehaviors.reticleDragEnd)
.call(d3.behavior.drag() // );
.on('drag', BuoyAnalysisUiBehaviors.reticleDrag)
.on('dragend', BuoyAnalysisUiBehaviors.reticleDragEnd)
);
}, },
}; };
// d3.selectAll('.detail')
// .on('mouseover', startAnimateStation)
// .on('mouseout', stopAnimateStation);
// function startAnimateStation() { // function startAnimateStation() {
// var id = d3.event.target.id || d3.event.target.parentNode.id; // var id = d3.event.target.id || d3.event.target.parentNode.id;

@ -0,0 +1,128 @@
'use strict';
var BuoyAnalysisChart = {
/**
*
*/
bars: {
padding: 24,
spacing: 2,
width: 23,
},
/**
*
*/
barYearX: function(d, i) {
return i * BuoyAnalysisChart.bars.width + i * BuoyAnalysisChart.bars.spacing + BuoyAnalysisChart.bars.padding;
},
/**
*
*/
barMonthX: function(d, i) {
var year = Math.floor(i / 12);
return year * BuoyAnalysisChart.bars.width + BuoyAnalysisChart.bars.padding + year * BuoyAnalysisChart.bars.spacing + (i % 12) * 2;
},
/**
*
*/
draw: function() {
var years = BuoyAnalysisData.calculateYearlyAverages(BuoyAnalysisMap.reticle.stations);
var months = BuoyAnalysisData.calculateMonthlyAverages(BuoyAnalysisMap.reticle.stations);
var chart = d3.select('#chart');
var toggles = d3.select('#year-toggles')
chart.selectAll('*').remove();
var gradient = chart.append("svg:defs")
.append("svg:linearGradient")
.attr("id", "Gradient1")
.attr('gradientTransform', 'rotate(90)')
gradient.append("svg:stop")
.attr("offset", "0%")
.attr("stop-color", "#6cf7ce")
.attr("stop-opacity", 1);
gradient.append("svg:stop")
.attr("offset", "100%")
.attr("stop-color", "#40596F")
.attr("stop-opacity", 1);
chart.selectAll('.bar-year').data(years).enter()
.append('rect')
.classed('bar-year', true)
.attr('fill', 'url("#Gradient1")')
.attr('width', 23)
.attr('height', BuoyAnalysisData.axis.h)
.attr('x', BuoyAnalysisChart.barYearX)
.attr('y', 0)
chart.selectAll('.mask-year').data(years).enter()
.append('rect')
.classed('.mask-year', true)
.attr('fill', '#fff')
.attr('width', 25)
.attr('height', function(d) {
return BuoyAnalysisData.axis.scale(d.average);
})
.attr('x', function(d, i) {
return BuoyAnalysisChart.barYearX(d, i) - 1;
})
.attr('y', 0)
toggles.selectAll('div').data(years).enter()
.append('div')
.classed('year-toggle', true)
.text(function(d) {
return d.year.toString().slice(-2);
})
.attr('x', BuoyAnalysisChart.barYearX)
.attr('y', 180)
chart.append("g")
.classed('axis', true)
.classed('axis-fahrenheit', true)
.attr('transform', 'translate(24, 0)')
.attr('fill', '#000')
.call(BuoyAnalysisData.axis.fahrenheit);
chart.append("g")
.classed('axis', true)
.classed('axis-celsius', true)
.attr('transform', 'translate(871, 0)')
.call(BuoyAnalysisData.axis.celsius);
chart.append('text')
.classed('label-axis-y', true)
.attr('text-anchor', 'middle')
.text('F')
.attr('x', 10)
.attr('y', 15)
chart.append('text')
.classed('label-axis-y', true)
.attr('text-anchor', 'middle')
.text('C')
.attr('x', 885)
.attr('y', 15)
chart.selectAll('.bar-month').data(months).enter()
.append('rect')
.attr('fill', 'rgba(0, 0, 0, 0.2)')
.attr('width', 1)
.attr('height', function(d) {
return BuoyAnalysisData.axis.scaleInverted(d.average)
})
.attr('x', BuoyAnalysisChart.barMonthX)
.attr('y', function(d) {
return BuoyAnalysisData.axis.h - BuoyAnalysisData.axis.scaleInverted(d.average);
})
}
};

@ -1,12 +1,27 @@
var BuoyAnalysisData = { var BuoyAnalysisData = {
mapW: 450, mapW: 900,
mapH: 450, mapH: 600,
mapJson: {}, mapJson: {},
stationJson: {}, stationJson: {},
years: {
start: 1982,
end: 2015
},
axis: {
h: 200,
min: 100,
max: 0,
scale: null,
scaleInverted: null,
fahrenheit: null,
celsius: null
},
/** /**
* *
*/ */
@ -31,29 +46,79 @@ var BuoyAnalysisData = {
}); });
}, },
/**
*
*/
setAxisProperties: function() {
var json = BuoyAnalysisData.stationJson;
for (var id in json) {
for (var prop in json[id]) {
if (prop === 'id' || prop === 'lat' || prop === 'lon' || prop === 'name') {
continue;
}
for (var i = 0; i < 12; i++) {
if (json[id][prop]['m'][i] <= 0) {
continue;
}
if (json[id][prop]['m'][i] < BuoyAnalysisData.axis.min) {
BuoyAnalysisData.axis.min = json[id][prop]['m'][i];
}
if (json[id][prop]['m'][i] > BuoyAnalysisData.axis.max) {
BuoyAnalysisData.axis.max = json[id][prop]['m'][i];
}
}
}
}
// console.warn("MIN: " + BuoyAnalysisData.axis.min + ', MAX: ' + BuoyAnalysisData.axis.max)
BuoyAnalysisData.axis.scale = d3.scale.linear()
.domain([BuoyAnalysisData.axis.min, BuoyAnalysisData.axis.max])
.range([BuoyAnalysisData.axis.h, 0]);
BuoyAnalysisData.axis.scaleInverted = d3.scale.linear()
.domain([BuoyAnalysisData.axis.min, BuoyAnalysisData.axis.max])
.range([0, BuoyAnalysisData.axis.h]);
BuoyAnalysisData.axis.fahrenheit = d3.svg.axis()
.scale(BuoyAnalysisData.axis.scale)
.orient("left")
.tickFormat(function(d) { return Math.round(d * 9 / 5 + 32); })
.tickValues([10, 13, 15.5, 18.5, 21]);
BuoyAnalysisData.axis.celsius = d3.svg.axis()
.scale(BuoyAnalysisData.axis.scale)
.orient("right")
.tickValues([10, 13, 15.5, 18.5, 21]);
},
/** /**
* *
*/ */
calculateYearlyAverages: function(stations) { calculateYearlyAverages: function(stations) {
var sum, count, avg; var sum, count, avg;
var years = {}; var years = [];
for (var i = 1982; i < 2016; i++) { for (var year = BuoyAnalysisData.years.start; year <= BuoyAnalysisData.years.end; year++) {
sum = 0; sum = 0;
count = 0; count = 0;
stations.forEach(function(id) { stations.forEach(function(id) {
avg = BuoyAnalysisData.stationJson[id]['avgs' + i]; data = BuoyAnalysisData.stationJson[id]['avgs' + year];
if (avg === undefined || avg.y === 0) { if (data === undefined || data.y === 0) {
return; return;
} }
sum += avg.y; sum += data.y;
count++; count++;
}); });
years['y' + i] = (sum / count) || 0; years.push({ average: (sum / count) || 0, year: year });
} }
return years; return years;
@ -62,28 +127,29 @@ var BuoyAnalysisData = {
/** /**
* *
*/ */
calculateMonthlyAverages: function(stations, year) { calculateMonthlyAverages: function(stations) {
var sum, count, avg; var sum, count, data;
var months = {}; var months = [];
for (var i = 0; i < 12; i++) { for (var year = BuoyAnalysisData.years.start; year <= BuoyAnalysisData.years.end; year++) {
sum = 0; for (var month = 0; month < 12; month++) {
count = 0; sum = 0;
count = 0;
stations.forEach(function(id) { stations.forEach(function(id) {
avg = BuoyAnalysisData.stationJson[id]['avgs' + year]; data = BuoyAnalysisData.stationJson[id]['avgs' + year];
if (avg === undefined || avg.m[i] === 0) { if (data === undefined || data.m[month] === 0) {
return; return;
} }
sum += data.m[month];
count++;
});
sum += avg.m[i]; months.push({ average: (sum / count) || 0, month: month, year: year });
count++; }
}); };
months['m' + i] = (sum / count) || 0;
}
return months; return months;
} }

@ -0,0 +1,20 @@
//=============================
//
// IIFE ENTRY POINT
//
//=============================
(function() {
Promise.resolve()
.then(BuoyAnalysisData.populateMapData)
.then(BuoyAnalysisData.populateSrcFile)
.then(BuoyAnalysisData.setAxisProperties)
.then(BuoyAnalysisMap.drawMap)
.then(BuoyAnalysisMap.drawStations)
.then(BuoyAnalysisMap.drawReticle)
.then(BuoyAnalysisMap.findStationsUnderReticle)
.then(BuoyAnalysisBehaviors.attachBehaviors)
.then(BuoyAnalysisChart.draw)
})();

@ -0,0 +1,102 @@
'use strict';
var BuoyAnalysisMap = {
/**
*
*/
reticle: {
stations: [],
x: 400,
y: 300
},
/**
*
*/
projection: d3.geo.mercator()
.center([-122, 37.8])
.scale(2600)
.translate([BuoyAnalysisData.mapW / 2, BuoyAnalysisData.mapH / 2]),
/**
*
*/
drawMap: function() {
var path = d3.geo.path().projection(BuoyAnalysisMap.projection);
d3.select("svg#map").selectAll('path')
.data(BuoyAnalysisData.mapJson.features)
.enter().append('path')
.attr('d', path)
.attr('class', function(d) { return 'feature-' + d.properties.iso_3166_2; })
.classed('feature', true)
},
/**
*
*/
drawStations: function() {
var tmp;
var station;
var stations = [];
for (var prop in BuoyAnalysisData.stationJson) {
station = BuoyAnalysisData.stationJson[prop];
tmp = BuoyAnalysisMap.projection([station.lon, station.lat]);
station.x = tmp[0];
station.y = tmp[1];
stations.push(station);
}
d3.select("svg#map").selectAll('circle')
.data(stations)
.enter().append('circle')
.attr('cx', function(d) { return d.x; })
.attr('cy', function(d) { return d.y; })
.attr('r', 3)
.attr('id', function(d) { return 's' + d.id; })
.attr('fill', '#f00')
.attr('stroke', '#f00')
.attr('stroke-width', 5)
},
/**
*
*/
drawReticle: function() {
d3.select("svg#map").append('circle')
.attr('r', 50)
.attr('fill', 'rgba(200, 200, 200, 0.5)')
// .attr('stroke', '#f00')
.attr("transform", "translate(" + BuoyAnalysisMap.reticle.x + "," + BuoyAnalysisMap.reticle.y + ")")
.data([ {"x": BuoyAnalysisMap.reticle.x, "y": BuoyAnalysisMap.reticle.y } ])
.classed('reticle', true);
},
/**
*
*/
findStationsUnderReticle: function() {
var reticle = d3.select('.reticle').data()[0];
var dX, dY, squares, distance, station;
var stations = [];
for (var s in BuoyAnalysisData.stationJson) {
station = BuoyAnalysisData.stationJson[s];
dX = reticle.x - station.x;
dY = reticle.y - station.y;
squares = Math.pow(dX, 2) + Math.pow(dY, 2)
distance = Math.pow(squares, 0.5);
if (distance < 50) {
stations.push(s);
}
};
BuoyAnalysisMap.reticle.stations = stations;
}
};

@ -1,70 +0,0 @@
'use strict';
var BuoyAnalysisSvgMap = {
/**
*
*/
projection: d3.geo.mercator()
.center([-122, 38])
.scale(1960)
.translate([BuoyAnalysisData.mapW / 2, BuoyAnalysisData.mapH / 2]),
/**
*
*/
drawMap: function() {
var path = d3.geo.path().projection(BuoyAnalysisSvgMap.projection);
d3.select("svg#map").selectAll('.subunit')
.data(BuoyAnalysisData.mapJson.features)
.enter().append('path')
.attr('d', path)
.attr('fill', 'khaki')
.attr('stroke', 'lime');
},
/**
*
*/
drawStations: function() {
var tmp;
var station;
var stations = [];
for (var prop in BuoyAnalysisData.stationJson) {
station = BuoyAnalysisData.stationJson[prop];
tmp = BuoyAnalysisSvgMap.projection([station.lon, station.lat]);
station.x = tmp[0];
station.y = tmp[1];
stations.push(station);
}
d3.select("svg#map").selectAll('.station')
.data(stations)
.enter().append('circle')
.attr('cx', function(d) { return d.x; })
.attr('cy', function(d) { return d.y; })
.attr('r', 3)
.attr('id', function(d) { return 's' + d.id; })
.attr('fill', '#f00')
.attr('stroke', '#f00')
.attr('stroke-width', 5)
// .on("mouseover", startAnimateDetail)
// .on("mouseout", stopAnimateDetail)
},
/**
*
*/
drawReticle: function() {
d3.select("svg#map").append('circle')
.attr('r', 50)
.attr('fill', 'rgba(200, 200, 200, 0.5)')
.attr('stroke', '#f00')
.attr("transform", "translate(" + 100 + "," + 100 + ")")
.data([ {"x": 100, "y": 100} ])
.classed('reticle', true);
}
};

@ -1,67 +0,0 @@
'use strict';
var BuoyAnalysisUiDom = {
/**
*
*/
populateMonths: function() {
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
var div;
var bottom = document.querySelector('.container-bottom');
for (var i = 0; i < 12; i++) {
div = document.createElement('div');
div.className = 'month';
div.innerHTML = months[i];
bottom.appendChild(div);
}
},
/**
*
*/
populateStationDetail: function() {
var div, name, lat, lon;
var center = document.querySelector('.container-center');
var arr = [];
for (var prop in BuoyAnalysisData.stationJson) {
arr.push({
id: prop,
lat: BuoyAnalysisData.stationJson[prop].lat,
lon: BuoyAnalysisData.stationJson[prop].lon,
name: BuoyAnalysisData.stationJson[prop].name
});
}
arr.sort(function(a, b) {
return a.lon < b.lon;
});
arr.forEach(function(obj) {
name = document.createElement('span');
name.className = 'station-name';
name.innerHTML = obj.name;
lat = document.createElement('span');
lat.className = 'station-lat';
lat.innerHTML = obj.lat;
lon = document.createElement('span');
lon.className = 'station-lon';
lon.innerHTML = obj.lon;
div = document.createElement('div');
div.className = 'detail';
div.id = 'detail-' + obj.id;
div.style.border = '1px solid red'
div.appendChild(name);
div.appendChild(lat);
div.appendChild(lon);
center.appendChild(div);
});
}
};

@ -8,83 +8,121 @@
<style> <style>
* { * {
box-sizing:border-box; box-sizing:border-box;
font-family:'segoe ui'; font-family:'open sans';
letter-spacing:0.7px; letter-spacing:0.7px;
margin: 0; margin: 0;
padding: 0; padding: 0;
} }
#map { .main {
/*background: #098347;*/ height:900px;
height:450px; margin:50px auto;
width:450px; position:relative;
width:900px;
} }
.main { #map {
background:#e8fbfe;
border:1px solid #e8e8e8;
height:600px;
position:relative; position:relative;
height:550px; width:100%;
width:800px; z-index:0;
} }
.container-center { #chart {
height:450px; border:solid #e8e8e8;
left:450px; border-width:0 1px;
overflow:auto; cursor:pointer;
height:200px;
left:0;
position:absolute; position:absolute;
top:0; top:600px;
width:200px; width:100%;
} }
.container-right { #year-toggles {
background:lime; border:solid #e8e8e8;
bottom:0; border-width:0 1px 1px 1px;
height:100%; font-size:0;
height:30px;
padding-left:24px;
position:absolute; position:absolute;
right:0; top:800px;
width:150px; width:100%;
}
.year-toggle {
border:1px solid #e8e8e8;
color:#bbb;
cursor:pointer;
display:inline-block;
line-height:20px;
font-size:9px;
margin-right:2px;
text-align:center;
width:23px;
}
.year-toggle:hover {
background:#eee;
} }
.container-bottom { .feature {
background:salmon; fill:#dffbb8;
bottom:0; stroke:#bde484;
height:100px; }
padding-left:25px;
padding-top:70px; .reticle {
fill: rgba(153, 173, 40, 0.2);
stroke: #5D5336;
}
.reticle-sizer {
left:10px;
position:absolute; position:absolute;
width:650px; top:10px;
z-index:1;
} }
.month { .axis .domain {
background:#ff0; fill: none;
float:left; stroke: none;
font-size:11px;
height:30px;
line-height:30px;
text-align:center;
width:50px;
} }
.year { .axis .tick {
background:cadetblue; fill:#888;
height:60px; font-size:8px;
} }
.detail { .label-axis-y {
background:#ff0; font-size:10px;
transition:background 0.2s ease;
} }
.detail.active { input[type=range]{
background:#555; -webkit-appearance: none;
} }
.detail.obscured { input[type=range]::-webkit-slider-runnable-track {
opacity:0.2; width: 300px;
height: 2px;
background: #ddd;
border: none;
border-radius: 3px;
} }
.detail .station-lat, input[type=range]::-webkit-slider-thumb {
.detail .station-lon { background: #d8ebd3;
color:#aaa; border: 2px solid #5D5336;
border-radius: 50%;
height: 16px;
margin-top: -7px;
width: 16px;
-webkit-appearance: none;
}
input[type=range]:focus {
outline: none;
} }
</style> </style>
</head> </head>
@ -93,81 +131,35 @@
<div class="main"> <div class="main">
<svg id='map'></svg> <svg id='map'></svg>
<div class="container-center"> <input type="range" title='Reticle Size' class='reticle-sizer'>
<!-- <span class="label left">o</span>
<input type="range" title='Reticle Size'> <!-- <div class="container-center">
<span class="label left">o</span>
<span class="label right">O</span> <span class="label right">O</span>
<span class="label left">Slow</span> <span class="label left">Slow</span>
<input type="range" title='Animation Speed'> <input type="range" title='Animation Speed'>
<span class="label fast">Fast</span> <span class="label fast">Fast</span>
<hr> --> <hr>
<div class="title">Station Data</div> <div class="title">Station Data</div>
<div class="station-info"></div> <div class="station-info"></div>
</div> </div> -->
<div class="container-right"> <svg id="chart"></svg>
<!-- <svg id='yearly'></svg> --> <div id="year-toggles"></div>
<div class='year'>1980</div>
<!-- <div class='year'>1981</div>
<div class='year'>1982</div>
<div class='year'>1983</div>
<div class='year'>1984</div> -->
<div class='year'>1985</div>
<!-- <div class='year'>1986</div>
<div class='year'>1987</div>
<div class='year'>1988</div>
<div class='year'>1989</div> -->
<div class='year'>1990</div>
<!-- <div class='year'>1991</div>
<div class='year'>1992</div>
<div class='year'>1993</div>
<div class='year'>1994</div> -->
<div class='year'>1995</div>
<!-- <div class='year'>1996</div>
<div class='year'>1997</div>
<div class='year'>1998</div>
<div class='year'>1999</div> -->
<div class='year'>2000</div>
<!-- <div class='year'>2001</div>
<div class='year'>2002</div>
<div class='year'>2003</div>
<div class='year'>2004</div> -->
<div class='year'>2005</div>
<!-- <div class='year'>2006</div>
<div class='year'>2007</div>
<div class='year'>2008</div>
<div class='year'>2009</div> -->
<div class='year'>2010</div>
<!-- <div class='year'>2011</div>
<div class='year'>2012</div>
<div class='year'>2013</div>
<div class='year'>2014</div> -->
<div class='year'>2015</div>
</div>
<div class="container-bottom">
<!-- <svg id="monthly"></svg> -->
</div>
</div> </div>
<!-- <script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script> --> <!-- <script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script> -->
<script src="d3.min.js"></script> <script src="d3.min.js"></script>
<script src="client/data.js"></script> <script src="client/data.js"></script>
<script src="client/svg-map.js"></script> <script src="client/map.js"></script>
<script src="client/ui-behaviors.js"></script> <script src="client/behaviors.js"></script>
<script src="client/ui-dom.js"></script> <script src="client/chart.js"></script>
<script src="client/_init.js"></script> <script src="client/init.js"></script>
<!-- <script src="gradients-v1.js"></script> --> <!-- <script src="gradients-v1.js"></script> -->
<!-- <script src="gradients-v2.js"></script> --> <!-- <script src="gradients-v2.js"></script> -->
@ -196,7 +188,7 @@ http://www.gdal.org/ogr_sql.html
http://www.sarasafavi.com/intro-to-ogr-part-i-exploring-data.html http://www.sarasafavi.com/intro-to-ogr-part-i-exploring-data.html
--> -->
<h3>ETL Stage</h3> <!-- <h3>ETL Stage</h3> -->
</body> </body>
</html> </html>

@ -27,7 +27,7 @@
// .then(meteo.getAllMonths.bind(null, station, 2015)) // .then(meteo.getAllMonths.bind(null, station, 2015))
// .then(meteo.getAllNewest.bind(null, station, 2015)) // .then(meteo.getAllNewest.bind(null, station, 2015))
//===== Parse //===== Parse and write JSON years files
// .then(stations.parseStation.bind(null, station)) // .then(stations.parseStation.bind(null, station))
// .then(meteo.parseAllMonths.bind(null, station, 2015)) // .then(meteo.parseAllMonths.bind(null, station, 2015))
// .then(meteo.parseAllYears.bind(null, station, 1982, 2014)) // .then(meteo.parseAllYears.bind(null, station, 1982, 2014))

@ -29,8 +29,10 @@ var chalk = require('chalk');
module.exports = { module.exports = {
// 13 - WTMP (C) // Zero indexed column.
columnToAverage: 13, // #YY MM DD hh mm WDIR WSPD GST WVHT DPD APD MWD PRES ATMP WTMP DEWP VIS TIDE
// 14 - WTMP (C)
columnToAverage: 14,
/** /**
* *
@ -100,7 +102,6 @@ module.exports = {
months[row[1] - 1].push(parseFloat(row[col])); months[row[1] - 1].push(parseFloat(row[col]));
}); });
// Get the average for each collection of values in each day of the year. // Get the average for each collection of values in each day of the year.
months.forEach(function(values, index) { months.forEach(function(values, index) {
sum = 0; sum = 0;
@ -220,7 +221,7 @@ module.exports = {
IO.read(meteo.dirs.json + station + '-' + year + '.json') IO.read(meteo.dirs.json + station + '-' + year + '.json')
.then(module.exports.parse) .then(module.exports.parse)
.then(function(arr) { .then(function(arr) {
return module.exports.getYearlyAverages(arr, module.exports.columnToAverage); return module.exports.getYearlyAverages(arr, module.exports.columnToAverage, station === '46232');
}) })
); );
} }
@ -250,7 +251,7 @@ module.exports = {
if (index === stations.ids.length) { if (index === stations.ids.length) {
// if (index === 1) { // if (index === 1) {
// IO.write('final-output.json', JSON.stringify(finalResult, null, 4)); // IO.write('final-output.json', JSON.stringify(finalResult, null, 4));
IO.write('final-output.json', JSON.stringify(finalResult)); IO.write('_stations.json', JSON.stringify(finalResult));
return; return;
} }

@ -3,11 +3,26 @@
*/ */
module.exports = { module.exports = {
/** /**
* * Different years have added new columns.
* 46054h1998 --> 16 cols, Missing mm (col 5). Missing TIDE (col 18)
* 46054h2004 --> 17 cols. Added TIDE. Missing mm (col 5)
* 46054h2006 --> 18 cols, Added mm.
*/ */
splitLine: function(str) { parseLine: function(str) {
var arr = str.split(/\s+/); var arr = str.trim().split(/\s+/);
// REMOVE THIS LINE? Ben 290116
arr.filter(function(val) { return (val.length > 0); }) arr.filter(function(val) { return (val.length > 0); })
// Add TIDE value if not there
if (arr.length === 16) {
arr.push('99.00');
}
// Add mm value if not there
if (arr.length === 17) {
arr.splice(4, 0, '00');
}
return arr; return arr;
}, },
@ -24,7 +39,7 @@ module.exports = {
if (len > 8) { if (len > 8) {
for (var i = 0; i < len; i++) { for (var i = 0; i < len; i++) {
cols = module.exports.splitLine(lines[i]); cols = module.exports.parseLine(lines[i]);
cols.length > 0 ? arr.push(cols) : null; cols.length > 0 ? arr.push(cols) : null;
} }
} }

@ -30,6 +30,7 @@ module.exports = {
'46014', '46014',
'46022', '46022',
'46025', '46025',
'46026',
'46027', '46027',
'46028', '46028',
'46042', '46042',

Loading…
Cancel
Save