Skip to content

Basic architecture

Basile Simon edited this page Aug 19, 2014 · 17 revisions

Summary: we designed Datastringer in an easy to understand way, so you can hopefully grasp the concept quickly... and get started with your own stringers!

datastringer.js is the main program. It uses two concepts:

###Stringer A stringer is just a javascript function:

 function stringer(parameter1, parameter2, .., parameterN, callback) {
   // with the parameters, the stringer
   //  - fetches the data
   //  - does some process over it
   // if an alert is to be fired, the callback is called with the stringer's
   // name and the reason for the alert.

In Datastringer, each stringer is stored in its own js file, named after what the stringer is about. It must be located at the root of the repository.

####For example Datastringer comes with two builtin stringers, located in crime-stringer.js and local-police-stringer.js.

####Going further You can write your own stringers too! This page will get you started.

###Use-case A use-case is a javascript object that aggregates a stringer file name and a set of parameters for it. With that, one can load the stringer and pass it the set of parameters, plus a callback. It allows to re-use the stringer multiple times with different parameters.

####For example Datastringer stores the use-cases in ~/.local/share/datastringer/stringer_use_cases.json (when you first clone the repo, the file is'nt there: you can write it from scratch or run the wizard, which generate one for you). If you peak inside it you'll see something like that:

    "stringer": "local-police-stringer.js"   // the stringer that will be run
    "parameters": ["leicestershire", "C01"]  // the parameters that it's going to get
    "stringer": "local-police-stringer.js"   // this other use-case uses the same stringer
    "parameters": ["metropolitan", "005EG"]  // but see how the parameters are different in this case

  // other use-cases...

####Going further The use cases file is very easy to tweak and extend. Go over there to see how you can do that!

###Datastringer The main program just reads the list of use-cases stored in ~/.local/share/datastringer/stringers_use_cases.json, and for each one the concerned stringer is run with the given set of parameters, plus a callback that will send you a mail if it is called. And that's about it!

Again, note that this file is not present by default when you clone the repo. It will be created when you run the wizard for the first time.

You can’t perform that action at this time.