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

Remove obsolete code to build lists and metrics.

parent b674fc18
......@@ -4,21 +4,12 @@
import re
from gluon.dal import Field, smart_query
from harvest_tools import get_id
from gluon.dal import Field
from list_postprocessing import *
from list_tools import (category_article,
category_preprint,
category_proceeding,
category_report,
category_talk,
Diplomas,
ListTool,
Publications,
from list_tools import (ListTool,
get_sections,
get_selector)
from plugin_dbui import decode_field
MSG_NO_LIST = T("Please select a list....")
MSG_NO_SECTIONS = T('Please, define sections for the list "%s"')
......@@ -131,106 +122,3 @@ def index():
paths_keys=paths_keys,
paths_data=paths_data,
tool=tool)
def basic():
"""Basic list with preprint, articles, conferences and reports.
The parameter for the selection are setup via the list_selector interface.
"""
tool = Publications(db)
tool.decode_request()
# download the list as a file with a given format
iframe = tool.download()
if iframe:
return iframe
# query to build the list of publications
# taking into account user criteria
query = tool.query()
# preprint ordered by preprint number
# preprint number is a nice time marker following chronological order
q_preprints = (query) & (category_preprint(db))
preprints = db(q_preprints).select(orderby=(~db.publications.year,
db.publications.preprint))
# articles ordered by preprint number
# preprint number is a nice time marker following chronological order
q_articles = (query) & (category_article(db))
articles = db(q_articles).select(orderby=(~db.publications.year,
db.publications.preprint))
# proceeding ordered by report number
# report number is a nice time marker following chronological order
q_proceedings = (query) & (category_proceeding(db))
proceedings = db(q_proceedings).select(orderby=(~db.publications.year,
db.publications.report_numbers))
# talks
q_talks = (query) & (category_talk(db))
talks = db(q_talks).select(orderby=~db.publications.year)
# reports
q_reports = (query) & (category_report(db))
reports = db(q_reports).select(orderby=(~db.publications.year,
db.publications.report_numbers))
# Phd thesis
diplomas = Diplomas(db)
diplomas.decode_request()
query = diplomas.query()
id_phd = get_id(db, 'levels', level='PhD')
if id_phd:
q_phds = (query) & (db.diplomas.id_levels == id_phd)
phds = db(q_phds).select(db.diplomas.year,
db.diplomas.title,
db.diplomas.author,
db.diplomas.defense,
orderby=(~db.diplomas.year, db.diplomas.author))
else:
phds = []
# go to the view
return dict(articles=articles,
phds=phds,
preprints=preprints,
proceedings=proceedings,
reports=reports,
talks=talks,
tool=tool)
def category():
"""List where publications are sorted according to categories.
"""
tool = Publications(db)
tool.decode_request()
# download the list as a file with a given format
iframe = tool.download()
if iframe:
return iframe
# query to build the list of publications
# taking into account user criteria
query = tool.query()
# Get the list of AERES categories
categories = []
for row in db(db.categories.id>dbui.UNDEF_ID).select(db.categories.code):
categories.append(row.code)
# Get the publications for each category
di = {}
for category in categories:
q_category = (query) & (db.categories.code == category)
di[category] = db(q_category).select(orderby=(~db.publications.year,
db.publications.preprint,
db.publications.report_numbers))
return dict(data=di, tool=tool)
""" Controllers for building metrics tables
"""
from harvest_tools import get_id
from list_tools import (category_article,
category_preprint,
category_proceeding,
category_report,
category_talk,
Diplomas,
ListTool,
from list_tools import (Diplomas,
Publications,
get_selector)
......@@ -98,162 +91,3 @@ def index():
table[icol][irow] = row[count]
return dict(table=table, tool=tool)
def basic():
"""Publications count per basic categories articles, preprint, ...
applying selector constraints.
"""
tool = Publications(db)
tool.decode_request()
query = tool.query()
years = tool.years()
# queries associated to the basic categories
di = {}
q_preprints = (query) & (category_preprint(db))
di[q_preprints] = 'preprints'
q_articles = (query) & (category_article(db))
di[q_articles] = 'articles'
q_proceedings = (query) & (category_proceeding(db))
di[q_proceedings] = 'proceedings'
q_talks = (query) & (category_talk(db))
di[q_talks] = 'talks'
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))
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)
table.append([di[q]])
table[-1].extend(['']*len(years))
for row in rows:
icol = int(row.publications.year) - years[0] + 1
table[-1][icol] = row[count]
total[icol] += row[count]
# Count the number of phds
diplomas = Diplomas(db)
diplomas.decode_request()
query = diplomas.query()
count = db.diplomas.year.count()
id_phd = get_id(db, 'levels', level='PhD')
if id_phd:
q_phds = (query) & (db.diplomas.id_levels == id_phd)
rows = db(q_phds).select(db.diplomas.year,
count,
groupby=db.diplomas.year)
table.append(['phds'])
table[-1].extend(['']*len(years))
for row in rows:
icol = int(row.diplomas.year) - years[0] + 1
table[-1][icol] = row[count]
total[icol] += row[count]
# the table footer -- total per column
table.append(total)
response.view = '%s/layout.html' % request.controller
return dict(table=table, tool=tool)
def category():
"""Publications count per categories applying selector constraints.
"""
tool = Publications(db)
tool.decode_request()
query = tool.query()
years = tool.years()
# count the record per year and per category
count = db.publications.year.count()
rows = db(query).select(db.publications.year,
db.categories.code,
count,
groupby=(db.publications.year, db.publications.id_categories),
orderby=(db.categories.code, db.publications.year))
# the table header
table = [['']]
table[-1].extend(years)
# the table content
code = None
for row in rows:
if row.categories.code != code:
code = row.categories.code
table.append([code])
table[-1].extend(['']*len(years))
icol = int(row.publications.year) - years[0] + 1
table[-1][icol] = row[count]
response.view = '%s/layout.html' % request.controller
return dict(table=table, tool=tool)
def publisher():
"""Publication count per publishers applying selector constraints.
"""
tool = Publications(db)
tool.decode_request()
query = tool.query()
years = tool.years()
# query articles
q_articles = (query) & (category_article(db))
# count the record per year and per publisher
count = db.publications.year.count()
rows = db(q_articles).select(db.publications.year,
db.publishers.abbreviation,
count,
groupby=(db.publications.year, db.publications.id_publishers),
orderby=(db.publishers.abbreviation, db.publications.year))
# the table header
table = [['']]
table[-1].extend(years)
# the table content
publisher = None
for row in rows:
if row.publishers.abbreviation != publisher:
publisher = row.publishers.abbreviation
table.append([publisher])
table[-1].extend(['']*len(years))
icol = int(row.publications.year) - years[0] + 1
table[-1][icol] = row[count]
response.view = '%s/layout.html' % request.controller
return dict(table=table, tool=tool)
......@@ -10,47 +10,6 @@ from gluon.html import IFRAME, URL
from plugin_dbui import decode_field
def category_article(db):
"""Helper function defining publication categories
associated to article. The return value can be used as is in a query.
"""
return (db.categories.code == 'ACL') | (db.categories.code == 'ACLN')
def category_preprint(db):
"""Helper function defining publication categories
associated to preprint. The return value can be used as is in a query.
"""
return db.categories.code == 'PRE'
def category_proceeding(db):
"""Helper function defining publication categories
associated to proceeding. The return value can be used as is in a query.
"""
return (db.categories.code == 'ACTI') | (db.categories.code == 'ACTN')
def category_report(db):
"""Helper function defining publication categories
associated to report. The return value can be used as is in a query.
"""
return db.categories.code == 'AP'
def category_talk(db):
"""Helper function defining publication categories
associated to conference talk. The return value can be used as is
in a query.
"""
return db.categories.code == 'COM'
def get_sections(db, list):
"""Helper function returning a list of section.
Build the query and orderby directive for each section taking into
......
--------------------------------- CHANGELOG ----------------------------------
HEAD
- Redesign the metric to use the axes approach
- Remove obsolete code to build lists and metrics
0.5.1 (Sept 2012)
- Consolidation and bugs fixed
- Myseed map the CPPM organisation
......
......@@ -3,70 +3,6 @@
# Serie of helper functions to builds views
#
def extract_article_fields(record, undef_id):
li = [record.publications.title,
"%s %s" % (record.publications.first_author, 'et al.')]
if int(record.publications.id_collaborations) != undef_id:
li.append(record.collaborations.collaboration)
pass
ref = "%s %i (%i) %s" % (record.publishers.abbreviation,
record.publications.volume,
record.publications.year,
record.publications.pages)
li.append(ref)
return li
def extract_conference_fields(record, undef_id):
li = [record.publications.title,
record.publications.authors,
record.publications.conference_title,
record.publications.conference_town,
record.countries.country,
record.publications.conference_dates]
return li
def extract_phd_fields(record, undef_id):
li = [record.title,
record.author,
record.defense]
return li
def extract_preprint_fields(record, undef_id):
li = [record.publications.title,
"%s %s" % (record.publications.first_author, 'et al.')]
if int(record.publications.id_collaborations) != undef_id:
li.append(record.collaborations.collaboration)
pass
li.append(record.publications.preprint)
return li
def extract_report_fields(record, undef_id):
li = [record.publications.title]
if int(record.publications.id_collaborations) != undef_id:
li.append("%s %s" % (record.publications.first_author, 'et al.'))
li.append(record.collaborations.collaboration)
else:
li.append(record.publications.authors)
pass
if record.publications.report_numbers:
li.append(record.publications.report_numbers)
pass
return li
def get_title(selector, undef_id):
title = ''
......@@ -100,57 +36,6 @@
return url
def sortdiploma_per_year(records, fields_extractor, undef_id):
year, years = None, []
di = {}
for el in records:
if not year or year != el.year:
year = el.year
di[year] = []
years.append(year)
pass
li = fields_extractor(el, undef_id)
di[year].append(', '.join(li))
pass
return (years, di)
def sortpublications_per_year(records, fields_extractor, undef_id):
year, years = None, []
di = {}
for el in records:
if not year or year != el.publications.year:
year = el.publications.year
di[year] = []
years.append(year)
pass
li = fields_extractor(el, undef_id)
di[year].append(', '.join(li))
pass
return (years, di)
def to_html(section, years, items_per_year):
response.write(H2(T(section), _class="my-h2"))
for year in years:
if year in items_per_year:
response.write(P(year, _class="my-p"))
ol = OL(*[LI(el, _class="my-li") for el in items_per_year[year]],
_class="my-ol")
response.write(ol)
pass
pass
return
def to_html_table(table):
headers = [TD(el, _class="my-td") for el in table[0]]
html_table = TABLE(TR(*headers, _class="my-tr"), _class="my-table")
......@@ -164,26 +49,5 @@
response.write(CENTER(html_table))
return
def to_latex(section, years, data):
import textwrap
response.write("\n\n\section*{%s}" % T(section), escape=False)
for year in years:
if year in data:
response.write("\n \subsection*{%s}" % year, escape=False)
response.write("\n \\begin{enumerate}", escape=False)
for v in data[year]:
s = textwrap.fill("\\item %s" % v,
initial_indent=' '*4,
subsequent_indent=' '*4)
response.write("\n%s" % s, escape=False)
pass
response.write("\n \\end{enumerate}", escape=False)
pass
pass
return
}}
{{include}}
\ No newline at end of file
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