Commit 8461ec19 authored by Porter Libby's avatar Porter Libby
Browse files

hosts merge

parents b315ba23 e1da47ef
...@@ -255,6 +255,7 @@ function getReadings(spot_id,value){ ...@@ -255,6 +255,7 @@ function getReadings(spot_id,value){
document.getElementById("button_csv").disabled = true; document.getElementById("button_csv").disabled = true;
//togglediv('#spots-ls','spots-button'); //togglediv('#spots-ls','spots-button');
if (query_selection[3].length > 0){
$.ajax({ $.ajax({
type: 'GET', type: 'GET',
url: '/readings', url: '/readings',
...@@ -272,7 +273,7 @@ function getReadings(spot_id,value){ ...@@ -272,7 +273,7 @@ function getReadings(spot_id,value){
var color = getRandomColor(); var color = getRandomColor();
query_data = processReadings(readings); query_data = processReadings(readings);
//createPoints(query_data, color); createPoints(query_data, color);
createGraphReading(query_data, query_selection, color); createGraphReading(query_data, query_selection, color);
var dataview = document.getElementById("dataView") var dataview = document.getElementById("dataView")
...@@ -289,6 +290,9 @@ function getReadings(spot_id,value){ ...@@ -289,6 +290,9 @@ function getReadings(spot_id,value){
console.log(xhr.responseText); console.log(xhr.responseText);
} }
}); });
}else{
createGraphReading(null, null, null);
}
} }
// Streaming-specific routes // Streaming-specific routes
function getStreamingsHosts(sector_id){ function getStreamingsHosts(sector_id){
...@@ -588,6 +592,7 @@ function processReadings(readings){ ...@@ -588,6 +592,7 @@ function processReadings(readings){
} }
if (current_data.length != 0){ if (current_data.length != 0){
const timestamps = [...new Set(current_data.map(item => item.recordtime))]; // use earlier date to base data on; const timestamps = [...new Set(current_data.map(item => item.recordtime))]; // use earlier date to base data on;
console.log(timestamps);
var min = timestamps.reduce(function (a, b) { return a < b ? a : b; }); var min = timestamps.reduce(function (a, b) { return a < b ? a : b; });
out_node = {}; out_node = {};
...@@ -595,10 +600,14 @@ function processReadings(readings){ ...@@ -595,10 +600,14 @@ function processReadings(readings){
if (current_data[j].recordtime = min || !out_node.recordtime){ if (current_data[j].recordtime = min || !out_node.recordtime){
out_node.Spot = current_data[j].spotid; out_node.Spot = current_data[j].spotid;
out_node.recordtime = current_data[j].recordtime; out_node.recordtime = current_data[j].recordtime;
out_node.tripname = current_data[j].tripname;
out_node.sitename = current_data[j].sitename;
out_node.sectorname = current_data[j].sectorname;
out_node.elevation = current_data[j].elevation; out_node.elevation = current_data[j].elevation;
out_node.longitude = current_data[j].longitude; out_node.longitude = current_data[j].longitude;
out_node.latitude = current_data[j].latitude; out_node.latitude = current_data[j].latitude;
out_node.accuracy = current_data[j].accuracy; out_node.accuracy = current_data[j].accuracy; // 0 to 8
if (!out_node[current_data[j].sensortype]){ if (!out_node[current_data[j].sensortype]){
out_node[current_data[j].sensortype] = current_data[j].value; out_node[current_data[j].sensortype] = current_data[j].value;
} }
......
...@@ -33,45 +33,68 @@ function createGraphReading(dataset, q_arr, color){ ...@@ -33,45 +33,68 @@ function createGraphReading(dataset, q_arr, color){
var parent = document.getElementById('readingStats'); var parent = document.getElementById('readingStats');
parent.innerHTML = ""; parent.innerHTML = "";
if (dataset != null){
// create title // create title
var trip = q_arr[0]; var trip = dataset[0].tripname;
var site = q_arr[1]; var site = dataset[0].sitename;
var sector = q_arr[2]; var sector = dataset[0].sectorname;
var title = document.createElement('h'); var title = document.createElement('h');
title.innerHTML = "Trip " + trip + ", Site " + site + ", Sector " + sector; title.innerHTML = "Spots from " + trip + ", " + site + ", " + sector;
parent.append(title); parent.append(title);
const table = document.createElement('table'); const table = document.createElement('table');
var tableHTML = ""; var tableHTML = "";
var keys = Object.keys(dataset[0]); var keys = ["Spot","Date","Time","elevation","longitude","latitude","accuracy"];
for(x=9;x<Object.keys(dataset[0]).length;x++){
keys.push(Object.keys(dataset[0])[x]);
}
tableHTML += createTableHeader(keys); tableHTML += createTableHeader(keys);
for ( x = 0 ; x < dataset.length ; x++){ for ( x = 0 ; x < dataset.length ; x++){
prop_arr = []; prop_arr = [];
for (y=0;y<keys.length;y++){ for (y=0;y<keys.length;y++){
if (keys[y] == "Date"){
date = new Date(dataset[x]["recordtime"]);
prop_arr.push(date.getFullYear()+'-' + (date.getMonth()+1) + '-'+date.getDate());
prop_arr.push(date.toLocaleTimeString('en-US'));
y++;
}else{
prop_arr.push(dataset[x][keys[y]]); prop_arr.push(dataset[x][keys[y]]);
} }
}
tableHTML += createTableRow(prop_arr); tableHTML += createTableRow(prop_arr);
} }
// append table to parent // append table to parent
table.innerHTML = tableHTML; table.innerHTML = tableHTML;
parent.append(table); parent.append(table);
}
} }
function createTableRow(arr){ function createTableRow(arr){
text = '<tr>'; text = '<tr>';
for (j=0;j<arr.length;j++){ for (j=0;j<arr.length;j++){
if(j==0){
text += "<th>Spot " + arr[j] + "</th>"
}else{
text += "<td>" + arr[j] + "</td>" text += "<td>" + arr[j] + "</td>"
} }
}
text += '</tr>'; text += '</tr>';
return text; return text;
} }
function createTableHeader(arr){ function createTableHeader(arr){
text = '<tr>'; text = '<tr>';
for (j=0;j<arr.length;j++){ for (j=0;j<arr.length;j++){
if(j==0){
text += "<th>" + "" + "</th>"
}else{
text += "<th>" + arr[j] + "</th>" text += "<th>" + arr[j] + "</th>"
} }
}
text += '</tr>'; text += '</tr>';
return text; return text;
} }
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
id='nav-button-map' id='nav-button-map'
class='nav-button-select nav-view-button' class='nav-button-select nav-view-button'
type="image" type="image"
src="img/map-icon.png" src="img/globe-icon.png"
alt="Submit" alt="Submit"
width="24" height="24"> width="24" height="24">
</div> </div>
...@@ -78,7 +78,7 @@ ...@@ -78,7 +78,7 @@
class='nav-button-idle nav-view-button' class='nav-button-idle nav-view-button'
onclick='switchToMap()' onclick='switchToMap()'
type="image" type="image"
src="img/map-icon.png" src="img/globe-icon.png"
alt="Submit" alt="Submit"
width="24" height="24"> width="24" height="24">
</div> </div>
...@@ -183,7 +183,7 @@ ...@@ -183,7 +183,7 @@
class='nav-button-idle nav-view-button' class='nav-button-idle nav-view-button'
onclick='switchToMap()' onclick='switchToMap()'
type="image" type="image"
src="img/map-icon.png" src="img/globe-icon.png"
alt="Submit" alt="Submit"
width="24" height="24"> width="24" height="24">
</div> </div>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment