Skip to content

Commit

Permalink
Any changes for bargraph
Browse files Browse the repository at this point in the history
  • Loading branch information
efsny95 committed Jun 23, 2014
2 parents adc56f7 + d9c6e55 commit c91d22d
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 35 deletions.
13 changes: 0 additions & 13 deletions api/controllers/SessionController.js

This file was deleted.

67 changes: 58 additions & 9 deletions api/controllers/StationsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ module.exports = {
});
},
getStationGeoForState: function(req, res) {
console.log(req.session, req.sessionID);
if(typeof req.param('statefips') == 'undefined'){
res.send('{status:"error",message:"state FIPS required"}',500);
return;
Expand Down Expand Up @@ -220,7 +219,7 @@ module.exports = {
getTrucks:function(req,res){
var station_id = req.param('stationId'),
database = req.param('database');
console.time('auth');
//console.time('auth');
googleapis.discover('bigquery', 'v2').execute(function(err, client) {
//jwt.authorize(function(err, result) {
if (err) console.log(err);
Expand All @@ -229,7 +228,7 @@ module.exports = {
projectId: 'avail-wim',
timeoutMs: '30000'
});
console.timeEnd('auth');
//console.timeEnd('auth');
request.body = {};
request.body.query = 'select num_days,count(num_days) as numDay,month,day,class,year,sum(total_weight) from(select station_id,class,concat(string(year),string(month),string(day)) as num_days, month,day,year,total_weight FROM [tmasWIM12.'+database+'] where station_id="'+station_id+'" and station_id is not null) group by num_days,month,day,class,year';
request.body.projectId = 'avail-wim';
Expand All @@ -239,10 +238,10 @@ module.exports = {
.execute(function(err, response) {
if (err) console.log(err);
//console.log(response);
console.timeEnd('query');
console.time('send');
//console.timeEnd('query');
//console.time('send');
res.json(response);
console.timeEnd('send');
//console.timeEnd('send');
});
//});
});
Expand All @@ -252,7 +251,7 @@ module.exports = {
googleapis.discover('bigquery', 'v2').execute(function(err, client) {
jwt.authorize(function(err, result) {
if (err) console.log(err);
console.log()
//console.log()
var request = client.bigquery.jobs.query({
kind: "bigquery#queryRequest",
projectId: 'avail-wim',
Expand All @@ -261,16 +260,66 @@ module.exports = {
request.body = {};
request.body.query = 'Select min(year),max(year) from [tmasWIM12.'+database+']';
request.body.projectId = 'avail-wim';
console.log(request);
//console.log(request);
request.withAuthClient(jwt)
.execute(function(err, response) {
if (err) console.log(err);
console.log(response);
//console.log(response);
res.json(response);
});
});
});
},
getClass:function(req,res){
var database = req.param('database'),
station_id = req.param('stationId');
googleapis.discover('bigquery', 'v2').execute(function(err, client) {
jwt.authorize(function(err, result) {
if (err) console.log(err);
//console.log()
var request = client.bigquery.jobs.query({
kind: "bigquery#queryRequest",
projectId: 'avail-wim',
timeoutMs: '30000'
});
request.body = {};
request.body.query = 'SELECT year, month, day, sum(class1), sum(class2), sum(class3), sum(class4), sum(class5), sum(class6), sum(class7), sum(class8), sum(class9), sum(class10), sum(class11), sum(class12), sum(class13),FROM [tmasWIM12.'+database+'Class] where station_id="'+station_id+'" group by year, month, day';
request.body.projectId = 'avail-wim';
//console.log(request);
request.withAuthClient(jwt)
.execute(function(err, response) {
if (err) console.log(err);
//console.log(response);
res.json(response);
});
});
});
},
getStationInfo:function(req,res){
var database = req.param('database'),
station_id = req.param('stationId');
googleapis.discover('bigquery', 'v2').execute(function(err, client) {
jwt.authorize(function(err, result) {
if (err) console.log(err);
//console.log()
var request = client.bigquery.jobs.query({
kind: "bigquery#queryRequest",
projectId: 'avail-wim',
timeoutMs: '30000'
});
request.body = {};
request.body.query = 'select func_class_code, num_lanes_direc_indicated, sample_type_for_traffic_vol, method_of_traffic_vol_counting, alg_for_vehicle_class, class_sys_for_vehicle_class, method_of_truck_weighing, calibration_of_weighing_sys, type_of_sensor, second_type_of_sensor, primary_purpose, year_station_established, fips_county_code, concurrent_route_signing, concurrent_signed_route_num, national_highway_sys, posted_sign_route_num, station_location,latitude, longitude, from [tmasWIM12.allStations] where station_id="'+station_id+'" limit 1';
request.body.projectId = 'avail-wim';
//console.log(request);
request.withAuthClient(jwt)
.execute(function(err, response) {
if (err) console.log(err);
//console.log(response);
res.json(response);
});
});
});
},


/**
Expand Down
27 changes: 18 additions & 9 deletions config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,6 @@ module.exports.routes = {
'/': {
view: 'home/index'
},
'/session/database': {
controller : 'SessionController',
action : 'setDatabase',
cors: {
origin: '*',
methods: 'GET, POST, PUT, DELETE, OPTIONS, HEAD',
headers: 'content-type,X-Requested-With'
}
},
'/stations/geo':{
controller : 'StationsController',
action : 'stationsGeo',
Expand Down Expand Up @@ -117,6 +108,24 @@ module.exports.routes = {
headers: 'content-type,X-Requested-With'
}
},
'/stations/byStation/class/:stationId':{
controller : 'StationsController',
action : 'getClass',
cors: {
origin: '*',
methods: 'GET, POST, PUT, DELETE, OPTIONS, HEAD',
headers: 'content-type,X-Requested-With'
}
},
'/stations/byStation/state/info/:stationId':{
controller : 'StationsController',
action : 'getStationInfo',
cors: {
origin: '*',
methods: 'GET, POST, PUT, DELETE, OPTIONS, HEAD',
headers: 'content-type,X-Requested-With'
}
},



Expand Down
4 changes: 0 additions & 4 deletions config/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ module.exports.session = {
// forcing them to log in again.
secret: 'bdd8b8c4e4f56cab17153945bcf91210',

cookie: {
maxAge: 900000
}


// In production, uncomment the following lines to set up a shared redis session store
// that can be shared across multiple Sails.js servers
Expand Down

0 comments on commit c91d22d

Please sign in to comment.