API Documentation

api.py

hpdr.api.build(begin, end, dzone=u'UTC', qzone=u'UTC', slop=None, lslop=None, rslop=None, years=u'YYYY', months=u'MM', days=u'DD', hours=u'HH', minutes=u'MIN')

Build a specification for a date range.

Parameters:
  • begin (str/datetime) – begin date of range, a datetime or yyyy[mm[dd[mm[ss]]]] string
  • end (str/datetime) – end date of range, a datetime or yyyy[mm[dd[mm[ss]]]] string
  • dzone (str) – tzdata timezone data is stored in
  • qzone (str) – tzdata timezone query dates and times are specified in
  • slop (str) – duration to add to both ends of the partition range, specified as d+[years|months|days|hours|minutes], for example, 5hours
  • lslop (str) – duration to add to the front end of the partition range, specified as d+[years|months|days|hours|minutes], for example, 5hours
  • rslop (str) – duration to add to the back end of the partition range, specified as d+[years|months|days|hours|minutes], for example, 5hours
  • years (str) – name for years partition
  • months (str) – name for months partition
  • days (str) – name for days partition
  • hours (str) – name for hours partition
  • minutes (str) – name for hours partition
Returns:

Object representing the date range

Return type:

hpdr.models.Spec

hpdr.api.build_with_steps(begin, end, step=None, dzone=u'UTC', qzone=u'UTC', slop=None, lslop=None, rslop=None, years=u'YYYY', months=u'MM', days=u'DD', hours=u'HH', minutes=u'MIN')

Build a lists of specification for a date.

The specifications in the list are contiguous, chronological pieces of the list. Left slop followed by the begin-to-end range broken into parts of step size followed by right slop.

Parameters:
  • begin (str/datetime) – begin date of range, a datetime or yyyy[mm[dd[mm[ss]]]] string
  • end (str/datetime) – end date of range, a datetime or yyyy[mm[dd[mm[ss]]]] string
  • step (str) – duration to break individual Spec objects into, specified as d+[years|months|days|hours|minutes], for example, 5hours. If None, one Spec is returned.
  • dzone (str) – tzdata timezone data is stored in
  • qzone (str) – tzdata timezone query dates and times are specified in
  • slop (str) – duration to add to both ends of the partition range, specified as d+[years|months|days|hours|minutes], for example, 5hours
  • lslop (str) – duration to add to the front end of the partition range, specified as d+[years|months|days|hours|minutes], for example, 5hours
  • rslop (str) – duration to add to the back end of the partition range, specified as d+[years|months|days|hours|minutes], for example, 5hours
  • years (str) – name for years partition
  • months (str) – name for months partition
  • days (str) – name for days partition
  • hours (str) – name for hours partition
  • minutes (str) – name for hours partition
Returns:

List representing the date range. For example,

build_with_steps(begin=‘20160901’, end=20161001, step=10days, –slop=1hours)

returns a list of five Spec objects, representing these ranges:

(YYYY=2016 AND MM=08 AND DD=31 AND HH>=23) [left slop of 1 hour]

(YYYY=2016 AND MM=09 AND DD>=01 AND DD<11) [10 days]

(YYYY=2016 AND MM=09 AND DD>=11 AND DD<21) [10 days]

(YYYY=2016 AND MM=09 AND DD>=21) [10 days]

(YYYY=2016 AND MM=10 AND DD=01 AND HH=00) [right slop of 1 hour]

Return type:

A list of hpdr.model.Spec

models.py

class hpdr.models.Range(ands, ors)

A date range, abstractly represented by SQL conditions.

build_display(pretty=False)

Build a string for displaying the Range.

Create a string version of the Range in valid SQL syntax for a conditional clause.

class hpdr.models.Spec(begin, end, dzone=u'UTC', qzone=u'UTC', slop=None, lslop=None, rslop=None, years=u'YYYY', months=u'MM', days=u'DD', hours=u'HH', minutes=u'MIN')

Object for representing a partition date range.

substitute(query, verbose=False, pretty=False)

Fills in the HPDR_ varibles with the values.

Parameters:
  • query (string) – a string (optionally) containing HPDR_ variables
  • verbose (bool) – if True prints out lots of extra info as an SQL comment
  • pretty (bool) – if True returns just HPDR_range_pretty variable
Returns:

query with HDPR_ variables substituted for, or HPDR_range_pretty value if pretty=True

Return type:

str

variables()

Return a map of all HPDR_ variables and their values defined for the range.