Commit b315ba23 authored by Porter Libby's avatar Porter Libby
Browse files

work on adding host

parent 34d3135e
......@@ -24,6 +24,7 @@ app.get('/spots', q.getSpots);
app.get('/readingsplatforms', q.getReadingsPlatforms);
app.get('/readingsdates', q.getReadingsDates);
app.get('/readings', q.getReadings);
app.get('/streamingshosts', q.getStreamingsHosts);
app.get('/streamingsplatforms', q.getStreamingsPlatforms);
app.get('/streamingsdates', q.getStreamingsDates);
app.get('/streamings', q.getStreamings);
......
......@@ -10,7 +10,7 @@
// GET trips -> RENDER trips -> SELECT trip -> GET sites -> RENDER sites -> SELECT site ...
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_selection = [null,null,null,null,null,null]; // trip, site, sector, spot/host, platform, date
var query_data = null;
......@@ -291,9 +291,9 @@ function getReadings(spot_id,value){
});
}
// Streaming-specific routes
function getStreamingsPlatforms(sector_id){
function getStreamingsHosts(sector_id){
document.getElementById('data-prompt').innerHTML = "Select a platform to see recorded data.";
document.getElementById('streamingplatform').innerHTML = placeholderHTML;
document.getElementById('streaminghost').innerHTML = placeholderHTML;
resetElements(['streamingdates','streaming','reading']);
document.getElementById("button_permalink").disabled = true;
document.getElementById("button_csv").disabled = true;
......@@ -304,8 +304,37 @@ function getStreamingsPlatforms(sector_id){
$.ajax({
type: 'GET',
url: '/streamingsplatforms',
url: '/streamingshosts',
data: {sectorid: sector_id, siteid: query_selection[1], tripid: query_selection[0]},
success: function(response) {
var hosts = [];
for(x = 0; x < response.length; x++){
hosts.push(response[x]);
}
console.info('DATA - HOSTS');
console.table(response);
renderStreamingsHosts(hosts);
},
error: function(xhr, status, err) {
console.log(xhr.responseText);
}
});
}
function getStreamingsPlatforms(host_id){
document.getElementById('data-prompt').innerHTML = "Select a platform to see recorded data.";
document.getElementById('streamingplatform').innerHTML = placeholderHTML;
resetElements(['streamingdates','streaming','reading']);
document.getElementById("button_permalink").disabled = true;
document.getElementById("button_csv").disabled = true;
togglediv('#streamingshosts-ls','streamingshosts-button');
query_selection[3] = host_id;
$.ajax({
type: 'GET',
url: '/streamingsplatforms',
data: {hostid: host_id, sectorid: query_selection[2], siteid: query_selection[1], tripid: query_selection[0]},
success: function(response) {
var plats = [];
for(x = 0; x < response.length; x++){
......@@ -476,6 +505,24 @@ function renderSpots(spotids){
document.getElementById('data-prompt').innerHTML = "No Spots found for this sector"
}
}
function renderStreamingsHosts(hosts){
if (streamings.length != 0){
var container = document.getElementById('streaminghost');
container.innerHTML = "";
container.innerHTML += "<div onclick='togglediv(" + '"#streamingshosts-ls","streamingshosts-button"' + ")' class='data-header'><h1>Streaming Hosts<span id='streamingshosts-button'>-</span></h1></div>";
var streamingshosts_ls = document.createElement('div');
streamingshosts_ls.id = 'streamingshosts-ls';
for(x = 0; x < hosts.length; x++){
var elem = createRadioElementStreamingsHosts((x % 2),'hosts', false, hosts[x].hostid, hosts[x].hostname.toString()); // util function
streamingshosts_ls.innerHTML += elem;
}
container.append(streamingshosts_ls);
}else{
document.getElementById('data-prompt').innerHTML = "No Platforms found for this host" // if there are no streamings, default back to sector
document.getElementById('streaminghosts').innerHTML = '';
togglediv('#sectors-ls','sectors-button');
}
}
function renderStreamingsPlatforms(platforms){
if (streamings.length != 0){
var container = document.getElementById('streamingplatform');
......@@ -489,9 +536,9 @@ function renderStreamingsPlatforms(platforms){
}
container.append(streamingsplatforms_ls);
}else{
document.getElementById('data-prompt').innerHTML = "No Streaming data found for this sector" // if there are no streamings, default back to sector
document.getElementById('data-prompt').innerHTML = "No Streaming data found for this platform" // if there are no streamings, default back to sector
document.getElementById('streamingplatform').innerHTML = '';
togglediv('#sectors-ls','sectors-button');
togglediv('#streamingshosts-ls','streaminshosts-button');
}
}
function renderStreamingsDates(dates){
......@@ -573,7 +620,7 @@ function loadQuery(params){
query_type = params[1]
query_selection[0] = params[2]; // load trip
query_selection[1] = params[3]; // load site
query_selection[2] = params[4]; // load sector (skip spot)
query_selection[2] = params[4]; // load sector
query_selection[4] = params[5]; // load platform
query_selection[5] = params[6]; // load date
......
......@@ -76,7 +76,7 @@ function createRadioElementSites( mode, name, checked, label, id ) {
function createRadioElementSectors( mode, name, checked, label, id ) {
var f = "getSpots"; // if reading
if (query_type == 1){ // if streaming
f = "getStreamingsPlatforms";
f = "getStreamingsHosts";
}
return createRadioElement(name, id, label, f);
}
......@@ -98,6 +98,10 @@ function createRadioElementSpots( mode, name, checked, label,id ) {
return radioHtml;
}
function createRadioElementStreamingsHosts( mode, name, checked, id, label ) {
var f = "getStreamingsPlatforms";
return createRadioElement(name, id, label, f);
}
function createRadioElementStreamingsPlatforms( mode, name, checked, id, label ) {
var f = "getStreamingsDates";
return createRadioElement(name, id, label, f);
......
......@@ -23,7 +23,6 @@ const pool = new Pool({
})
const getTrips = (request, response) => {
console.info("Database: SELECT tripName, tripID from fieldday_trip;");
pool.query("SELECT tripName, tripID from fieldday_trip;", (error, results) => {
if (error) {
throw error
......@@ -32,7 +31,6 @@ const getTrips = (request, response) => {
})
}
const getSites = (request, response) => {
console.info('Database: SELECT siteName, siteID from fieldday_site where tripid='+ (request.query.id) + ';');
pool.query('SELECT siteName, siteID from fieldday_site where tripid='+ (request.query.id) + ';', (error, results) => {
if (error) {
throw error
......@@ -41,7 +39,6 @@ const getSites = (request, response) => {
})
}
const getSectors = (request, response) => {
console.info('Database: SELECT sectorname, sectorid from fieldday_sector where tripid='+ (request.query.tripid) + ' and siteid=' + (request.query.siteid) + ';');
pool.query('SELECT sectorname, sectorid from fieldday_sector where tripid='+ (request.query.tripid) + ' and siteid=' + (request.query.siteid) + ';', (error, results) => {
if (error) {
throw error
......@@ -50,7 +47,6 @@ const getSectors = (request, response) => {
})
}
const getSpots = (request, response) => {
console.info('Database: SELECT spotid from fieldday_spot where tripid='+ (request.query.tripid) +' and siteid='+ (request.query.siteid) +' and sectorid='+ request.query.sectorid +';');
pool.query('SELECT spotid from fieldday_spot where tripid='+ (request.query.tripid) +' and siteid='+ (request.query.siteid) +' and sectorid='+ request.query.sectorid +';', (error, results) => {
if (error) {
throw error
......@@ -59,7 +55,6 @@ const getSpots = (request, response) => {
})
}
const getReadingsPlatforms = (request, response) => {
console.info('Database: SELECT DISTINCT platformid, (SELECT DISTINCT platformname FROM fieldday_platform where platformid=fieldday_streaming.platformid) FROM fieldday_streaming where tripid='+ (request.query.tripid) +' and siteid='+ (request.query.siteid) +' and sectorid='+ request.query.sectorid + ';');
pool.query('SELECT DISTINCT platformid, (SELECT DISTINCT platformname FROM fieldday_platform where platformid=fieldday_streaming.platformid) FROM fieldday_streaming where tripid='+ (request.query.tripid) +' and siteid='+ (request.query.siteid) +' and sectorid='+ request.query.sectorid + ';', (error, results) => {
if (error) {
throw error
......@@ -68,7 +63,6 @@ const getReadingsPlatforms = (request, response) => {
})
}
const getReadingsDates = (request, response) => {
console.info('Database: SELECT DISTINCT recordtime FROM fieldday_streaming where tripid='+ (request.query.tripid) +' and siteid='+ (request.query.siteid) +' and sectorid='+ request.query.sectorid + " and platformid='" + request.query.platformid + "';");
pool.query('SELECT DISTINCT recordtime FROM fieldday_streaming where tripid='+ (request.query.tripid) +' and siteid='+ (request.query.siteid) +' and sectorid='+ request.query.sectorid + " and platformid='" + request.query.platformid + "';", (error, results) => {
if (error) {
throw error
......@@ -76,9 +70,7 @@ const getReadingsDates = (request, response) => {
response.status(200).json(results.rows)
})
}
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 +';');
const getReadings = (request, response) => {
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 += "(";
......@@ -93,6 +85,7 @@ const getReadings = (request, response) => {
query += ")";
}
query += ';';
console.info("Database:" + query);
pool.query(query, (error, results) => {
......@@ -102,9 +95,18 @@ const getReadings = (request, response) => {
response.status(200).json(results.rows)
})
}
const getStreamingsHosts = (request, response) => {
pool.query('SELECT DISTINCT hostid, (SELECT DISTINCT hostname FROM fieldday_host_temp where hostid=fieldday_streaming.hostid) FROM fieldday_streaming where tripid='+ (request.query.tripid) +' and siteid='+ (request.query.siteid) +' and sectorid='+ request.query.sectorid + ';', (error, results) => {
if (error) {
throw error
}
response.status(200).json(results.rows)
})
}
const getStreamingsPlatforms = (request, response) => {
console.info('Database: SELECT DISTINCT platformid, (SELECT DISTINCT platformname FROM fieldday_platform where platformid=fieldday_streaming.platformid) FROM fieldday_streaming where tripid='+ (request.query.tripid) +' and siteid='+ (request.query.siteid) +' and sectorid='+ request.query.sectorid + ';');
pool.query('SELECT DISTINCT platformid, (SELECT DISTINCT platformname FROM fieldday_platform where platformid=fieldday_streaming.platformid) FROM fieldday_streaming where tripid='+ (request.query.tripid) +' and siteid='+ (request.query.siteid) +' and sectorid='+ request.query.sectorid + ';', (error, results) => {
console.log('SELECT DISTINCT platformid, (SELECT DISTINCT platformname FROM fieldday_platform where platformid=fieldday_streaming.platformid) FROM fieldday_streaming where tripid='+ (request.query.tripid) +' and siteid='+ (request.query.siteid) +' and sectorid='+ request.query.sectorid +' and hostid='+ request.query.hostid + ';');
pool.query('SELECT DISTINCT platformid, (SELECT DISTINCT platformname FROM fieldday_platform where platformid=fieldday_streaming.platformid) FROM fieldday_streaming where tripid='+ (request.query.tripid) +' and siteid='+ (request.query.siteid) +' and sectorid='+ request.query.sectorid +" and hostid='"+ request.query.hostid + "';", (error, results) => {
if (error) {
throw error
}
......@@ -112,7 +114,6 @@ const getStreamingsPlatforms = (request, response) => {
})
}
const getStreamingsDates = (request, response) => {
console.info('Database: SELECT DISTINCT recordtime FROM fieldday_streaming where tripid='+ (request.query.tripid) +' and siteid='+ (request.query.siteid) +' and sectorid='+ request.query.sectorid + " and platformid='" + request.query.platformid + "';");
pool.query('SELECT DISTINCT recordtime FROM fieldday_streaming where tripid='+ (request.query.tripid) +' and siteid='+ (request.query.siteid) +' and sectorid='+ request.query.sectorid + " and platformid='" + request.query.platformid + "';", (error, results) => {
if (error) {
throw error
......@@ -121,13 +122,6 @@ const getStreamingsDates = (request, response) => {
})
}
const getStreamings = (request, response) => {
console.log('Database: SELECT tripid,siteid,sectorid,hostid,platformid,sensorid,recordtime,longitude,latitude,quality,elevation,accuracy,satellites,value_2,value_3,value_4,value_5,value_6'
+' from fieldday_streaming where tripid=' + (request.query.tripid)
+' and siteid='+ (request.query.siteid)
+' and sectorid='+ request.query.sectorid
+' and platformid='+ "'"+ request.query.platformid + "'"
+" and substr(recordtime::text, 0, 11) like '" + request.query.date + "'"
+ ';')
pool.query('SELECT tripid,siteid,sectorid,hostid,platformid,sensorid,(SELECT sensortype FROM fieldday_sensor where sensorid=fieldday_streaming.sensorid),(SELECT sensorunits FROM fieldday_sensor where sensorid=fieldday_streaming.sensorid),recordtime,longitude,latitude,quality,elevation,accuracy,satellites,value_1,value_2,value_3,value_4,value_5,value_6'
+' from fieldday_streaming where tripid=' + (request.query.tripid)
+' and siteid='+ (request.query.siteid)
......@@ -164,6 +158,7 @@ module.exports = { // export routes to server side.
getReadingsPlatforms,
getReadingsDates,
getReadings,
getStreamingsHosts,
getStreamingsPlatforms,
getStreamingsDates,
getStreamings
......
......@@ -125,6 +125,7 @@
<div class='data-catagory data-catagory-simple' id='sites'></div>
<div class='data-catagory data-catagory-simple' id='sectors'></div>
<div class='data-catagory data-catagory-simple' id='spots'></div>
<div class='data-catagory data-catagory-simple' id='streaminghost'></div>
<div class='data-catagory data-catagory-simple' id='streamingplatform'></div>
<div class='data-catagory data-catagory-simple' id='streamingdates'></div>
<div class='data-catagory data-catagory-simple' id='streaming'></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