DataStore.py - stores readings in easy to access files
This module is at the core of pywws. It stores data on disc, but without the overhead of a full scale database system. I have designed it to run on a small memory machine such as my Asus router. To minimise memory usage it only loads one day’s worth of raw data at a time into memory.
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
from pywws import DataStore
hourly = DataStore.hourly_store('weather_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.
The module provides five classes to store different data. data_store takes “raw” data from the weather station; calib_store, hourly_store, daily_store and monthly_store store processed data (see pywws.Process). All three are derived from the same core_store class, they only differ in the keys and types of data stored in each record.
Functions
safestrptime(date_string[, format]) |
Classes
ParamStore(root_dir, file_name) | |
RawConfigParser([defaults, dict_type, ...]) | |
calib_store(root_dir) | Stores ‘calibrated’ weather station data. |
core_store(root_dir) | |
daily_store(root_dir) | Stores daily summary weather station data. |
data_store(root_dir) | Stores raw weather station data. |
date | date(year, month, day) –> date object |
datetime | datetime(year, month, day[, hour[, minute[, second[, microsecond[,tzinfo]]]]]) |
hourly_store(root_dir) | Stores hourly summary weather station data. |
monthly_store(root_dir) | Stores monthly summary weather station data. |
params(root_dir) | Parameters are stored in a file “weather.ini” in root_dir. |
status(root_dir) | Status is stored in a file “status.ini” in root_dir. |
timedelta | Difference between two datetime values. |
Parameters are stored in a file “weather.ini” in root_dir.
Status is stored in a file “status.ini” in root_dir.
Return datetime of newest existing data record whose datetime is < idx.
Might not even be in the same year! If no such record exists, return None.
Stores raw weather station data.
Stores ‘calibrated’ weather station data.
Stores hourly summary weather station data.
Stores daily summary weather station data.
Stores monthly summary weather station data.