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