Commit 5ecb4657 authored by Porter Libby's avatar Porter Libby
Browse files

start working on multiple readings

parent 5bd9e98e
......@@ -13,6 +13,8 @@ var query_type = null; // 0 = reading, 1 = streaming
var query_selection = [null,null,null,null,null,null]; // trip, site, sector, spot, platform, date
var query_data = null;
var current_spots = [];
var placeholderHTML = "<div style='float: left; width: 100%; height: 100%; text-align:center; padding-top:20px;color: var(--themep)'>Organizing numbers...</div><div class='lds-ellipsis'><div></div><div></div><div></div><div></div></div>";
var placeholder2HTML = "<div style='float: left; width: 100%; height: 100%; text-align:center; padding-top:20px;color: var(--themep)'>Adding points to Chart and Map...</div><div class='lds-ellipsis'><div></div><div></div><div></div><div></div></div>";
......@@ -238,6 +240,9 @@ function getReadingsDates(platformid){
});
}
function getReadings(spot_id){
if (!current_spots.includes(spot_id)){
current_spots.push(spot_id);
}
document.getElementById('data-prompt').innerHTML = "Pick a set of data to visualize";
document.getElementById('reading').innerHTML = placeholderHTML;
document.getElementById("button_permalink").disabled = true;
......@@ -245,11 +250,11 @@ function getReadings(spot_id){
togglediv('#spots-ls','spots-button');
query_selection[3] = spot_id;
query_selection[3] = current_spots;
$.ajax({
type: 'GET',
url: '/readings',
data: {spotid: spot_id, sectorid: query_selection[2], siteid: query_selection[1], tripid: query_selection[0]},
data: {spotids: current_spots, sectorid: query_selection[2], siteid: query_selection[1], tripid: query_selection[0]},
success: function(response) {
var readings = [];
......@@ -261,10 +266,10 @@ function getReadings(spot_id){
console.info('Loaded ' + readings.length + " points.");
var color = getRandomColor();
query_data = readings;
query_data = processReadings(readings);
createPoints([readings[0]], color);
createGraphReading(readings, query_selection, color);
//createPoints([readings[0]], color);
//createGraphReading(readings, query_selection, color);
var dataview = document.getElementById("dataView")
dataview.querySelector("#nav-button-graph").classList.add("new_data_button");
......@@ -520,6 +525,39 @@ function togglediv(target_div,btn_span){
$(target_div).slideToggle();
}
}
function processReadings(readings){
spotids = query_selection[3];
spots_out = [];
for (x=0;x<spotids.length;x++){
current_data = [];
for(y=0;y<readings.length;y++){
if (readings[y].spotid == spotids[x]){
current_data.push(readings[y]);
}
}
const timestamps = [...new Set(current_data.map(item => item.recordtime))]; // use earlier date to base data on;
var min = timestamps.reduce(function (a, b) { return a < b ? a : b; });
out_node = {};
for(j=0;j<current_data.length;j++){
if (current_data[j].recordtime = min || !out_node.recordtime){
out_node.recordtime = current_data[j].recordtime;
out_node.elevation = current_data[j].elevation;
out_node.longitude = current_data[j].longitude;
out_node.latitude = current_data[j].latitude;
out_node.accuracy = current_data[j].accuracy;
out_node.spotid = current_data[j].spotid;
if (!out_node[current_data[j].sensortype]){
out_node[current_data[j].sensortype] = current_data[j].value;
}
}else if (!out_node[current_data[j].sensortype]){
out_node[current_data[j].sensortype] = current_data[j].value;
}
}
spots_out.push(out_node);
}
return spots_out;
}
function loadQuery(params){
console.info('Loading query from permalink...')
document.getElementById("button_permalink").disabled = true;
......
......@@ -48,22 +48,39 @@ function createGraphReading(dataset, q_arr, color){
const table = document.createElement('table');
// create headings
var tableHTML = "<tr><th> Spot </th><th>Latitude </th><th> Longitude </th><th> Elevation </th><th> Accuracy </th>";
for (x=0;x<dataset.length;x++){
tableHTML += "<th>" + dataset[x].sensortype + "</th>";
var table_arr = [['spot','latitude','longitude','elevation','accuracy']];
for (x=0;x<dataset[0].length;x++){
if (!table_arr.includes(dataset[0][x].sensortype)){
table_arr[0].push(dataset[0][x].sensortype);
}
}
tableHTML += "</tr>";
// create values
tableHTML += "<tr><th>" + spot + "</th><th>" + dataset[0].latitude + "</th><th>" + dataset[0].longitude + "</th><th>" + dataset[0].elevation + "</th><th>" + dataset[0].accuracy + "</th>";
for (x=0;x<dataset.length;x++){
tableHTML += "<th> " + dataset[x].value + "</th>";
current_dataset = dataset[x];
new_row = [];
new_row.push(current_dataset[0].spotid);
new_row.push(current_dataset[0].latitude);
new_row.push(current_dataset[0].longitude);
new_row.push(current_dataset[0].elevation);
new_row.push(current_dataset[0].accuracy);
for (y=0;y<current_dataset.length;y++){
current_record = current_dataset[y];
for(t in table_arr[0]){
if (current_record.sensortype == table_arr[0][t] && !new_row[t]){
new_row.push(current_record.value);
}
}
}
table_arr.push(new_row);
}
tableHTML += "</tr>";
console.log('data to render')
console.log(table_arr);
// append table to parent
table.innerHTML = tableHTML;
parent.append(table);
//table.innerHTML = tableHTML;
//parent.append(table);
}
function createGraphStreaming(dataset, title,color){
......
......@@ -83,8 +83,22 @@ function createRadioElementSectors( mode, name, checked, label, id ) {
}
function createRadioElementSpots( mode, name, checked, label,id ) {
var f = "getReadings";
return createRadioElement(name, id, label, f);
//return createRadioElement(name, id, label, f);
console.log(name,id,label);
var radioHtml = '<div class="elem-div elem-0">'
if (typeof id === 'string' || id instanceof String){
radioHtml += '<input class="data-radio form-radio" onchange="'+ f +'(';
radioHtml += "'" + id + "'";
radioHtml +=')" type="checkbox" name="' + name + '" id="' + label + '" />';
}else{
radioHtml += '<input class="data-radio form-radio" onchange="'+ f +'(' + id + ')" type="checkbox" name="' + name + '" id="' + label + '" />';
}
radioHtml += '<label for="' + label + '">';
radioHtml += '<strong>'+ label + "</strong>";
radioHtml += '<span class="detailed_info"> (ID: ' + id +')</span>';
radioHtml += '</label></div>';
return radioHtml;
}
function createRadioElementStreamingsPlatforms( mode, name, checked, id, label ) {
var f = "getStreamingsDates";
......
......@@ -78,7 +78,24 @@ 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 +';');
pool.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 spotid='+ request.query.spotid +';', (error, results) => {
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 ';
if (request.query.spotids.length > 1){
query += "(";
}
for(x=0;x<request.query.spotids.length;x++){
if (x > 0){
query += " OR ";
}
query += 'spotid='+ request.query.spotids[x];
}
if (request.query.spotids.length > 1){
query += ")";
}
query += ';';
console.info("Database:" + query);
pool.query(query, (error, results) => {
if (error) {
throw error
}
......
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