cloudpss 3.2.0a2__py3-none-any.whl → 4.0.0a5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. cloudpss/__init__.py +6 -4
  2. cloudpss/dslab/DSLabFinancialResult.py +96 -0
  3. cloudpss/dslab/__init__.py +2 -0
  4. cloudpss/dslab/dataManageModel.py +267 -0
  5. cloudpss/dslab/dslab.py +145 -0
  6. cloudpss/dslab/files/__init__.py +2 -0
  7. cloudpss/dslab/files/curveData.py +140205 -0
  8. cloudpss/dslab/files/files.py +19 -0
  9. cloudpss/dslab/financialAnalysisModel.py +137 -0
  10. cloudpss/function/functionExecution.py +0 -2
  11. cloudpss/ieslab/DataManageModel.py +415 -0
  12. cloudpss/ieslab/EvaluationModel.py +189 -0
  13. cloudpss/ieslab/IESLabPlan.py +132 -0
  14. cloudpss/ieslab/IESLabSimulation.py +54 -0
  15. cloudpss/ieslab/PlanModel.py +143 -0
  16. cloudpss/ieslab/__init__.py +4 -0
  17. cloudpss/model/jobDefinitions.py +34 -0
  18. cloudpss/model/model.py +202 -15
  19. cloudpss/model/revision.py +2 -2
  20. cloudpss/project/project.py +4 -3
  21. cloudpss/runner/DSLabResult.py +92 -0
  22. cloudpss/runner/IESLabEvaluationResult.py +143 -0
  23. cloudpss/runner/IESLabPlanResult.py +195 -0
  24. cloudpss/runner/IESLabTypicalDayResult.py +142 -0
  25. cloudpss/runner/MessageStreamReceiver.py +193 -0
  26. cloudpss/runner/receiver.py +3 -3
  27. cloudpss/runner/result.py +38 -4
  28. cloudpss/runner/runner.py +61 -18
  29. cloudpss/utils/IO.py +153 -0
  30. cloudpss/utils/httprequests.py +14 -11
  31. cloudpss/verify.py +27 -14
  32. cloudpss/version.py +1 -0
  33. {cloudpss-3.2.0a2.dist-info → cloudpss-4.0.0a5.dist-info}/METADATA +2 -4
  34. cloudpss-4.0.0a5.dist-info/RECORD +54 -0
  35. {cloudpss-3.2.0a2.dist-info → cloudpss-4.0.0a5.dist-info}/WHEEL +1 -1
  36. cloudpss-3.2.0a2.dist-info/RECORD +0 -33
  37. {cloudpss-3.2.0a2.dist-info → cloudpss-4.0.0a5.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,189 @@
1
+ import time
2
+ from cloudpss.runner.runner import HttpRunner, Runner
3
+ from cloudpss.runner.IESLabEvaluationResult import IESLabEvaluationResult
4
+ from ..utils import request
5
+ import json
6
+ from enum import IntEnum, unique
7
+
8
+ class IESLabEvaluationModel(object):
9
+ _baseUri = 'api/ieslab-plan/rest/'
10
+ _taskUri = 'api/ieslab-plan/taskmanager/getSimuLastTasks'
11
+ _kindNameMap = {
12
+ "投资组成": "investmentbanchandproportion",
13
+ "资金来源": "capitalsource",
14
+ "资产形式": "assetformation",
15
+ "生产成本": "productioncost",
16
+ "流动资金及财务费用": "workingcapitalandfinancialexpenses",
17
+ "税率及附加": "projectcalculation",
18
+ }
19
+
20
+ # 财务评价基础参数接口默认值
21
+ _financialParasDefaultValues = {
22
+ "资产形式": {
23
+ "fixedAssetsRatio": "95",
24
+ "residualRrate": "5",
25
+ "depreciationPeriod": "15",
26
+ "reimbursementPeriod": "5"
27
+ },
28
+ "生产成本": {
29
+ 'annualSalary': "8",
30
+ 'capacity': "4",
31
+ 'insuranceRate': "0.25",
32
+ 'materialsExpenses': "5.0",
33
+ 'otherExpenses': "1.0",
34
+ 'welfareFactor': "0"
35
+ },
36
+ "流动资金及财务费用": {
37
+ "annualAPCirculationTimes": "12",
38
+ "annualARCirculationTimes": "12",
39
+ "annualCashCirculationTimes": "12",
40
+ "annualStockCirculationTimes": "12",
41
+ "interestRateAndWorkingCapital": "4",
42
+ "workingCapitalLoanRatio": "70"
43
+ },
44
+ "税率及附加": {
45
+ "aleatoricAccumulationFundRate": "0",
46
+ "basicDiscountRate": "8",
47
+ "cityMaintenanceConstructionTaxTate": "5",
48
+ "corporateIncomeTaxRate": "25",
49
+ "educationFeePlus": "5",
50
+ "electricityVATRate": "18",
51
+ "fuelBoughtVATRate": "10",
52
+ "hotColdVATRate": "12",
53
+ "legalAccumulationFundRate": "10",
54
+ "localEducationPlus": "2",
55
+ "materialBoughtVATRate": "17",
56
+ "steamSaleVATRate": "12"
57
+ }
58
+ }
59
+
60
+ # 评价基础参数接口默认值
61
+ _evaluationType = {
62
+ "环保评价": "environmentalEvaluation",
63
+ "能效评价": "energyEvaluation"
64
+ }
65
+
66
+ def __init__(self, simulationId):
67
+ '''
68
+ 初始化
69
+ '''
70
+ self.simulationId = simulationId
71
+
72
+ def _saveItemData(self, url, data):
73
+ '''
74
+ 保存url链接对应的优化方案下财务评估模块的基础信息
75
+ :param url string类型,表示优化方案的接口链接
76
+
77
+ :return: dict 类型,代表方案对应的财务评价基础参数信息
78
+ '''
79
+ r = request('POST', url, data=json.dumps(data))
80
+ dataList = json.loads(r.text)
81
+ return dataList
82
+
83
+ def _fetchItemData(self, url, planID):
84
+ '''
85
+ 获取planID对应的优化方案下财务评估模块的基础信息
86
+ :param planID int类型,表示优化方案的ID,数值位于0~优化方案数量之间
87
+
88
+ :return: dict 类型,为源数据的引用,代表方案对应的财务评价基础参数信息
89
+ '''
90
+ r = request('GET',
91
+ url,
92
+ params={
93
+ "simu_id": self.simulationId,
94
+ "planId": planID,
95
+ })
96
+ data = json.loads(r.text)
97
+ return data
98
+
99
+ def GetFinancialParams(self, planID):
100
+ '''
101
+ 获取planID对应的优化方案下财务评估模块的基础信息
102
+ :param planID int类型,表示优化方案的ID,数值位于0~优化方案数量之间
103
+
104
+ :return: dict 类型,为源数据的引用,代表方案对应的财务评价基础参数信息
105
+ '''
106
+ dict_result = dict()
107
+ for k, v in self._kindNameMap.items():
108
+ kind = self._kindNameMap.get(k, k)
109
+ url = self._baseUri + kind + '/'
110
+ list = self._fetchItemData(url, planID)
111
+ if (len(list['results']) == 0):
112
+ data = {
113
+ "simu": self.simulationId,
114
+ "planId": planID,
115
+ }
116
+ if (k in self._financialParasDefaultValues):
117
+ data.update(self._financialParasDefaultValues[k])
118
+ res = self._saveItemData(url, data)
119
+ dict_result[v] = res
120
+ else:
121
+ pass
122
+ else:
123
+ dict_result[v] = list['results']
124
+ return dict_result
125
+
126
+ def run(self, planID, type=None) -> Runner[IESLabEvaluationResult]:
127
+ '''
128
+ 运行方案评估
129
+
130
+ :param planID int类型,表示优化方案的ID,数值位于0~优化方案数量之间
131
+ :params type: string类型,任务类型:环保评价/能效评价
132
+
133
+ :return: Runner[IESLabEvaluationResult]
134
+ '''
135
+ url = 'api/ieslab-plan/taskmanager/saveDataToclickhouse'
136
+ CMD_TYPE = type if type is None else self._evaluationType[type]
137
+ try:
138
+ timeId = int(time.time() * 1000)
139
+ r = request('GET',
140
+ url,
141
+ params={
142
+ "simuid": self.simulationId,
143
+ "planId": planID,
144
+ "CMD_TYPE": CMD_TYPE
145
+ })
146
+ data = json.loads(r.text)
147
+ return HttpRunner({'rid': 'function/ieslab/evaluation'},
148
+ self.simulationId,
149
+ timeId=timeId,
150
+ planId=planID,
151
+ cmdType=CMD_TYPE)
152
+ except:
153
+ raise Exception('方案评估开始计算失败')
154
+
155
+ def EnvironmentalEvaluationRun(self, planID):
156
+ '''
157
+ 运行环保评价方案评估
158
+
159
+ :param planID int类型,表示优化方案的ID,数值位于0~优化方案数量之间
160
+
161
+ :return: 方案评估运行实例
162
+ '''
163
+ return self.run(planID, 'environmentalEvaluation')
164
+
165
+ def EnergyEvaluationRun(self, planID):
166
+ '''
167
+ 运行能效评价方案评估
168
+
169
+ :param planID int类型,表示优化方案的ID,数值位于0~优化方案数量之间
170
+
171
+ :return: 方案评估运行实例
172
+ '''
173
+ return self.run(planID, 'energyEvaluation')
174
+
175
+ def GetRunner(self, planID) -> Runner[IESLabEvaluationResult]:
176
+ '''
177
+ 获得运行实例
178
+
179
+ :return: Runner[IESLabEvaluationResult]
180
+ '''
181
+ return HttpRunner({'rid': 'function/ieslab/evaluation'},
182
+ self.simulationId,
183
+ planId=planID)
184
+
185
+
186
+ @unique
187
+ class OptimizationMode(IntEnum):
188
+ 经济性 = 0
189
+ 环保性 = 1
@@ -0,0 +1,132 @@
1
+ import json
2
+
3
+ from cloudpss.ieslab.DataManageModel import IESPlanDataManageModel
4
+ from cloudpss.ieslab.EvaluationModel import IESLabEvaluationModel
5
+ from cloudpss.ieslab.PlanModel import IESLabPlanModel
6
+ from cloudpss.runner.IESLabTypicalDayResult import IESLabTypicalDayResult
7
+ from ..utils import request
8
+ from ..model.model import Model
9
+ from cloudpss.runner.runner import Runner
10
+ from cloudpss.runner.IESLabPlanResult import IESLabPlanResult
11
+ from cloudpss.runner.IESLabEvaluationResult import IESLabEvaluationResult
12
+
13
+ class IESLabPlan(object):
14
+ def __init__(self, project={}):
15
+ '''
16
+ 初始化
17
+ '''
18
+ self.id = project.get('id', None)
19
+ self.name = project.get('name', None)
20
+ self.__modelRid = project.get('model', None)
21
+ self.project_group = project.get('project_group', None)
22
+ if self.__modelRid is not None:
23
+ self.model = Model.fetch(self.__modelRid)
24
+ self.dataManageModel = IESPlanDataManageModel(self.id)
25
+ self.planModel = IESLabPlanModel(self.id)
26
+ self.evaluationModel = IESLabEvaluationModel(self.id)
27
+ self.currentPlanResult = IESLabPlanResult(self.id)
28
+ self.currentEvaluationResult = IESLabEvaluationResult(self.id)
29
+
30
+ @staticmethod
31
+ def fetch(simulationId):
32
+ '''
33
+ 获取算例信息
34
+
35
+ :params: simulationId string类型,代表数据项的算例id
36
+
37
+ :return: IESLabPlan
38
+ '''
39
+ try:
40
+ r = request('GET',
41
+ 'api/ieslab-plan/rest/simu/{0}/'.format(simulationId))
42
+ project = json.loads(r.text)
43
+ return IESLabPlan(project)
44
+ except:
45
+ raise Exception('未查询到当前算例')
46
+
47
+ def __run(self, job=None, name=None):
48
+ '''
49
+ 调用仿真
50
+
51
+ :params job: 调用仿真时使用的计算方案,不指定将使用算例保存时选中的计算方案
52
+ :params name: 任务名称,为空时使用项目的参数方案名称和计算方案名称
53
+
54
+ :return: 返回一个运行实例
55
+ '''
56
+ if job is None:
57
+ currentJob = self.model.context['currentJob']
58
+ job = self.model.jobs[currentJob]
59
+ job['args']['simulationId'] = self.id
60
+ return self.model.run(job, name=name)
61
+
62
+ def iesLabTypicalDayRun(self, job=None, name=None, **kwargs)->Runner[IESLabTypicalDayResult]:
63
+ '''
64
+ 运行典型日计算
65
+
66
+ :params job: 调用仿真时使用的计算方案,不指定将使用算例保存时选中的计算方案
67
+ :params name: 任务名称,为空时使用项目的参数方案名称和计算方案名称
68
+
69
+ :return: Runner[IESLabTypicalDayResult]
70
+ '''
71
+ if job is None:
72
+ currentJob = self.model.context['currentJob']
73
+ job = self.model.jobs[currentJob]
74
+ if job['rid'] != 'function/CloudPSS/ieslab-gmm':
75
+ for j in self.model.jobs:
76
+ if j['rid'] == 'job-definition/ies/ies-gmm' or j['rid'] == 'job-definition/cloudpss/ieslab-gmm':
77
+ j['rid'] = 'function/CloudPSS/ieslab-gmm'
78
+ job = j
79
+ if job is None:
80
+ raise Exception("找不到默认的综合能源系统规划典型日生成算法的计算方案")
81
+ if job['rid'] != 'function/CloudPSS/ieslab-gmm':
82
+ raise Exception("不是综合能源系统规划典型日生成算法的计算方案")
83
+ return self.__run(job=job, name=name)
84
+
85
+ def iesLabEvaluationRun(self, planId, type=None):
86
+ '''
87
+ 运行方案评估
88
+
89
+ :param planID int类型,表示优化方案的ID,数值位于0~优化方案数量之间
90
+ :param type string类型,表示评估类型,可选值为:能效评价、环保评价
91
+
92
+ :return: 方案评估运行实例
93
+
94
+ '''
95
+ return self.evaluationModel.run(planId, type)
96
+
97
+ def iesLabEnergyEvaluationRun(self, planId):
98
+ '''
99
+ 运行能效评价
100
+
101
+ :param planID int类型,表示优化方案的ID,数值位于0~优化方案数量之间
102
+
103
+ :return: 能效评价运行实例
104
+
105
+ '''
106
+ return self.evaluationModel.EnergyEvaluationRun(planId)
107
+
108
+ def iesLabEnvironmentalEvaluationRun(self, planId):
109
+ '''
110
+ 运行环保评价
111
+
112
+ :param planID int类型,表示优化方案的ID,数值位于0~优化方案数量之间
113
+
114
+ :return: 环保评价运行实例
115
+ '''
116
+ return self.evaluationModel.EnvironmentalEvaluationRun(planId)
117
+
118
+ def iesLabPlanRun(self):
119
+ '''
120
+ 生成方案优选算例
121
+
122
+ :return: 方案优选运行实例
123
+ '''
124
+ return self.planModel.run()
125
+
126
+ def iesLabPlanKill(self):
127
+ '''
128
+ 停止并删除方案优选算例
129
+
130
+ :return: Boolean
131
+ '''
132
+ return self.planModel.kill()
@@ -0,0 +1,54 @@
1
+ import json
2
+ from ..utils import request
3
+ from ..model.model import Model
4
+ from .DataManageModel import IESSimulationDataManageModel
5
+
6
+
7
+ class IESLabSimulation(object):
8
+ def __init__(self, project={}):
9
+ '''
10
+ 初始化
11
+ '''
12
+ self.id = project.get('id', None)
13
+ self.name = project.get('name', None)
14
+ self.__modelRid = project.get('model', None)
15
+ self.project_group = project.get('project_group', None)
16
+ if self.__modelRid is not None:
17
+ self.model = Model.fetch(self.__modelRid)
18
+ self.dataManageModel = IESSimulationDataManageModel(self.id)
19
+
20
+ @staticmethod
21
+ def fetch(simulationId):
22
+ '''
23
+ 获取算例信息
24
+
25
+ :params: simulationId string类型,代表数据项的算例id
26
+
27
+ :return: IESLabSimulation
28
+ '''
29
+ try:
30
+ r = request(
31
+ 'GET', 'api/ieslab-simulation/rest/simu/{0}/'.format(simulationId))
32
+ project = json.loads(r.text)
33
+ print(project)
34
+ return IESLabSimulation(project)
35
+ except:
36
+ raise Exception('未查询到当前算例')
37
+
38
+ def run(self, job=None, name=None):
39
+ '''
40
+ 调用仿真
41
+
42
+ :params job: 调用仿真时使用的计算方案,不指定将使用算例保存时选中的计算方案
43
+ :params name: 任务名称,为空时使用项目的参数方案名称和计算方案名称
44
+
45
+ :return: 返回一个运行实例
46
+ '''
47
+ if job is None:
48
+ currentJob = self.model.context['currentJob']
49
+ job = self.model.jobs[currentJob]
50
+
51
+ job['args']['simulationId'] = self.id
52
+ print(job)
53
+ return self.model.run(job, name=name)
54
+
@@ -0,0 +1,143 @@
1
+ from cloudpss.runner.IESLabPlanResult import IESLabPlanResult
2
+ from cloudpss.runner.runner import HttpRunner, Runner
3
+ from ..utils import request, fileLoad
4
+ import json
5
+ from enum import IntEnum, unique
6
+
7
+
8
+ class IESLabPlanModel(object):
9
+ _baseUri = 'api/ieslab-plan/taskmanager/getSimuLastTasks'
10
+
11
+ def __init__(self, simulationId):
12
+ '''
13
+ 初始化
14
+ '''
15
+ self.simulationId = simulationId
16
+ self.optimizationInfo = self.GetOptimizationInfo()
17
+ self.OptimizationMode = OptimizationMode
18
+
19
+ def _fetchItemData(self, url):
20
+ '''
21
+ 获取当前算例的优化目标设置信息
22
+
23
+ :return: enum 类型,代表经济性优化和环保性优化的类型
24
+ '''
25
+ r = request('GET', url, params={"simuid": self.simulationId})
26
+ data = json.loads(r.text)
27
+ return data
28
+
29
+ def GetOptimizationInfo(self):
30
+ '''
31
+ 获取当前算例的优化目标设置信息
32
+
33
+ :return: enum 类型,代表经济性优化和环保性优化的类型
34
+ '''
35
+ try:
36
+ data = self._fetchItemData(self._baseUri)
37
+ for e in OptimizationMode:
38
+ if (e.value == data['data']['optimizationpara']
39
+ ['OptimizationMode']):
40
+ return e
41
+ except:
42
+ return OptimizationMode['经济性']
43
+
44
+ def SetOptimizationInfo(self, optType):
45
+ '''
46
+ 无对应接口
47
+ 设置当前算例的优化目标
48
+
49
+ :param optType: enum 类型,代表经济性优化和环保性优化的类型
50
+ '''
51
+ self.optimizationInfo = optType
52
+ return True
53
+
54
+ def run(self) -> Runner[IESLabPlanResult]:
55
+ '''
56
+ 生成方案优选算例
57
+
58
+ :return: Runner[IESLabPlanResult]
59
+ '''
60
+ isRunning = self.GetLastTaskResult()
61
+ if isRunning:
62
+ raise Exception('该算例正在运行!请从浏览器算例页面点击结束运行或者调用IESPlan对象的kill接口终止计算后重试!')
63
+ else:
64
+ url = 'api/ieslab-plan/taskmanager/runOptimization'
65
+ if self.optimizationInfo is None:
66
+ self.optimizationInfo = OptimizationMode['经济性']
67
+ optType = self.optimizationInfo.value or 0
68
+ try:
69
+ r = request('GET',
70
+ url,
71
+ params={
72
+ "simuid":
73
+ self.simulationId,
74
+ "optPara":
75
+ json.dumps({
76
+ "OptimizationMode": optType,
77
+ "ProjectPeriod": "20"
78
+ })
79
+ })
80
+ data = json.loads(r.text)
81
+ return HttpRunner({}, self.simulationId)
82
+ except:
83
+ raise Exception('生成方案优选算例失败')
84
+
85
+ def GetRunner(self) -> Runner[IESLabPlanResult]:
86
+ '''
87
+ 获得运行实例
88
+
89
+ :return: Runner[IESLabPlanResult]
90
+ '''
91
+ return HttpRunner({}, self.simulationId)
92
+
93
+ def kill(self) -> bool:
94
+ '''
95
+ 停止并删除当前运行的优化算例
96
+ '''
97
+ res = IESLabPlanResult(self.simulationId).getLastTaskResult()
98
+ error = res.get('error', 0)
99
+ if error == 0:
100
+ data = res.get('data', {})
101
+ if data is not None:
102
+ taskID = data.get('task_id', '')
103
+ url = f'api/ieslab-plan/taskmanager/removeOptimizationTask'
104
+ try:
105
+ r = request('GET',
106
+ url,
107
+ params={
108
+ "taskid": taskID,
109
+ "stopFlag": '2'
110
+ })
111
+ json.loads(r.text)
112
+ return True
113
+ except:
114
+ return False
115
+
116
+ def GetLastTaskResult(self)-> bool:
117
+ '''
118
+ 获取最后一次运行的taskID的运行结果与日志
119
+
120
+ :return: boolean 类型
121
+ '''
122
+ isRunning = True
123
+ res = IESLabPlanResult(self.simulationId).getLastTaskResult()
124
+ error = res.get('error', 0)
125
+ if error == 0:
126
+ data = res.get('data', {})
127
+ if data is not None:
128
+ status = data.get('status', '')
129
+ if status == 'stop':
130
+ isRunning = False
131
+ logs = IESLabPlanResult(self.simulationId).GetLogs()
132
+ if logs is not None:
133
+ for log in logs:
134
+ if(log.get('data', '') == 'run ends'):
135
+ isRunning = False
136
+ break
137
+ return isRunning
138
+
139
+
140
+ # @unique
141
+ class OptimizationMode(IntEnum):
142
+ 经济性 = 0
143
+ 环保性 = 1
@@ -0,0 +1,4 @@
1
+ from .IESLabSimulation import IESLabSimulation
2
+ from .IESLabPlan import IESLabPlan
3
+ from .PlanModel import OptimizationMode
4
+ __all__ = ['IESLabSimulation','IESLabPlan', 'OptimizationMode']
@@ -112,5 +112,39 @@ JOB_DEFINITIONS = {
112
112
  "SkipPF": "0",
113
113
  "MaxIteration": "30"
114
114
  }
115
+ },
116
+ "iesLoadPrediction": {
117
+ "name": "负荷预测方案 1",
118
+ "rid": "job-definition/ies/ies-load-prediction",
119
+ "arcs": {
120
+ "startTime": "2022 -01-01 00:00:00",
121
+ "endTime": "2022 -12-31 23:00:00",
122
+ "layer_forcast": "0",
123
+ "forcast_algorithm": "0",
124
+ "ratio_sub": [],
125
+ "ratio_feeder": [],
126
+ "ratio_trans": []
127
+ }
128
+ },
129
+ "iesPowerFlow": {
130
+ "name": "时序潮流方案 1",
131
+ "rid": "job-definition/ies/ies-power-flow",
132
+ "arcs": {
133
+ "startTime": "2022 -01-01 00:00:00",
134
+ "endTime": "2022 -12-31 23:00:00",
135
+ "solveMethod": "0",
136
+ "maxIteration": "30"
137
+ }
138
+ },
139
+ "iesEnergyStoragePlan": {
140
+ "name": "储能规划方案 1",
141
+ "rid": "job-definition/ies/ies-energy-storage-plan",
142
+ "arcs": {
143
+ "Planyear": "15",
144
+ "NetConfig": [],
145
+ "SourceConfig": [],
146
+ "LoadConfig": []
147
+ }
115
148
  }
149
+
116
150
  }