Пример #1
0
def on_start_up(ctx):
    if sys.platform.startswith('java'):
        jython_start(ctx)
    else:
        cpython_start()

    Monad.getUtils()['impt'](globals(), *LIBS)

    for lib_name in LIBS:
        try:
            globals()[lib_name].startup()
        except AttributeError:
            pass
Пример #2
0
from net.sf.chellow.monad import Monad
import StringIO
import sys
import os
import db
import utils
import templater
import hh_importer
Monad.getUtils()['impt'](
    globals(), 'db', 'utils', 'templater', 'general_import', 'hh_importer')
Contract = db.Contract
UserException = utils.UserException
render = templater.render
inv, template = globals()['inv'], globals()['template']


def make_fields(sess, contract, message=None):
    messages = None if message is None else [str(message)]
    return {
        'contract': contract,
        'processes': hh_importer.get_hh_import_processes(contract.id),
        'messages': messages}

sess = None
contract = None
try:
    sess = db.session()
    hh_importer_contract = Contract.get_non_core_by_name(sess, 'hh_importer')

    if inv.getRequest().getMethod() == 'GET':
        hhdc_contract_id = inv.getLong('hhdc_contract_id')
Пример #3
0
def get_lib(lib_name):
    return Monad.getContext().getAttribute("net.sf.chellow." + lib_name)
Пример #4
0
import sys
from net.sf.chellow.monad import Monad
import utils
import db
Monad.getUtils()['impt'](globals(), 'utils', 'db')
inv, template = globals()['inv'], globals()['template']
hh_format = utils.hh_format

if sys.platform.startswith('java'):
    from java.awt.image import BufferedImage
    from javax.imageio import ImageIO
    from java.awt import Color, Font
    from java.lang import System
    import math
    import datetime
    import pytz
    from dateutil.relativedelta import relativedelta

    HH = utils.HH
    Site = db.Site

    colour_list = [
        Color.BLUE, Color.GREEN, Color.RED, Color.YELLOW, Color.MAGENTA,
        Color.CYAN, Color.PINK, Color.ORANGE]

    def set_colour(graphics, supplies, id):
        graphics.setColor(supplies[id][0])

    def add_colour(supplies, id, name, source_code):
        if id not in supplies:
            supplies[id] = [len(supplies), name, source_code]
Пример #5
0
from net.sf.chellow.monad import Monad
import time
import traceback
import utils
import db
import hh_importer
import bsuos
import system_price
import bank_holidays
import rcrc
import tlms
import dloads
Monad.getUtils()['impt'](
    globals(), 'utils', 'hh_importer', 'bsuos', 'rcrc', 'tlms', 'db',
    'system_price', 'bank_holidays', 'dloads')

UserException = utils.UserException


def on_shut_down(ctx):
    messages = []
    sess = None
    try:
        sess = db.session()
        for md in (
                hh_importer, bsuos, system_price, rcrc, tlms, bank_holidays,
                dloads):
            try:
                md.shutdown()
            except UserException, e:
                time.sleep(2)
Пример #6
0
from net.sf.chellow.monad import Monad
import datetime
import os
import traceback
import threading
import pytz
from dateutil.relativedelta import relativedelta
from sqlalchemy import or_
from sqlalchemy.sql.expression import null
import db
import utils
import computer
import dloads
import sys

Monad.getUtils()['impt'](
    globals(), 'templater', 'db', 'utils', 'computer', 'dloads')
inv = globals()['inv']
Site, Era, Bill = db.Site, db.Era, db.Bill
HH, hh_after, hh_format = utils.HH, utils.hh_after, utils.hh_format
totalseconds = utils.totalseconds

caches = {}

year = inv.getInteger("finish_year")
month = inv.getInteger("finish_month")
months = inv.getInteger("months")

if inv.hasParameter('site_id'):
    st_id = inv.getLong('site_id')
else:
    st_id = None
Пример #7
0
from net.sf.chellow.monad import Monad
import db
import system_price_elexon
import templater
import utils
Monad.getUtils()['impt'](
    globals(), 'utils', 'templater', 'db', 'system_price_elexon')
Contract = db.Contract
render = templater.render
inv, template = globals()['inv'], globals()['template']

sess = None
importer = None
try:
    sess = db.session()
    if inv.getRequest().getMethod() == "GET":
        importer = system_price_elexon.get_importer()
        contract = Contract.get_non_core_by_name(sess, 'system_price_elexon')
        render(inv, template, {'importer': importer, 'contract': contract})
    else:
        importer = system_price_elexon.get_importer()
        contract = Contract.get_non_core_by_name(sess, 'system_price_elexon')
        importer.go()
        inv.sendSeeOther("/reports/385/output/")
except utils.UserException, e:
    sess.rollback()
    render(
        inv, template, {
            'messages': [str(e)], 'importer': importer, 'contract': contract})
finally:
    if sess is not None:
Пример #8
0
from net.sf.chellow.monad import Monad
import datetime
import pytz
from dateutil.relativedelta import relativedelta
from sqlalchemy import or_, and_
import traceback
import utils
import db

Monad.getUtils()["impt"](globals(), "utils", "db")

HH, hh_format = utils.HH, utils.hh_format
RegisterRead, Bill, Supply, Era = db.RegisterRead, db.Bill, db.Supply, db.Era
inv = globals()["inv"]

year = inv.getInteger("end_year")
month = inv.getInteger("end_month")
months = inv.getInteger("months")
if inv.hasParameter("supply_id"):
    supply_id = inv.getLong("supply_id")
else:
    supply_id = None


def content():
    sess = None
    try:
        sess = db.session()

        finish_date = datetime.datetime(year, month, 1, tzinfo=pytz.utc) + relativedelta(months=1) - HH
Пример #9
0
from net.sf.chellow.monad import Monad
import traceback
import collections
import pytz
import threading
import sys
import os
import os.path
import time
import datetime
import utils

Monad.getUtils()['impt'](globals(), 'db', 'utils', 'templater')

UserException = utils.UserException

if sys.platform.startswith('java'):
    download_path = Monad.getContext().getRealPath("/downloads")
else:
    import chellow
    download_path = os.path.join(chellow.app.instance_path, 'downloads')

if not os.path.exists(download_path):
    os.makedirs(download_path)


download_id = 0

lock = threading.Lock()

files = sorted(os.listdir(download_path), reverse=True)
Пример #10
0
import os
import traceback
import sys
from net.sf.chellow.monad import Monad
import utils
Monad.getUtils()['impt'](globals(), 'computer', 'db', 'utils', 'triad', 'duos')
UserException = utils.UserException
inv = globals()['inv']

name = inv.getString("name")
head, name = os.path.split(os.path.normcase(os.path.normpath(name)))

if sys.platform.startswith('java'):
    download_path = Monad.getContext().getRealPath("/downloads")
else:
    import chellow
    download_path = os.path.join(chellow.app.instance_path, 'downloads')

full_name = os.path.join(download_path, name)
method = inv.getRequest().getMethod()

if method == 'GET':
    def content():
        fl = None
        try:
            fl = open(full_name)

            for line in fl:
                yield line

        except:
Пример #11
0
from net.sf.chellow.monad import Monad
import templater
import db
import hh_importer

Monad.getUtils()["impt"](globals(), "db", "utils", "templater", "hh_importer")
render = templater.render
inv, template = globals()["inv"], globals()["template"]

sess = None
try:
    sess = db.session()
    contract_id = inv.getLong("hhdc_contract_id")
    contract = db.Contract.get_hhdc_by_id(sess, contract_id)
    process_id = inv.getLong("process_id")
    process = hh_importer.get_hh_import_processes(contract_id)[process_id]

    render(inv, template, {"contract": contract, "process": process})
finally:
    if sess is not None:
        sess.close()
Пример #12
0
from net.sf.chellow.monad import Monad
import pytz
import datetime
from sqlalchemy import or_
from sqlalchemy.sql.expression import null
import traceback
import utils
import db
import computer
import duos
import triad

Monad.getUtils()["impt"](globals(), "computer", "db", "utils", "triad", "duos")
HH, hh_format = utils.HH, utils.hh_format
Site, SiteEra, Era, Supply = db.Site, db.SiteEra, db.Era, db.Supply
Source, Channel = db.Source, db.Channel
inv = globals()["inv"]

caches = {}
if inv.hasParameter("site_id"):
    site_id = inv.getLong("site_id")
else:
    site_id = None

year = inv.getInteger("year")


def content():
    sess = None
    try:
        sess = db.session()
Пример #13
0
from net.sf.chellow.monad import Monad
import scenario

Monad.getUtils()["impt"](globals(), "scenario")
db_id = globals()["db_id"]

create_future_func = scenario.make_create_future_func_simple("aahedc", ["aahedc_gbp_per_gsp_kwh"])


def hh(supply_source):
    bill = supply_source.supplier_bill
    rate_set = supply_source.supplier_rate_sets["aahedc-rate"]

    try:
        supply_source.caches["aahedc"]
    except KeyError:
        supply_source.caches["aahedc"] = {}

        try:
            future_funcs = supply_source.caches["future_funcs"]
        except KeyError:
            future_funcs = {}
            supply_source.caches["future_funcs"] = future_funcs

        try:
            future_funcs[db_id]
        except KeyError:
            future_funcs[db_id] = {"start_date": None, "func": create_future_func(1, 0)}

    for hh in supply_source.hh_data:
        bill["aahedc-msp-kwh"] += hh["msp-kwh"]
Пример #14
0
from decimal import Decimal
from net.sf.chellow.monad import Monad
import utils
import edi_lib

Monad.getUtils()["impt"](globals(), "db", "utils", "templater", "bill_import", "edi_lib")
hh_after = utils.hh_after

read_type_map = {"00": "N", "01": "E", "02": "E", "04": "C", "06": "X", "07": "N"}


class Parser:
    def __init__(self, f):
        self.parser = edi_lib.EdiParser(f)
        self.line_number = None

    def make_raw_bills(self):
        raw_bills = []
        for self.line_number, code in enumerate(self.parser):
            if code == "CLO":
                cloc = self.parser.elements[0]
                account = cloc[1]
            elif code == "BCD":
                ivdt = self.parser.elements[0]
                invn = self.parser.elements[2]
                btcd = self.parser.elements[5]

                reference = invn[0]
                bill_type_code = btcd[0]
                issue_date = self.parser.to_date(ivdt[0])
            elif code == "MHD":
Пример #15
0
from net.sf.chellow.monad import Monad
import scenario
Monad.getUtils()['impt'](globals(), 'scenario')
db_id = globals()['db_id']

create_future_func = scenario.make_create_future_func_simple(
    'ro', ['gbp_per_msp_kwh'])


def hh(supply_source):
    bill = supply_source.supplier_bill
    rate_set = supply_source.supplier_rate_sets['ro-rate']

    try:
        supply_source.caches['ro']
    except KeyError:
        supply_source.caches['ro'] = {}

        try:
            future_funcs = supply_source.caches['future_funcs']
        except KeyError:
            future_funcs = {}
            supply_source.caches['future_funcs'] = future_funcs

        try:
            future_funcs[db_id]
        except KeyError:
            future_funcs[db_id] = {
                'start_date': None, 'func': create_future_func(1, 0)}

    for hh in supply_source.hh_data:
Пример #16
0
from net.sf.chellow.monad import Monad
import db
import templater
import utils
import bank_holidays
Monad.getUtils()['impt'](
    globals(), 'db', 'utils', 'templater', 'bank_holidays')
Contract = db.Contract
render = templater.render
UserException = utils.UserException
inv, template = globals()['inv'], globals()['template']

sess = None
importer = None
try:
    sess = db.session()
    if inv.getRequest().getMethod() == "GET":
        importer = bank_holidays.get_importer()
        contract = Contract.get_non_core_by_name(sess, 'bank_holidays')
        render(inv, template, {'importer': importer, 'contract': contract})
    else:
        importer = bank_holidays.get_importer()
        contract = Contract.get_non_core_by_name(sess, 'bank_holidays')
        importer.go()
        inv.sendSeeOther("/reports/221/output/")
except UserException, e:
    sess.rollback()
    render(
        inv, template, {
            'messages': [str(e)], 'importer': importer, 'contract': contract})
finally:
Пример #17
0
import db
import utils
import computer
import csv
import dloads
import StringIO
import threading
import odswriter
import sys

CATEGORY_ORDER = {
    None: 0, 'unmetered': 1, 'nhh': 2, 'amr': 3, 'hh': 4}


Monad.getUtils()['impt'](
    globals(), 'templater', 'db', 'utils', 'computer', 'bsuos', 'aahedc',
    'dloads', 'ccl', 'system_price')
Site, Era, Bill, SiteEra = db.Site, db.Era, db.Bill, db.SiteEra
Contract, Supply, Source = db.Contract, db.Supply, db.Source
HhDatum, Channel = db.HhDatum, db.Channel
MarketRole = db.MarketRole
HH, hh_after, hh_format = utils.HH, utils.hh_after, utils.hh_format
totalseconds, UserException = utils.totalseconds, utils.UserException
hh_before, form_int = utils.hh_before, utils.form_int
SupplySource = computer.SupplySource
inv = globals()['inv']

base_name = []

now = datetime.datetime.now(pytz.utc)
Пример #18
0
from net.sf.chellow.monad import Monad
import db
import templater
import utils
import system_price

Monad.getUtils()["impt"](globals(), "db", "utils", "templater", "system_price")
Contract = db.Contract
render = templater.render
UserException = utils.UserException
inv, template = globals()["inv"], globals()["template"]

sess = None
importer = None
try:
    sess = db.session()
    if inv.getRequest().getMethod() == "GET":
        importer = system_price.get_importer()
        contract = Contract.get_non_core_by_name(sess, "system_price")
        render(inv, template, {"importer": importer, "contract": contract})
    else:
        importer = system_price.get_importer()
        contract = Contract.get_non_core_by_name(sess, "system_price")
        importer.go()
        inv.sendSeeOther("/reports/381/output/")
except UserException, e:
    sess.rollback()
    render(inv, template, {"messages": [str(e)], "importer": importer, "contract": contract})
finally:
    if sess is not None:
        sess.close()
Пример #19
0
from net.sf.chellow.monad import Monad
import datetime
import os
import shutil
import StringIO
import tarfile
import templater
import dloads
import utils

Monad.getUtils()['impt'](globals(), 'utils', 'templater', 'dloads')
render = templater.render
inv, template = globals()['inv'], globals()['template']


def make_fields(lib_path, message=None):
    messages = [] if message is None else [str(message)]
    files = []
    for fl in sorted(os.listdir(lib_path)):
        full_file = os.path.join(lib_path, fl)
        statinfo = os.stat(full_file)
        files.append(
            {
                'name': fl,
                'last_modified': datetime.datetime.utcfromtimestamp(
                    statinfo.st_mtime),
                'size': statinfo.st_size,
                'creation_date': datetime.datetime.utcfromtimestamp(
                    statinfo.st_ctime)})
    mem_items = dloads.get_mem_items()
    mem_keys = sorted(mem_items.keys())
Пример #20
0
from net.sf.chellow.monad import Monad
import db
import templater

Monad.getUtils()["impt"](globals(), "templater", "db")
Contract = db.Contract
inv, template = globals()["inv"], globals()["templater"]

sess = None
try:
    sess = db.session()
    contract_id = inv.getLong("mop_contract_id")

    contract = Contract.get_mop_by_id(contract_id)
    templater.render(inv, template, {"contract": contract})
finally:
    if sess is not None:
        sess.close()
Пример #21
0
    from java.io import StringWriter, InputStreamReader
    from net.sf.chellow.monad import Hiber, Monad, MonadMessage
    from java.lang.management import ManagementFactory
    from com.jezhumble.javasysmon import JavaSysMon
    from net.sf.chellow.billing import Contract

    source, doc = globals()["source"], globals()["doc"]

    interrupt_id = None
    if inv.getRequest().getMethod() == "POST":
        if inv.hasParameter("interrupt"):
            interrupt_id = inv.getLong("thread-id")
            Monad.getUtils()["imprt"](
                globals(),
                {
                    "db": ["HhDatum", "Site", "Supply", "set_read_write", "session"],
                    "utils": ["UserException", "HH", "form_date"],
                    "templater": ["render", "on_start_report", "get_report"],
                },
            )

        elif inv.hasParameter("run_shutdown"):
            shutdown_contract = Contract.getNonCoreContract("shutdown")
            shutdown_contract.callFunction("on_shut_down", [Monad.getContext()])
            source.appendChild(MonadMessage("Shut down successfully.").toXml(doc))

        elif inv.hasParameter("run_startup"):
            startup_contract = Contract.getNonCoreContract("startup")
            startup_contract.callFunction("on_start_up", [Monad.getContext()])
        elif inv.hasParameter("cancel_backend"):
            backend_pid = inv.getLong("backend_pid")
            con = Hiber.session().connection()
Пример #22
0
from net.sf.chellow.monad import Monad
import datetime
import pytz
from sqlalchemy import or_
from sqlalchemy.sql.expression import null
from dateutil.relativedelta import relativedelta
import traceback
import utils
import db
import computer
Monad.getUtils()['impt'](globals(), 'computer', 'db', 'utils')
inv, template = globals()['inv'], globals()['template']

hh_before, HH, hh_format = utils.hh_before, utils.HH, utils.hh_format
form_int = utils.form_int
Contract, Era = db.Contract, db.Era

caches = {}
end_year = form_int(inv, "end_year")
end_month = form_int(inv, "end_month")
months = form_int(inv, "months")
contract_id = form_int(inv, 'hhdc_contract_id')


def content():
    sess = None
    try:
        sess = db.session()

        contract = Contract.get_hhdc_by_id(sess, contract_id)
Пример #23
0
from net.sf.chellow.monad import Monad
from dateutil.relativedelta import relativedelta
from sqlalchemy.sql.expression import null
from sqlalchemy import or_
import utils
import db
import triad_rates
import computer
import duos
Monad.getUtils()['impt'](
    globals(), 'db', 'utils', 'templater', 'computer', 'duos', 'triad_rates')
HH, hh_after = utils.HH, utils.hh_after
Contract, RateScript = db.Contract, db.RateScript
db_id = globals()['db_id']


def triad_calc(
        bill, prefix, triad_data, financial_year_start, financial_year_finish,
        data_source, month_begin):
    gsp_kw = 0
    for i, triad_hh in enumerate(triad_data):
        triad_prefix = prefix + '-' + str(i + 1)
        bill[triad_prefix + '-date'] = triad_hh['hist-start']
        bill[triad_prefix + '-msp-kw'] = triad_hh['msp-kw']
        bill[triad_prefix + '-status'] = triad_hh['status']
        bill[triad_prefix + '-laf'] = triad_hh['laf']
        bill[triad_prefix + '-gsp-kw'] = triad_hh['gsp-kw']
        gsp_kw += triad_hh['gsp-kw']

    bill[prefix + '-gsp-kw'] = gsp_kw / 3
Пример #24
0
from net.sf.chellow.monad import Monad
import db
import bill_import
import templater
import utils

Monad.getUtils()['impt'](globals(), 'db', 'utils', 'templater', 'bill_import')
Batch = db.Batch
inv, template = globals()['inv'], globals()['template']
render = templater.render
UserException = utils.UserException


def make_fields(sess, importer, message=None):
    messages = None if message is None else [str(message)]
    batch = Batch.get_by_id(sess, importer.batch_id)
    fields = {'batch': batch, 'messages': messages}
    if importer is not None:
        imp_fields = importer.make_fields()
        if 'successful_bills' in imp_fields and \
                len(imp_fields['successful_bills']) > 0:
            fields['successful_max_registers'] = \
                max(
                    len(bill['reads']) for bill in imp_fields[
                        'successful_bills'])
        fields.update(imp_fields)
        fields['status'] = importer.status()
    return fields

sess = None
try:
Пример #25
0
import traceback
from net.sf.chellow.monad import Monad
from sqlalchemy import or_
from sqlalchemy.sql.expression import null, true
import db
import utils
import computer

Monad.getUtils()["impt"](globals(), "db", "utils", "templater", "computer")
inv = globals()["inv"]

Supply, Era, Site, SiteEra = db.Supply, db.Era, db.Site, db.SiteEra
HH, hh_format = utils.HH, utils.hh_format

caches = {}

supply_id = inv.getLong("supply_id")
start_date = utils.form_date(inv, "start")
finish_date = utils.form_date(inv, "finish")
file_name = "supply_virtual_bills_hh_" + str(supply_id) + ".csv"


def content():
    sess = None
    try:
        sess = db.session()
        supply = Supply.get_by_id(sess, supply_id)

        forecast_date = computer.forecast_date()

        prev_titles = None
Пример #26
0
from net.sf.chellow.monad import Monad
import db
import utils
import templater
Monad.getUtils()['impt'](globals(), 'db', 'utils', 'templater')
Source, GeneratorType, GspGroup = db.Source, db.GeneratorType, db.GspGroup
Era, Supply = db.Era, db.Supply
UserException, form_date = utils.UserException, utils.form_date
render = templater.render
inv, template = globals()['inv'], globals()['template']


def make_fields(sess, supply, message=None):
    messages = [] if message is None else [str(message)]
    sources = sess.query(Source).order_by(Source.code)
    generator_types = sess.query(GeneratorType).order_by(GeneratorType.code)
    gsp_groups = sess.query(GspGroup).order_by(GspGroup.code)
    eras = sess.query(Era).filter(
        Era.supply == supply).order_by(Era.start_date.desc())
    return {
        'supply': supply, 'messages': messages, 'sources': sources,
        'generator_types': generator_types, 'gsp_groups': gsp_groups,
        'eras': eras}

sess = None
try:
    sess = db.session()
    if inv.getRequest().getMethod() == 'GET':
        supply_id = inv.getLong('supply_id')
        supply = Supply.get_by_id(sess, supply_id)
        render(inv, template, make_fields(sess, supply))
Пример #27
0
from net.sf.chellow.monad import Monad
import datetime
import pytz
import utils
import db
import computer
import scenario

Monad.getUtils()["impt"](globals(), "db", "utils", "computer", "scenario")
HH = utils.HH
Contract = db.Contract
db_id = globals()["db_id"]

create_future_func = scenario.make_create_future_func_simple("ccl", ["ccl_rate"])


def ccl(data_source):
    rate_set = data_source.supplier_rate_sets["ccl-rate"]

    if data_source.supply.find_era_at(data_source.sess, data_source.finish_date + HH) is None:
        sup_end = data_source.finish_date
    else:
        sup_end = None

    try:
        cache = data_source.caches["ccl"]
    except:
        data_source.caches["ccl"] = {}
        cache = data_source.caches["ccl"]

        try: