Skip to content
module

htcollector.Database

Classes
  • Measurement Represents a measurement of temperature and humidity by a station.</>
  • MeasurementDatabase Implements a databases containing measurements and station descriptions.</>
class

htcollector.Database.Measurement(stationid, temperature, humidity)

Represents a measurement of temperature and humidity by a station.

Parameters
  • stationid (str) station identification. Must contain only 1 or more alphnumeric characters or hyphens
  • temperature (float) description
  • humidity (float) description
Raises
  • ValueError if the stationid argument contains illegal characters or temperature or humidity arguments are not compatible to floats
class

htcollector.Database.MeasurementDatabase(database, host, port, user, password)

Implements a databases containing measurements and station descriptions.

The backing database should be a MariaDB database server.

Parameters
  • database (str) name of the database
  • host (str) hostname or ip-address of teh database server
  • port (str) port that the database server is listening on
  • user (str) username of a user with access privileges to the database
  • password (str) password of the user
Methods
  • names(stationid, name) (dict) Insert or replace a name for a stationid, or return a list of all stations._</>
  • retrieveDatetimeBefore(stationid, t) (datetime or None) Returns the time of the last measurement preceding a given time.</>
  • retrieveLastMeasurement(stationid, _names, _unique_stations) (list) Return the last measurement data for a station or all stations.</>
  • retrieveMeasurements(stationid, starttime, endtime) (list) Get measurements inside a given timeframe.</>
  • storeMeasurement(measurement) Store a measurement into the database.</>
method

storeMeasurement(measurement)

Store a measurement into the database.

Parameters
  • measurement (Measurement) the measurement

Measurements do not contain timestamps, the are added automatically.

method

retrieveMeasurements(stationid, starttime, endtime=None)

Get measurements inside a given timeframe.

Parameters
  • stationid (str) stationid or asterisk '*'
  • starttime (datetime) starttime of measurement period (inclusive)
  • endtime (datetime, optional) endtime of measurement period (inclusive) or None for now. Defaults to None.
Returns (list)

of dict(timestamp:t, stationid:id, temperature:t, humidity:h)

method

retrieveLastMeasurement(stationid=None, _names=None, _unique_stations=None)

Return the last measurement data for a station or all stations.

Parameters
  • stationid (str) the stationid or an asterisk '*'
Returns (list)

a list of dict objects, one for each station

method

retrieveDatetimeBefore(stationid, t)

Returns the time of the last measurement preceding a given time.

Parameters
  • stationid (str) the station id
  • t (datetime) the timestamp
Returns (datetime or None)

the time of the last measurement preceding a given time or None if the isn one

method

names(stationid, name=None)

Insert or replace a name for a stationid, or return a list of all stations._

Parameters
  • stationid (str) the shellyht station id or an asterisk '*'
  • name (str) the name to associate with a stationid (ignored if stationid is '*')
Returns (dict)

a dict(stationid:name)