Git Product home page Git Product logo

backdrop-collector-plugins's Introduction

backdrop-collector-plugins

Plugins to work in conjunction with collectors for the alphagov/backdrop system.

An example configuration is given at the end of this document.

The basic form of a collector is like so:

documents = get_documents_from_somewhere()

... magic happens ...

send_documents_to_backdrop(documents)

This package is a part of the ... magic happens .... To extend it, add your code in the plugins directory, import the relevant symbols in the __init__.py and send a pull request.

Caveat

In the backdrop-ga-collector, if plugins are used, the final plugin must be ComputeIdFrom at the moment, and this is likely to be true for a while.

This is because only the person writing plugin sequence can really know what makes records unique.

Installation

This module stands alone and is pip installable, but not currently on PyPi.

Tests

Indirection is painful and the tests are small, so they live in the same module as the code they are testing. Nosetests find them by virtual of the --all-modules configuration option. If anyone disagrees strongly with this arrangement, a pull request is welcome to fix it.

Tests are run on travis-ci.

Available plugins

Plugins are arbitrary python expressions, which are evaluated in the backdrop.collector.plugins namespace. They return a callable which accepts a list of dictionaries and returns a list of dictionaries.

Plugins can do whatever they like to those dictionaries and the resulting list, including modifying them in place or discarding some. This allows for aggregation and discarding records.

The plugin loading mechanism is very simple and if in doubt you should take a look at how it and other example plugins work.

ComputeDepartmentKey ('variable name')

Computes a department field based on the contents of the given variable name.

ComputeIdFrom('varname1', [varname2]...)

Recomputes the _id and humanId fields from the specified

ComputeRank('varname')

Fills the varname key with the rank of the document, starting from 1.

Useful key for filling "top N" tables.

RemoveKey('varname1', [varname2]...)

Delete the given keys from all documents.

AggregateKey(aggregation_func('varname1'), [a_f('varname2')]...)

Aggregates the given values according to the given aggregation_func where aggregation_func might be aggregate_count('varname') which sums 'varname', or aggregate_rate('rate_varname', 'count_varname') which can be used to combine records where 'rate_varname' represent a rate (e.g, a bounce rate), weighted according to an appropriate 'count_varname'

Comment(args...)

Ignores its arguments, useful for putting comments into the list of plugins to explain what they are doing.

Example configuration

{
  "dataType": "content_dashboard_visitors_count",
  "query": {
    "id": "ga:123456",
    "metrics": [
      "visitors"
    ],
    "dimensions": [
      "customVarValue9"
    ]
  },
  "target": {
    "url": "http://localhost:3039/data/foo/visitors-count",
    "token": "foo-bearer-token"
  },
  "plugins": [
    "ComputeDepartmentKey('customVarValue9')",
    "Comment('customVarValue9 must be removed from the document before aggregation')",
    "RemoveKey('_id', 'humanId', 'customVarValue9')",
    "AggregateKey(aggregate_count('visitors'))",
    "ComputeIdFrom('_timestamp', 'timeSpan', 'dataType', 'department')"
  ]
}

backdrop-collector-plugins's People

Contributors

jabley avatar pwaller avatar robyoung avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.