1.0.4 • Published 6 years ago

lpdg-iomanager v1.0.4

Weekly downloads
4
License
ISC
Repository
-
Last release
6 years ago

lpdg-iomanager

An IOManager that saves the generated result to files, is able to use websockets to stream or let a client poll for data or just returns the value of the lpdgenerator.

Usage

First install lpdg-iomanager:

npm install lpdg-iomanager -s
const lpdgenerator = require('lpdgenerator');
const lpdgiomanager = require('lpdg-iomanager')

var generator = new lpdgenerator();
var manager = new lpdgiomanager();

manager.run(generator);

And then run the program with an input file as parameter:

node myprog <input-file>

Input

There is an example input file in the root.

NameDescriptionDefault
time:intervalThe interval at which the parkings get updated and the stream sends updates30
file:outputThe output directory""
file:output_meta_dataBool to see if meta data should be put in the filefalse
file:extensionDefines the extension of the generated files""
file:name_formatDefines the format of the output filenames. DEFAULT: city-YYYY-MM-DDThhmmss, UNIX: UNIX timestamp of beginning of interval."DEFAULT"
file:splitIf files of cities should be split, if false will ignore "time:time_per_file"true
io:modeMode can be FILE, STREAM, POLL or STRING. If something other then FILE is used, most "file:xxxxx" variables will be ignored"FILE"
io:portPort at which the websockt is made8080

Websockets

When the "io:mode" is STREAM or POLL, the manager will create a websocket to send data over the network.

STREAM

When streaming, the IOManager will send data to subscribed clients every "time:interval" seconds. To subscribe, clients have to send a JSON object with following parameters:

NameDescription
typeCan have te value INFO (if we just want to get info on the cities and parkings), SUB (if we want to subscribe to a city) or UNSUB (if we want to unsubscribe from a city)
cityIf the type of the request is SUB or UNSUB this value should be the number of the city we want to (un)subscribe

Sample client

const WebSocket = require('ws');

const ws = new WebSocket('ws://localhost:8080');
 
ws.on('open', function open() {
  ws.send('{"type" : "SUB", "city":0}');
});
 
ws.on('message', function incoming(data) {
  console.log(data.toString());
});

POLL

When the mode is POLL, clients have to requist data every time they want to have an update. CLients should send a JSON object with following parameters:

NameDescription
typeCan have te value INFO (if we just want to get info on the cities and parkings), GET (if we want to get the parking data)
cityIf the type of the request is GET this value should be the number of the city we want
timeIf the type of the request is GET this value should be the begin value of the data

Sample client

const WebSocket = require('ws');

const ws = new WebSocket('ws://localhost:8080');
 
ws.on('open', function open() {
  ws.send('{"type" : "GET", "city":0, "time": "1970-01-01T00:00:00"}');
});
 
ws.on('message', function incoming(data) {
  console.log(data.toString());
});

FILE

File output will just output the result for every city in separate files.

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago