]license-url
Askro
This tool allow you to parse, collect and traverse through the radiation monitoring data provided by ROSATOM SARMS(Sectoral Automated Radiation Monitoring System).
More reading about SARMS.
Installation
npm install askro
Data structure
Every request performed by this tool, returns you data in the following structure:
list // root-object
|
`--territories // list of sites where Nuclear Plants are located
|
`--sensors // list of sensors that surrounds potential hazardous site
|
`--measurements // series of measurements with timestamp and value of radiation level, in microsieverts
Data is structured in a logical way rather then relational.
I've tried to store and analize it in noSQL storage and it was smooth.
Usage
Parsing
First, you should initialize parser:
var ASKRO = require('askro');
var parser = new ASKRO();
Also, you may pass data from previous crawling session into parser (to avoid data duplication):
var ASKRO = require('askro');
var parser = new ASKRO({
territories: ArrayOfTerritoriesFromDB
});
To get latest data (this includes one measurement per sensor. Each measurement should be less than two hours old):
parser
.fetchLatest()
.then(function (parser) {
console.log(parser.territories[0]);
});
BTW, all async methods implements Promise/A+ standard.
To get data for last 24 hours (one measurement per hour):
parser.fetch();
Last week:
parser.fetch(ASKRO.WEEK);
Last month:
parser.fetch(ASKRO.MONTH);
To get data in an arbitrary time interval:
parser.fetch(startDate, endDate);
Beware, the more time interval is, the less measurements you will receive. If time interval is more than five days,
provider will return you one measurement per day.
Data traversing
parser.territories;
parser.add(territoryFromDB);
parser.remove(territoryId);
parser.get(territoryId);
When you get access to specific territory object, you may ask it and only it to fetch data.
var territory = parser.territories[0];
territory.fetchSeriesOfMeasurements();
territory.fetchSeriesOfMeasurements(ASKRO.WEEK)
territory.fetchSeriesOfMeasurements(ASKRO.MONTH)
territory.fetchSeriesOfMeasurements(startDate, endDate)
Each territory has array of sensors which belongs to it. You can have access for them:
territory.sensors
territory.addSensor(sensorFromDB);
territory.removeSensor(sensorId);
territory.getSensor(sensorId);
Each sensor has measurements array which contain series of measurements belonging to it.
sensor.measurements;
Warning: Sensor will drop duplicate measurements.
Cleanup
If you want to remove measurements, you can call method cleanMeasurements
.
Each data structure provide such a method:
parser.cleanMeasurements();
territory.cleanMeasurements();
sensor.cleanMeasurements();
Real-world example
Say, you want to copy data from provider to your own storage:
var _ = require('lodash');
var ASKRO = require('askro');
var parser = new ASKRO();
parser
.fetchLatest()
.then(function (parser) {
return db.territories.insert(parser.territories);
})
.then(function () {
var endDate = new Date();
var startDate = new Date();
startDate.setDate(startDate.getDate() - 5);
return parser.fetch(startDate, endDate);
})
.then(function (parser) {
var measurements = _.reduce(
_.reduce(
parser.territories,
function (sensorList, territory) {
return territory.sensors.concat(sensorList);
},
[]
),
function (measurementsList, sensor) {
return _.map(sensor.measurements, function (measurement) {
measurement.sensorId = sensor.id;
measurement.territoryId = sensor.territory.id;
return measurement;
}).concat(measurementsList);
},
[]
);
return db.measurements.insert(measurements);
})
.then(function (dbResult) {
})
.catch(function (e) {
});
Tests
Just run npm test
.
License
MIT, see LICENSE for details.