{{ #-------------------------------------------------------------------------- # The python controller return: # - collection_logs (list of MsgCollection) one for each collection # - controller (String) harvester controller # - 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 # - the title of the page # - the DIV block # - the HTML page footer # - export python variable to the javascript # #-------------------------------------------------------------------------- import gluon import json from datetime import datetime # # 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.action in count and 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': 'action', 'type': 'string'}, {'name': 'collection', 'type': 'string'}, {'name': 'harvester', 'type': 'string'}, {'name': 'host', 'type': 'string'}, {'name': 'record_id', 'type': 'string'}, {'name': 'synonym', '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.action, row.collection, json.dumps(row.harvester), row.harvester.host, row.record_id, row.synonym, row.title, row.txt, row.url, row.year]) pass cfg_logsStore = json.dumps(cfg) # # Write the Title on the HTML page # period = "" if selector.year_start and selector.year_end: period = T("from %s to %s") % (selector.year_start, selector.year_end) elif selector.year_start: period = str(selector.year_start) pass project = "" if selector.id_projects: project = db.projects[selector.id_projects].project pass title = "%s %s %s" % (controller.title(), project, period) style = ["font-size: 12px;", "font-variant: small-caps;", "margin-left: 10px;", "margin-bottom: 3ex;", "margin-top: 2ex;"] response.write(P(title, _style="".join(style))) # # the DIV blocks, one for each grid # divstat = "grid-%s" % id(cfg_statStore) divlogs = "grid-%s" % id(cfg_logsStore) response.write(DIV(_id=divstat)) response.write(DIV(_id=divlogs)) # # the footer, processing time of the request # delta = (datetime.now()-request.now).total_seconds() delta = T('Harvester took %s seconds') % round(delta, 2) style = ["font-size: 10px;", "margin-left: 10px;", "margin-bottom: 3ex;", "margin-top: 2ex;"] response.write(P(delta, _style="".join(style))) }}