Commit 9f467378 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Sphinxify selector.py.

parent d288cf16
......@@ -15,19 +15,18 @@ class SelectorActiveItems(Selector):
"""Selector to get records active during a given period of time.
The period of time are defined by the selector fields
C{_period_start} and C{_period_end} as well as C{_year}.
``_period_start`` and ``_period_end`` as well as ``_year}``.
Args:
table (gluon.dal.Table): the virtual table defining the selector.
exclude_fields (list of string):
name of the selector fields which are
excluded in the query.
"""
def __init__(self, table, exclude_fields=('year_end', 'year_start')):
"""
@type table: gluon.dal.Table
@param table: the virtual table defining the selector.
@type exclude_fields: list of string
@param exclude_fields: name of the selector fields which are
excluded in the query.
"""
self._cache_period = None
self._period_end = None
......@@ -48,8 +47,8 @@ class SelectorActiveItems(Selector):
def get_years(self):
"""
@rtype: list
@return: the list of year between period start and end
Returns:
list: the list of year between period start and end
"""
if self._cache_period:
......@@ -66,14 +65,15 @@ class SelectorActiveItems(Selector):
including inner join for foreign keys, selector constraints and
extra queries.
@type table: gluon.dal.Table
@param table: the database table in which records are selected.
@rtype: gluon.dal.Query
Args:
table (gluon.dal.Table):
the database table in which records are selected.
@return: The query selects active items during the given period of
time. It only works for table having the database fields
C{start_date} and C{end_date}.
Returns:
gluon.dal.Query:
The query selects active items during the given period of
time. It only works for table having the database fields
``start_date`` and ``end_date``.
"""
query = Selector.query(self, table)
......@@ -98,8 +98,8 @@ class SelectorActiveItems(Selector):
"""Modify the period attributes in order to query records active
during the given year.
@type year: integer
@param year:
Args:
year (integer):
"""
# keep original period
......@@ -120,18 +120,17 @@ class MySelector(SelectorActiveItems):
- For each record computes virtual field age, coverage, duration,
fte and is_over.
Args:
table (gluon.dal.Table): the virtual table defining the selector.
exclude_fields (tuple of string):
extend the list selector fields which are
excluded in the query. The field category, period_end, period_start
and year are systematically excluded.
"""
def __init__(self, table, exclude_fields=()):
"""
@type table: gluon.dal.Table
@param table: the virtual table defining the selector.
@type exclude_fields: tuple of string
@param exclude_fields: extend the list selector fields which are
excluded in the query. The field category, period_end, period_start
and year are systematically excluded.
"""
li = ['data',
'id_object_categories',
'id_object_code',
......@@ -160,10 +159,11 @@ class MySelector(SelectorActiveItems):
def _age(self, row):
"""Compute the age of the person associated to the history record, now.
@type row: gluon.dal.Row
@param row: row of the history table.
Args:
row (gluon.dal.Row): row of the history table.
@rtype: int or None
Returns:
int or None:
"""
value = None
......@@ -177,12 +177,11 @@ class MySelector(SelectorActiveItems):
"""Compute the time coverage of the history record with respect
to the period range.
Args:
row (gluon.dal.Row): row of the history table.
@type row: gluon.dal.Row
@param row: row of the history table.
@rtype: float
@return: a value between C{0} and C{1}.
Returns:
float: a value between ``0`` and ``1``.
"""
value = 0.
......@@ -206,12 +205,13 @@ class MySelector(SelectorActiveItems):
def _duration(self, row):
"""Compute the duration of the history record.
The end date is C{now} when the history record is not finished.
The end date is ``now`` when the history record is not finished.
@type row: gluon.dal.Row
@param row: row of the history table.
Args:
row (gluon.dal.Row): row of the history table.
@rtype: datetime.timedelta
Returns:
datetime.timedelta:
"""
value = timedelta(seconds=0)
......@@ -236,11 +236,11 @@ class MySelector(SelectorActiveItems):
to the history record. It is the product of the time coverage
and the percentage of the person assigned to the record.
@type row: gluon.dal.Row
@param row: row of the history table.
Args:
row (gluon.dal.Row): row of the history table.
@rtype: float
@return: a value between 0 and 1.
Returns:
float: a value between 0 and 1.
"""
value = 0.
......@@ -252,10 +252,11 @@ class MySelector(SelectorActiveItems):
def _is_end(self, row):
"""Return true is the history record ends during the period range.
@type row: gluon.dal.Row
@param row: row of the history table.
Args:
row (gluon.dal.Row): row of the history table.
@rtype: bool
Returns:
bool:
"""
end = row.history.end_date
......@@ -272,10 +273,11 @@ class MySelector(SelectorActiveItems):
def _is_over(self, row):
"""Return true is the history record is over now.
@type row: gluon.dal.Row
@param row: row of the history table.
Args:
row (gluon.dal.Row): row of the history table.
@rtype: bool
Returns:
bool:
"""
end = row.history.end_date
......@@ -290,10 +292,11 @@ class MySelector(SelectorActiveItems):
def _is_start(self, row):
"""Return true is the history record starts during the period range.
@type row: gluon.dal.Row
@param row: row of the history table.
Args:
row (gluon.dal.Row): row of the history table.
@rtype: bool
Returns:
bool:
"""
end = row.history.end_date
......@@ -310,14 +313,15 @@ class MySelector(SelectorActiveItems):
def query(self, table):
"""Supersede the base class method to handle quality constraints.
@type table: gluon.dal.Table
@param table:
Args:
table (gluon.dal.Table):
@note: Translate the selector category, defined as a string,
into a query.
Notes:
* Translate the selector category, defined as a string,
into a query.
@note: append the query on events for table containing the field
id_events.
* append the query on events for table containing the field
id_events.
"""
db = table._db
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment