openspending / datapackage-pipelines-fiscal

Fiscal Data Package extensions to Datapackage Pipelines
MIT License
3 stars 6 forks source link

datapackage-pipelines-fiscal

PyPI - Python Version Travis

Extension for datapackage-pipelines used for loading Fiscal Data Packages into:

This extension works with a custom source spec and a set of processors. The generator will convert the source spec into a set of inter-dependent pipelines, which when run in order will perform data processing and loading to selected endpoints (based on environment variables).

This extension is used by os-conductor and os-data-importers.

Environment variables

DPP_DB_ENGINE - connection string for an SQL database to dump data into

ELASTICSEARCH_ADDRESS [OPTIONAL] - connection string for an elasticsearch instance (used for package registry updating)

S3_BUCKET_NAME [OPTIONAL] - S3 bucket for uploading data. If not provided, local ZIP files will be created instead.

AWS_ACCESS_KEY_ID - S3 credentials (required if S3 bucket was specified)

AWS_SECRET_ACCESS_KEY - S3 credentials (required if S3 bucket was specified)

Dependencies

In order to fully run the fiscal datapackage flow you need to have os-types installed, using npm:

$ npm install -g os-types

This external node.js utility is used to perform fiscal modelling for the processed datapackage.

fiscal.source-spec.yaml

Each source-spec contains information regarding a single Fiscal Data Package.

Top level properties are:

title

Title, or Display name, of the data package

dataset-name [OPTIONAL]

A slug to be used as the data package's name.

If not provided, a slugified version of the title will be used.

resource-name [OPTIONAL]

A slug to be used as the main resource's name in the final data package.

If not provided, the dataset name will be used.

owner-id

The id of the owner of this datapackage.

This identifier is used to generate various paths and storage names.

sources

Contains a non-empty list of data sources for the fiscal data package.

Each data source has these properties:

Other tabulator parameters can also be added as properties here, e.g. sheet, encoding, compression etc.

fields

Contains a non-empty list of fields for the fiscal data package.

Each field definition has these properties:

measures [OPTIONAL]

Extra information for measure normalization processing. (Measure normalization is the process of reducing the number of measures to one while multipltying the number of rows and adding extra columns to contain values for identifying the original measure).

Contains the following sub-properties:

The unpivoting map is a map from a measure's name to its unpivoting data.

"Unpivoting data" is a map from an extra column's name to a value

Example:

measures:
  currency: GTQ
  mapping:
    APPROVED:
      PHASE_ID: "0"
      PHASE: Inicial
    RELEASED:
      PHASE_ID: "1"
      PHASE: Vigente
    COMMITTED:
      PHASE_ID: "2"
      PHASE: Comprometido

currency-conversion [OPTIONAL]

Instructions for adding an extra column or columns with measure values in another currency.

datapackage-url [OPTIONAL]

Contains the URL for a source datapackage from which this data came from. If provided, metadata for this datapackage will be loaded from this URL.

deduplicate [OPTIONAL]

If true, then the source data will be processed to remove duplicate rows (i.e. rows which have the same values in the primary key). Measure values for these rows will be summed in order to generate a single output row.

postprocessing [OPTIONAL]

A list of extra processors (and parameters) that will be applied to the data. Format is as in any pipeline-spec.yaml

suppress-os [OPTIONAL, default is False]

If False, an OpenSpending compatible datapackage is created on the datastore. This basic datapackage ensures a basic FDP is available for editing with OpenSpending. Packages created with os-conductor already create this artefact, so would use suppress-os: True, to prevent another being created unnecessarily.

keep-artifacts [OPTIONAL, default is False]

By default, pipeline artifacts (temporary directories and files creating during pipeline execution) will be removed after all pipelines have successfully been run. To keep the artifact, set this option to True.

Generated Pipelines

./denormalized_flow

Outputs:

./finalize_datapackage_flow_splitter

_(depends on ./denormalized_flow)_

./finalize_datapackage_flow

_(depends on ./finalize_datapackage_flow_splitter)_

Outputs:

./dimensionflow{hierarchy}

_(depends on ./denormalized_flow)_

Outputs:

./normalized_flow

_(depends on ./denormalized_flow and all ./dimension_flow_{hierarchy})_

Outputs:

./dumperflow{hierarchy}

_(depends on corresponding ./dimension_flow_{hierarchy})_

Outputs

./dumper_flow

_(depends on ./normalized_flow)_

Outputs

./dumper_flow_update_status

_(depends on ./dumper_flow)_

Outputs

Contributing

Please read the contribution guideline:

How to Contribute