Commit faa6d3fd authored by lou-morriet's avatar lou-morriet
Browse files

update economy

parent 957505a4
......@@ -28,34 +28,34 @@ __docformat__ = "restructuredtext en"
class Transaction(EconomicObject):
def __init__(self, time, name, beneficiary, payer, good: Quantity = None,
price=None, subscription=None):
def __init__(self, time, name, beneficiary, payer):
EconomicObject.__init__(self, time=time, name=name,
unit1=beneficiary, unit2=payer)
self.description = 'Transactions'
for unit in (beneficiary, payer):
if isinstance(unit, EnergyUnit) or isinstance(unit, Actor):
if not hasattr(unit, 'transactions'):
unit._set_optobject_as_attr(optobject=self,
attribute_name=
'transactions')
self.transactions = Quantity(name='transactions', unit='€',
description='economic '
'transaction',
vlen=time.LEN, parent=self)
self.transactions_tot = Quantity(name='transactions_tot',
unit='€',
vlen=1, parent=self)
else:
raise TypeError(
"Transactions should be added to an energy unit "
"or an actor and is added instead to "
"a {}".format(type(unit)))
# for unit in (beneficiary, payer):
# if isinstance(unit, EnergyUnit) or isinstance(unit, Actor):
# if not hasattr(unit, 'transactions'):
# unit._set_optobject_as_attr(optobject=self,
# attribute_name=
# 'transactions')
#
# self.transactions = Quantity(name='transactions_t',
# unit='€',
# description='economic '
# 'transaction',
# vlen=time.LEN, parent=self)
#
# self.transactions_tot = Quantity(name='transactions_tot',
# unit='€',
# vlen=1, parent=self)
#
# else:
# raise TypeError(
# "Transactions should be added to an energy unit "
# "or an actor and is added instead to "
# "a {}".format(type(unit)))
class EnergyUnitTransaction(Transaction):
......@@ -86,88 +86,68 @@ class EnergyUnitTransaction(Transaction):
# TODO no subscription if u=0. Question: does it work with something
# else than p ?
transactions_list = []
self.name = name
self.beneficiary = beneficiary
self.payer = payer
if energy_price is not None:
self.add_energy_price_transaction(time=time, name=name,
ep_name = '{}_energy_price'.format(
self.name)
self.add_energy_price_transaction(time=time,
name=ep_name,
energy_price=energy_price,
energy_unit=energy_unit)
transactions_list.append(self.price.name)
quantity_unit=energy_unit,
beneficiary=beneficiary,
payer=payer)
self.add_income_to_incomes_exp(unit=beneficiary,
income_name=ep_name)
self.add_cost_to_costs_exp(unit=beneficiary,
cost_name=ep_name)
if fixed_cashflow is not None:
if spread_cashflow_duration is not None:
sc_name = '{}_spread_cashflow'.format(self.name)
self.add_spread_fixed_cashflow(
time=time,
name='spread_cashflow',
name=sc_name,
cashflow_value=fixed_cashflow,
spread_duration=spread_cashflow_duration)
transactions_list.append(self.spread_cashflow.name)
spread_duration=spread_cashflow_duration,
beneficiary=beneficiary,
payer=payer)
self.add_income_to_incomes_exp(unit=beneficiary,
income_name=sc_name)
self.add_cost_to_costs_exp(unit=beneficiary,
cost_name=sc_name)
else:
self.add_fixed_cashflow(time=time, name='fixed_cashflow',
fixed_cashflow_value=fixed_cashflow)
transactions_list.append(self.fixed_cashflow.name)
self.calc_transactions_constraints(unit=beneficiary, pole='+',
transactions_list=transactions_list)
self.calc_transactions_constraints(unit=payer, pole='-',
transactions_list=transactions_list)
def calc_transactions_constraints(self, unit, pole, transactions_list):
transactions_exp = '0'
for i in transactions_list:
transactions_exp += '{2} {0}_{1}[t] '.format(pole, self.name, i)
self.calc_transactions = DefinitionDynamicConstraint(
name='calc_transactions',
exp_t='{0}_transactions[t] == ({1})'.format(
self.name, transactions_exp),
t_range='for t in time.I',
parent=self)
self.calc_transactions_tot = DefinitionConstraint(
name='calc_transactions_tot',
exp='{0}_transactions_transactions_tot == lpSum({1} for t in '
'time.I)'.format(
energy_unit.name, transactions_exp),
parent=self)
self.add_transaction(receiver=beneficiary)
self.subtract_transaction(giver=payer)
def add_transaction(self, receiver):
if not hasattr(receiver, 'budget_list'):
receiver.budget_list = []
receiver.budget_list.append(' {0}_subscription_transaction[t] + {'
'0}_goods_and_prices_transaction['
't]'.format(
self.name))
def subtract_transaction(self, giver):
if not hasattr(giver, 'budget_list'):
giver.budget_list = []
giver.budget_list.append('- {0}_subscription_transaction[t] - {'
'0}_goods_and_prices_transaction[t]'.format(
self.name))
sfc_name = '{}_fixed_cashflow'.format(
self.name)
self.add_fixed_cashflow(time=time,
name=sfc_name,
fixed_cashflow_value=fixed_cashflow,
beneficiary=beneficiary,
payer=payer)
self.add_income_to_incomes_exp(unit=beneficiary,
income_name=sfc_name)
self.add_cost_to_costs_exp(unit=beneficiary,
cost_name=sfc_name)
def add_energy_price_transaction(self, time, name, energy_price,
energy_unit):
quantity_unit, beneficiary, payer):
"""
Add an transaction linked to the energy produced or consummed by
one of the energy unit
"""
self.add_quantity_dependant_cashflow(time=time, name=name,
description='energy transaction',
description='energy price',
value=energy_price,
quantity_name='p',
unit=energy_unit)
quantity_unit=quantity_unit,
unit1=beneficiary,
unit2=payer)
def add_fixed_cashflow(self, time, name, fixed_cashflow_value):
def add_fixed_cashflow(self, time, name, fixed_cashflow_value,
beneficiary, payer):
"""
Add fixed cashflow to the energy unit
......@@ -182,10 +162,11 @@ class EnergyUnitTransaction(Transaction):
"""
self.add_cashflow(time=time, name=name,
description='basic fixed cashflow',
cashflow_value=fixed_cashflow_value)
cashflow_value=fixed_cashflow_value,
unit1=beneficiary, unit2=payer)
def add_spread_fixed_cashflow(self, time, name, cashflow_value,
spread_duration):
spread_duration, beneficiary, payer):
"""
**Description**
......@@ -200,7 +181,8 @@ class EnergyUnitTransaction(Transaction):
self.add_spread_cashflow(time=time, name=name,
description='spread fixed cashflow',
cashflow_value=cashflow_value,
spread_duration=spread_duration)
spread_duration=spread_duration,
unit1=beneficiary, unit2=payer)
def budget_calc(unit):
......@@ -229,12 +211,18 @@ class Contract(Transaction):
"""
def __init__(self, time, name, seller, buyer, price, good, subscription,
subscription_duration):
def __init__(self, time, name, seller, buyer,
fixed_cashflow=None, spread_cashflow_duration=None,
energy_price=None, energy_unit=None):
Transaction.__init__(self, time=time, name=name, beneficiary=seller,
payer=buyer)
payer=buyer, fixed_cashflow=fixed_cashflow,
spread_cashflow_duration=spread_cashflow_duration,
energy_price=energy_price,
energy_unit=energy_unit)
if not isinstance(buyer, Actor):
raise TypeError('The buyer should be an Actor')
if not isinstance(seller, Actor):
raise TypeError('The seller should be an Actor')
# TODO check the energy unit is on the scope of the actor
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