-
Notifications
You must be signed in to change notification settings - Fork 0
/
Scenarios.py
executable file
·73 lines (62 loc) · 2.52 KB
/
Scenarios.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import numpy as np
from Sectors import *
from Configuration import Configuration
class Scenario:
def __init__(self, name, scenarioData):
self.name = name
self.ef = scenarioData['ef']
if 'Sectors' in scenarioData:
self.__createSectors(scenarioData["Sectors"])
def __createSectors(self, sectorsData):
cfg = Configuration()
self.sectorsP = []
self.sectorNames = []
#@todo: comprobar que no se incumplen las restricciones de emisiones
i = 0
depentedSectors = []
for sectorID in sectorsData:
self.sectorNames.append(sectorID)
if sectorID in sectorsData:
if (sectorsData[sectorID]["type"] == "Dependent"):
depentedSectors.append(i)
self.sectorsP.append(self.__newSector(sectorID, sectorsData[sectorID]))
#else:
# self.sectorsP.append(self.__newNoneDataSector(self.ef[i], sectorID))
i+=1
for i in depentedSectors:
assSectorsStr = sectorsData[self.sectorsP[i].name]['data']['assSector']
assSectorsList = assSectorsStr.split('/')
print(assSectorsList)
for assSector in assSectorsList:
assSectorN = self.sectorNames.index(assSector)
self.sectorsP[i].assSectorObjs.append(self.sectorsP[assSectorN])
# def __newNoneDataSector(self, ef, sectorID):
# cfg = Configuration()
# endYear=cfg.firstYear+cfg.nYears-1
# n = cfg.sectorIDs.index(sectorID)
# e0 = cfg.e0[n]
# t0 = cfg.t0[n]
# stdSData = {
# 'type': "Interpolated",
# 'indV': 'e',
# 'maxIncr': 5,
# 'maxDecr': 5,
# 'data': {
# cfg.firstYear: eval(self.indV+"0"),
# endYear: eval("self."+self.indV+"f["+str(n)+"]")
# }
# }
# return InterpolatedSector(ef, sectorID, stdSData)
def __newSector(self, sectorID, sectorsData):
return eval(Sector.STypes[sectorsData['type']]+"(sectorID, sectorsData)")
# def __checkETFContraints(self):
# etf = self.ef/self.tf
# cfg = Configuration()
# for etfSector in self.etf:
# if ( etfSector<(cfg.et0-0.01) or etfSector>(cfg.et0+0.01)):
# raise Exception("ef/tf violates restriction in scenario " + self.name)
# def step(self):
# for sector in sectorsP:
# sector.step()
def getNSectors(self):
return len(self.sectorsP)