Commit 6c369ce3 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Uniform organisation and processing between views.

parent d725ceae
......@@ -4,10 +4,7 @@
import traceback
from gluon.storage import Storage
from harvest_tools import (get_harvester_tool,
to_logsStore,
ToolException,
to_statStore)
from harvest_tools import get_harvester_tool, ToolException
from plugin_dbui import Selector
from docutils.nodes import Inline
......@@ -184,9 +181,7 @@ def run_all():
# delegate rendering to the report view
response.view = 'harvest/layout.%s' % request.extension
return dict(cfg_statStore=to_statStore(collection_logs, logs),
cfg_logsStore=to_logsStore(logs),
collection_logs=collection_logs,
return dict(collection_logs=collection_logs,
harvester=harvester,
logs=logs,
selector=selector)
......@@ -225,6 +225,7 @@
'install': 'installé',
'Institute': 'Institut',
'Institute number associated to CPPM authors': "Numéro de l'Institut associé aux auteurs du CPPM",
'Invalid': 'Non conforme',
"Invalid database table '%s'": "Invalid database table '%s'",
'Invalid email': 'Invalid email',
'invalid expression': 'expression invalide',
......@@ -439,6 +440,7 @@
'Statistics': 'Statistique',
'Status': 'Status',
'status': 'status',
'Status OK': 'Status OK',
'Store': 'Entrepôt',
'String containing blabla and the database fields to be displayed. The substitution mechanism is: {tablename.fieldname} or {foreigntablename.fieldname}': 'String containing blabla and the database fields to be displayed. The substitution mechanism is: {tablename.fieldname} or {foreigntablename.fieldname}',
'String containing the author names with their institutes number.': 'Chaîne de caractère contenant le nom des auteurs avec le numéro de leurs instituts.',
......
......@@ -402,97 +402,6 @@ def learn_cppm_authors(db, authors=None,
db.cppm_authors[row.id] = dict(authors=', '.join(database_authors))
def to_logsStore(logs):
"""Convert a list of publication message into the configuration
of the Ext.data.ArrayStore. It will contain the information on
what happen to each publication found in the harvester repository.
@type logs: list of L{Msg}
@param logs: list of publication message
@rtype: str
@return: the configuration of the Ext JS store is serialized
as a JSON string.
"""
cfg = dict(groupField='txt',
sorters=['txt', 'title'])
cfg['fields'] = [{'name': 'collection', 'type': 'string'},
{'name': 'title', 'type': 'string'},
{'name': 'txt', 'type': 'string'},
{'name': 'url', 'type': 'string'},
{'name': 'year', 'type': 'string'}]
cfg['data'] = []
for row in logs:
cfg['data'].append([row.collection,
row.title,
row.txt,
row.url,
row.year])
return json.dumps(cfg)
def to_statStore(collection_logs, logs):
"""Convert a list of collection and publication messages into the
configuration of the Ext.data.ArrayStore. It will containing the
statistic of the harvester scan for each collection.
@type logs: list of L{MsgCollection}
@param logs: list of collection message
@type logs: list of L{Msg}
@param logs: list of publication message
@rtype: str
@return: the configuration of the Ext JS store is serialized
as a JSON string.
"""
cfg = dict(sorters=['collection'])
cfg['fields'] = [{'name': 'add', 'type': 'int'},
{'name': 'error', 'type': 'string'},
{'name': 'found', 'type': 'int'},
{'name': 'idle', 'type': 'int'},
{'name': 'lost', 'type': 'int'},
{'name': 'modify', 'type': 'int'},
{'name': 'reject', 'type': 'int'},
{'name': 'title', 'type': 'string'},
{'name': 'url', 'type': 'string'}]
cfg['data'] = []
for collection in collection_logs:
# count database action for this collection
count = Storage(idle=0, load=0, modify=0, process=0, reject=0)
for row in logs:
if row.collection != collection.title:
continue
count.process += 1
count[row.action] += 1
stat = [count.load,
collection.error,
collection.found,
count.idle,
collection.found - count.process,
count.modify,
count.reject,
collection.title,
collection.url_hb()]
cfg['data'].append(stat)
return json.dumps(cfg)
class Msg(Storage):
"""Message and action taken for a publication.
- The publication is found by an harvester tool, in a store.
......@@ -1007,9 +916,7 @@ class PublicationsTool(object):
"""
return dict(cfg_statStore=to_statStore(self.collection_logs, self.logs),
cfg_logsStore=to_logsStore(self.logs),
collection_logs=self.collection_logs,
return dict(collection_logs=self.collection_logs,
harvester=self.harvester,
logs=self.logs,
selector=self.selector)
......
<!--
The title of the report
Compute an unique identifier for each DIV associated to a grid.
The python controller return:
- collection_logs (list of MsgCollection) one for each collection
- harvester (Storage)
- logs (list of MSg) one for each publication
- selector (Selector)
-->
{{
#--------------------------------------------------------------------------
#
# prepare the data
# - configure the Ext.data.Array for the statistics
# - configure the Ext.data.Array for the logs
# - build unique DIV identifier
# - write the title
#
#--------------------------------------------------------------------------
import json
#
# configure the Ext.data.Array for the statistics
# transform the collection_logs in a series of counters per collection
#
cfg = dict(sorters=['collection'])
cfg['fields'] = [{'name': 'add', 'type': 'int'},
{'name': 'error', 'type': 'string'},
{'name': 'found', 'type': 'int'},
{'name': 'idle', 'type': 'int'},
{'name': 'lost', 'type': 'int'},
{'name': 'modify', 'type': 'int'},
{'name': 'reject', 'type': 'int'},
{'name': 'title', 'type': 'string'},
{'name': 'url', 'type': 'string'}]
cfg['data'] = []
for collection in collection_logs:
# count database action for this collection
count = Storage(idle=0, load=0, modify=0, process=0, reject=0)
for row in logs:
if row.collection == collection.title:
count.process += 1
count[row.action] += 1
pass
pass
stat = [count.load,
collection.error,
collection.found,
count.idle,
collection.found - count.process,
count.modify,
count.reject,
collection.title,
collection.url_hb()]
cfg['data'].append(stat)
pass
cfg_statStore = json.dumps(cfg)
#
# configure the Ext.data.Array for the logs
#
cfg = dict(groupField='txt',
sorters=['txt', 'title'])
cfg['fields'] = [{'name': 'collection', 'type': 'string'},
{'name': 'title', 'type': 'string'},
{'name': 'txt', 'type': 'string'},
{'name': 'url', 'type': 'string'},
{'name': 'year', 'type': 'string'}]
cfg['data'] = []
for row in logs:
cfg['data'].append([row.collection,
row.title,
row.txt,
row.url,
row.year])
pass
cfg_logsStore = json.dumps(cfg)
#
# unique identifier for each DIV block associated to a grid
#
divstat = abs(hash(cfg_statStore))
divlogs = abs(hash(cfg_logsStore))
# the title
period = ""
if selector.year_start and selector.year_end:
period = T("from %s to %s") % (selector.year_start, selector.year_end)
......@@ -12,6 +103,9 @@
pass
#
# Write the Title on the HTML page
#
project = ""
if selector.id_projects:
project = db.projects[selector.id_projects].project
......@@ -26,10 +120,6 @@
"margin-top: 2ex;"]
response.write(P(title, _style="".join(style)))
# identifier for each DIV block associated to a grid
divstat = abs(hash(cfg_statStore))
divlogs = abs(hash(cfg_logsStore))
}}
<!--
The two DIV blocks to hook the Ext JS grid
......
......@@ -4,21 +4,25 @@
- selector (Selector)
- counters (dict of Storage) the key are the project
The storage keys are: found, ok, validated
Prepare the data
- Configuration for the Ext.data.Array
- Unique DIV identifiers
- Title
-->
{{
#--------------------------------------------------------------------------
#
# prepare the data
# - configure the Ext.data.Array for the statistics
# - configure the Ext.data.Array for the logs
# - build unique DIV identifier
# - write the title
#
#--------------------------------------------------------------------------
import json
#
# transform the counters into a configuration of the Ext.data.Array
# configure the Ext.data.Array for the statistics
#
cfg = dict(sorters=['project'])
cfg['fields'] = [{'name': 'found', 'type': 'int'},
cfg['fields'] = [{'name': 'records', 'type': 'int'},
{'name': 'ok', 'type': 'int'},
{'name': 'project', 'type': 'string'},
{'name': 'validated', 'type': 'int'},
......@@ -34,7 +38,7 @@
cfg_statStore = json.dumps(cfg)
#
# transform the logs into a configuration for the Ext.data.Array
# configure the Ext.data.Array for the logs
#
cfg = dict(groupField='txt',
sorters=['txt', 'title'])
......@@ -49,19 +53,21 @@
cfg['data'] = []
for row in logs:
cfg['data'].append([row.category,
row.id,
','.join(row.ids),
row.project,
row.title,
', '.join(row.txt),
row.year])
for txt in row.txt:
cfg['data'].append([row.category,
row.id,
','.join(row.ids),
row.project,
row.title,
txt,
row.year])
pass
pass
cfg_logsStore = json.dumps(cfg)
#
# identifier for each DIV block associated to a grid
# unique identifier for each DIV block associated to a grid
#
divlogs = abs(hash(cfg_logsStore))
divstat = abs(hash(cfg_statStore))
......@@ -126,11 +132,11 @@
trCollection,
trDuplicate,
trError,
trFound,
trId,
trOk,
trInvalid,
trProject,
trStatistics,
trStatusOK,
trTitle,
trValidated,
trYear;
......@@ -152,11 +158,12 @@
response.write("trCollection = '%s';" % T('Collection'), escape=False)
response.write("trDuplicate = '%s';" % T('Duplicate'), escape=False),
response.write("trError = '%s';" % T('Error'), escape=False),
response.write("trFound = '%s';" % T('Found'), escape=False),
response.write("trId = '%s';" % T('Id'), escape=False),
response.write("trOk = '%s';" % T('Ok'), escape=False),
response.write("trInvalid = '%s';" % T('Invalid'), escape=False),
response.write("trProject = '%s';" % T('Project'), escape=False),
response.write("trRecords = '%s';" % T('Records'), escape=False),
response.write("trStatistics = '%s';" % T('Statistics'), escape=False)
response.write("trStatusOK = '%s';" % T('Status OK'), escape=False),
response.write("trTitle = '%s';" % T('Title'), escape=False)
response.write("trValidated = '%s';" % T('Validated'), escape=False),
response.write("trYear = '%s';" % T('Year'), escape=False)
......@@ -169,10 +176,10 @@
columns: [
{xtype: 'rownumberer'},
{text: trProject, dataIndex: 'project', flex: 2, summaryRenderer: rTotal},
{text: trFound, dataIndex: 'found', flex: 1, summaryType: 'sum'},
{text: trOk, dataIndex: 'ok', flex: 1, summaryType: 'sum'},
{text: trRecords, dataIndex: 'records', flex: 1, summaryType: 'sum'},
{text: trStatusOK, dataIndex: 'ok', flex: 1, summaryType: 'sum'},
{text: trValidated, dataIndex: 'validated', flex: 1, summaryType: 'sum'},
{text: trError, dataIndex: 'error', flex: 1, summaryType: 'sum'}
{text: trInvalid, dataIndex: 'error', flex: 1, summaryType: 'sum'}
],
forceFit: true,
features: [{ftype:'summary'}],
......
......@@ -15,9 +15,6 @@
\makeatother
\begin{document}
{{
from datetime import datetime
from view_tools import compare_latex
#--------------------------------------------------------------------------
#
# prepare the data
......@@ -26,6 +23,9 @@
# - sort the projects as well as the logs per error and then per title
#
#--------------------------------------------------------------------------
from datetime import datetime
from view_tools import compare_latex
# projects
projects = counters.keys()
projects.sort()
......
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