Skip to content

Commit

Permalink
feat: improve preds by loc data.
Browse files Browse the repository at this point in the history
  • Loading branch information
morganney authored Nov 9, 2023
2 parents b05c121 + 409327e commit e05dda8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
13 changes: 9 additions & 4 deletions lib/api/predictions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var https = require('https');
var zlib = require('zlib');
var qs = require('querystring');
var utils = require('../utils');
var C = utils.c;
Expand Down Expand Up @@ -200,13 +199,15 @@ predictions.location = function(req, res) {
latlonrgx = /^([-+]?\d{1,2}([.]\d+)?),\s*([-+]?\d{1,3}([.]\d+)?)$/,
layoverrgx = /sup/gi,
busatstoprgx = /arriving|due|departing/gi,
maxNumStops = req.query.max || '32',
postdata, options, postreq;

if(latlonrgx.test(latlon)) {
postdata = qs.stringify({
preds: 'byLoc',
maxDis: '2300',
accuracy: '2400',
maxNumStops: maxNumStops,
lat: alatlon[0].trim(),
lon: alatlon[1].trim()
});
Expand Down Expand Up @@ -241,9 +242,13 @@ predictions.location = function(req, res) {
var p = {},
pfs = pred.pred_for_stop,
ps = pred.pred_str.replace(/minutes|min|mins/g,'').trim(),
directionTitle = pred.route_dir,
directionTitle = pred.route_dir.replace(/^to\s?:/i, '').trim(),
aps;

if (!directionTitle) {
directionTitle = pred.route_short_dir || '';
}

p.agency = {
id: pfs.a,
title: pred.agency_name,
Expand All @@ -255,7 +260,7 @@ predictions.location = function(req, res) {
};
p.stop = {
id: pfs.s,
title: pred.stop_name,
title: pred.stop_name.replace(/^stop\s?:/i, '').trim(),
distance: pred.stop_distance
};
p.messages = [];
Expand All @@ -275,9 +280,9 @@ predictions.location = function(req, res) {
mins = parseInt(pstr.replace("<SUP>*</SUP>", ''), 10);
}

v.epochTime = null;
v.seconds = isNaN(mins) ? -1 : mins * 60;
v.minutes = isNaN(mins) ? -1 : mins;
v.epochTime = isNaN(mins) ? null : Date.now() + mins * 60 * 1000;
v.branch = null;
v.isDeparture = null;
v.affectedByLayover = affected;
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "restbus",
"description": "RESTful JSON API for the NextBus Inc. public XML feed.",
"version": "2.0.3",
"version": "2.1.0",
"main": "index",
"dependencies": {
"compression": "1.7.4",
Expand All @@ -11,7 +11,7 @@
"xml2js": "0.5.0"
},
"engines": {
"node": ">= 0.8.0"
"node": ">= 0.10.0"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit e05dda8

Please sign in to comment.