Commit 3de4974c authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Run code analysis.

parent 646bce24
......@@ -11,7 +11,6 @@ import time
from datetime import date
from gluon import current
from gluon.storage import Storage
from plugin_dbui import get_id
DATE_MIN = date(1990, 01, 01)
......@@ -75,7 +74,9 @@ def _get_items_per_year(func, **kwargs):
"""
is_start = "year_start" in kwargs and kwargs["year_start"] not in (None, '')
is_start = \
"year_start" in kwargs and kwargs["year_start"] not in (None, '')
is_end = "year_end" in kwargs and kwargs["year_end"] not in (None, '')
if not is_start and not is_end:
......@@ -135,7 +136,7 @@ def active_period(**kwargs):
query = query_history(db, **kwargs)
fields = [history.start_date, history.end_date]
rows = db.executesql(db(query)._select(*fields))
rows = db.executesql(db(query)._select(*fields))
# fin the start / end point using DataFrame
df = (pd.DataFrame(list(rows), columns=["start", "end"])
......@@ -160,8 +161,8 @@ def coverage(start_date, end_date, year_start, year_end):
float64
"""
coverage = np.minimum(end_date, year_end) - \
np.maximum(start_date, year_start)
coverage = \
np.minimum(end_date, year_end) - np.maximum(start_date, year_start)
return coverage / (year_end - year_start)
......@@ -832,7 +833,7 @@ def get_objectlike_items_per_year(**kwargs):
* one column for each key of the history.data dictionary
"""
return _get_items_per_year(get_object_like_items, **kwargs)
return _get_items_per_year(get_objectlike_items, **kwargs)
def get_peoplelike_items(**kwargs):
......@@ -952,9 +953,10 @@ def get_people_per_year(**kwargs):
several years.
The DataFrame contains a reduced set of information for each item, namely
the meta-data, category, domain, funding, people, project, team information,
the ``history.data`` and a set of computed values. The ``history.data``
is a dictionary which is "json normalised", one column per key.
the meta-data, category, domain, funding, people, project, team
information, the ``history.data`` and a set of computed values.
The ``history.data`` is a dictionary which is "json normalised",
one column per key.
The DataFrame contains computed columns:
* coverage
......@@ -1033,13 +1035,13 @@ def get_people_per_year(**kwargs):
df = (_get_items_per_year(get_peoplelike_items, **kwargs)
.assign(
period=lambda x:
x.apply(lambda y:
active_period(id_events=y.id_events,
id_people=y.id_people,
id_domains=y.id_domains,
id_teams=y.id_teams,
id_projects=y.id_projects),
axis="columns"))
x.apply(lambda y:
active_period(id_events=y.id_events,
id_people=y.id_people,
id_domains=y.id_domains,
id_teams=y.id_teams,
id_projects=y.id_projects),
axis="columns"))
.assign(
period_start=lambda x: x.period.apply(lambda y: y[0]),
period_end=lambda x: x.period.apply(lambda y: y[1]),
......@@ -1053,18 +1055,18 @@ def get_people_per_year(**kwargs):
.assign(
coverage=lambda x:
coverage(x.start_date,
x.end_date,
x.year_start,
x.year_end),
coverage(x.start_date,
x.end_date,
x.year_start,
x.year_end),
full_name=lambda x: full_name(x.first_name, x.last_name),
is_start=lambda x:
is_start(x.year_start, x.year_end, x.period_start),
is_start(x.year_start, x.year_end, x.period_start),
is_end=lambda x:
is_end(x.year_start, x.year_end, x.period_end))
is_end(x.year_start, x.year_end, x.period_end))
.assign(fte=lambda x: x.coverage * x.percentage * 0.01))
......@@ -1085,11 +1087,11 @@ def get_people_per_year(**kwargs):
.assign(
agency=lambda x: pd.Categorical(x.agency),
people_categories_category=
lambda x: pd.Categorical(x.people_categories_category),
people_categories_category=lambda x:
pd.Categorical(x.people_categories_category),
people_categories_code=
lambda x: pd.Categorical(x.people_categories_code),
people_categories_code=lambda x:
pd.Categorical(x.people_categories_code),
team=lambda x: pd.Categorical(x.team)))
......@@ -1266,7 +1268,7 @@ def query_history(db, **kwargs):
elif k == "year_start":
year_start = date(int(di["year_start"]), 01, 01)
qi = (history.end_date == None) | (history.end_date >= year_start)
qi = (history.end_date is None) | (history.end_date >= year_start)
else:
qi = history[k] == v
......@@ -1333,7 +1335,7 @@ def to_extjs_gridcolumns(df):
cfg.dataIndex = cfg.text = colname
if colname.startswith("id"):
if colname.startswith("id"):
cfg.flex = 0.5
cfg.format = "0"
cfg.hidden = True
......
......@@ -14,6 +14,7 @@ from dataframes import (get_items,
get_peoplelike_items_per_year,
get_people_per_year)
class Event(object):
"""Initialise the plugin event.
......@@ -42,7 +43,6 @@ class Event(object):
"lg": "static/plugin_event/locale/event-lang-%s.js" % lg,
"libmin": "static/plugin_event/event-min.js"}
@staticmethod
def register_source(name, func):
"""Register sources which are used in the reporting section.
......@@ -64,12 +64,18 @@ class Event(object):
"""Register all sources defined in plugin_event.
"""
Event.register_source("items",get_items)
Event.register_source("items per year",get_items_per_year)
Event.register_source("items small",get_items_small)
Event.register_source("items small per year",get_items_small_per_year)
Event.register_source("object like",get_objectlike_items)
Event.register_source("object like per year",get_objectlike_items_per_year)
Event.register_source("people like",get_peoplelike_items)
Event.register_source("people like per year",get_peoplelike_items_per_year)
Event.register_source("people per year",get_people_per_year)
Event.register_source("items", get_items)
Event.register_source("items per year", get_items_per_year)
Event.register_source("items small", get_items_small)
Event.register_source("items small per year", get_items_small_per_year)
Event.register_source("object like", get_objectlike_items)
Event.register_source("object like per year",
get_objectlike_items_per_year)
Event.register_source("people like", get_peoplelike_items)
Event.register_source("people like per year",
get_peoplelike_items_per_year)
Event.register_source("people per year", get_people_per_year)
......@@ -4,10 +4,12 @@
"""
import matplotlib as mpl
import os
import pandas as pd
from datetime import datetime
from gluon import current
from math import sqrt
from matplotlib.backends.backend_pdf import PdfPages
from matplotlib.ticker import IndexLocator
......@@ -108,14 +110,16 @@ def plot_references(ax, lines, values, xpos, stacked=False):
transform=ax.transData)
def plot_values(ax, series, fmt="%.0f",
fontsize=8.,
maxseries=None,
percentage=0.10,
xoffset=0,
yoffset=-10,
zero=1E-05,
**kwargs):
def plot_values(ax,
series,
fmt="%.0f",
fontsize=8.,
maxseries=None,
percentage=0.10,
xoffset=0,
yoffset=-10,
zero=1E-05,
**kwargs):
"""plot values in bar graph.
Args:
......@@ -155,7 +159,7 @@ def plot_values(ax, series, fmt="%.0f",
# plot values
if maxseries is None:
maxseries = max(series)
cut = round( maxseries * percentage)
cut = round(maxseries * percentage)
for i in xrange(ndata):
value = series.iloc[i]
......
......@@ -7,7 +7,6 @@ import plugin_dbui as dbui
from callbacks import INHIBIT_CASCADE_DELETE
from datetime import datetime
from gluon import current
from gluon.validators import IS_IN_DB
from pydal import Field
......@@ -243,7 +242,13 @@ class Core(object):
"""
table = db.define_table(
"objects",
Field("reference", "string", length=255, notnull=True, unique=True),
Field("reference",
"string",
length=255,
notnull=True,
unique=True),
Field("serial_number", "string", length=255),
Field("batch_number", "string", length=255),
Field("note", "text"),
......
......@@ -3,13 +3,10 @@
"""
import numpy as np
import plugin_dbui as dbui
from callbacks import (INHIBIT_CASCADE_DELETE,
ON_CREATE_LISTS2,
ON_UPDATE_LISTS2)
from gluon import current, IS_IN_DB, IS_IN_SET
from callbacks import ON_CREATE_LISTS2, ON_UPDATE_LISTS2
from gluon import current, IS_IN_SET
from gluon.tools import PluginManager
from pydal import Field
......@@ -105,9 +102,9 @@ TP_GROUP_FIELD_METRICS = \
TP_FEATURES = "Summary value can be computed for columns."
TP_SORTERS = \
"Entries are sorted according to the value of these fields. " \
"It can be any field of the history table including those of the " \
"foreign tables, the individual property of the history.data dictionary, " \
"Entries are sorted according to the value of these fields. "\
"It can be any field of the history table including those of the "\
"foreign tables, the individual property of the history.data dictionary, "\
"or 'year'. Descending order is obtained by using the '~field' construct."
TP_SUMMARY_X = "To sum, for example, the content of each row."
......@@ -219,7 +216,6 @@ class Report(object):
"""
migrate = current.globalenv["MIGRATE"]
def_features = (None if migrate else DEF_FEATURES)
table = db.define_table(
"lists2",
......@@ -285,7 +281,7 @@ class Report(object):
"""
def_columns = (None if db._migrate else DEF_COLUMNS_METRIC1D)
table = db.define_table(
db.define_table(
"metrics1d",
Field("name", "string", length=255, notnull=True, unique=True),
Field("title", "string", length=255),
......@@ -412,7 +408,12 @@ class Report(object):
notnull=True),
Field("summary_x", "json", default=DEF_SUMMARY, label="Per row"),
Field("summary_y", "json", default=DEF_SUMMARY, label="Per column"),
Field("summary_y",
"json",
default=DEF_SUMMARY,
label="Per column"),
Field("graph", "json", default=DEF_GRAPH),
migrate="metrics2d2.table")
......
......@@ -59,9 +59,9 @@ class Selector(object):
"reference people_categories",
label="Quality"),
Field("id_objects", "reference objects", label="Reference"),
Field("id_objects", "reference objects", label="Reference"),
Field("id_object_categories",
Field("id_object_categories",
"reference alias_object_categories",
label="Category"),
......@@ -92,16 +92,16 @@ class Selector(object):
"box, kde, area, pie, scatter, hexbin"))
table.id_object_categories.requires = \
IS_IN_DB(db, "alias_object_categories.category")
IS_IN_DB(db, "alias_object_categories.category")
table.id_object_code.requires = \
IS_IN_DB(db, "object_categories.code")
IS_IN_DB(db, "object_categories.code")
table.id_people.requires = \
IS_IN_DB(db, "people.last_name")
IS_IN_DB(db, "people.last_name")
table.id_people_categories.requires = \
IS_IN_DB(db, "alias_people_categories.category")
IS_IN_DB(db, "alias_people_categories.category")
table.id_domains.requires = IS_IN_DB(db, "domains.domain")
table.id_fundings.requires = IS_IN_DB(db, "fundings.agency")
......
......@@ -9,7 +9,6 @@ import pandas as pd
from gluon import current
from gluon.storage import Storage
from gluon.tools import PluginManager
from matplotlib_tools import style
from model_report import AGGREGATE_FUNCS
from plugin_dbui import Selector, Store
from StringIO import StringIO
......@@ -300,7 +299,6 @@ class List2(BaseReport):
db = current.globalenv["db"]
BaseReport.__init__(self, db.lists2, id_list)
# ....................................................................
#
# Get the configuration for the grid columns and check it
......@@ -310,7 +308,6 @@ class List2(BaseReport):
grid_columns = [Storage(el) for el in json.loads(config.columns)]
[self._check_column(el) for el in grid_columns]
# ....................................................................
#
# Configure Ext JS store
......@@ -352,7 +349,6 @@ class List2(BaseReport):
if config.summary_all:
grid.features.append(SUMMARY)
def _add_store_fields(self, column):
"""Add ``Ext.data.Field`` to the store configuration
It is derived from the ``Ext.grid.Column`` configuration.
......
......@@ -8,7 +8,7 @@ import json
from datetime import date, timedelta
from gluon import current
from gluon.dal import Field
from plugin_dbui import get_id, Selector
from plugin_dbui import Selector
RAWSQL_ACTIVITY = \
......@@ -195,7 +195,7 @@ class EvtSelector(SelectorActiveItems):
id_domain,
id_team)
rows = self._db.executesql(rawsql)
rows = self._db.executesql(rawsql)
nrows = len(rows)
if nrows == 1:
......
......@@ -43,7 +43,7 @@ class CoreUi(object):
T (gluon.languages.translator): language translator
"""
#.....................................................................
# ....................................................................
#
# Store
#
......@@ -58,7 +58,7 @@ class CoreUi(object):
T (gluon.languages.translator): language translator
"""
#.....................................................................
# ....................................................................
#
# Fields
#
......@@ -69,7 +69,7 @@ class CoreUi(object):
fieldLabel="",
xtype="xuserdata")
#.....................................................................
# ....................................................................
#
# Form
#
......@@ -81,7 +81,7 @@ class CoreUi(object):
mdf.set_mapper(dbui.map_tabpanel)
mdf.configure(plugins=["pUserDataConsistency"], width=450)
#.....................................................................
# ....................................................................
#
# Grid
#
......@@ -106,7 +106,7 @@ class CoreUi(object):
mdf.configure(plugins=[row_widget])
#.....................................................................
# ....................................................................
#
# Store
#
......@@ -121,14 +121,14 @@ class CoreUi(object):
T (gluon.languages.translator): language translator
"""
#.....................................................................
# ....................................................................
#
# Grid
#
mdf = gridModifier("fundings")
mdf.configure_column("agency", width=40)
#.....................................................................
# ....................................................................
#
# Store
#
......@@ -145,7 +145,7 @@ class CoreUi(object):
"""
undef = current.T(dbui.UNDEF)
#.....................................................................
# ....................................................................
#
# Fields
#
......@@ -166,7 +166,7 @@ class CoreUi(object):
mdf.configure_field("note", height=150)
#.....................................................................
# ....................................................................
#
# Form
#
......@@ -197,7 +197,7 @@ class CoreUi(object):
mdf.configure(buttonAlign="right", width=450)
#.....................................................................
# ....................................................................
#
# Grid
#
......@@ -228,7 +228,10 @@ class CoreUi(object):
mdf.append_filter(("end_date", "<=", T("less or equal to")))
mdf.append_filter(
("data", "like", "key(s) is(are) equal to value(s). The jocker is %"),
("data", "like",
"key(s) is(are) equal to value(s). The jocker is %"),
fieldLabel=T("Data"),
header=[T("key"), T("value")],
numColumns=2,
......@@ -239,7 +242,7 @@ class CoreUi(object):
width=300,
xtype="xhistorygridfilter")
#.....................................................................
# ....................................................................
#
# Store
#
......@@ -254,7 +257,7 @@ class CoreUi(object):
T (gluon.languages.translator): language translator
"""
#.....................................................................
# ....................................................................
#
# Grid
#
......@@ -262,7 +265,7 @@ class CoreUi(object):
mdf.configure_column("code", width=20)
mdf.configure_column("category", width=20)
#.....................................................................
# ....................................................................
#
# Store
#
......@@ -277,7 +280,7 @@ class CoreUi(object):
T (gluon.languages.translator): language translator
"""
#.....................................................................
# ....................................................................
#
# Grid
#
......@@ -289,8 +292,7 @@ class CoreUi(object):
mdf.configure_filters(plugins=["pFormToolTip"], width=300)
#.....................................................................
# ....................................................................
#
# Store
#
......@@ -305,7 +307,7 @@ class CoreUi(object):
T (gluon.languages.translator): language translator
"""
#.....................................................................
# ....................................................................
#
# Grid
#
......@@ -313,8 +315,7 @@ class CoreUi(object):
mdf.configure_column("code", width=20)
mdf.configure_column("category", width=20)
#.....................................................................
# ....................................................................
#
# Store
#
......@@ -329,7 +330,7 @@ class CoreUi(object):
T (gluon.languages.translator): language translator
"""
#.....................................................................
# ....................................................................
#
# Grid
#
......@@ -345,7 +346,7 @@ class CoreUi(object):
mdf.configure_filters(plugins=["pFormToolTip"], width=300)
#.....................................................................
# ....................................................................
#
# Store
#
......@@ -360,16 +361,16 @@ class CoreUi(object):
T (gluon.languages.translator): language translator
"""
#.....................................................................
# ....................................................................
#
# Grid
#
mdf = gridModifier("projects")
mdf.configure_column("project", width=20)
#.....................................................................
# ....................................................................
#
# STORE CONFIGURATiON
# Store
#
storeModifier("projects").orderby(db.projects.project)
......@@ -382,14 +383,14 @@ class CoreUi(object):
T (gluon.languages.translator): language translator
"""
#.....................................................................
# ....................................................................
#
# Grid
#
mdf = gridModifier("teams")
mdf.configure_column("team", width=20)
#.....................................................................
# ....................................................................
#
# Store
#
......
......@@ -54,7 +54,7 @@ class ReportUi(object):
T (gluon.languages.translator): language translator
"""
#.....................................................................
# ....................................................................
#
# Fields
#
......@@ -75,7 +75,7 @@ class ReportUi(object):
mdf.configure_field("report_type",
displayField="report_type",
emptyText= T("select..."),
emptyText=T("select..."),
itemId="mastercombo_report_type",
refStore=store,
valueField="report_type",
......@@ -90,7 +90,7 @@ class ReportUi(object):
valueField="report_name",
xtype="xcomboboxslave")
#.....................................................................