Commit 913ce635 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Add controllers and view graphs/citations.

parent 58ee526c
......@@ -17,6 +17,80 @@ from graph_tools import (FROM_TO,
from models.selector import YEAR_SUBMIT
def citations():
"""Return graphs showing citations
"""
import matplotlib.ticker as ticker
import numpy as np
import pandas as pd
from plugin_dbui import Selector
selector = Selector(
virtdb.graph_citation_selector,
exclude_fields=("id_graphs"))
selector.append_query(db.publications.id == db.citations.id_publications)
query = selector.query(db.publications)
rows = db(query).iterselect(db.publications.id,
db.teams.team,
db.teams.domain,
db.projects.project,
db.citations.date,
db.citations.count)
columns = ["id_publi", "date", "citations", "domain", "team", "project"]
data = (
(el.publications.id,
el.citations.date,
el.citations.count,
el.teams.domain,
el.teams.team,
el.projects.project) for el in rows)
df = (pd.DataFrame(data, columns=columns)
.groupby(["id_publi", "date"])
.last())
data = df.citations
bins = [-0.5, 0.5, 9.5, 49.5, 99.5, 249.5, 499.5, data.max()+1]
hist, dummy = np.histogram(data, bins)
ind = np.arange(len(hist))
mplstyle()
fig = Figure()
ax = fig.subplots(nrows=1, ncols=1)
ax.bar(ind, hist)
ax.minorticks_on()
xlabels = ("",
"0",
"1 à 9",
"10 à 49",
"50 à 99",
"100 à 249",
"250 à 499",
"+500")
ax.xaxis.set_ticklabels(xlabels)
ax.grid(True)
ax.set_xlabel("Number of citations", horizontalalignment='right', x=1.)
ax.set_ylabel("Number of publications", horizontalalignment='right', y=1.)
ax.xaxis.set_minor_locator(ticker.NullLocator())
buf = io.BytesIO()
fig.savefig(buf, format="svg")
data = base64.b64encode(buf.getbuffer()).decode("ascii")
return dict(data=data)
def dashboard():
"""Return a pre-configure linechart for public used.
Cumulative distribution for the publications are shown for
......
......@@ -127,6 +127,7 @@
'Check latex syntax in the title': 'Vérifier la syntaxe latex dans le titre',
'Check that the publication URL corresponds to a pdf file.': 'Check that the publication URL corresponds to a pdf file.',
'Check to delete': 'Check to delete',
'citations': 'citations',
'Click on the link %(link)s to verify your email': 'Click on the link %(link)s to verify your email',
'Click on the link http://localhost:8000/limbra/default/user/reset_password/%(key)s to reset your password': 'Click on the link http://localhost:8000/limbra/default/user/reset_password/%(key)s to reset your password',
'Client IP': 'Client IP',
......
......@@ -42,6 +42,7 @@ class Selector(object):
Selector.citation_selector(virtdb, db, T)
Selector.edit_insert_selector(virtdb, db, T)
Selector.free_harvester_selector(virtdb, db, T)
Selector.graph_citation_selector(virtdb, db, T)
Selector.graph_selector(virtdb, db, T)
Selector.harvester_selector(virtdb, db, T)
Selector.list_selector(virtdb, db, T)
......@@ -278,6 +279,39 @@ class Selector(object):
return table
@staticmethod
def graph_citation_selector(virtdb, db, T):
"""graph 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(
"graph_citation_selector",
Field("year_start", "integer"),
Field("year_end", "integer"),
Field("id_teams", "reference teams", label="Team"),
Field("id_projects", "reference projects", label="Project"),
Field("author", "string"),
Field("id_authors_roles", "reference authors_roles", label="Role"),
Field("id_graphs", "reference graphs", label="Graph"))
table.id_authors_roles.requires = IS_IN_DB(db, "authors_roles.role")
table.id_graphs.requires = IS_IN_DB(db, "graphs.graph")
table.id_projects.requires = IS_IN_DB(db, "projects.project")
table.id_teams.requires = IS_IN_DB(db, "teams.team")
return table
@staticmethod
def harvester_selector(virtdb, db, T):
"""harvester selector.
......
......@@ -25,6 +25,7 @@ class SelectorUI(object):
SelectorUI.edit_insert_selector(virtdb, db, T)
SelectorUI.free_harvester_selector(virtdb, db, T)
SelectorUI.graph_selector(virtdb, db, T)
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)
......@@ -179,6 +180,42 @@ class SelectorUI(object):
emptyText=tr_select,
xtype="xcomboboxuserreset")
@staticmethod
def graph_citation_selector(virtdb, db, T):
"""UI for the graph_citation_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("graph_citation_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_graphs", selectFirst=True)
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")
@staticmethod
def harvester_selector(virtdb, db, T):
"""UI for the harvester_selector table
......
......@@ -417,6 +417,10 @@ class ViewportUi(object):
baseUrl=URL("graphs", "publications_versus_time"),
extField="format")
graph_citation_panel = to_panelWithUrlSelector(
virtdb.graph_citation_selector,
baseUrl=URL("graphs", "citations"))
list_panel = to_panelWithUrlSelector(
virtdb.list_selector,
baseUrl=URL("lists", "index"),
......@@ -433,6 +437,7 @@ class ViewportUi(object):
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)
return node
......
{{
#--------------------------------------------------------------------------
#
# The python controller return image as a string:
# - data (string)
#
#--------------------------------------------------------------------------
import urllib.parse
# encode special charactier bo be used in the image URI
data = urllib.parse.quote(data)
}}
<img src="data:image/svg+xml;base64,{{=data}}" height=400></img>
{{
from datetime import datetime
#
# the footer, processing time of 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()
}}
\ 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