Commit 19b769d1 authored by Porter Libby's avatar Porter Libby
Browse files

fix null array of spots

parent 34d3135e
......@@ -255,40 +255,44 @@ function getReadings(spot_id,value){
document.getElementById("button_csv").disabled = true;
//togglediv('#spots-ls','spots-button');
$.ajax({
type: 'GET',
url: '/readings',
data: {spotids: query_selection[3], sectorid: query_selection[2], siteid: query_selection[1], tripid: query_selection[0]},
success: function(response) {
var readings = [];
for(x = 0; x < response.length; x++){
readings.push(response[x]);
if (query_selection[3].length > 0){
$.ajax({
type: 'GET',
url: '/readings',
data: {spotids: query_selection[3], sectorid: query_selection[2], siteid: query_selection[1], tripid: query_selection[0]},
success: function(response) {
var readings = [];
for(x = 0; x < response.length; x++){
readings.push(response[x]);
}
console.info('DATA - readings');
console.info('Loaded ' + readings.length + " data points.");
var color = getRandomColor();
query_data = processReadings(readings);
//createPoints(query_data, color);
createGraphReading(query_data, query_selection, color);
var dataview = document.getElementById("dataView")
dataview.querySelector("#nav-button-graph").classList.add("new_data_button");
dataview.querySelector("#nav-button-map").classList.add("new_data_button");
document.getElementById('reading').innerHTML = "";
document.getElementById('data-prompt').innerHTML = "Loaded "+query_selection[3].length+" spots to the graph and map! <br> Pick some more?";
document.getElementById("button_permalink").disabled = false;
document.getElementById("button_csv").disabled = false;
},
error: function(xhr, status, err) {
console.log(xhr.responseText);
}
console.info('DATA - readings');
console.info('Loaded ' + readings.length + " data points.");
var color = getRandomColor();
query_data = processReadings(readings);
//createPoints(query_data, color);
createGraphReading(query_data, query_selection, color);
var dataview = document.getElementById("dataView")
dataview.querySelector("#nav-button-graph").classList.add("new_data_button");
dataview.querySelector("#nav-button-map").classList.add("new_data_button");
document.getElementById('reading').innerHTML = "";
document.getElementById('data-prompt').innerHTML = "Loaded "+query_selection[3].length+" spots to the graph and map! <br> Pick some more?";
document.getElementById("button_permalink").disabled = false;
document.getElementById("button_csv").disabled = false;
},
error: function(xhr, status, err) {
console.log(xhr.responseText);
}
});
});
}else{
createGraphReading(null, null, null);
}
}
// Streaming-specific routes
function getStreamingsPlatforms(sector_id){
......@@ -541,6 +545,7 @@ function processReadings(readings){
}
if (current_data.length != 0){
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; });
out_node = {};
......
......@@ -33,32 +33,34 @@ function createGraphReading(dataset, q_arr, color){
var parent = document.getElementById('readingStats');
parent.innerHTML = "";
// create title
var trip = q_arr[0];
var site = q_arr[1];
var sector = q_arr[2];
if (dataset != null){
// create title
var trip = q_arr[0];
var site = q_arr[1];
var sector = q_arr[2];
var title = document.createElement('h');
title.innerHTML = "Trip " + trip + ", Site " + site + ", Sector " + sector;
parent.append(title);
var title = document.createElement('h');
title.innerHTML = "Trip " + trip + ", Site " + site + ", Sector " + sector;
parent.append(title);
const table = document.createElement('table');
var tableHTML = "";
var keys = Object.keys(dataset[0]);
tableHTML += createTableHeader(keys);
const table = document.createElement('table');
var tableHTML = "";
var keys = Object.keys(dataset[0]);
tableHTML += createTableHeader(keys);
for ( x = 0 ; x < dataset.length ; x++){
prop_arr = [];
for (y=0;y<keys.length;y++){
prop_arr.push(dataset[x][keys[y]]);
for ( x = 0 ; x < dataset.length ; x++){
prop_arr = [];
for (y=0;y<keys.length;y++){
prop_arr.push(dataset[x][keys[y]]);
}
tableHTML += createTableRow(prop_arr);
}
tableHTML += createTableRow(prop_arr);
// append table to parent
table.innerHTML = tableHTML;
parent.append(table);
}
// append table to parent
table.innerHTML = tableHTML;
parent.append(table);
}
function createTableRow(arr){
text = '<tr>';
for (j=0;j<arr.length;j++){
......
......@@ -77,9 +77,9 @@ const getReadingsDates = (request, response) => {
})
}
const getReadings = (request, response) => {
console.info("Database: SELECT tripid,siteid,sectorid,spotid,platformid,(SELECT sensortype FROM fieldday_sensor where sensorid=fieldday_reading.sensorid),recordtime,latitude,longitude,elevation,accuracy,satellites,quality,value,value_2,value_3,value_4,value_5,value_6 from fieldday_reading where tripid="+ (request.query.tripid) +' and siteid='+ (request.query.siteid) +' and sectorid='+ request.query.sectorid + ' and spotid='+ request.query.spotid +';');
console.info("Database: SELECT tripid,siteid,sectorid,spotid,platformid,sensorid,(SELECT sensortype FROM fieldday_sensor where sensorid=fieldday_reading.sensorid),recordtime,latitude,longitude,elevation,accuracy,satellites,quality,value,value_2,value_3,value_4,value_5,value_6 from fieldday_reading where tripid="+ (request.query.tripid) +' and siteid='+ (request.query.siteid) +' and sectorid='+ request.query.sectorid + ' and spotid='+ request.query.spotid +';');
var query = "SELECT tripid,siteid,sectorid,spotid,platformid,(SELECT sensortype FROM fieldday_sensor where sensorid=fieldday_reading.sensorid),recordtime,latitude,longitude,elevation,accuracy,satellites,quality,value,value_2,value_3,value_4,value_5,value_6 from fieldday_reading where tripid="+ (request.query.tripid) +' and siteid='+ (request.query.siteid) +' and sectorid='+ request.query.sectorid + ' and ';
var query = "SELECT tripid,siteid,sectorid,spotid,platformid,sensorid,(SELECT sensortype FROM fieldday_sensor where sensorid=fieldday_reading.sensorid),recordtime,latitude,longitude,elevation,accuracy,satellites,quality,value,value_2,value_3,value_4,value_5,value_6 from fieldday_reading where tripid="+ (request.query.tripid) +' and siteid='+ (request.query.siteid) +' and sectorid='+ request.query.sectorid + ' and ';
if (request.query.spotids.length > 1){
query += "(";
}
......
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