feat(node-request-bindings-debug): initial commit
This commit is contained in:
parent
e38c0b1104
commit
6c93c0ed40
|
@ -1,14 +1,14 @@
|
|||
## Overview
|
||||
# Overview
|
||||
|
||||
use node.js to read pbf file from file system and export as debug log
|
||||
|
||||
## Preparation
|
||||
# Preparation
|
||||
|
||||
```
|
||||
npm i
|
||||
```
|
||||
|
||||
## Test
|
||||
# Test
|
||||
|
||||
```
|
||||
DEBUG=debug,pbf npm run dev
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
URL=https://dedriver.org/gtfs-rt/vehiclePositions.pb
|
|
@ -0,0 +1 @@
|
|||
URL=https://wimb-api-ops-gis.ew1p3.k8s.mfb.io/v1/gtfs-rt/flavour/rmv/region/de/agency/bus_train/vehicle-position
|
|
@ -0,0 +1 @@
|
|||
URL=http://localhost:8080/vehicle-positions
|
|
@ -0,0 +1 @@
|
|||
URL=https://cdn.mbta.com/realtime/VehiclePositions.pb
|
|
@ -0,0 +1 @@
|
|||
URL=https://gtfs.openov.nl/gtfs-rt/vehiclePositions.pb
|
|
@ -0,0 +1 @@
|
|||
URL=http://gtfsr.vbn.de/gtfsr_connect.bin
|
|
@ -0,0 +1,120 @@
|
|||
# Other
|
||||
.env
|
||||
*~
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Snowpack dependency directory (https://snowpack.dev/)
|
||||
web_modules/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Microbundle cache
|
||||
.rpt2_cache/
|
||||
.rts2_cache_cjs/
|
||||
.rts2_cache_es/
|
||||
.rts2_cache_umd/
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
.env.test
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
.parcel-cache
|
||||
|
||||
# Next.js build output
|
||||
.next
|
||||
out
|
||||
|
||||
# Nuxt.js build / generate output
|
||||
.nuxt
|
||||
dist
|
||||
|
||||
# Gatsby files
|
||||
.cache/
|
||||
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||
# public
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
# TernJS port file
|
||||
.tern-port
|
||||
|
||||
# Stores VSCode versions used for testing VSCode extensions
|
||||
.vscode-test
|
||||
|
||||
# yarn v2
|
||||
.yarn/cache
|
||||
.yarn/unplugged
|
||||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.*
|
|
@ -0,0 +1,86 @@
|
|||
const debug = require('debug')('gtfs');
|
||||
const GtfsRealtimeBindings = require('gtfs-realtime-bindings');
|
||||
|
||||
function decode(buffer){
|
||||
debug('decode...');
|
||||
|
||||
var feed = GtfsRealtimeBindings.transit_realtime.FeedMessage.decode(buffer);
|
||||
if(feed){
|
||||
debug('feed: %s',feed)
|
||||
let header=feed.header;
|
||||
if(header){
|
||||
debug('header: %s',header)
|
||||
let gtfsRealtimeVersion=header.gtfsRealtimeVersion;
|
||||
if(gtfsRealtimeVersion){
|
||||
debug('gtfsRealtimeVersion: %s',gtfsRealtimeVersion)
|
||||
}
|
||||
}
|
||||
feed.entity.forEach(function(entity) {
|
||||
if (entity.tripUpdate) {
|
||||
debug('tripUpdate')
|
||||
const tripUpdate=entity.tripUpdate;
|
||||
if(tripUpdate.trip){
|
||||
debug('TripDescriptor')
|
||||
const trip=tripUpdate.trip
|
||||
if(trip.tripId){
|
||||
debug('trip_id: %s',trip.tripId)
|
||||
}
|
||||
if(trip.routeId){
|
||||
debug('route_id: %s',trip.routeId)
|
||||
}
|
||||
if(trip.directionId){
|
||||
debug('direction_id: %s',trip.directionId)
|
||||
}
|
||||
if(trip.startTime){
|
||||
debug('start_time: %s',trip.startTime)
|
||||
}
|
||||
if(trip.startDate){
|
||||
debug('start_date: %s',trip.startDate)
|
||||
}
|
||||
if(trip.scheduleRelationship){
|
||||
debug('schedule_relationship: %s',trip.scheduleRelationship)
|
||||
}
|
||||
}
|
||||
if(tripUpdate.vehicle){
|
||||
debug('VehicleDescriptor')
|
||||
}
|
||||
if(tripUpdate.timestamp){
|
||||
debug('timestamp: %s',tripUpdate.timestamp)
|
||||
}
|
||||
}else if(entity.vehicle){
|
||||
const vehPos=entity.vehicle;
|
||||
debug('vehiclePosition')
|
||||
if(vehPos.position){
|
||||
const pos=vehPos.position;
|
||||
debug('position')
|
||||
if(pos.latitude){
|
||||
const lat=pos.latitude;
|
||||
debug('lat: %s',lat)
|
||||
}
|
||||
if(pos.longitude){
|
||||
const lon=pos.longitude;
|
||||
debug('lon: %s',lon)
|
||||
}
|
||||
}
|
||||
}else if(entity.alert){
|
||||
debug('alert')
|
||||
}else{
|
||||
debug('entity unknown')
|
||||
}
|
||||
});
|
||||
// Verify the payload if necessary (i.e. when possibly incomplete or invalid)
|
||||
let errMsg = GtfsRealtimeBindings.transit_realtime.FeedMessage.verify(feed);
|
||||
if (errMsg){
|
||||
debug('msg invalid')
|
||||
throw Error(errMsg);
|
||||
}else{
|
||||
debug('msg valid')
|
||||
}
|
||||
}else{
|
||||
debug('feed unavailable')
|
||||
}
|
||||
debug('...done.')
|
||||
return feed;
|
||||
}
|
||||
module.exports = {decode}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
const gtfsRt = require('./gtfsRtDecode');
|
||||
const debug = require('debug')('gtfs');
|
||||
var request = require('request');
|
||||
require('dotenv').config();
|
||||
|
||||
const URL=process.env.URL||'TODO: Adjust URL according to use case!'
|
||||
debug('URL: '+URL)
|
||||
|
||||
var requestSettings = {
|
||||
method: 'GET',
|
||||
url:URL,
|
||||
encoding: null
|
||||
};
|
||||
|
||||
request(requestSettings, function (error, response, body) {
|
||||
if (!error && response.statusCode == 200) {
|
||||
debug('response 200');
|
||||
let feed=gtfsRt.decode(body);
|
||||
}else{
|
||||
debug('error or unsatisfactory status code')
|
||||
}
|
||||
});
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"name": "gtfs-rt2console",
|
||||
"version": "0.0.1",
|
||||
"description": "decode GTFS Realtime and log to console",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"dev": "nodemon index.js",
|
||||
"start": "node index.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "Stefan Begerad",
|
||||
"license": "GPL-3.0",
|
||||
"dependencies": {
|
||||
"debug": "3.2.7",
|
||||
"dotenv": "8.2.0",
|
||||
"gtfs-realtime-bindings": "0.0.6",
|
||||
"request": "2.88.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "2.0.7"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
## Overview
|
||||
|
||||
Decode GTFS Realtime and log to console
|
||||
|
||||
It translates message feeds from the GTFS Realtime format to human readable text and logs it onto the command line interface.
|
||||
|
||||
## Preparation
|
||||
|
||||
```
|
||||
npm i
|
||||
```
|
||||
|
||||
# Test
|
||||
|
||||
```
|
||||
DEBUG=debug,gtfs npm run dev
|
||||
```
|
Loading…
Reference in New Issue