Commit 7f84f53f authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Add controller and view metrics/top_citations.

parent 52d223a0
......@@ -130,3 +130,107 @@ def index():
return dict(cfg_store=json.dumps(cfg, cls=JSONEncoder),
team_project=repr_team_project(db, selector),
selector=selector)
def top_citations():
"""controller to display publications with highest citations score.
"""
citations = db.citations
projects = db.projects
publications = db.publications
publishers = db.publishers
teams = db.teams
# get the user constraint.
# the selector fields year_start, year_end are excluded
# from the selector query.
tpl = ("id_authors_roles",
"id_teams",
"id_projects",
"top",
"year_start", "year_end")
selector = Selector(virtdb.top_citations_selector, exclude_fields=tpl)
# query directive for the citations table
query = selector.query(citations)
query &= publications.id_projects == projects.id
query &= publications.id_teams == teams.id
query &= publications.id_publishers == publishers.id
id_role = selector.id_authors_roles
if len(id_role) > 0:
query &= publications.id_authors_roles == id_role
id_team = selector.id_teams
if len(id_team) > 0:
query &= publications.id_teams == id_team
id_project = selector.id_projects
if len(id_project) > 0:
query &= publications.id_projects == id_project
if selector.year_start and not selector.year_end:
query &= (publications.year == selector.year_start)
elif selector.year_start and selector.year_end:
q_start = publications.year >= selector.year_start
q_end = publications.year <= selector.year_end
query &= ((q_start) & (q_end))
# configure the Ext.data.ArrayStore for the grid
max_count = citations.count.max()
irows = db(query).iterselect(
teams.domain,
teams.team,
projects.project,
publications.title,
publishers.abbreviation,
publications.volume,
publications.year,
publications.pages,
max_count,
groupby=citations.id_publications,
orderby=~max_count,
limitby=(0, selector.top))
data = [[
el.teams.domain,
el.teams.team,
el.projects.project,
f"{el.publications.title}, "
f"{el.publishers.abbreviation} {el.publications.volume} "
f"({el.publications.year}) {el.publications.pages}",
el._extra["MAX(`citations`.`count`)"]
] for el in irows]
fields = [
{"name": "domain", "type": "string"},
{"name": "team", "type": "string"},
{"name": "project", "type": "string"},
{"name": "reference", "type": "string"},
{"name": "citations", "type": "int"}]
cfg = dict(fields=fields, data=data)
# configure the grid
columns = [
{"xtype": "rownumberer"},
{"text": T("domain"), "dataIndex": "domain", "flex": 1},
{"text": T("team"), "dataIndex": "team", "flex": 0.9},
{"text": T("project"), "dataIndex": "project", "flex": 0.5},
{"text": T("reference"), "dataIndex": "reference", "flex": 2.5},
{
"text": T("citations"),
"dataIndex": "citations",
"flex": 0.5,
"align": "end"
}
]
return dict(cfg_store=json.dumps(cfg, cls=JSONEncoder),
columns=json.dumps(columns, cls=JSONEncoder),
team_project=repr_team_project(db, selector),
selector=selector)
......@@ -380,7 +380,7 @@
'List of university separated by comma': 'Liste des universités séparé par une virgule',
'List shorted by AERES category, by project and by year': 'Liste triée par catégorie AERES par projet et par année',
'List shorted by usual category, by team and by year': 'Liste triée par catégorie usuelle par équipe et par année',
'list size is not one': "La liste a plusieurs éléments",
'list size is not one': 'La liste a plusieurs éléments',
'lists': 'listes',
'Load': 'Charger',
'load in the database': 'chargé dans la base de données',
......@@ -550,6 +550,7 @@
'Record not link to a conference': 'Enregistrement sans lien à une conférence',
'Records': 'Enregistrements',
'Reference': 'Référence',
'reference': 'référence',
'Register': 'Register',
'Registration identifier': 'Registration identifier',
'Registration is pending approval': 'Registration is pending approval',
......@@ -763,6 +764,9 @@
'Too many data': 'Too many data',
'too short': 'too short',
'Tools': 'Outils',
'Top': 'Top',
'top citations': 'top citations',
'Top citations': 'Top citations',
'total': 'total',
'Total': 'Total',
'Town': 'Ville',
......
......@@ -48,9 +48,10 @@ class Selector(object):
Selector.graph_selector(virtdb, db, T)
Selector.harvester_selector(virtdb, db, T)
Selector.list_selector(virtdb, db, T)
Selector.recjson_selector(virtdb, db, T)
Selector.metric_selector(virtdb, db, T)
Selector.recjson_selector(virtdb, db, T)
Selector.run_all_harvesters_selector(virtdb, db, T)
Selector.top_citations_selector(virtdb, db, T)
@staticmethod
def authors_selector(virtdb, db, T):
......@@ -527,3 +528,34 @@ class Selector(object):
IS_INT_IN_RANGE(harvester_start_year, year)
return table
@staticmethod
def top_citations_selector(virtdb, db, T):
"""top citation selector.
Note:
selector table are store in a virtual database.
Args:
virtdb (pyDAL.DAL): connection to the virtual database
db (pyDAL.DAL): connection to the database of the application
T (gluon.languages.translator): language translator
Returns:
pyDAL.Table
"""
table = virtdb.define_table(
"top_citations_selector",
Field("year_start", "integer"),
Field("year_end", "integer"),
Field("id_teams", "reference teams", label="Team"),
Field("id_projects", "reference projects", label="Project"),
Field("id_authors_roles", "reference authors_roles", label="Role"),
Field("top", "integer", default=10))
table.id_authors_roles.requires = IS_IN_DB(db, "authors_roles.role")
table.id_projects.requires = IS_IN_DB(db, "projects.project")
table.id_teams.requires = IS_IN_DB(db, "teams.team")
return table
......@@ -28,9 +28,10 @@ class SelectorUI(object):
SelectorUI.graph_citation_selector(virtdb, db, T)
SelectorUI.harvester_selector(virtdb, db, T)
SelectorUI.list_selector(virtdb, db, T)
SelectorUI.recjson_selector(virtdb, db, T)
SelectorUI.metric_selector(virtdb, db, T)
SelectorUI.recjson_selector(virtdb, db, T)
SelectorUI.run_all_harvesters_selector(virtdb, db, T)
SelectorUI.top_citations_selector(virtdb, db, T)
@staticmethod
def check_selector(virtdb, db, T):
......@@ -395,3 +396,37 @@ class SelectorUI(object):
mdf.configure_field("id_teams",
emptyText=tr_select,
xtype="xcomboboxuserreset")
@staticmethod
def top_citations_selector(virtdb, db, T):
"""UI for the top_citations_selector table
Args:
virtdb (pyDAL.DAL): connection to the virtual database
db (pyDAL.DAL): database connection
T (gluon.languages.translator): language translator
"""
tr_select = T("select...")
# ....................................................................
#
# Fields
#
mdf = FieldsModifier("top_citations_selector")
mdf.configure_field("year_start", flex=1)
mdf.configure_field("year_end", flex=1)
mdf.merge_fields("year_start", "year_end", fieldLabel=T("Year"))
mdf.configure_field("id_authors_roles",
emptyText=tr_select,
xtype="xcomboboxuserreset")
mdf.configure_field("id_projects",
emptyText=tr_select,
xtype="xcomboboxuserreset")
mdf.configure_field("id_teams",
emptyText=tr_select,
xtype="xcomboboxuserreset")
......@@ -441,12 +441,18 @@ class ViewportUi(object):
baseUrl=URL("metrics", "index"),
extField="format")
top_citations_panel = to_panelWithUrlSelector(
virtdb.top_citations_selector,
baseUrl=URL("metrics", "top_citations"),
plugins=["pMathJax"])
add_child = node.add_child
add_child(T("dashboard"), dashboard_panel)
add_child(T("lists"), list_panel)
add_child(T("metrics"), metric_panel)
add_child(T("graphs"), graph_panel)
add_child(T("citations"), graph_citation_panel)
add_child(T("top citations"), top_citations_panel)
return node
......
{{
#--------------------------------------------------------------------------
#
# The python controller return:
# - cfg_store, the configuration of the Ext.data.Array
# - columns, definition for the grid
# - team_project (string)
# - selector object
#
# prepare the data
# - build unique DIV identifier
# - Title and DIV block
#
#--------------------------------------------------------------------------
from datetime import datetime
#
# unique identifier for the DIV block associated to the grid
#
divgrid = "grid-%s" % id(cfg_store)
#
# The title and the DIV block for the Ext.grid.Panel
#
title = "%s %s" % (T("Top citations"), team_project)
=H2(title, _class="dbui-h2 dbui-small-cap")
=DIV(_id=divgrid)
#
# The footer, procesing time for the request
#
delta = (datetime.now()-request.now).total_seconds()
delta = T('Page generated in %s seconds') % round(delta, 2)
=P(delta, BR(), request.now.strftime("%d %b %Y %H:%M"), _class="dbui-p")
=BR()
}}
<script type="text/javascript">
var cfgStore = {{=XML(cfg_store)}},
columns = {{=XML(columns)}},
divgrid = '{{=divgrid}}',
grid;
//
// check that the Ext JS library is loaded
//
if (typeof Ext === "undefined") {
alert("The javascript library Ext JS is missing !");
}
//
// instantiate the grid with a summary row.
// data can be extracted via the plugin pGridExport
//
grid = Ext.create('Dbui.grid.Panel', {
plugins: ['pGridExport',
{
ptype: 'rowexpander',
rowBodyTpl: new Ext.Template('<p>{reference}</p>')
}
],
store: Ext.create('Ext.data.ArrayStore', cfgStore),
columns: columns,
forceFit: true,
hideHeaders: false,
padding: "0 25 20 30",
renderTo: divgrid
});
</script>
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