@dms/io

    0.9.1 • Public • Published

    The official Data Mining & Supply IO wrapper module.

    Currently, DMS is in a private beta release and this package requires an active DMS account. Once out of beta, installing and using public supplies will no longer require an account or login prompt. Full documentation and more information can be found in the DMS Docs.

    Loading the module:

    var supply = require('@dms/io');

    The @dms/io wrapper module loads as a function. Calling this function loads and initializes an instance of the Supply class.

    Initializing a Supply:

    Some examples for loading a supply using the /s/running-numbers supply:

    // Using the default options
    var mySupply = supply('running-numbers')
    // If we have data that looks like this:
    var data = [
      {
        id: "ABC",
        number: 10
      },
      {
        id: "ABC",
        number: 12
      },
      {
        id: "ABC",
        number: 15
      }
    ]
     
     
    // ... then we might want to add some options
    var mySupply = supply('running-numbers', {
        inputs: { // Renaming inputs
          value: "number" 
        },
        parameters: { // tuning parameters
          population: false
        },
        bypass: [ "id" ] // adding bypass fields
      });

    supply(name [,options])

    • name - string name of the supply to load

    • options - optional object

      • inputs - object for remapping input names
      • parameters - object for tuning this supply's parameters
      • bypass - array of field names to pass around this supply's logic
      • version - specific version to load, defaults to newest installed

    Using a Supply

    Data can be sent through a supply as an array of data points, or one point at a time. The loaded supply object will remember whatever is required to mine the next data point. If the data argument is left out, it will default to {}.

    Using a supply's $main route

    // asynchronously
    mySupply(data, function(err, result){
      console.log(err, result);
    });
     
    // synchronously
    var result = mySupply(data);

    Some supplies have multiple routes for data:

    Using a supply's custom $on route

    // asynchronously
    mySupply.$on('routeName', data, function(err, result){
      console.log(err, result);
    });
     
    // synchronously
    var result = mySupply.$on('routeName', data);

    Extra Stuff

    // Check how many points a supply has mined
    console.log(mySupply.points_mined);
     
    // Access a supply's internal memory
    var memory = mySupply.$;
     
    // Get the epoch time the supply was initialized
    console.log(mySupply.created_on);

    Exporting a supply's current state:

    // Extract a supply's memory and settings as a base64 string
    var b64 = mySupply.toBase64();
     
    // Extract a supply's memory and settings as an object
    var obj = mySupply.toObject();
     
    // Extract a supply's memory and settings as a stringified object
    var str = mySupply.toString();

    Configuring a supply from an exported state:

    // Set a supply's memory and settings from a base64 string
    mySupply.fromBase64(b64);
     
    // Set a supply's memory and settings from an object
    mySupply.toObject(obj);
     
    // Set a supply's memory and settings from a stringified object
    mySupply.toString(str);

    Check out https://datamining.supply for more info.

    Keywords

    none

    Install

    npm i @dms/io

    DownloadsWeekly Downloads

    14

    Version

    0.9.1

    License

    Apache-2.0

    Last publish

    Collaborators

    • kgarg
    • pbinggeser