Commit 320eb7c2 authored by legac's avatar legac
Browse files

Add the method years to the ListTool and deploy it in the controller

metrics.
parent df91374a
......@@ -24,32 +24,8 @@ def category():
tool = Publications(db)
tool.decode_request()
query = tool.query()
table = []
years = tool.years()
# the table header
if tool.y1 and not tool.y2:
ny = 1
y1 = int(tool.y1)
table.append(['', tool.y1])
elif tool.y1 and tool.y2:
y1, y2 = int(tool.y1), int(tool.y2)
ny = y2 - y1 + 1
li = ['']
li.extend(range(y1, y2+1))
table.append(li)
else:
min = db.publications.year.min()
max = db.publications.year.max()
row = db(query).select(min, max).first()
y1, y2 = int(row[min]), int(row[max])
ny = y2 - y1 + 1
li = ['']
li.extend(range(y1, y2+1))
table.append(li)
# count the record per year and per category
count = db.publications.year.count()
rows = db(query).select(db.publications.year,
......@@ -57,19 +33,24 @@ def category():
count,
groupby=(db.publications.year, db.publications.id_categories),
orderby=(db.categories.code, db.publications.year))
# the table header
table = [['']]
table[-1].extend(years)
# fill the table
# the table content
code = None
for row in rows:
if row.categories.code != code:
code = row.categories.code
li = [code]
li.extend(['']*ny)
table.append(li)
table.append([code])
table[-1].extend(['']*len(years))
icol = int(row.publications.year) - y1 + 1
li[icol] = row[count]
icol = int(row.publications.year) - years[0] + 1
table[-1][icol] = row[count]
response.view = '%s/generic.html' % request.controller
return dict(table=table)
......@@ -83,33 +64,9 @@ def basic():
tool = Publications(db)
tool.decode_request()
query = tool.query()
years = tool.years()
table = []
# the table header
if tool.y1 and not tool.y2:
ny = 1
y1 = int(tool.y1)
table.append(['', tool.y1])
elif tool.y1 and tool.y2:
y1, y2 = int(tool.y1), int(tool.y2)
ny = y2 - y1 + 1
li = ['']
li.extend(range(y1, y2+1))
table.append(li)
else:
min = db.publications.year.min()
max = db.publications.year.max()
row = db(query).select(min, max).first()
y1, y2 = int(row[min]), int(row[max])
ny = y2 - y1 + 1
li = ['']
li.extend(range(y1, y2+1))
table.append(li)
# list of queries
# queries associated to the basic categories
di = {}
q_preprints = (query) & (category_preprint(db))
di[q_preprints] = 'preprints'
......@@ -125,27 +82,31 @@ def basic():
q_reports = (query) & (category_report(db))
di[q_reports] = 'reports'
# the table header
table = [['']]
table[-1].extend(years)
# the table content
total = [T('total')]
total.extend([0]*len(years))
# fill the table
total = [0]*ny
count = db.publications.year.count()
for q in (q_preprints, q_articles, q_proceedings, q_talks, q_reports):
rows = db(q).select(db.publications.year,
count,
groupby=db.publications.year)
li = ['']*ny
table.append([di[q]])
table[-1].extend(['']*len(years))
for row in rows:
icol = int(row.publications.year)-y1
li[icol] = row[count]
icol = int(row.publications.year) - years[0] +1
table[-1][icol] = row[count]
total[icol] += row[count]
li.insert(0, di[q])
table.append(li)
# the footer -- total per column
total.insert(0, T('total'))
# the table footer -- total per column
table.append(total)
response.view = '%s/generic.html' % request.controller
......@@ -159,32 +120,8 @@ def publisher():
tool = Publications(db)
tool.decode_request()
query = tool.query()
table = []
years = tool.years()
# the table header
if tool.y1 and not tool.y2:
ny = 1
y1 = int(tool.y1)
table.append(['', tool.y1])
elif tool.y1 and tool.y2:
y1, y2 = int(tool.y1), int(tool.y2)
ny = y2 - y1 + 1
li = ['']
li.extend(range(y1, y2+1))
table.append(li)
else:
min = db.publications.year.min()
max = db.publications.year.max()
row = db(query).select(min, max).first()
y1, y2 = int(row[min]), int(row[max])
ny = y2 - y1 + 1
li = ['']
li.extend(range(y1, y2+1))
table.append(li)
# query articles
q_articles = (query) & (category_article(db))
......@@ -195,19 +132,22 @@ def publisher():
count,
groupby=(db.publications.year, db.publications.id_publishers),
orderby=(db.publishers.abbreviation, db.publications.year))
# the table header
table = [['']]
table[-1].extend(years)
# fill the table
# the table content
publisher = None
for row in rows:
if row.publishers.abbreviation != publisher:
publisher = row.publishers.abbreviation
li = [publisher]
li.extend(['']*ny)
table.append(li)
table.append([publisher])
table[-1].extend(['']*len(years))
icol = int(row.publications.year) - y1 + 1
li[icol] = row[count]
icol = int(row.publications.year) - years[0] + 1
table[-1][icol] = row[count]
response.view = '%s/generic.html' % request.controller
return dict(table=table)
......@@ -75,14 +75,19 @@ class ListTool(object):
if 'author' in t:
self.author = current.request.vars[key]
elif self.ext_field in t:
self.extension = current.request.vars[key]
elif 'id_projects' in t:
self.id_project = current.request.vars[key]
elif 'id_teams' in t:
self.id_team = current.request.vars[key]
elif 'year_start' in t:
self.y1 = current.request.vars[key]
elif 'year_end' in t:
self.y2 = current.request.vars[key]
......@@ -141,6 +146,28 @@ class ListTool(object):
return None
def years(self):
"""Return the list of years corresponding to the selection criteria.
"""
if self.y1 and not self.y2:
y1 = int(self.y1)
return [y1]
elif self.y1 and self.y2:
y1, y2 = int(self.y1), int(self.y2)
return range(y1, y2+1)
else:
# interrogate the database in order to find the
# year range corresponding to the current selection criteria
min = self.db.publications.year.min()
max = self.db.publications.year.max()
row = self.db(self.query()).select(min, max).first()
y1, y2 = int(row[min]), int(row[max])
return range(y1, y2+1)
class Diplomas(ListTool):
def query(self):
......
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