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';
var BuoyAnalysisUiBehaviors = {
var BuoyAnalysisBehaviors = {
stationClick: function() {
},
@ -10,32 +10,33 @@ var BuoyAnalysisUiBehaviors = {
},
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) {
var dX, dY, squares, distance, station;
var stations = [];
reticleDragEnd: function() {
var x = d3.mouse(this)[0];
var y = d3.mouse(this)[1];
for (var s in BuoyAnalysisData.stationJson) {
station = BuoyAnalysisData.stationJson[s];
if (x < 200) {
x = 200;
}
dX = d.x - station.x;
dY = d.y - station.y;
if (x > 800) {
x = 800;
}
squares = Math.pow(dX, 2) + Math.pow(dY, 2)
distance = Math.pow(squares, 0.5);
if (distance < 50) {
stations.push(s);
}
};
var d = d3.select('.reticle').data()[0];
d.x = x;
d.y = y;
BuoyAnalysisData.calculateYearlyAverages(stations);
BuoyAnalysisData.calculateMonthlyAverages(stations, 1982);
d3.select('.reticle')
.transition()
.duration(300)
.attr('transform', 'translate(' + [ d.x, d.y ] + ')')
BuoyAnalysisMap.findStationsUnderReticle();
BuoyAnalysisChart.draw();
},
reticleResize: function() {
@ -43,21 +44,18 @@ var BuoyAnalysisUiBehaviors = {
},
attachBehaviors: function() {
// d3.selectAll('.detail')
// .on('mouseover', startAnimateStation)
// .on('mouseout', stopAnimateStation);
d3.select('.reticle')
.call(d3.behavior.drag()
.on('drag', BuoyAnalysisUiBehaviors.reticleDrag)
.on('dragend', BuoyAnalysisUiBehaviors.reticleDragEnd)
);
d3.select('#map')
.on('click', BuoyAnalysisBehaviors.reticleDragEnd)
// .call(d3.behavior.drag()
// .on('drag', BuoyAnalysisBehaviors.reticleDrag)
// .on('dragend', BuoyAnalysisBehaviors.reticleDragEnd)
// );
},
};
// d3.selectAll('.detail')
// .on('mouseover', startAnimateStation)
// .on('mouseout', stopAnimateStation);
// function startAnimateStation() {
// 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 = {
mapW: 450,
mapW: 900,
mapH: 450,
mapH: 600,
mapJson: {},
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) {
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;
count = 0;
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;
}
sum += avg.y;
sum += data.y;
count++;
});
years['y' + i] = (sum / count) || 0;
years.push({ average: (sum / count) || 0, year: year });
}
return years;
@ -62,28 +127,29 @@ var BuoyAnalysisData = {
/**
*
*/
calculateMonthlyAverages: function(stations, year) {
var sum, count, avg;
var months = {};
calculateMonthlyAverages: function(stations) {
var sum, count, data;
var months = [];
for (var i = 0; i < 12; i++) {
sum = 0;
count = 0;
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) {
avg = BuoyAnalysisData.stationJson[id]['avgs' + year];
stations.forEach(function(id) {
data = BuoyAnalysisData.stationJson[id]['avgs' + year];
if (avg === undefined || avg.m[i] === 0) {
return;
}
if (data === undefined || data.m[month] === 0) {
return;
}
sum += data.m[month];
count++;
});
sum += avg.m[i];
count++;
});
months['m' + i] = (sum / count) || 0;
}
months.push({ average: (sum / count) || 0, month: month, year: year });
}
};
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>
* {
box-sizing:border-box;
font-family:'segoe ui';
font-family:'open sans';
letter-spacing:0.7px;
margin: 0;
padding: 0;
}
#map {
/*background: #098347;*/
height:450px;
width:450px;
.main {
height:900px;
margin:50px auto;
position:relative;
width:900px;
}
.main {
#map {
background:#e8fbfe;
border:1px solid #e8e8e8;
height:600px;
position:relative;
height:550px;
width:800px;
width:100%;
z-index:0;
}
.container-center {
height:450px;
left:450px;
overflow:auto;
#chart {
border:solid #e8e8e8;
border-width:0 1px;
cursor:pointer;
height:200px;
left:0;
position:absolute;
top:0;
width:200px;
top:600px;
width:100%;
}
.container-right {
background:lime;
bottom:0;
height:100%;
#year-toggles {
border:solid #e8e8e8;
border-width:0 1px 1px 1px;
font-size:0;
height:30px;
padding-left:24px;
position:absolute;
right:0;
width:150px;
top:800px;
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 {
background:salmon;
bottom:0;
height:100px;
padding-left:25px;
padding-top:70px;
.feature {
fill:#dffbb8;
stroke:#bde484;
}
.reticle {
fill: rgba(153, 173, 40, 0.2);
stroke: #5D5336;
}
.reticle-sizer {
left:10px;
position:absolute;
width:650px;
top:10px;
z-index:1;
}
.month {
background:#ff0;
float:left;
font-size:11px;
height:30px;
line-height:30px;
text-align:center;
width:50px;
.axis .domain {
fill: none;
stroke: none;
}
.year {
background:cadetblue;
height:60px;
.axis .tick {
fill:#888;
font-size:8px;
}
.detail {
background:#ff0;
transition:background 0.2s ease;
.label-axis-y {
font-size:10px;
}
.detail.active {
background:#555;
input[type=range]{
-webkit-appearance: none;
}
.detail.obscured {
opacity:0.2;
input[type=range]::-webkit-slider-runnable-track {
width: 300px;
height: 2px;
background: #ddd;
border: none;
border-radius: 3px;
}
.detail .station-lat,
.detail .station-lon {
color:#aaa;
input[type=range]::-webkit-slider-thumb {
background: #d8ebd3;
border: 2px solid #5D5336;
border-radius: 50%;
height: 16px;
margin-top: -7px;
width: 16px;
-webkit-appearance: none;
}
input[type=range]:focus {
outline: none;
}
</style>
</head>
@ -93,81 +131,35 @@
<div class="main">
<svg id='map'></svg>
<div class="container-center">
<!-- <span class="label left">o</span>
<input type="range" title='Reticle Size'>
<input type="range" title='Reticle Size' class='reticle-sizer'>
<!-- <div class="container-center">
<span class="label left">o</span>
<span class="label right">O</span>
<span class="label left">Slow</span>
<input type="range" title='Animation Speed'>
<span class="label fast">Fast</span>
<hr> -->
<hr>
<div class="title">Station Data</div>
<div class="station-info"></div>
</div>
<div class="container-right">
<!-- <svg id='yearly'></svg> -->
<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> -->
<svg id="chart"></svg>
<div id="year-toggles"></div>
</div>
<!-- <script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script> -->
<script src="d3.min.js"></script>
<script src="client/data.js"></script>
<script src="client/svg-map.js"></script>
<script src="client/ui-behaviors.js"></script>
<script src="client/ui-dom.js"></script>
<script src="client/_init.js"></script>
<script src="client/map.js"></script>
<script src="client/behaviors.js"></script>
<script src="client/chart.js"></script>
<script src="client/init.js"></script>
<!-- <script src="gradients-v1.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
-->
<h3>ETL Stage</h3>
<!-- <h3>ETL Stage</h3> -->
</body>
</html>

@ -27,7 +27,7 @@
// .then(meteo.getAllMonths.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(meteo.parseAllMonths.bind(null, station, 2015))
// .then(meteo.parseAllYears.bind(null, station, 1982, 2014))

@ -29,8 +29,10 @@ var chalk = require('chalk');
module.exports = {
// 13 - WTMP (C)
columnToAverage: 13,
// Zero indexed column.
// #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]));
});
// Get the average for each collection of values in each day of the year.
months.forEach(function(values, index) {
sum = 0;
@ -220,7 +221,7 @@ module.exports = {
IO.read(meteo.dirs.json + station + '-' + year + '.json')
.then(module.exports.parse)
.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 === 1) {
// 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;
}

@ -3,11 +3,26 @@
*/
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) {
var arr = str.split(/\s+/);
parseLine: function(str) {
var arr = str.trim().split(/\s+/);
// REMOVE THIS LINE? Ben 290116
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;
},
@ -24,7 +39,7 @@ module.exports = {
if (len > 8) {
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;
}
}

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

Loading…
Cancel
Save