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

setup for future work, no function change

parent 73bc4859
......@@ -9,25 +9,25 @@ app.get('/', function(req, res) {
res.render("index",{
})
});
app.use(express.static(__dirname + '/public'));
//////////
// Create routes for aquiring DB information from server-side
app.get('/trips', q.getTrips);
app.get('/sites', q.getSites);
app.get('/sectors', q.getSectors);
app.get('/spots', q.getSpots);
app.get('/readingsplatforms', q.getReadingsPlatforms);
app.get('/readingsdates', q.getReadingsDates);
app.get('/readings', q.getReadings);
app.get('/streamingsplatforms', q.getStreamingsPlatforms);
app.get('/streamingsdates', q.getStreamingsDates);
app.get('/streamings', q.getStreamings);
//////////
// LISTEN
app.listen(process.env.PORT || 9900, function(){
console.log("Express server listening on port %d in %s mode", this.address().port, app.settings.env);
console.log("Server: Running Datavis 2 v1.0");
console.log("Server: Running on port %d in %s mode", this.address().port, app.settings.env);
});
......@@ -45,6 +45,7 @@ it to the screen, or displaying it. Each makes a call to a server-side function
'queries.js' file, which gets the data from the database and returns it to the client-side,
which then passes the data to a renderer.
*/
// General routes
function getTrips(){
if (query_type == 0){
document.getElementById('data-prompt').innerHTML = "Pick a trip, site, sector, and spot to see data."
......@@ -175,6 +176,67 @@ function getSpots(sector_id){
}
});
}
// Reading-specific routes
// NOT SET UP YET
function getReadingsPlatforms(sector_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('#sectors-ls','sectors-button');
query_selection[2] = sector_id;
$.ajax({
type: 'GET',
url: '/streamingsplatforms',
data: {sectorid: sector_id, siteid: query_selection[1], tripid: query_selection[0]},
success: function(response) {
var plats = [];
for(x = 0; x < response.length; x++){
plats.push(response[x]);
}
console.info('DATA - PLATFORMS');
console.table(response);
renderStreamingsPlatforms(plats);
},
error: function(xhr, status, err) {
console.log(xhr.responseText);
}
});
}
// NOT SET UP YET
function getReadingsDates(platformid){
document.getElementById('data-prompt').innerHTML = "Pick a set of data to visualize";
document.getElementById('streamingdates').innerHTML = placeholderHTML;
resetElements(['streaming','reading']);
document.getElementById("button_permalink").disabled = true;
document.getElementById("button_csv").disabled = true;
togglediv('#streamingsplatforms-ls','streamingsplatforms-button');
query_selection[4] = platformid;
$.ajax({
type: 'GET',
url: '/streamingsdates',
data: {platformid: platformid, sectorid: query_selection[2], siteid: query_selection[1], tripid: query_selection[0]},
success: function(response) {
var dates = [];
for(x = 0; x < response.length; x++){
dates.push(response[x]);
}
console.info('DATA - DATES');
dates = [...new Set(dates.map(item => (item.recordtime.substring(0, 10))))];
console.table(dates);
renderStreamingsDates(dates);
},
error: function(xhr, status, err) {
console.log(xhr.responseText);
}
});
}
function getReadings(spot_id){
document.getElementById('data-prompt').innerHTML = "Pick a set of data to visualize";
document.getElementById('reading').innerHTML = placeholderHTML;
......@@ -202,6 +264,7 @@ function getReadings(spot_id){
}
});
}
// Streaming-specific routes
function getStreamingsPlatforms(sector_id){
document.getElementById('data-prompt').innerHTML = "Select a platform to see recorded data.";
document.getElementById('streamingplatform').innerHTML = placeholderHTML;
......
......@@ -9,7 +9,6 @@
*/
// IMPORTANT: The .ENV file must be setup before running, see README for template
const dotenv = require('dotenv');
dotenv.config();
......@@ -24,7 +23,7 @@ const pool = new Pool({
})
const getTrips = (request, response) => {
console.info("SELECT tripName, tripID from fieldday_trip;");
console.info("Database: SELECT tripName, tripID from fieldday_trip;");
pool.query("SELECT tripName, tripID from fieldday_trip;", (error, results) => {
if (error) {
throw error
......@@ -33,7 +32,7 @@ const getTrips = (request, response) => {
})
}
const getSites = (request, response) => {
console.info('SELECT siteName, siteID from fieldday_site where tripid='+ (request.query.id) + ';');
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
......@@ -42,7 +41,7 @@ const getSites = (request, response) => {
})
}
const getSectors = (request, response) => {
console.info('SELECT sectorname, sectorid from fieldday_sector where tripid='+ (request.query.tripid) + ' and siteid=' + (request.query.siteid) + ';');
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
......@@ -51,7 +50,7 @@ const getSectors = (request, response) => {
})
}
const getSpots = (request, response) => {
console.info('SELECT spotid from fieldday_spot where tripid='+ (request.query.tripid) +' and siteid='+ (request.query.siteid) +' and sectorid='+ request.query.sectorid +';');
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,8 +58,26 @@ const getSpots = (request, response) => {
response.status(200).json(results.rows)
})
}
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
}
response.status(200).json(results.rows)
})
}
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
}
response.status(200).json(results.rows)
})
}
const getReadings = (request, response) => {
console.info('SELECT tripid,siteid,sectorid,spotid,platformid,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,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,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) => {
if (error) {
throw error
......@@ -69,7 +86,7 @@ const getReadings = (request, response) => {
})
}
const getStreamingsPlatforms = (request, response) => {
console.info('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 + ';');
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
......@@ -78,7 +95,7 @@ const getStreamingsPlatforms = (request, response) => {
})
}
const getStreamingsDates = (request, response) => {
console.info('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 + "';");
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
......@@ -87,7 +104,7 @@ const getStreamingsDates = (request, response) => {
})
}
const getStreamings = (request, response) => {
console.log('SELECT tripid,siteid,sectorid,hostid,platformid,sensorid,recordtime,longitude,latitude,quality,elevation,accuracy,satellites,value_2,value_3,value_4,value_5,value_6'
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
......@@ -108,11 +125,27 @@ const getStreamings = (request, response) => {
})
}
function checkConnection(){
console.log('Database: starting connection...');
pool.query("SELECT * FROM fieldday_trip;", (error, results) => {
if (error) {
console.log('Database: connection to database failed, check .ENV file.');
console.log('Halting...');
process.exit(1);
}else{
console.log('Database: connection successful!');
}
})
}
checkConnection();
module.exports = { // export routes to server side.
getTrips,
getSites,
getSectors,
getSpots,
getReadingsPlatforms,
getReadingsDates,
getReadings,
getStreamingsPlatforms,
getStreamingsDates,
......
......@@ -123,6 +123,8 @@
<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>
<div class='data-catagory data-catagory-simple' id='readingplatform'></div>
<div class='data-catagory data-catagory-simple' id='readingdates'></div>
<div class='data-catagory data-catagory-simple' id='reading'></div>
<div id='data-prompt-box'>
......
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