Commit 2eca8dc1 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Update lbfr_report_rh.py to introduce the period function.

parent 3b26bef3
......@@ -117,7 +117,6 @@ def df_people_start_leave(year):
"""
db = current.globalenv['db']
data = []
id_people = get_id(db.events, event="People")
selector = current.selector
# scan people active during the given year
......@@ -126,57 +125,49 @@ def df_people_start_leave(year):
db.teams.team,
db.people.first_name)
for row1 in db(selector.query(db.history)).iterselect(orderby=orderby):
for row in db(selector.query(db.history)).iterselect(orderby=orderby):
people_category = row1.people_categories.category
people_category = people_category.replace("é", "e")
history = row.history
people = row.people
agency = main_agency(row1.fundings.agency)
start_date, end_date = period(history.id_people,
history.id_domains,
history.id_teams)
cdd = row1.history.data["cdd"]
agency = main_agency(row.fundings.agency)
full_name = "%s %s" % (people.first_name, people.last_name)
year_start = (None if start_date is None else start_date.year)
year_end = (None if end_date is None else end_date.year)
# people starting
# find the first date
if row1.history.is_start:
if year_start == year and year_end == year:
mindate = db.history.start_date.min()
query = db.history.id_events == id_people
query &= db.history.id_people == row1.history.id_people
myset = db(query).iterselect(mindate, groupby=db.history.id_people)
start_date = myset.first()[mindate]
data.append((
row.teams.team,
full_name,
row.people_categories.category,
1, 1, start_date,
agency,
history.data["cdd"]))
if start_date.year < year:
continue
elif year_start == year:
data.append((
row1.teams.team,
"%s %s" % (row1.people.first_name, row1.people.last_name),
people_category,
row.teams.team,
full_name,
row.people_categories.category,
1, 0, start_date,
agency,
cdd))
# people leaving
if row1.history.is_end:
history.data["cdd"]))
query = db.history.id_events == id_people
query &= db.history.id_people == row1.history.id_people
myset = db(query).select(orderby=db.history.start_date)
end_date = myset.last().end_date
if end_date is None or end_date.year > year:
continue
elif year_end == year:
data.append((
row1.teams.team,
"%s %s" % (row1.people.first_name, row1.people.last_name),
people_category,
0, 1, row1.history.end_date,
row.teams.team,
full_name,
row.people_categories.category,
0, 1, end_date,
agency,
cdd))
history.data["cdd"]))
# build the data frame
columns = ["team",
......@@ -520,9 +511,10 @@ def setup_selector(year):
virtdb = current.globalenv["virtdb"]
selector = MySelector(virtdb.selector)
id_people = get_id(db.events, event="People")
selector.append_query(db.history.id_events == id_people)
id_event_people = get_id(db.events, event="People")
selector.append_query(db.history.id_events == id_event_people)
current.id_event_people = id_event_people
return selector
......@@ -551,6 +543,45 @@ def main_agency(agency):
return value
def period(id_people, id_domain, id_team):
"""Determine the period for a person belonging to a domain and to a team.
Args:
id_people (int):
id_domain (int):
id_team (int):
Returns
tuple:
start (datetime or None)
stop (datetime or None)
"""
db = current.globalenv['db']
history = db.history
query = history.id_events == current.id_event_people
query &= history.id_people == id_people
query &= history.id_domains == id_domain
query &= history.id_teams == id_team
orderby = (history.start_date, history.end_date)
myset = db(query).select(orderby=orderby)
nset = len(myset)
if nset == 1:
row = myset.first()
return (row.start_date, row.end_date)
elif nset > 1:
return (myset.first().start_date, myset.last().end_date)
else:
raise StandardError("Failed to find start / leave date !")
def top_category(category):
"""Determine the top category EME, IT or PHY.
......
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