py_wlc.data package

Submodules

py_wlc.data.webtag_data module

Exposes the parsed WebTAG data as py_wlc objects.

class py_wlc.data.webtag_data.WebTagData(base_year, released, version, source, **data)[source]

Bases: object

Holds the data extracted from WebTAG.

classmethod from_json(file)[source]

Extract data from the specified JSON.

Parameters:file (str) – The file to import from.
Returns:class:~.WebTagData: A new class instance.
Return type::py
classmethod from_latest_json(dir_)[source]

Extract data from the most recent JSON in the directory.

Parameters:dir (str) – The directory to start searching from.
Returns:class:~.WebTagData: A new class instance.
Return type::py

py_wlc.data.webtag_parser module

WebTAG Parser - functionality for extracting from the Data Book.

This class parses the databook to a more convenient JSON format for use by WebTagData.

class py_wlc.data.webtag_parser.WebTagParser(filename)[source]

Bases: object

Class to handle access to a WebTAG Databook Excel file.

The class is designed to operate as a context manager if needed.

Where possible, the workbook is opened in on_demand mode, to avoid loading all worksheets at once. extract_data() will load and unload the appropriate worksheets as required.

Parameters:filename (str) – The WebTAG Databook file to open.
book

xlrd.Workbook

The Excel workbook.

date

datetime.datetime

The release date of the databook.

filename

str

The name of the file to open.

version

str

The version of the databook.

BASE = ('User Parameters', 0, 11, 'Price year')

Where to find the base year.

CHECK = ('Cover', 2, 0, 'WebTAG Databook')

Defines the check for a valid WebTAG workbook.

DATE = ('Audit', 0, 2)

Where to locate the workbook date.

LOCATIONS = {'rail_electricity_price': ('A1.3.7', 27, 1, 7), 'rail_fuel_duty': ('A1.3.7', 27, 1, 10), 'discount_rate': ('A1.1.1', 24, 1, 3), 'rail_diesel_price': ('A1.3.7', 27, 1, 5), 'gdp_growth': ('Annual Parameters', 30, 1, 5)}

Locations of defined data series for extraction.

VERSION = ('Cover', 3, 0)

Where to locate the workbook version.

close()[source]

Release the book resources.

extract_all(verbose=False)[source]

Extract all data from LOCATIONS and useful metadata.

Parameters:verbose (bool, optional) – Whether to report progress. Implemented primarily for cli() usage. Defaults to False.
Returns:The data extracted from the book.
Return type:dict
extract_data(sheet_name, start_row, key_col, value_col)[source]

Extract data from the specified worksheet.

Assumes that cell A3 contains the worksheet title and that cell A4 contains the table name.

Parameters:
  • sheet_name (str) – The name of the worksheet.
  • start_row (int) – The first row to extract data from.
  • key_col (int) – The column to extract keys from.
  • value_col (int) – The column to extract values from.
Returns:

The extracted data

Return type:

dict

extract_named_data(name)[source]

Extract a named data series from LOCATIONS.

Parameters:name (str) – The name of the data series (must be in Locations).
Returns:The extracted data series.
Return type:dict
Raises:KeyError – If name is not in Locations.
py_wlc.data.webtag_parser.cli(args)[source]

Provide a CLI for the WebTagParser.

Will either output to a specified file (with optional verbose reporting) or dump the JSON data to stdout.

Parameters:args (argparse.Namespace) – The parsed command line arguments.
Raises:ValueError – If -v is supplied without -o.
py_wlc.data.webtag_parser.parse_args(args)[source]

Parse the arguments for cli().

Parameters:args (list of str) – Arguments from command line.
Returns:The parsed arguments.
Return type:argparse.Namespace
Raises:ArgumentError – If -v is supplied without -o.

Module contents

py_wlc.data provides external data handling functionality.

Various sources of external data may be required for carrying out economic appraisals; this module provides convenience functions and classes for handling that data.