# 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.

Latest version **1.0.4** (published 2017-11-13) · ISC license · 0 weekly downloads

## Install

```sh
npm install lpdg-iomanager
pnpm add lpdg-iomanager
yarn add lpdg-iomanager
bun add lpdg-iomanager
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2017-11-13 |
| First published | 2017-11-13 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| Author | Vanhove Sander |
| Maintainers | sandervanhove |

## Links

- npm: https://www.npmjs.com/package/lpdg-iomanager
- Repository: https://ext-sruvhove@git.datasciencelab.ugent.be/linkedtimeseries/lpdg-iomanager
- npm.io page: https://npm.io/package/lpdg-iomanager

## Dependencies (2)

- [ws](https://npm.io/package/ws.md) ^3.3.1
- [mkdirp](https://npm.io/package/mkdirp.md) ^0.5.1

## Recent versions

- 1.0.4 (latest) — 2017-11-13
- 1.0.3 — 2017-11-13
- 1.0.2 — 2017-11-13
- 1.0.1 — 2017-11-13
- 1.0.0 — 2017-11-13

## README

# 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.

Name | Description | Default
--- | --- | ---
time:interval | The interval at which the parkings get updated and the stream sends updates | 30
file:output | The output directory | ""
file:output_meta_data | Bool to see if meta data should be put in the file | false
file:extension | Defines the extension of the generated files | ""
file:name_format | Defines the format of the output filenames. `DEFAULT`: `city-YYYY-MM-DDThhmmss`, `UNIX`: UNIX timestamp of beginning of interval. | "DEFAULT"
file:split | If files of cities should be split, if false will ignore "time:time_per_file" | true
io:mode | Mode can be FILE, STREAM, POLL or STRING. If something other then FILE is used, most "file:xxxxx" variables will be ignored | "FILE"
io:port | Port at which the websockt is made | 8080

## 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:

Name | Description
--- | --- 
type | Can 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)
city | If 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:

Name | Description
--- | --- 
type | Can 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)
city | If the type of the request is GET this value should be the number of the city we want
time | If 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.

---
_Source: https://npm.io/package/lpdg-iomanager · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
