Commit 6967ade6 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Apply 2to3 converter to modules.

parent e3256b57
# -*- coding: utf-8 -*- from .auth import (ADMIN,
configure_auth,
ID_ADMIN,
ID_USER,
USER)
from auth import (ADMIN, from .callbacks import (INHIBIT_CASCADE_DELETE,
configure_auth, ON_CREATE_LISTS2,
ID_ADMIN, ON_UPDATE_LISTS2)
ID_USER,
USER)
from callbacks import (INHIBIT_CASCADE_DELETE, from .dataframes import (active_period,
ON_CREATE_LISTS2, coverage,
ON_UPDATE_LISTS2) DATE_MAX,
DATE_MIN,
db2df,
debug_df,
elapse_time,
expand_per_year,
full_name,
get_column_names,
get_items,
get_items_per_year,
get_items_small,
get_items_small_per_year,
get_objectlike_items,
get_objectlike_items_per_year,
get_peoplelike_items,
get_peoplelike_items_per_year,
get_people_per_year,
is_end,
is_start,
normalize_history_data,
query_history,
Timer,
to_extjs_gridcolumns,
to_items_per_year)
from dataframes import (active_period, from .event import (Event,
coverage, EventException)
DATE_MAX,
DATE_MIN,
db2df,
debug_df,
elapse_time,
expand_per_year,
full_name,
get_column_names,
get_items,
get_items_per_year,
get_items_small,
get_items_small_per_year,
get_objectlike_items,
get_objectlike_items_per_year,
get_peoplelike_items,
get_peoplelike_items_per_year,
get_people_per_year,
is_end,
is_start,
normalize_history_data,
query_history,
Timer,
to_extjs_gridcolumns,
to_items_per_year)
from event import (Event, from .matplotlib_tools import (bicolor,
EventException) create_pdf,
header_footer,
plot_references,
plot_values,
style,
table_only,
ticks_and_labels,
xticks_and_labels)
from matplotlib_tools import (bicolor, from .model_core import Core
create_pdf, from .model_report import Report
header_footer, from .model_selector import Selector
plot_references,
plot_values,
style,
table_only,
ticks_and_labels,
xticks_and_labels)
from model_core import Core from .report_tools import (BaseReport,
from model_report import Report Graph,
from model_selector import Selector List,
Metric2D,
ReportException,
Source)
from report_tools import (BaseReport, from .ui_core import CoreUi
Graph, from .ui_report import ReportUi
List, from .ui_selector import SelectorUi
Metric2D, from .ui_viewport import ViewportUi
ReportException,
Source)
from ui_core import CoreUi
from ui_report import ReportUi
from ui_selector import SelectorUi
from ui_viewport import ViewportUi
# -*- coding: utf-8 -*-
""" auth """ auth
* Customise the authentication * Customise the authentication
......
# -*- coding: utf-8 -*-
"""a collections of functions to be used in _before_delete, before_insert """a collections of functions to be used in _before_delete, before_insert
and _before_update callbacks. and _before_update callbacks.
...@@ -6,8 +5,8 @@ and _before_update callbacks. ...@@ -6,8 +5,8 @@ and _before_update callbacks.
import json import json
from dataframes import to_extjs_gridcolumns from .dataframes import to_extjs_gridcolumns
from event import Event from .event import Event
from gluon import current from gluon import current
from plugin_dbui import CALLBACK_ERRORS, get_where_query from plugin_dbui import CALLBACK_ERRORS, get_where_query
......
# -*- coding: utf-8 -*-
"""report_dataframe module """report_dataframe module
""" """
...@@ -13,7 +12,7 @@ from gluon import current ...@@ -13,7 +12,7 @@ from gluon import current
from gluon.storage import Storage from gluon.storage import Storage
DATE_MIN = date(1990, 01, 01) DATE_MIN = date(1990, 1, 1)
DATE_MAX = date(2050, 12, 31) DATE_MAX = date(2050, 12, 31)
HISTORY_QUERY_FIELDS = [ HISTORY_QUERY_FIELDS = [
...@@ -175,22 +174,22 @@ def debug_df(df, opt=""): ...@@ -175,22 +174,22 @@ def debug_df(df, opt=""):
""" """
if "i" in opt or "a" in opt: if "i" in opt or "a" in opt:
df.memory_usage() df.memory_usage()
print df.info() print(df.info())
if "c" in opt or "a" in opt: if "c" in opt or "a" in opt:
print df.columns.sort_values() print(df.columns.sort_values())
if "I" in opt or "a" in opt: if "I" in opt or "a" in opt:
print df.index print(df.index)
if "h" in opt or "a" in opt: if "h" in opt or "a" in opt:
print df.head() print(df.head())
if "t" in opt or "a" in opt: if "t" in opt or "a" in opt:
print df.tail() print(df.tail())
if "f" in opt or "a" in opt: if "f" in opt or "a" in opt:
print df print(df)
def elapse_time(start_date, end_date, xdate): def elapse_time(start_date, end_date, xdate):
...@@ -260,7 +259,7 @@ def expand_per_year(df, year_start, year_end): ...@@ -260,7 +259,7 @@ def expand_per_year(df, year_start, year_end):
# an item appears several time when it is active during several years. # an item appears several time when it is active during several years.
df2 = pd.DataFrame() df2 = pd.DataFrame()
for year in xrange(year_start, year_end+1): for year in range(year_start, year_end+1):
dfi = (df1.loc[[str(year) in el for el in df1.years]] dfi = (df1.loc[[str(year) in el for el in df1.years]]
.assign(year=year)) .assign(year=year))
df2 = pd.concat((df2, dfi), ignore_index=True) df2 = pd.concat((df2, dfi), ignore_index=True)
...@@ -1048,7 +1047,7 @@ def get_people_per_year(**kwargs): ...@@ -1048,7 +1047,7 @@ def get_people_per_year(**kwargs):
.assign( .assign(
period_start=lambda x: x.period.apply(lambda y: y[0]), period_start=lambda x: x.period.apply(lambda y: y[0]),
period_end=lambda x: x.period.apply(lambda y: y[1]), period_end=lambda x: x.period.apply(lambda y: y[1]),
year_start=lambda x: x.year.apply(lambda y: date(y, 01, 01)), year_start=lambda x: x.year.apply(lambda y: date(y, 1, 1)),
year_end=lambda x: x.year.apply(lambda y: date(y, 12, 31)))) year_end=lambda x: x.year.apply(lambda y: date(y, 12, 31))))
# #
...@@ -1268,7 +1267,7 @@ def query_history(db, **kwargs): ...@@ -1268,7 +1267,7 @@ def query_history(db, **kwargs):
di = {k: kwargs[k] for k in HISTORY_QUERY_FIELDS if k in kwargs} di = {k: kwargs[k] for k in HISTORY_QUERY_FIELDS if k in kwargs}
for k, v in di.iteritems(): for k, v in di.items():
if (v in ('', None)) or (k == "data"): if (v in ('', None)) or (k == "data"):
continue continue
...@@ -1278,7 +1277,7 @@ def query_history(db, **kwargs): ...@@ -1278,7 +1277,7 @@ def query_history(db, **kwargs):
qi = history.start_date <= year_end qi = history.start_date <= year_end
elif k == "year_start": elif k == "year_start":
year_start = date(int(di["year_start"]), 01, 01) year_start = date(int(di["year_start"]), 1, 1)
qi = (history.end_date == None) | (history.end_date >= year_start) qi = (history.end_date == None) | (history.end_date >= year_start)
elif k == "id_object_code": elif k == "id_object_code":
...@@ -1326,7 +1325,7 @@ class Timer(object): ...@@ -1326,7 +1325,7 @@ class Timer(object):
self.end = time.time() self.end = time.time()
self.secs = self.end - self.start self.secs = self.end - self.start
self.msecs = self.secs * 1000 # millisecs self.msecs = self.secs * 1000 # millisecs
print '\n%s\n\telapsed time: %f ms' % (self.msg, self.msecs) print('\n%s\n\telapsed time: %f ms' % (self.msg, self.msecs))
def to_extjs_gridcolumns(df, meta=False): def to_extjs_gridcolumns(df, meta=False):
...@@ -1358,7 +1357,7 @@ def to_extjs_gridcolumns(df, meta=False): ...@@ -1358,7 +1357,7 @@ def to_extjs_gridcolumns(df, meta=False):
text="", text="",
xtype="gridcolumn") xtype="gridcolumn")
for colname, coltype in df.dtypes.sort_index().iteritems(): for colname, coltype in df.dtypes.sort_index().items():
cfg = Storage(cfgcol) cfg = Storage(cfgcol)
cfg.dataIndex = cfg.text = colname cfg.dataIndex = cfg.text = colname
......
# -*- coding: utf-8 -*-
""" event.py """ event.py
""" """
from gluon.storage import Storage from gluon.storage import Storage
from gluon.tools import PluginManager from gluon.tools import PluginManager
from dataframes import (get_items, from .dataframes import (get_items,
get_items_per_year, get_items_per_year,
get_items_small, get_items_small,
get_items_small_per_year, get_items_small_per_year,
get_objectlike_items, get_objectlike_items,
get_objectlike_items_per_year, get_objectlike_items_per_year,
get_peoplelike_items, get_peoplelike_items,
get_peoplelike_items_per_year, get_peoplelike_items_per_year,
get_people_per_year) get_people_per_year)
class EventException(BaseException): class EventException(BaseException):
...@@ -95,7 +94,7 @@ class Event(object): ...@@ -95,7 +94,7 @@ class Event(object):
if sources is None: if sources is None:
raise EventException("Sources are not configured.") raise EventException("Sources are not configured.")
return sources.iterkeys() return sources.keys()
@staticmethod @staticmethod
def register_source(name, func): def register_source(name, func):
......
# -*- coding: utf-8 -*-
"""matplotlib_tools module """matplotlib_tools module
""" """
...@@ -34,7 +33,7 @@ def bicolor(df, color1, color2): ...@@ -34,7 +33,7 @@ def bicolor(df, color1, color2):
ncols, nrows = df.columns.size, df.index.size ncols, nrows = df.columns.size, df.index.size
colors = pd.DataFrame([[color1] * ncols] * nrows) colors = pd.DataFrame([[color1] * ncols] * nrows)
colors.iloc[xrange(1, nrows, 2)] = color2 colors.iloc[range(1, nrows, 2)] = color2
return colors.values return colors.values
...@@ -161,7 +160,7 @@ def plot_values(ax, ...@@ -161,7 +160,7 @@ def plot_values(ax,
maxseries = max(series) maxseries = max(series)
cut = round(maxseries * percentage) cut = round(maxseries * percentage)
for i in xrange(ndata): for i in range(ndata):
value = series.iloc[i] value = series.iloc[i]
if value < zero: if value < zero:
......
# -*- coding: utf-8 -*-
"""Definitions of the core tables """Definitions of the core tables
""" """
from callbacks import INHIBIT_CASCADE_DELETE from .callbacks import INHIBIT_CASCADE_DELETE
from datetime import datetime from datetime import datetime
from gluon.validators import IS_IN_DB from gluon.validators import IS_IN_DB
......
# -*- coding: utf-8 -*-
"""Definitions of the report tables """Definitions of the report tables
""" """
import numpy as np import numpy as np
from callbacks import ON_CREATE_LISTS2, ON_UPDATE_LISTS2 from .callbacks import ON_CREATE_LISTS2, ON_UPDATE_LISTS2
from event import Event from .event import Event
from gluon import IS_IN_SET from gluon import IS_IN_SET
from pydal import Field from pydal import Field
...@@ -216,7 +215,7 @@ class Report(object): ...@@ -216,7 +215,7 @@ class Report(object):
sources = sorted(Event.get_sources()) sources = sorted(Event.get_sources())
table.source.requires = IS_IN_SET(sources) table.source.requires = IS_IN_SET(sources)
funcs = AGGREGATE_FUNCS.keys() funcs = list(AGGREGATE_FUNCS.keys())
funcs.sort() funcs.sort()
table.aggregate_func_z.requires = IS_IN_SET(funcs) table.aggregate_func_z.requires = IS_IN_SET(funcs)
......
# -*- coding: utf-8 -*-
"""Definitions of the selector(s) """Definitions of the selector(s)
""" """
from datetime import datetime from datetime import datetime
from gluon.validators import IS_IN_DB from gluon.validators import IS_IN_DB
from model_report import DEF_GRAPH, DEF_SUMMARY from .model_report import DEF_GRAPH, DEF_SUMMARY
from pydal import Field from pydal import Field
......
# -*- coding: utf-8 -*-
"""report_tools module """report_tools module
""" """
...@@ -7,11 +6,11 @@ import matplotlib as mpl ...@@ -7,11 +6,11 @@ import matplotlib as mpl
import pandas as pd import pandas as pd
from dataframes import to_extjs_gridcolumns from .dataframes import to_extjs_gridcolumns
from event import Event from .event import Event
from gluon import current from gluon import current
from gluon.storage import Storage from gluon.storage import Storage
from model_report import AGGREGATE_FUNCS from .model_report import AGGREGATE_FUNCS
from matplotlib_tools import ticks_and_labels from matplotlib_tools import ticks_and_labels
from plugin_dbui import Selector, Store from plugin_dbui import Selector, Store
from StringIO import StringIO from StringIO import StringIO
...@@ -215,11 +214,11 @@ class Graph(object): ...@@ -215,11 +214,11 @@ class Graph(object):
config_graph = (selector.graph if selector.is_graph else config.graph) config_graph = (selector.graph if selector.is_graph else config.graph)
if config_graph is None or config_graph[u"kind"] in (None, ""): if config_graph is None or config_graph["kind"] in (None, ""):
self.ax = None self.ax = None
return return
kind = config_graph[u"kind"] kind = config_graph["kind"]
if selector.is_graph and kind in (None, ""): if selector.is_graph and kind in (None, ""):
raise ReportException(MSG_NO_KIND) raise ReportException(MSG_NO_KIND)
...@@ -229,12 +228,12 @@ class Graph(object): ...@@ -229,12 +228,12 @@ class Graph(object):
metric_field_z = config.metric_field_z metric_field_z = config.metric_field_z
# decode ylim # decode ylim
ylim = config_graph[u"ylim"] ylim = config_graph["ylim"]
if len(ylim) == 0: if len(ylim) == 0:
del config_graph[u"ylim"] del config_graph["ylim"]
else: else:
config_graph[u"ylim"] = (int(el) for el in ylim.split(",")) config_graph["ylim"] = (int(el) for el in ylim.split(","))
# setup the matplotlib back-end # setup the matplotlib back-end
mpl.use(backend) mpl.use(backend)
...@@ -293,10 +292,10 @@ class Graph(object): ...@@ -293,10 +292,10 @@ class Graph(object):
# tick and axis labels # tick and axis labels
xlabel, ylabel = group_field_x, metric_field_z xlabel, ylabel = group_field_x, metric_field_z
if config_graph[u"stacked"]: if config_graph["stacked"]:
ylabel += " (stacked)" ylabel += " (stacked)"
if config_graph[u"kind"] == "barh": if config_graph["kind"] == "barh":
xlabel, ylabel = ylabel, xlabel xlabel, ylabel = ylabel, xlabel
ticks_and_labels(ax, xlabel, ylabel) ticks_and_labels(ax, xlabel, ylabel)
...@@ -328,11 +327,11 @@ class Graph(object): ...@@ -328,11 +327,11 @@ class Graph(object):
""" """
# clean the configuration of the graph # clean the configuration of the graph
del config_graph[u"width"] del config_graph["width"]
# protection # protection
linewidth = config_graph[u"linewidth"] linewidth = config_graph["linewidth"]
config_graph[u"linewidth"] = (1 if linewidth == 0 else linewidth) config_graph["linewidth"] = (1 if linewidth == 0 else linewidth)
# graph # graph
df1 = df.transpose() df1 = df.transpose()
...@@ -346,7 +345,7 @@ class Graph(object): ...@@ -346,7 +345,7 @@ class Graph(object):
# tick and axis labels # tick and axis labels
xlabel, ylabel = group_field_x, metric_field_z xlabel, ylabel = group_field_x, metric_field_z
if config_graph[u"stacked"]: if config_graph["stacked"]:
ylabel += " (stacked)" ylabel += " (stacked)"
if group_field_x == "year": if group_field_x == "year":
...@@ -688,7 +687,7 @@ class Metric2D(BaseReport): ...@@ -688,7 +687,7 @@ class Metric2D(BaseReport):
df = pd.concat((df, dfx), axis="columns") df = pd.concat((df, dfx), axis="columns")
if isinstance(df.index, pd.CategoricalIndex): if isinstance(df.index, pd.CategoricalIndex):
df.index = df.index.astype(unicode) df.index = df.index.astype(str)
dfy = self.summaries(df0, summary_y, axis="rows") dfy = self.summaries(df0, summary_y, axis="rows")
df = pd.concat((df, dfy)) df = pd.concat((df, dfy))
...@@ -724,14 +723,14 @@ class Metric2D(BaseReport): ...@@ -724,14 +723,14 @@ class Metric2D(BaseReport):
""" """
df1 = pd.DataFrame() df1 = pd.DataFrame()
funcs = config[u"functions"] funcs = config["functions"]
if funcs in ("", '""', "''", '[]'): if funcs in ("", '""', "''", '[]'):
return df1 return df1
if isinstance(funcs, (str, unicode)): if isinstance(funcs, str):
funcs = funcs.split(",") funcs = funcs.split(",")
labels = config[u"labels"] labels = config["labels"]
if labels in ("", '""', "''", "[]"): if labels in ("", '""', "''", "[]"):
labels = funcs labels = funcs
else: