Exemple #1
0
class Iteration:
    """Class for running a single iteration."""

    def __init__(self, iteration_no, simulation_no, country, seed):
        """Iteration number of this iteration and link to simulation module."""
        random.seed(seed)
        numpy.random.seed(seed)

        self.iteration_no = iteration_no
        self.simulation_no = simulation_no
        self.country = country
        self.db =  Database()  #connection to Db

        self.config = MainConfig(self.country)
        self.em = EnergyModule(self.config, self.country)
        self.sm = SubsidyModule(self.config, self.country)
        self.tm = TechnologyModule(self.config, self.em, self.country)
        self.enm = EnvironmentalModule(self.config, self.country, self.tm.total_nominal_power)
        self.ecm = EconomicModule(self.config, self.tm, self.sm, self.enm, self.country)
        self.r = Report(self.config, self.ecm, iteration_no, self.simulation_no)

    def run(self):
        """Runs one iteration and prepares new data."""
        self.r.calcReportValues()
        self.o = ReportOutput(self.r)
        self._prepareIterationResults()  # main func to prepare results in one dict

    def saveAndReturn(self):
        """Saves the data to simulation fields and database."""
        self.db.insertIteration(self.line)  # save iteration to db
        return self._getIrrValues() + self._getTepValues()

    def _prepareIterationResults(self):
        """Prepare iteration results before saving to database."""
        obj = self.r
        line = dict()  #main dict for holding results of one iteration

        line["simulation"] = self.simulation_no
        line["iteration"] = self.iteration_no

        line["main_configs"] = self.config.getConfigsValues()
        line["ecm_configs"] = self.ecm.getConfigsValues()
        line["tm_configs"] = self.tm.getConfigsValues()
        line["sm_configs"] = self.sm.getConfigsValues()
        line["em_configs"] = self.em.getConfigsValues()
        line["enm_configs"] = self.enm.getConfigsValues()

        #####################################

        line["revenue"] = obj.revenue.values()  #values of revenue
        line["revenue_electricity"] = obj.revenue_electricity.values()
        line["revenue_subsidy"] = obj.revenue_subsidy.values()
        line["cost"] = obj.cost.values()
        line["insurance_cost"] = obj.insurance_cost.values()
        line["operational_cost"] = obj.operational_cost.values()
        line["development_cost"] = obj.development_cost.values()
        line["repair_costs_modules"] = obj.repair_costs_modules.values()
        line["repair_costs_inverters"] = obj.repair_costs_inverters.values()
        line["ebitda"] = obj.ebitda.values()
        line["ebit"] = obj.ebit.values()
        line["ebt"] = obj.ebt.values()
        line["interest_paid"] = obj.interest_paid.values()
        line["depreciation"] = obj.depreciation.values()
        line["tax"] = obj.tax.values()
        line["net_earning"] = obj.net_earning.values()
        line["investment"] = obj.investment.values()
        line["fixed_asset"] = obj.fixed_asset.values()
        line["asset"] = obj.asset.values()
        line["inventory"] = obj.inventory.values()
        line["operating_receivable"] = obj.operating_receivable.values()
        line["short_term_investment"] = obj.short_term_investment.values()
        line["asset_bank_account"] = obj.asset_bank_account.values()
        line["paid_in_capital"] = obj.paid_in_capital.values()
        line["current_asset"] = obj.current_asset.values()
        line["unallocated_earning"] = obj.unallocated_earning.values()
        line["retained_earning"] = obj.retained_earning.values()
        line["financial_operating_obligation"] = obj.financial_operating_obligation.values()
        line["long_term_loan"] = obj.long_term_loan.values()
        line["short_term_loan"] = obj.short_term_loan.values()
        line["long_term_operating_liability"] = obj.long_term_operating_liability.values()
        line["short_term_debt_suppliers"] = obj.short_term_debt_suppliers.values()
        line["liability"] = obj.liability.values()
        line["equity"] = obj.equity.values()
        line["control"] = obj.control.values()
        line["report_header"] = obj.control.keys()

        ###############################
        line["revenue_y"] = obj.revenue_y.values()
        line["revenue_electricity_y"] = obj.revenue_electricity_y.values()
        line["revenue_subsidy_y"] = obj.revenue_subsidy_y.values()
        line["cost_y"] = obj.cost_y.values()
        line["insurance_cost_y"] = obj.insurance_cost_y.values()
        line["operational_cost_y"] = obj.operational_cost_y.values()
        line["development_cost_y"] = obj.development_cost_y.values()
        line["repair_costs_modules_y"] = obj.repair_costs_modules_y.values()
        line["repair_costs_inverters_y"] = obj.repair_costs_inverters_y.values()
        line["ebitda_y"] = obj.ebitda_y.values()
        line["ebit_y"] = obj.ebit_y.values()
        line["ebt_y"] = obj.ebt_y.values()
        line["interest_paid_y"] = obj.interest_paid_y.values()
        line["depreciation_y"] = obj.depreciation_y.values()
        line["tax_y"] = obj.tax_y.values()
        line["net_earning_y"] = obj.net_earning_y.values()
        line["investment_y"] = obj.investment_y.values()
        line["fixed_asset_y"] = obj.fixed_asset_y.values()
        line["asset_y"] = obj.asset_y.values()
        line["inventory_y"] = obj.inventory_y.values()
        line["operating_receivable_y"] = obj.operating_receivable_y.values()
        line["short_term_investment_y"] = obj.short_term_investment_y.values()
        line["asset_bank_account_y"] = obj.asset_bank_account_y.values()
        line["paid_in_capital_y"] = obj.paid_in_capital_y.values()
        line["current_asset_y"] = obj.current_asset_y.values()
        line["unallocated_earning_y"] = obj.unallocated_earning_y.values()
        line["retained_earning_y"] = obj.retained_earning_y.values()
        line["financial_operating_obligation_y"] = obj.financial_operating_obligation_y.values()
        line["long_term_loan_y"] = obj.long_term_loan_y.values()
        line["short_term_loan_y"] = obj.short_term_loan_y.values()
        line["long_term_operating_liability_y"] = obj.long_term_operating_liability_y.values()
        line["short_term_debt_suppliers_y"] = obj.short_term_debt_suppliers_y.values()
        line["liability_y"] = obj.liability_y.values()
        line["equity_y"] = obj.equity_y.values()
        line["control_y"] = obj.control_y.values()
        line["report_header_y"] = obj.control_y.keys()

        ##################################
        line["fcf_project"] = obj.fcf_project.values()  #FCF values
        line["fcf_project_before_tax"] = obj.fcf_project_before_tax.values()
        line["fcf_owners"] = obj.fcf_owners.values()
        line["fcf_project_y"] = obj.fcf_project_y.values()
        line["fcf_project_before_tax_y"] = obj.fcf_project_before_tax_y.values()
        line["fcf_owners_y"] = obj.fcf_owners_y.values()

        line["irr_project"] = obj.irr_project
        line["irr_project_before_tax"] = obj.irr_project_before_tax
        line["irr_owners"] = obj.irr_owners
        line["irr_project_y"] = obj.irr_project_y
        line["irr_project_before_tax_y"] = obj.irr_project_before_tax_y
        line["irr_owners_y"] = obj.irr_owners_y

        line["npv_project"] = obj.npv_project
        line["npv_owners"] = obj.npv_owners
        line["npv_project_y"] = obj.npv_project_y
        line["npv_owners_y"] = obj.npv_owners_y

        line["wacc"] = obj.wacc
        line["wacc_y"] = obj.wacc

        #########################################
        line["project_days"] = self.ecm.electricity_prices.keys()  #list of all project days

        line["equipment_description"] = self.tm.equipmentDescription()
        line["average_degradation_rate"] = self.tm.getAverageDegradationRate()
        line["average_power_ratio"] = self.tm.getAveragePowerRatio()
        line["total_power"] = self.tm.total_power
        line["total_investment_cost"] = self.tm.getInvestmentCost()
        line["pvequipment_disposal"] = self.enm.getEquipmentDisposalCosts()
        line["insolations_daily"] = self.em.getInsolationsLifetime().values()
        line["electricity_production_daily"] = self.ecm.electricity_production.values()

        line["sun_insolation"] = obj.sun_insolation.values()
        line["sun_insolation_y"] = obj.sun_insolation_y.values()

        line["electricity_production"] = obj.electricity_production.values()
        line["electricity_production_y"] = obj.electricity_production_y.values()

        line["electricity_production_per_kW"] = obj.electricity_production_per_kW.values()
        line["electricity_production_per_kW_y"] = obj.electricity_production_per_kW_y.values()

        line["electricity_prices"] = obj.electricity_prices.values()
        line["electricity_prices_y"] = obj.electricity_prices_y.values()

        line["non_working_days"] = obj.non_working_days.values()
        line["non_working_days_y"] = obj.non_working_days_y.values()

        line["pv_owners"] = obj.pv_owners.values()
        line["pv_project"] = obj.pv_project.values()

        line["pv_owners_y"] = obj.pv_owners_y.values()
        line["pv_project_y"] = obj.pv_project_y.values()

        self.line = convertValue(line)

    def _getIrrValues(self):
        """Returns irr results for specified attrributes."""
        return [getattr(self.r, field) for field in IRR_REPORT_FIELDS]

    def _getTepValues(self):
        """Returns total energy produced, system not working and electricity prod 2nd year attributes."""
        return [getattr(self.r, field) for field in TEP_REPORT_FIELDS]
import datetime
from config_readers import MainConfig, SubsidyModuleConfigReader, \
    TechnologyModuleConfigReader, EconomicModuleConfigReader, EnergyModuleConfigReader, RiskModuleConfigReader

_country='1ITALY'
config = MainConfig(_country)
# print config.getConfigsValues()

_country='ITALY'
startdate = datetime.datetime(2000,1,1)
config = SubsidyModuleConfigReader(_country, startdate)
# print config.getConfigsValues()


config = TechnologyModuleConfigReader(_country)
# print config.getConfigsValues()

config = EconomicModuleConfigReader(_country)
# print config.getConfigsValues()

config = EnergyModuleConfigReader(_country)
# print config.getConfigsValues()

config = RiskModuleConfigReader(_country)
print config.getConfigsValues()