Skip to content

Commit

Permalink
v2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
answerquest committed Sep 5, 2018
1 parent f4d7a8f commit 1d7cf9e
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 144 deletions.
1 change: 1 addition & 0 deletions GTFSManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class allStops(tornado.web.RequestHandler):
def get(self):
start = time.time()
logmessage('\nallStops GET call')

allStopsJson = readTableDB('stops').to_json(orient='records', force_ascii=False)
self.write(allStopsJson)
# time check, from https://stackoverflow.com/a/24878413/4355695
Expand Down
9 changes: 8 additions & 1 deletion GTFSserverfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,8 @@ def deletefromDB(dbfile,key,value,tables):

def replaceIDfunc(valueFrom,valueTo,tableKeys):
returnList = []
# to do: wean off tableKeys, bring in the deleteRules.csv code blocks from diagnose, delete functions.

if debugMode: logmessage('replaceIDfunc: valueFrom:',valueFrom,\
'\nvalueTo:',valueTo,'\ntableKeys:',tableKeys)

Expand Down Expand Up @@ -1010,6 +1012,11 @@ def replaceIDfunc(valueFrom,valueTo,tableKeys):

######################
def replaceIDChunk(valueFrom,valueTo,tablename,column):
'''
replaceIDChunk: this function finds the relevant chunks where replacement is to be done, and passes back the filenames in a list.
It does NOT do the actual replacing in the .h5 file. That is done by the subsequently called replaceTableCell function.
But it does edit the lookup JSON in case the column to be edited is the primary column of the chunked table. (like: stop_times > trip_id)
'''
# do NOT call any other function for replacing db etc now!
# first, figure out if this is a key column or other column
if column == chunkRules[tablename]['key']:
Expand Down Expand Up @@ -1479,4 +1486,4 @@ def sequenceDel(column,value):

sDb.close();

return content
return content
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ Big thanks to :
- Srinivas from Hyderabad, India for connecting folks together and sharing guidance
- Devdatta from Pune, India for a sharing a very simple [working example](https://github.com/devdattaT/sampleTornadoApp) to learn about Tornado web server serving asynchronous requests
- Tony Laidig from the global GTFS community for helping build a docker image
- Aaron and other co-ordinators of the GTFS community for including this program on [Awesome Transit](https://github.com/CUTR-at-USF/awesome-transit#gtfs-tools) and giving encouragement and feedback on the GTFS forum.
- Sean Barbeau and other co-ordinators of the GTFS community for including this program on [Awesome Transit](https://github.com/CUTR-at-USF/awesome-transit#gtfs-tools) and giving encouragement and feedback on the GTFS forum.



4 changes: 4 additions & 0 deletions js/commonfuncs.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ var navBarContentEnd = '</ul> \
<input id="password" class="form-control mr-sm-2" type="text" placeholder="pw for edits" aria-label="Search" style="width:200px;"> \
</nav>';


// loader:
const loaderHTML = '<div class="loader loader--style1"> <svg version="1.1" id="loader-1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="100px" height="100px" viewBox="0 0 40 40" enable-background="new 0 0 40 40" xml:space="preserve"> <path opacity="0.2" fill="#000" d="M20.201,5.169c-8.254,0-14.946,6.692-14.946,14.946c0,8.255,6.692,14.946,14.946,14.946 s14.946-6.691,14.946-14.946C35.146,11.861,28.455,5.169,20.201,5.169z M20.201,31.749c-6.425,0-11.634-5.208-11.634-11.634 c0-6.425,5.209-11.634,11.634-11.634c6.425,0,11.633,5.209,11.633,11.634C31.834,26.541,26.626,31.749,20.201,31.749z"/> <path fill="#000" d="M26.013,10.047l1.654-2.866c-2.198-1.272-4.743-2.012-7.466-2.012h0v3.312h0 C22.32,8.481,24.301,9.057,26.013,10.047z"> <animateTransform attributeType="xml" attributeName="transform" type="rotate" from="0 20 20" to="360 20 20" dur="1.0s" repeatCount="indefinite"/> </path> </svg></div><br>Loading data.. please wait..';

// ############################
// RUN ON ALL PAGES
$(document).ready(function() {
Expand Down
166 changes: 90 additions & 76 deletions js/fares.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//#########################
// Global variables
var allStopsKeyed = '';
//var allStopsKeyed = ''; // not sure if this is used anywhere..

// #########################################
// Function-variables to be used in tabulator
Expand Down Expand Up @@ -59,6 +59,11 @@ $("#fare-attributes-table").tabulator({
{title:"currency_type", field:"currency_type", headerSort:false, width:120 },
{title:"route_id", field:"route_id", headerSort:false, width:120, tooltip:'' }
],
ajaxURL: APIpath + 'fareAttributes', //ajax URL
ajaxLoaderLoading: loaderHTML,
ajaxError:function(xhr, textStatus, errorThrown){
console.log('GET request to fareAttributes failed. Returned status of: ' + errorThrown);
},
cellEdited:function(cell){
// on editing a cell, log changes
let fare_id = cell.getRow().getIndex(); //get corresponding stop_id for that cell
Expand Down Expand Up @@ -92,13 +97,12 @@ $("#fare-attributes-table").tabulator({
logmessage(message);
},
dataLoaded: function(data){
var list = [];
// populate Fare id dropdown in simple fare rules tab
var dropdown = '';
data.forEach(function(row){
list.push(row.fare_id);
});
/* just ditch the autocomplete for now yaar, for just fare ids this is overkill
$( "#targetFareid" ).autocomplete({
source: list */
dropdown += `<option value="${row.fare_id}">${row.fare_id} - ${row.price} ${row.currency_type}</option>`;
});
$('#fareSelect').html(dropdown);
},
rowSelected:function(row){
$('#targetFareid').val(row.getIndex());
Expand All @@ -124,19 +128,24 @@ $("#fare-rules-simple-table").tabulator({
if(confirm('Are you sure you want to delete this entry?'))
cell.getRow().delete();
}}
]
],
ajaxURL: APIpath + 'fareRules', //ajax URL
ajaxLoaderLoading: loaderHTML,
ajaxError:function(xhr, textStatus, errorThrown){
console.log('GET request to API fareRules failed. Returned status of: ' + errorThrown);
}
});
//#######################
// initiating commands
$(document).ready(function(){
//Initiate fare attributes table
getPythonFareAttributes();
// Initiating Fare Rules table.
getPythonFareRules();
getPythonSimpleFareRules();
getPythonStopsKeyed();
getPythonRouteIdList();
getPythonZones();
// getPythonSimpleFareRules();
// getPythonStopsKeyed();
//Initiate fare attributes table
//getPythonFareAttributes(); // tabulator will self-load by ajax
});


Expand Down Expand Up @@ -261,51 +270,6 @@ function getPythonFareRules() {
xhr.send();
}

function getPythonSimpleFareRules() {
// Here we want to fetch JSON from backend, which will take it from fare_rules.txt
let xhr = new XMLHttpRequest();
//make API call from with this as get parameter name
xhr.open('GET', `${APIpath}fareRules`);
xhr.onload = function () {
if (xhr.status === 200) { //we have got a Response
console.log(`Loaded Simple Fare Rules data from Server API/fareRules .`);
var data = JSON.parse(xhr.responseText);
if(data.length) $("#fare-rules-simple-table").tabulator('setData',data);
else $("#fare-rules-simple-table").html('No fare rules data found.');
}
else {
console.log('Server request to API/fareRules failed. Returned status of ' + xhr.status + ', message: ' + xhr.responseText );
}
};
xhr.send();
}

function getPythonFareAttributes(){
// Here we want to fetch JSON from backend, which will take it from fare_attributes.txt
let xhr = new XMLHttpRequest();
//make API call from with this as get parameter name
xhr.open('GET', `${APIpath}fareAttributes`);
xhr.onload = function () {
if (xhr.status === 200) { //we have got a Response
console.log(`Loaded Fare Attributes data from Server API/fareAttributes .`);
var data = JSON.parse(xhr.responseText);
$("#fare-attributes-table").tabulator('setData', data);

// populate Fare id dropdown in simple fare rules tab
var dropdown = '';
data.forEach(function(row){
dropdown += `<option value="${row.fare_id}">${row.fare_id} - ${row.price} ${row.currency_type}</option>`;
});
$('#fareSelect').html(dropdown);

}
else {
console.log('Server request to API/fareAttributes failed. Returned status of ' + xhr.status );
}
};
xhr.send();

}

function initiateFareRules(rulesData) {
// check if already initialized
Expand Down Expand Up @@ -457,22 +421,6 @@ function saveFareRulesSimple() {
});
}

function getPythonStopsKeyed() {
// loading KEYED JSON of the stops.txt data, keyed by stop_id.
let xhr = new XMLHttpRequest();
xhr.open('GET', `API/allStopsKeyed`);
xhr.onload = function () {
if (xhr.status === 200) { //we have got a Response
console.log(`Loaded data from Server API/allStopsKeyed .`);
var data = JSON.parse(xhr.responseText);
allStopsKeyed = data;
}
else {
console.log('Server request to API/allStopsKeyed failed. Returned status of ' + xhr.status + ', message: ' + xhr.responseText);
}
};
xhr.send();
}

function getPythonZones() {
let xhr = new XMLHttpRequest();
Expand Down Expand Up @@ -503,8 +451,7 @@ function getPythonZones() {
}

function getPythonRouteIdList() {
// loading KEYED JSON of the stops.txt data, keyed by stop_id.
let xhr = new XMLHttpRequest();
let xhr = new XMLHttpRequest();
xhr.open('GET', `API/routeIdList`);
xhr.onload = function () {
if (xhr.status === 200) { //we have got a Response
Expand Down Expand Up @@ -532,4 +479,71 @@ function addFareRule() {
var fare_id = $('#fareSelect').val();
$("#fare-rules-simple-table").tabulator('addRow', {fare_id:fare_id, origin_id:origin_id, destination_id:destination_id, route_id:route_id}, true );

}
}

/* retired functions
function getPythonFareAttributes(){
// Here we want to fetch JSON from backend, which will take it from fare_attributes.txt
let xhr = new XMLHttpRequest();
//make API call from with this as get parameter name
xhr.open('GET', `${APIpath}fareAttributes`);
xhr.onload = function () {
if (xhr.status === 200) { //we have got a Response
console.log(`Loaded Fare Attributes data from Server API/fareAttributes .`);
var data = JSON.parse(xhr.responseText);
$("#fare-attributes-table").tabulator('setData', data);
// populate Fare id dropdown in simple fare rules tab
var dropdown = '';
data.forEach(function(row){
dropdown += `<option value="${row.fare_id}">${row.fare_id} - ${row.price} ${row.currency_type}</option>`;
});
$('#fareSelect').html(dropdown);
}
else {
console.log('Server request to API/fareAttributes failed. Returned status of ' + xhr.status );
}
};
xhr.send();
}
function getPythonStopsKeyed() {
// loading KEYED JSON of the stops.txt data, keyed by stop_id.
let xhr = new XMLHttpRequest();
xhr.open('GET', `API/allStopsKeyed`);
xhr.onload = function () {
if (xhr.status === 200) { //we have got a Response
console.log(`Loaded data from Server API/allStopsKeyed .`);
var data = JSON.parse(xhr.responseText);
allStopsKeyed = data;
}
else {
console.log('Server request to API/allStopsKeyed failed. Returned status of ' + xhr.status + ', message: ' + xhr.responseText);
}
};
xhr.send();
}
function getPythonSimpleFareRules() {
// Here we want to fetch JSON from backend, which will take it from fare_rules.txt
let xhr = new XMLHttpRequest();
//make API call from with this as get parameter name
xhr.open('GET', `${APIpath}fareRules`);
xhr.onload = function () {
if (xhr.status === 200) { //we have got a Response
console.log(`Loaded Simple Fare Rules data from Server API/fareRules .`);
var data = JSON.parse(xhr.responseText);
if(data.length) $("#fare-rules-simple-table").tabulator('setData',data);
//else $("#fare-rules-simple-table").html('No fare rules data found.');
// what're you doing here, let the user create new fare rules!
}
else {
console.log('Server request to API/fareRules failed. Returned status of ' + xhr.status + ', message: ' + xhr.responseText );
}
};
xhr.send();
}
*/
Loading

0 comments on commit 1d7cf9e

Please sign in to comment.