Пример #1
0
    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)
Пример #2
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]
Пример #3
0
            for title, source_key in SOURCE.items():
                dic_values = source[source_key]
                header = dic_values.keys()
                values = dic_values.values()
                w.writerow([title])
                for name, value in dic_values.items():
                    if isinstance(value, (dict, list)):
                        continue  #because SECOND sheet is for only config values, so we dont want to save to XLS large structures like lists and dicts
                    else:
                        w.writerow([name, value])  #else write to XLS
                w.writerow('')  #write last row blank


if __name__ == '__main__':
    from tm import TechnologyModule
    from em import EnergyModule
    from sm import SubsidyModule
    from ecm import EconomicModule
    from report import Report
    from config_readers import MainConfig
    mainconfig = MainConfig('ITALY')
    energy_module = EnergyModule(mainconfig)
    technology_module = TechnologyModule(mainconfig, energy_module)
    subsidy_module = SubsidyModule(mainconfig)
    economic_module = EconomicModule(mainconfig, technology_module,
                                     subsidy_module)

    o = ReportOutput(None)
    o.source_filename = r"C:\temp2.csv"
    o.prepareSourceSecondSheetExcel(20, 1)
Пример #4
0
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()

Пример #5
0
 def getAllDates(country):
     return MainConfig(country).getAllDates()
Пример #6
0
    def checkBalanceSheet(self, date):
        """Checks balance sheet Assets - Liabilities should be 0
        return  Nothing if all it OK,
        return  ValueError if check failed
        """
        if self.asset[date] - self.liability[date] == 0:
            self.control[date] = 0
        else:
            self.control[date] = self.asset[date] - self.liability[date]


if __name__ == '__main__':
    from enm import EnvironmentalModule
    country = 'SLOVENIA'
    mainconfig = MainConfig(country)
    em = EnergyModule(mainconfig, country)
    technology_module = TechnologyModule(mainconfig, em, country)
    subsidy_module = SubsidyModule(mainconfig, country)
    environment_module = EnvironmentalModule(mainconfig,
                                             country,
                                             total_nominal_power=1)
    ecm = EconomicModule(mainconfig, technology_module, subsidy_module,
                         environment_module, country)

    r = Report(mainconfig, ecm)
    import time
    s = time.time()
    for i in range(1):
        r.calcReportValues()
Пример #7
0
Файл: sm.py Проект: vogrinm/MIRR
#!/usr/bin/env python
# -*- coding utf-8 -*-

from base_class import BaseClassConfig
from config_readers import MainConfig, SubsidyModuleConfigReader


class SubsidyModule(BaseClassConfig, SubsidyModuleConfigReader):
    """Module for calculation subsidy values for production electricity"""
    def __init__(self, config_module, country):
        BaseClassConfig.__init__(
            self, config_module
        )  #init base class config to have ability to use all main config values
        SubsidyModuleConfigReader.__init__(
            self, country, last_day_construction=self.last_day_construction
        )  #load config values for current module


if __name__ == '__main__':
    s = SubsidyModule(MainConfig('ITALY'))
    print s.getConfigsValues()