Commit aa63a683 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Merge branch '6-filter-history-data' into 'master'

6 filter history data

* Modify the `selector` by adding a citeria on the field `history.data`.
* The comparison operation is `contains`
* Close #6

See merge request !7
parents 8233e214 f5c53ac5
......@@ -339,6 +339,7 @@
'Team': 'Équipe',
'teams': 'équipes',
'The aggregation function applies on the metric field. It is computed on the subset of row having a given values for the group_field x and y.': "La function d'agrégation est appliquée sur les valeurs du champ métrique. Elle est calculée sur le sous-ensemble d'enregisteremnts ayant une certain valeurs pour les champs 'group_field' x et y.",
'The field history.data contains the given value.': 'Le champ history.data contiens la valeur donnée.',
'the graphs': 'les graphiques',
'The graphs': 'Les graphiques',
'The lists': 'Les listes',
......
......@@ -2,6 +2,8 @@
""" selector
"""
tp_data = T("The field history.data contains the given value.")
virtdb.define_table('selector',
Field('year_start', 'integer', default=year),
Field('year_end', 'integer'),
......@@ -11,8 +13,8 @@ virtdb.define_table('selector',
Field('id_people_categories', 'reference alias_people_categories', label= T("People category")),
Field('id_people_code', 'reference people_categories', label= T("People quality")),
Field('id_object_categories', 'reference alias_object_categories', label= T("Object category")),
Field('id_object_code', 'reference object_categories', label= T("Object code")))
Field('id_object_code', 'reference object_categories', label= T("Object code")),
Field('data', 'string', comment=tp_data, label= T("Data")))
virtdb.selector.id_object_categories.requires = \
IS_IN_DB(db, 'alias_object_categories.category')
......
......@@ -7,7 +7,8 @@ from gluon.dal import Field
from plugin_dbui import Selector
class SelectorActiveItemsException(BaseException): pass
class SelectorActiveItemsException(BaseException):
pass
class SelectorActiveItems(Selector):
......@@ -45,7 +46,6 @@ class SelectorActiveItems(Selector):
else:
raise SelectorActiveItemsException("Period is not defined.")
def get_years(self):
"""
@rtype: list
......@@ -61,7 +61,6 @@ class SelectorActiveItems(Selector):
return range(start, end + 1)
def query(self, table):
"""Build the database query for the database table
including inner join for foreign keys, selector constraints and
......@@ -86,7 +85,6 @@ class SelectorActiveItems(Selector):
return query
def reset_period(self):
"""Reset the period to the initial values.
......@@ -95,7 +93,6 @@ class SelectorActiveItems(Selector):
self._period_start, self._period_end = self._cache_period
self._cache_period = None
def set_year(self, year):
"""Modify the period attributes in order to query records active
during the given year.
......@@ -105,7 +102,7 @@ class SelectorActiveItems(Selector):
"""
# keep original period
if self._cache_period == None:
if self._cache_period is None:
self._cache_period = (self._period_start, self._period_end)
self._period_start = date(year, 1, 1)
......@@ -134,7 +131,8 @@ class MySelector(SelectorActiveItems):
and year are systematically excluded.
"""
li = ['id_object_categories',
li = ['data',
'id_object_categories',
'id_object_code',
'id_people_categories',
'id_people_code',
......@@ -147,14 +145,16 @@ class MySelector(SelectorActiveItems):
# add virtual fields
db = current.globalenv['db']
db.people.age = Field.Virtual('age', self._age, ftype='integer')
db.history.coverage = Field.Virtual('coverage', self._coverage, ftype='double')
db.history.duration = Field.Virtual('duration', self._duration, ftype='double')
db.history.fte = Field.Virtual('fte', self._fte, ftype='double')
db.history.is_end = Field.Virtual('is_end', self._is_end, ftype='boolean')
db.history.is_over = Field.Virtual('is_over', self._is_over, ftype='boolean')
db.history.is_start = Field.Virtual('is_start', self._is_start, ftype='boolean')
history = db.history
virtual = Field.Virtual
db.people.age = virtual('age', self._age, ftype='integer')
history.coverage = virtual('coverage', self._coverage, ftype='double')
history.duration = virtual('duration', self._duration, ftype='double')
history.fte = virtual('fte', self._fte, ftype='double')
history.is_end = virtual('is_end', self._is_end, ftype='boolean')
history.is_over = virtual('is_over', self._is_over, ftype='boolean')
history.is_start = virtual('is_start', self._is_start, ftype='boolean')
def _age(self, row):
"""Compute the age of the person associated to the history record, now.
......@@ -172,7 +172,6 @@ class MySelector(SelectorActiveItems):
return value
def _coverage(self, row):
"""Compute the time coverage of the history record with respect
to the period range.
......@@ -204,7 +203,6 @@ class MySelector(SelectorActiveItems):
return value
def _duration(self, row):
"""Compute the duration of the history record.
The end date is C{now} when the history record is not finished.
......@@ -224,7 +222,7 @@ class MySelector(SelectorActiveItems):
if start and end and start <= now <= end:
value = now - start
elif start and end == None and start <= now:
elif start and end is None and start <= now:
value = now - start
elif start and end and end < now:
......@@ -232,7 +230,6 @@ class MySelector(SelectorActiveItems):
return value
def _fte(self, row):
"""Compute the full time equivalent of the person associated
to the history record. It is the product of the time coverage
......@@ -251,7 +248,6 @@ class MySelector(SelectorActiveItems):
return value
def _is_end(self, row):
"""Return true is the history record ends during the period range.
......@@ -272,7 +268,6 @@ class MySelector(SelectorActiveItems):
return False
def _is_over(self, row):
"""Return true is the history record is over now.
......@@ -291,7 +286,6 @@ class MySelector(SelectorActiveItems):
return False
def _is_start(self, row):
"""Return true is the history record starts during the period range.
......@@ -312,7 +306,6 @@ class MySelector(SelectorActiveItems):
return False
def query(self, table):
"""Supersede the base class method to handle quality constraints.
......@@ -329,40 +322,40 @@ class MySelector(SelectorActiveItems):
db = table._db
query = SelectorActiveItems.query(self, table)
# history data block contains
query &= db.history.data.contains(self.data)
# object category and code
id_object_code = self.id_object_code
if id_object_code:
q = db.history.id_object_categories == id_object_code
query = (query) & (q)
query &= db.history.id_object_categories == id_object_code
id_object_category = self.id_object_categories
if id_object_category:
category = db.object_categories[id_object_category].category
qcat = db.object_categories.category == category
myset = {row.id for row in db(qcat).select(db.object_categories.id)}
object_categories = db.object_categories
q = db.history.id_object_categories.belongs(myset)
query = (query) & (q)
category = object_categories[id_object_category].category
qcat = object_categories.category == category
myset = {row.id for row in db(qcat).select(object_categories.id)}
query &= db.history.id_object_categories.belongs(myset)
# people category and code
id_people_code = self.id_people_code
if id_people_code:
q = db.history.id_people_categories == id_people_code
query &= q
query &= db.history.id_people_categories == id_people_code
id_people_category = self.id_people_categories
if id_people_category:
category = db.people_categories[id_people_category].category
qcat = db.people_categories.category == category
myset = {row.id for row in db(qcat).select(db.people_categories.id)}
people_categories = db.people_categories
q = db.history.id_people_categories.belongs(myset)
query &= q
category = people_categories[id_people_category].category
qcat = people_categories.category == category
myset = {row.id for row in db(qcat).select(people_categories.id)}
return query
query &= db.history.id_people_categories.belongs(myset)
return query
def reset_extra_queries(self):
self._extra_queries = []
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