pywws.storage

Store parameters in easy to access files, and access backend data

Introduction

This module is at the core of pywws. By default it stores data on disc, using a backend module which uses text files (see pywws.filedata) but other plugin backend modules can be used to use alternative means. These modules must adopt the same API (Class names and methods) as pywws.filedata so as to be transparent to the rest of pywws.

From a “user” point of view, the data is accessed as a cross between a list and a dictionary. Each data record is indexed by a datetime.datetime object (dictionary behaviour), but records are stored in order and can be accessed as slices (list behaviour).

For example, to access the hourly data for Christmas day 2009, one might do the following:

from datetime import datetime
import pywws.storage
datastore = pywws.storage.PywwsContext('weather_data', False)
hourly = datastore.hourly_data
for data in hourly[datetime(2009, 12, 25):datetime(2009, 12, 26)]:
    print(data['idx'], data['temp_out'])

Some more examples of data access:

# get value nearest 9:30 on Christmas day 2008
data[data.nearest(datetime(2008, 12, 25, 9, 30))]
# get entire array, equivalent to data[:]
data[datetime.min:datetime.max]
# get last 12 hours worth of data
data[datetime.utcnow() - timedelta(hours=12):]

Note that the datetime.datetime index is in UTC. You may need to apply an offset to convert to local time.

See pywws.filedata for more details on the underlying data store API.

Detailed API

Functions

pywws_context(data_dir[, live_logging])

Classes

ParamStore(root_dir, file_name)

PywwsContext(data_dir, live_logging)


Comments or questions? Please subscribe to the pywws mailing list http://groups.google.com/group/pywws and let us know.