
pywws.DataStore
***************


Introduction
============

This module is at the core of my weather station software. 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
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``
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 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']

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.


Detailed API
============

DataStore.py - stores readings in easy to access files

A separate file is used for each day's data, to keep memory load
reasonable. One day at a time is held in memory, and saved to disc
when another day needs to be accessed.

Data is accessed in a cross between dictionary and list behaviour. The
following are all valid: # get value nearest 9:30 on Christmas day
data[data.nearest(datetime(2008, 12, 25, 9, 30))] # get entire array,
equivalent to data[:] or just data data[datetime.min:datetime.max] #
get last 12 hours of data data[datetime.utcnow() -
timedelta(hours=12):]

-[ Functions ]-

+------------+--------------------------------------------------------------------------------------------+
| ``safestrp |                                                                                            |
| time``(dat |                                                                                            |
| e_string[, |                                                                                            |
| format])   |                                                                                            |
+------------+--------------------------------------------------------------------------------------------+

-[ Classes ]-

+------------+--------------------------------------------------------------------------------------------+
| ``data_sto | Stores raw weather station data.                                                           |
| re``(root_ |                                                                                            |
| dir)       |                                                                                            |
+------------+--------------------------------------------------------------------------------------------+
| ``calib_st | Stores 'calibrated' weather station data.                                                  |
| ore``(root |                                                                                            |
| _dir)      |                                                                                            |
+------------+--------------------------------------------------------------------------------------------+
| ``hourly_s | Stores hourly summary weather station data.                                                |
| tore``(roo |                                                                                            |
| t_dir)     |                                                                                            |
+------------+--------------------------------------------------------------------------------------------+
| ``daily_st | Stores daily summary weather station data.                                                 |
| ore``(root |                                                                                            |
| _dir)      |                                                                                            |
+------------+--------------------------------------------------------------------------------------------+
| ``monthly_ | Stores monthly summary weather station data.                                               |
| store``(ro |                                                                                            |
| ot_dir)    |                                                                                            |
+------------+--------------------------------------------------------------------------------------------+
| ``core_sto |                                                                                            |
| re``(root_ |                                                                                            |
| dir)       |                                                                                            |
+------------+--------------------------------------------------------------------------------------------+
| ``params`` | Parameters are stored in a file "weather.ini" in root_dir.                                 |
| (root_dir) |                                                                                            |
+------------+--------------------------------------------------------------------------------------------+

pywws.DataStore.safestrptime(date_string, format=None)

class class pywws.DataStore.params(root_dir)

   Parameters are stored in a file "weather.ini" in root_dir.

   flush()

   get(section, option, default=None)

      Get a parameter value and return a string.

      If default is specified and section or option are not defined in
      the weather.ini file, they are created and set to default, which
      is then the return value.

   get_datetime(section, option, default=None)

   set(section, option, value)

      Set option in section to string value.

class class pywws.DataStore.core_store(root_dir)

   before(idx)

      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.

   after(idx)

      Return datetime of oldest existing data record whose datetime is
      >= idx.

      Might not even be in the same year! If no such record exists,
      return None.

   nearest(idx)

      Return datetime of record whose datetime is nearest idx.

   flush()

class class pywws.DataStore.data_store(root_dir)

   Stores raw weather station data.

class class pywws.DataStore.calib_store(root_dir)

   Stores 'calibrated' weather station data.

class class pywws.DataStore.hourly_store(root_dir)

   Stores hourly summary weather station data.

class class pywws.DataStore.daily_store(root_dir)

   Stores daily summary weather station data.

class class pywws.DataStore.monthly_store(root_dir)

   Stores monthly summary weather station data.
