Merge remote-tracking branch 'origin_myems/develop' into develop
commit
e253cf3617
46
CHANGELOG.md
46
CHANGELOG.md
|
@ -16,6 +16,48 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||
### Removed
|
||||
- None.
|
||||
|
||||
|
||||
## [v1.1.0] - 2021-03-18
|
||||
### Added
|
||||
- added excel exporter of equipmentefficiency report.
|
||||
- added excel exporter of conbinedequipmentefficiency report in API.
|
||||
- added 'optional' tips to meter,virtual meter and offline meter setting in admin UI.
|
||||
- added Optional key to translation in admin UI.
|
||||
- added cominbedequipmentefficiency report to api and web.
|
||||
- added equipmentefficiency report api.
|
||||
|
||||
### Changed
|
||||
- updated cost file controller in admin UI
|
||||
- updated user login session expire time to 8 hours.
|
||||
- changed web UI and API to set contact of space is optional.
|
||||
|
||||
### Fixed
|
||||
- fixed http headers issues of offlinemeterfile, knowledgefile and costfile in admin UI
|
||||
- changed float datatype to Decimal datatype for offline meter normalization.
|
||||
- fixed issue of add space in web UI.
|
||||
- added historical database close and disconnect at the end of reports.
|
||||
|
||||
### Removed
|
||||
- None.
|
||||
|
||||
## [v1.0.8] - 2021-03-11
|
||||
### Added
|
||||
- added excel exporter of combinedequipmentstatistics report
|
||||
- added translation for German
|
||||
- added excel exporter of storesaving report
|
||||
- added excel exporter of equipmentincome report
|
||||
- added excel exporter of shopfloorsaving report
|
||||
- added excel exporter of equipmentload report
|
||||
|
||||
### Changed
|
||||
- Changed default reporting range in EnergyFlowDiagram.
|
||||
|
||||
### Fixed
|
||||
- None.
|
||||
|
||||
### Removed
|
||||
- None.
|
||||
|
||||
## [v1.0.7] - 2021-03-07
|
||||
### Added
|
||||
- added excel exporter of storeload report
|
||||
|
@ -77,7 +119,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||
### Removed
|
||||
- None.
|
||||
|
||||
[Unreleased]: https://github.com/MyEMS/myems/compare/v1.0.7...HEAD
|
||||
[Unreleased]: https://github.com/MyEMS/myems/compare/v1.1.0...HEAD
|
||||
[v1.0.8]: https://github.com/MyEMS/myems/compare/v1.0.8...v1.1.0
|
||||
[v1.0.8]: https://github.com/MyEMS/myems/compare/v1.0.7...v1.0.8
|
||||
[v1.0.7]: https://github.com/MyEMS/myems/compare/v1.0.6...v1.0.7
|
||||
[v1.0.6]: https://github.com/MyEMS/myems/compare/v1.0.5...v1.0.6
|
||||
[v1.0.5]: https://github.com/MyEMS/myems/releases/tag/v1.0.5
|
||||
|
|
85
README.md
85
README.md
|
@ -19,52 +19,58 @@ MyEMS是行业领先的开源能源管理系统,利用云计算、物联网、
|
|||
## MyEMS架构
|
||||

|
||||
|
||||
## MyEMS组件(社区版 )
|
||||
## MyEMS组件(社区版)
|
||||
|
||||
MyEMS项目由下列组件构成:
|
||||
|
||||
### MyEMS Web APP
|
||||
|
||||
参考[web](./web/README.md) 获取更多信息。
|
||||
|
||||
### MyEMS 管理面板
|
||||
|
||||
参考[admin](./admin/README.md) 获取更多信息。
|
||||
|
||||
### MyEMS 数据库
|
||||
SQL
|
||||
|
||||
参考[database](./database/README.md) 获取更多信息。
|
||||
[安装 数据库](./database/README.md)
|
||||
|
||||
### MyEMS 数据清洗服务
|
||||
### MyEMS API 应用程序接口
|
||||
Python
|
||||
|
||||
参考[myems-cleaning](./myems-cleaning/README.md) 获取更多信息。
|
||||
[安装 myems-api](./myems-api/README.md)
|
||||
|
||||
### MyEMS 数据规范化服务
|
||||
### MyEMS 管理 UI
|
||||
AngularJS
|
||||
|
||||
参考[myems-normalization](./myems-normalization/README.md) 获取更多信息。
|
||||
|
||||
### MyEMS 数据汇总服务
|
||||
|
||||
参考[myems-aggregation](./myems-aggregation/README.md) 获取更多信息。
|
||||
|
||||
### MyEMS 数据接口API
|
||||
|
||||
参考[myems-api](./myems-api/README.md) 获取更多信息。
|
||||
|
||||
### MyEMS MQTT 数据发布服务 (从MyEMS转发到第三方)
|
||||
|
||||
参考[myems-mqtt-publisher](./myems-mqtt-publisher/README.md) 获取更多信息。
|
||||
[安装 admin UI](./admin/README.md)
|
||||
|
||||
### MyEMS BACnet/IP 数据采集服务
|
||||
Python
|
||||
|
||||
参考[myems-bacnet](./myems-bacnet/README.md) 获取更多信息。
|
||||
[安装 myems-bacnet](./myems-bacnet/README.md)
|
||||
|
||||
### MyEMS Modbus TCP 数据采集服务
|
||||
Python
|
||||
|
||||
参考[myems-modbus-tcp](./myems-modbus-tcp/README.md) 获取更多信息。
|
||||
[安装 myems-modbus-tcp](./myems-modbus-tcp/README.md)
|
||||
|
||||
## MyEMS截图
|
||||

|
||||
### MyEMS MQTT数据转发服务
|
||||
Python
|
||||
|
||||
[安装 myems-mqtt-publisher](./myems-mqtt-publisher/README.md)
|
||||
|
||||
### MyEMS 数据清洗服务
|
||||
Python
|
||||
|
||||
[安装 myems-cleaning](./myems-cleaning/README.md)
|
||||
|
||||
### MyEMS 数据规范化服务
|
||||
Python
|
||||
|
||||
[安装 myems-normalization](./myems-normalization/README.md)
|
||||
|
||||
### MyEMS 数据汇总服务
|
||||
Python
|
||||
|
||||
[安装 myems-aggregation](./myems-aggregation/README.md)
|
||||
|
||||
### MyEMS Web UI
|
||||
ReactJS
|
||||
|
||||
[安装 web UI](./web/README.md)
|
||||
|
||||
## 功能版本对比
|
||||
| 功能 |社区版(MyEMS) |企业版(AlbertEOS)|
|
||||
|
@ -149,7 +155,8 @@ MyEMS项目由下列组件构成:
|
|||
| 能流图分析 | ✔️ | ✔️ |
|
||||
| 配电系统分析 | ✔️ | ✔️ |
|
||||
| REST API | ✔️ | ✔️ |
|
||||
| Web APP | ✔️ | ✔️ |
|
||||
| Web UI | ✔️ | ✔️ |
|
||||
| Admin UI | ✔️ | ✔️ |
|
||||
| MQTT 协议订阅数据 | ❌ | ✔️ |
|
||||
| Modbus RTU 协议 | ❌ | ✔️ |
|
||||
| OPC UA 协议 | ❌ | ✔️ |
|
||||
|
@ -159,13 +166,18 @@ MyEMS项目由下列组件构成:
|
|||
| Johnson Controls Metasys | ✔️ | ✔️ |
|
||||
| Honeywell EBI | ✔️ | ✔️ |
|
||||
| SIEMENS Desigo CC | ❌ | ✔️ |
|
||||
| FDD 能效故障诊断规系统 | ❌ | ✔️ |
|
||||
| QWeather API | ❌ | ✔️ |
|
||||
| FDD 能效故障诊断系统 | ❌ | ✔️ |
|
||||
| 高级报表系统 | ❌ | ✔️ |
|
||||
| 组态图形绘制工具 | ❌ | ✔️ |
|
||||
| 设备远程控制 | ❌ | ✔️ |
|
||||
| BACnet Server | ❌ | ✔️ |
|
||||
| Modbus TCP Server(Slave) | ❌ | ✔️ |
|
||||
| OPC UA Server | ❌ | ✔️ |
|
||||
| iOS APP | ❌ | ✔️ |
|
||||
| Android APP | ❌ | ✔️ |
|
||||
| 微信小程序 | ❌ | ✔️ |
|
||||
| 支付宝小程序 | ❌ | ✔️ |
|
||||
| 工控机硬件网关(数据采集和远程控制) | ❌ | ✔️ |
|
||||
| LoRa无线数传电台模块(数据采集和远程控制)| ❌ | ✔️ |
|
||||
| 重点用能单位能耗在线监测系统上传省级平台通信协议| ❌ | ✔️ |
|
||||
|
@ -179,6 +191,11 @@ MyEMS项目由下列组件构成:
|
|||
| 投标技术支持服务 | ❌ | ✔️ |
|
||||
| 二次开发技术支持服务 | ❌ | ✔️ |
|
||||
|
||||
## MyEMS截图
|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
## MyEMS镜像
|
||||
|
||||
|
@ -188,3 +205,5 @@ MyEMS项目由下列组件构成:
|
|||
|
||||
[3]. http://bitbucket.org/myems/myems
|
||||
|
||||
[4]. https://gitlab.com/myems/myems
|
||||
|
||||
|
|
84
README_DE.md
84
README_DE.md
|
@ -23,48 +23,56 @@ MyEMS wird von einem erfahrenen Entwicklungsteam entwickelt und gewartet, und de
|
|||
|
||||
Dieses Projekt besteht aus folgenden Komponenten:
|
||||
|
||||
### MyEMS Web APP
|
||||
|
||||
Weitere Informationen finden Sie [web](./web/README.md).
|
||||
|
||||
### MyEMS Admin Panel
|
||||
|
||||
Weitere Informationen finden Sie im [admin](./admin/README.md).
|
||||
|
||||
### MyEMS Database
|
||||
SQL
|
||||
|
||||
Weitere Informationen finden Sie im [database](./database/README.md).
|
||||
|
||||
### MyEMS Cleaning Service
|
||||
|
||||
Weitere Informationen finden Sie im [myems-cleaning](./myems-cleaning/README.md).
|
||||
|
||||
### MyEMS Normalization Service
|
||||
|
||||
Weitere Informationen finden Sie im [myems-normalization](./myems-normalization/README.md).
|
||||
|
||||
### MyEMS Aggregation Service
|
||||
|
||||
Weitere Informationen finden Sie im [myems-aggregation](./myems-aggregation/README.md).
|
||||
[Installieren database](./database/README.md)
|
||||
|
||||
### MyEMS API
|
||||
Python
|
||||
|
||||
Weitere Informationen finden Sie im [myems-api](./myems-api/README.md).
|
||||
[Installieren myems-api](./myems-api/README.md)
|
||||
|
||||
### MyEMS MQTT Data Publisher Service (transmit data from MyEMS to 3rd Party)
|
||||
### MyEMS Admin UI
|
||||
AngularJS
|
||||
|
||||
Weitere Informationen finden Sie im [myems-mqtt-publisher](./myems-mqtt-publisher/README.md).
|
||||
[Installieren admin UI](./admin/README.md)
|
||||
|
||||
### MyEMS BACnet/IP Acquisition Service
|
||||
Python
|
||||
|
||||
Weitere Informationen finden Sie im [myems-bacnet](./myems-bacnet/README.md).
|
||||
[Installieren myems-bacnet](./myems-bacnet/README.md)
|
||||
|
||||
### MyEMS Modbus TCP Acquisition Service
|
||||
Python
|
||||
|
||||
Weitere Informationen finden Sie im [myems-modbus-tcp](./myems-modbus-tcp/README.md).
|
||||
[Installieren myems-modbus-tcp](./myems-modbus-tcp/README.md)
|
||||
|
||||
### MyEMS MQTT Data vorwärts Service
|
||||
Python
|
||||
|
||||
[Installieren myems-mqtt-publisher](./myems-mqtt-publisher/README.md)
|
||||
|
||||
### MyEMS Cleaning Service
|
||||
Python
|
||||
|
||||
[Installieren myems-cleaning](./myems-cleaning/README.md)
|
||||
|
||||
### MyEMS Normalization Service
|
||||
Python
|
||||
|
||||
[Installieren myems-normalization](./myems-normalization/README.md)
|
||||
|
||||
### MyEMS Aggregation Service
|
||||
Python
|
||||
|
||||
[Installieren myems-aggregation](./myems-aggregation/README.md)
|
||||
|
||||
### MyEMS Web UI
|
||||
ReactJS
|
||||
|
||||
[Installieren web UI](./web/README.md)
|
||||
|
||||
## MyEMS Bildschirmfoto
|
||||

|
||||
|
||||
## Editionen vergleichen
|
||||
|
||||
|
@ -152,7 +160,8 @@ Weitere Informationen finden Sie im [myems-modbus-tcp](./myems-modbus-tcp/README
|
|||
| Energy Flow Diagram | ✔️ | ✔️ |
|
||||
| Distribution System | ✔️ | ✔️ |
|
||||
| REST API | ✔️ | ✔️ |
|
||||
| Web APP | ✔️ | ✔️ |
|
||||
| Web UI | ✔️ | ✔️ |
|
||||
| Admin UI | ✔️ | ✔️ |
|
||||
| MQTT Subscriber | ❌ | ✔️ |
|
||||
| Modbus RTU | ❌ | ✔️ |
|
||||
| OPC UA | ❌ | ✔️ |
|
||||
|
@ -162,17 +171,22 @@ Weitere Informationen finden Sie im [myems-modbus-tcp](./myems-modbus-tcp/README
|
|||
| Johnson Controls Metasys | ✔️ | ✔️ |
|
||||
| Honeywell EBI | ✔️ | ✔️ |
|
||||
| SIEMENS Desigo CC | ❌ | ✔️ |
|
||||
| QWeather API | ❌ | ✔️ |
|
||||
| FDD Rule Engine | ❌ | ✔️ |
|
||||
| Advanced Reporting Engine | ❌ | ✔️ |
|
||||
| Graphics Drwaing Tool | ❌ | ✔️ |
|
||||
| Graphics Drawing Tool | ❌ | ✔️ |
|
||||
| Equipments Remote Control | ❌ | ✔️ |
|
||||
| BACnet Server | ❌ | ✔️ |
|
||||
| Modbus TCP Server(Slave) | ❌ | ✔️ |
|
||||
| OPC UA Server | ❌ | ✔️ |
|
||||
| iOS APP | ❌ | ✔️ |
|
||||
| Android APP | ❌ | ✔️ |
|
||||
| WeChat Mini Program | ❌ | ✔️ |
|
||||
| Alipay Mini Program | ❌ | ✔️ |
|
||||
| IPC Hardware Gateway (Data Acquisition and Remote Control)| ❌ | ✔️ |
|
||||
| LoRa Radio Module (Data Acquisition and Remote Control)| ❌ | ✔️ |
|
||||
| Protocol for Uploading to Provincial Platform of On-line monitoring system for Key Energy-Consuming Unit| ❌ | ✔️ |
|
||||
| 3rd Party Systems Integration | ❌ | ✔️ |
|
||||
| 3rd Party Systems Integration Service | ❌ | ✔️ |
|
||||
| Online Community Customer Support| ✔️ | ✔️ |
|
||||
| Email Customer Support | ✔️ | ✔️ |
|
||||
| Telephone Customer Support | ❌ | ✔️ |
|
||||
|
@ -182,6 +196,13 @@ Weitere Informationen finden Sie im [myems-modbus-tcp](./myems-modbus-tcp/README
|
|||
| Bidding Support Service | ❌ | ✔️ |
|
||||
| Customize Support Service | ❌ | ✔️ |
|
||||
|
||||
|
||||
## MyEMS Bildschirmfoto
|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
## MyEMS Spiegel
|
||||
|
||||
[1]. http://github.com/MyEMS/myems
|
||||
|
@ -190,3 +211,4 @@ Weitere Informationen finden Sie im [myems-modbus-tcp](./myems-modbus-tcp/README
|
|||
|
||||
[3]. http://bitbucket.org/myems/myems
|
||||
|
||||
[4]. https://gitlab.com/myems/myems
|
||||
|
|
85
README_EN.md
85
README_EN.md
|
@ -23,48 +23,56 @@ MyEMS is being developed and maintained by an experienced development team, and
|
|||
|
||||
This project is compose of following components:
|
||||
|
||||
### MyEMS Web APP
|
||||
|
||||
See the repository [web](./web/README.md) for more information.
|
||||
|
||||
### MyEMS Admin Panel
|
||||
|
||||
See [admin](./admin/README.md) for more information.
|
||||
|
||||
### MyEMS Database
|
||||
SQL
|
||||
|
||||
See [database](./database/README.md) for more information.
|
||||
|
||||
### MyEMS Cleaning Service
|
||||
|
||||
See [myems-cleaning](./myems-cleaning/README.md) for more information.
|
||||
|
||||
### MyEMS Normalization Service
|
||||
|
||||
See [myems-normalization](./myems-normalization/README.md) for more information.
|
||||
|
||||
### MyEMS Aggregation Service
|
||||
|
||||
See [myems-aggregation](./myems-aggregation/README.md) for more information.
|
||||
[Install database](./database/README.md)
|
||||
|
||||
### MyEMS API
|
||||
Python
|
||||
|
||||
See the repository [myems-api](./myems-api/README.md) for more information.
|
||||
[Install myems-api](./myems-api/README.md)
|
||||
|
||||
### MyEMS MQTT Data Publisher Service (transmit data from MyEMS to 3rd Party)
|
||||
### MyEMS Admin UI
|
||||
ReactJS
|
||||
|
||||
See [myems-mqtt-publisher](./myems-mqtt-publisher/README.md) for more information.
|
||||
[Install admin UI](./admin/README.md)
|
||||
|
||||
### MyEMS BACnet/IP Acquisition Service
|
||||
Python
|
||||
|
||||
See [myems-bacnet](./myems-bacnet/README.md) for more information.
|
||||
[Install myems-bacnet](./myems-bacnet/README.md)
|
||||
|
||||
### MyEMS Modbus TCP Acquisition Service
|
||||
Python
|
||||
|
||||
See [myems-modbus-tcp](./myems-modbus-tcp/README.md) for more information.
|
||||
[Install myems-modbus-tcp](./myems-modbus-tcp/README.md)
|
||||
|
||||
### MyEMS MQTT Data Forwarding Service
|
||||
Python
|
||||
|
||||
[Install myems-mqtt-publisher](./myems-mqtt-publisher/README.md)
|
||||
|
||||
### MyEMS Cleaning Service
|
||||
Python
|
||||
|
||||
[Install myems-cleaning](./myems-cleaning/README.md)
|
||||
|
||||
### MyEMS Normalization Service
|
||||
Python
|
||||
|
||||
[Install myems-normalization](./myems-normalization/README.md)
|
||||
|
||||
### MyEMS Aggregation Service
|
||||
Python
|
||||
|
||||
[Install myems-aggregation](./myems-aggregation/README.md)
|
||||
|
||||
### MyEMS Web UI
|
||||
AngularJS
|
||||
|
||||
[Install web UI](./web/README.md)
|
||||
|
||||
## MyEMS Screenshot
|
||||

|
||||
|
||||
## Compare Editions
|
||||
|
||||
|
@ -152,7 +160,8 @@ See [myems-modbus-tcp](./myems-modbus-tcp/README.md) for more information.
|
|||
| Energy Flow Diagram | ✔️ | ✔️ |
|
||||
| Distribution System | ✔️ | ✔️ |
|
||||
| REST API | ✔️ | ✔️ |
|
||||
| Web APP | ✔️ | ✔️ |
|
||||
| Web UI | ✔️ | ✔️ |
|
||||
| Admin UI | ✔️ | ✔️ |
|
||||
| MQTT Subscriber | ❌ | ✔️ |
|
||||
| Modbus RTU | ❌ | ✔️ |
|
||||
| OPC UA | ❌ | ✔️ |
|
||||
|
@ -162,17 +171,22 @@ See [myems-modbus-tcp](./myems-modbus-tcp/README.md) for more information.
|
|||
| Johnson Controls Metasys | ✔️ | ✔️ |
|
||||
| Honeywell EBI | ✔️ | ✔️ |
|
||||
| SIEMENS Desigo CC | ❌ | ✔️ |
|
||||
| QWeather API | ❌ | ✔️ |
|
||||
| FDD Rule Engine | ❌ | ✔️ |
|
||||
| Advanced Reporting Engine | ❌ | ✔️ |
|
||||
| Graphics Drwaing Tool | ❌ | ✔️ |
|
||||
| Graphics Drawing Tool | ❌ | ✔️ |
|
||||
| Equipments Remote Control | ❌ | ✔️ |
|
||||
| BACnet Server | ❌ | ✔️ |
|
||||
| Modbus TCP Server(Slave) | ❌ | ✔️ |
|
||||
| OPC UA Server | ❌ | ✔️ |
|
||||
| iOS APP | ❌ | ✔️ |
|
||||
| Android APP | ❌ | ✔️ |
|
||||
| WeChat Mini Program | ❌ | ✔️ |
|
||||
| Alipay Mini Program | ❌ | ✔️ |
|
||||
| IPC Hardware Gateway (Data Acquisition and Remote Control)| ❌ | ✔️ |
|
||||
| LoRa Radio Module (Data Acquisition and Remote Control)| ❌ | ✔️ |
|
||||
| Protocol for Uploading to Provincial Platform of On-line monitoring system for Key Energy-Consuming Unit| ❌ | ✔️ |
|
||||
| 3rd Party Systems Integration | ❌ | ✔️ |
|
||||
| 3rd Party Systems Integration Service | ❌ | ✔️ |
|
||||
| Online Community Customer Support| ✔️ | ✔️ |
|
||||
| Email Customer Support | ✔️ | ✔️ |
|
||||
| Telephone Customer Support | ❌ | ✔️ |
|
||||
|
@ -182,6 +196,13 @@ See [myems-modbus-tcp](./myems-modbus-tcp/README.md) for more information.
|
|||
| Bidding Support Service | ❌ | ✔️ |
|
||||
| Customize Support Service | ❌ | ✔️ |
|
||||
|
||||
## MyEMS Screenshot
|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
|
||||
## MyEMS Mirrors
|
||||
|
||||
[1]. http://github.com/MyEMS/myems
|
||||
|
@ -190,3 +211,5 @@ See [myems-modbus-tcp](./myems-modbus-tcp/README.md) for more information.
|
|||
|
||||
[3]. http://bitbucket.org/myems/myems
|
||||
|
||||
[4]. https://gitlab.com/myems/myems
|
||||
|
||||
|
|
|
@ -3,12 +3,10 @@
|
|||
app.controller('RuleController', function($scope, $common, $uibModal, $translate, RuleService, toaster, SweetAlert) {
|
||||
|
||||
$scope.initExpression = [{
|
||||
"spaceid": 1,
|
||||
"sample_object_id": 1,
|
||||
"limit": 1000.000,
|
||||
"recipients": [{
|
||||
"user_id": "1"
|
||||
}, {
|
||||
"user_id": "2"
|
||||
}]
|
||||
}];
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ app.controller('LoginController', function ($rootScope,
|
|||
$window,
|
||||
$common,
|
||||
$uibModal,
|
||||
$cookies,
|
||||
$scope,
|
||||
$interval,
|
||||
LoginService,
|
||||
|
|
|
@ -1,6 +1,17 @@
|
|||
'use strict';
|
||||
|
||||
app.controller('CostFileController', function ($scope, $common, $translate, $uibModal, $interval, CostFileService, toaster, SweetAlert) {
|
||||
app.controller('CostFileController', function (
|
||||
$scope,
|
||||
$window,
|
||||
$common,
|
||||
$translate,
|
||||
$uibModal,
|
||||
$interval,
|
||||
CostFileService,
|
||||
toaster,
|
||||
SweetAlert) {
|
||||
|
||||
$scope.cur_user = JSON.parse($window.localStorage.getItem("currentUser"));
|
||||
|
||||
$scope.getAllCostFiles = function () {
|
||||
CostFileService.getAllCostFiles(function (error, data) {
|
||||
|
@ -17,7 +28,8 @@ app.controller('CostFileController', function ($scope, $common, $translate, $ui
|
|||
url: getAPI() + 'offlinecostfiles',
|
||||
acceptedFiles: '.xlsx',
|
||||
dictDefaultMessage: 'Click(or Drop) to add files',
|
||||
maxFilesize: '100'
|
||||
maxFilesize: '100',
|
||||
headers: { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }
|
||||
};
|
||||
|
||||
$scope.dzCallbacks = {
|
||||
|
|
|
@ -1,6 +1,16 @@
|
|||
'use strict';
|
||||
|
||||
app.controller('KnowledgeFileController', function ($scope, $common, $cookies, $translate, $uibModal, KnowledgeFileService, toaster, SweetAlert) {
|
||||
app.controller('KnowledgeFileController', function (
|
||||
$scope,
|
||||
$window,
|
||||
$common,
|
||||
$translate,
|
||||
$uibModal,
|
||||
KnowledgeFileService,
|
||||
toaster,
|
||||
SweetAlert) {
|
||||
|
||||
$scope.cur_user = JSON.parse($window.localStorage.getItem("currentUser"));
|
||||
|
||||
$scope.getAllKnowledgeFiles = function () {
|
||||
KnowledgeFileService.getAllKnowledgeFiles(function (error, data) {
|
||||
|
@ -18,7 +28,7 @@ app.controller('KnowledgeFileController', function ($scope, $common, $cookies, $
|
|||
acceptedFiles: '.xlsx,.xls,.pdf,.docx,.doc,.dwg,.jpg,.png,.csv',
|
||||
dictDefaultMessage: 'Click(or Drop) to add files',
|
||||
maxFilesize: '100',
|
||||
headers: { "User-UUID": $cookies.get("user_uuid"), "Token": $cookies.get("token") }
|
||||
headers: { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }
|
||||
};
|
||||
|
||||
$scope.dzCallbacks = {
|
||||
|
|
|
@ -1,6 +1,17 @@
|
|||
'use strict';
|
||||
|
||||
app.controller('OfflineMeterFileController', function($scope, $common, $cookies, $translate,$uibModal,$interval, OfflineMeterFileService, toaster, SweetAlert) {
|
||||
app.controller('OfflineMeterFileController', function(
|
||||
$scope,
|
||||
$window,
|
||||
$common,
|
||||
$translate,
|
||||
$uibModal,
|
||||
$interval,
|
||||
OfflineMeterFileService,
|
||||
toaster,
|
||||
SweetAlert) {
|
||||
|
||||
$scope.cur_user = JSON.parse($window.localStorage.getItem("currentUser"));
|
||||
|
||||
$scope.getAllOfflineMeterFiles = function() {
|
||||
OfflineMeterFileService.getAllOfflineMeterFiles(function(error, data) {
|
||||
|
@ -16,9 +27,9 @@ app.controller('OfflineMeterFileController', function($scope, $common, $cookies
|
|||
$scope.dzOptions = {
|
||||
url: getAPI() + 'offlinemeterfiles',
|
||||
acceptedFiles: '.xlsx',
|
||||
dictDefaultMessage : 'Click(or Drop) to add files',
|
||||
dictDefaultMessage: 'Click(or Drop) to add files',
|
||||
maxFilesize: '100',
|
||||
headers: { "User-UUID": $cookies.get("user_uuid"), "Token": $cookies.get("token") }
|
||||
headers: { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }
|
||||
};
|
||||
|
||||
$scope.dzCallbacks = {
|
||||
|
@ -27,22 +38,22 @@ app.controller('OfflineMeterFileController', function($scope, $common, $cookies
|
|||
},
|
||||
'success': function(file, xhr) {
|
||||
//console.log('File success to upload from dropzone', file, xhr);
|
||||
var templateName = file.name;
|
||||
var templateName = file.name;
|
||||
|
||||
var popType = 'TOASTER.SUCCESS';
|
||||
var popTitle = $common.toaster.success_title;
|
||||
var popBody = $common.toaster.success_add_body;
|
||||
var popType = 'TOASTER.SUCCESS';
|
||||
var popTitle = $common.toaster.success_title;
|
||||
var popBody = $common.toaster.success_add_body;
|
||||
|
||||
popType = $translate.instant(popType);
|
||||
popTitle = $translate.instant(popTitle);
|
||||
popBody = $translate.instant(popBody,{template: templateName});
|
||||
popType = $translate.instant(popType);
|
||||
popTitle = $translate.instant(popTitle);
|
||||
popBody = $translate.instant(popBody,{template: templateName});
|
||||
|
||||
toaster.pop({
|
||||
type: popType,
|
||||
title: popTitle,
|
||||
body: popBody,
|
||||
showCloseButton: true,
|
||||
});
|
||||
toaster.pop({
|
||||
type: popType,
|
||||
title: popTitle,
|
||||
body: popBody,
|
||||
showCloseButton: true,
|
||||
});
|
||||
|
||||
// toaster.pop({
|
||||
// type: 'success',
|
||||
|
@ -77,15 +88,15 @@ app.controller('OfflineMeterFileController', function($scope, $common, $cookies
|
|||
|
||||
$scope.deleteOfflineMeterFile = function(offlinemeterfile) {
|
||||
SweetAlert.swal({
|
||||
title: $translate.instant($common.sweet.title),
|
||||
text: $translate.instant($common.sweet.text),
|
||||
type: "warning",
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: "#DD6B55",
|
||||
confirmButtonText: $translate.instant($common.sweet.confirmButtonText),
|
||||
cancelButtonText: $translate.instant($common.sweet.cancelButtonText),
|
||||
closeOnConfirm: true,
|
||||
closeOnCancel: true
|
||||
title: $translate.instant($common.sweet.title),
|
||||
text: $translate.instant($common.sweet.text),
|
||||
type: "warning",
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: "#DD6B55",
|
||||
confirmButtonText: $translate.instant($common.sweet.confirmButtonText),
|
||||
cancelButtonText: $translate.instant($common.sweet.cancelButtonText),
|
||||
closeOnConfirm: true,
|
||||
closeOnCancel: true
|
||||
},
|
||||
function(isConfirm) {
|
||||
if (isConfirm) {
|
||||
|
|
|
@ -136,7 +136,9 @@ app.controller('SpaceController', function ($scope, $common, $uibModal, SpaceSer
|
|||
modalInstance.result.then(function (space) {
|
||||
space.timezone_id = space.timezone.id;
|
||||
space.cost_center_id = space.cost_center.id;
|
||||
space.contact_id = space.contact.id;
|
||||
if (space.contact != null) {
|
||||
space.contact_id = space.contact.id;
|
||||
}
|
||||
SpaceService.addSpace(space, function (error, status) {
|
||||
if (angular.isDefined(status) && status == 201) {
|
||||
var templateName = "COMMON.SPACE";
|
||||
|
|
|
@ -100,9 +100,11 @@ function config($translateProvider) {
|
|||
PRIORITY: 'Priority',
|
||||
CHANNEL: 'Channel',
|
||||
IS_ENABLED: 'Is Enabled',
|
||||
LAST_RUN_DATETIME: 'Last Run Datetime',
|
||||
NEXT_RUN_DATETIME: 'Next Run Datetime',
|
||||
EXPRESSION: 'Expression',
|
||||
MESSAGE_TEMPLATE: 'Message Template',
|
||||
DES_EXPRESSION: 'Click "Edit" for details',
|
||||
CLICK_EDIT_FOR_DETAILS: 'Click "Edit" for details',
|
||||
|
||||
SMS_ALARM_LIST: 'SMS Alarm List',
|
||||
RECIPIENT_NAME: 'Recipient Name',
|
||||
|
@ -228,6 +230,7 @@ function config($translateProvider) {
|
|||
ON: 'On',
|
||||
OFF: 'OFF',
|
||||
OK: 'OK',
|
||||
OPTIONAL: 'Optional',
|
||||
ADD_SPACE: 'Add Space',
|
||||
ADD_TENANT: 'Add Tenant',
|
||||
ADD_STORE: 'Add Store',
|
||||
|
@ -373,7 +376,7 @@ function config($translateProvider) {
|
|||
SROSS: 'shutdown rate of standard status on non-working days',
|
||||
|
||||
USER: 'User',
|
||||
|
||||
|
||||
TEAM: 'Team',
|
||||
ADD_TEAM: 'Add Team',
|
||||
EDIT_TEAM: 'Edit Team',
|
||||
|
@ -387,7 +390,7 @@ function config($translateProvider) {
|
|||
CONTACT: {
|
||||
EMAIL: 'Email',
|
||||
PHONE: 'Phone',
|
||||
DESCRIPTION: 'Description(Optional)',
|
||||
DESCRIPTION: 'Description',
|
||||
INPUT_EMAIL: 'Please Input Email',
|
||||
INPUT_PHONE: 'Please Input Phone',
|
||||
INPUT_DESCRIPTION: 'Please Input Description',
|
||||
|
@ -453,7 +456,7 @@ function config($translateProvider) {
|
|||
SELECT_DISTRIBUTION_SYSTEM: 'Select Distribution System',
|
||||
SVG: 'SVG',
|
||||
INPUT_SVG: 'Please Input SVG',
|
||||
DESCRIPTION: 'Description(Optional)',
|
||||
DESCRIPTION: 'Description',
|
||||
DISTRIBUTION_CIRCUIT: 'Distribution Circuit',
|
||||
N_S_DISTRIBUTION_CIRCUIT: ' Associated Distribution Circuit',
|
||||
ADD_DISTRIBUTION_CIRCUIT: 'Add Distribution Circuit',
|
||||
|
@ -483,7 +486,7 @@ function config($translateProvider) {
|
|||
SELECT_EQUIPMENT: 'Please Select Equipment',
|
||||
COST_CENTER: 'Cost Center',
|
||||
SELECT_COST_CENTER: 'Please Select Cost Center',
|
||||
DESCRIPTION: 'Description(Optional)',
|
||||
DESCRIPTION: 'Description',
|
||||
INPUT_DESCRIPTION: 'Please Input Description',
|
||||
INPUT_METER: 'Please Input Meter',
|
||||
OUTPUT_METER: 'Output Meter',
|
||||
|
@ -512,7 +515,7 @@ function config($translateProvider) {
|
|||
SELECT_COMBINED_EQUIPMENT: 'Please Select Combined Equipment',
|
||||
COST_CENTER: 'Cost Center',
|
||||
SELECT_COST_CENTER: 'Please Select Cost Center',
|
||||
DESCRIPTION: 'Description(Optional)',
|
||||
DESCRIPTION: 'Description',
|
||||
INPUT_DESCRIPTION: 'Please Input Description',
|
||||
BIND_EQUIPMENT: 'Bind Equipment',
|
||||
N_S_EQUIPMENT: 'Bound Equipments',
|
||||
|
@ -549,7 +552,7 @@ function config($translateProvider) {
|
|||
PARENT_SPACE: 'Parent Space',
|
||||
AREA: 'Area',
|
||||
INPUT_AREA: 'Please Input Area',
|
||||
DESCRIPTION: 'Description(Optional)',
|
||||
DESCRIPTION: 'Description',
|
||||
INPUT_DESCRIPTION: 'Please Input Description',
|
||||
CURRENT_SELECTED_SPACE: 'Current Selected Space',
|
||||
CHILD_SPACES: 'Child Spaces',
|
||||
|
@ -571,7 +574,7 @@ function config($translateProvider) {
|
|||
LATITUDE: 'Latitude',
|
||||
LONGITUDE: 'Longitude',
|
||||
TYPE: 'Store Type',
|
||||
DESCRIPTION: 'Description(Optional)',
|
||||
DESCRIPTION: 'Description',
|
||||
INPUT_ADDRESS: 'Please Input Address',
|
||||
INPUT_LATITUDE: 'Please Input Latitude',
|
||||
INPUT_LONGITUDE: 'Please Input Longitude',
|
||||
|
@ -587,7 +590,7 @@ function config($translateProvider) {
|
|||
LEASE_START_DATETIME: 'Lease Start Datetime',
|
||||
LEASE_END_DATETIME: 'Lease End Datetime',
|
||||
IS_IN_LEASE: 'Is In Lease',
|
||||
DESCRIPTION: 'Description(Optional)',
|
||||
DESCRIPTION: 'Description',
|
||||
INPUT_BUILDINGS: 'Please Input Buildings',
|
||||
INPUT_FLOORS: 'Please Input Floors',
|
||||
INPUT_ROOMS: 'Rooms',
|
||||
|
@ -600,7 +603,7 @@ function config($translateProvider) {
|
|||
SELECT_SHOPFLOOR: 'Select Shopfloor',
|
||||
AREA: 'Area',
|
||||
INPUT_AREA: 'Please Input Area',
|
||||
DESCRIPTION: 'Description(Optional)',
|
||||
DESCRIPTION: 'Description',
|
||||
INPUT_DESCRIPTION: 'Please Input Description',
|
||||
BIND_EQUIPMENT: 'Bind Equipment',
|
||||
N_S_EQUIPMENT: 'Bound Equipments',
|
||||
|
@ -611,7 +614,7 @@ function config($translateProvider) {
|
|||
INPUT_HOURLY_LOW_LIMIT: 'Please Input Hourly Low Limit',
|
||||
HOURLY_HIGH_LIMIT: 'Hourly High Limit (Inclusive)',
|
||||
INPUT_HOURLY_HIGH_LIMIT: 'Please Input Hourly High Limit',
|
||||
DESCRIPTION: 'Description(Optional)',
|
||||
DESCRIPTION: 'Description',
|
||||
INPUT_DESCRIPTION: 'Please Input Description',
|
||||
MASTER_METER: 'Master Meter',
|
||||
SELECT_MASTER_METER: 'Select Master Meter',
|
||||
|
@ -622,7 +625,7 @@ function config($translateProvider) {
|
|||
ADD_SENSOR: 'Add Sensor',
|
||||
EDIT_SENSOR: 'Edit Sensor',
|
||||
DELETE_SENSOR: 'Delete Sensor',
|
||||
DESCRIPTION: 'Description(Optional)',
|
||||
DESCRIPTION: 'Description',
|
||||
INPUT_DESCRIPTION: 'Please Input Description',
|
||||
SELECT_SENSOR: 'Select Sensor',
|
||||
},
|
||||
|
@ -1150,9 +1153,11 @@ function config($translateProvider) {
|
|||
PRIORITY: '报警优先级',
|
||||
CHANNEL: '报警通道',
|
||||
IS_ENABLED: '报警开关',
|
||||
LAST_RUN_DATETIME: '上次运行时间',
|
||||
NEXT_RUN_DATETIME: '下次运行时间',
|
||||
EXPRESSION: '表达式',
|
||||
MESSAGE_TEMPLATE: '消息模板',
|
||||
DES_EXPRESSION: '点击"修改"查看详情',
|
||||
CLICK_EDIT_FOR_DETAILS: '点击"修改"查看详情',
|
||||
|
||||
SMS_ALARM_LIST: '短信报警列表',
|
||||
RECIPIENT_NAME: '接收人',
|
||||
|
@ -1275,6 +1280,7 @@ function config($translateProvider) {
|
|||
ON: '打开',
|
||||
OFF: '关闭',
|
||||
OK: '确定',
|
||||
OPTIONAL: '可选',
|
||||
ADD_SPACE: '添加空间',
|
||||
ADD_TENANT: '添加租户',
|
||||
ADD_STORE: '添加门店',
|
||||
|
@ -1429,7 +1435,7 @@ function config($translateProvider) {
|
|||
SROSS: '非生产日标准状态下关闭率',
|
||||
|
||||
USER: '用户',
|
||||
|
||||
|
||||
|
||||
TEAM: '班组',
|
||||
ADD_TEAM: '添加班组',
|
||||
|
@ -1444,7 +1450,7 @@ function config($translateProvider) {
|
|||
CONTACT: {
|
||||
EMAIL: '邮箱',
|
||||
PHONE: '电话',
|
||||
DESCRIPTION: '描述(可选)',
|
||||
DESCRIPTION: '描述',
|
||||
INPUT_EMAIL: '请输入邮箱',
|
||||
INPUT_PHONE: '请输入电话',
|
||||
INPUT_DESCRIPTION: '请输入描述',
|
||||
|
@ -1473,7 +1479,7 @@ function config($translateProvider) {
|
|||
RATIO: '比例系数',
|
||||
IS_TREND: '保存趋势',
|
||||
ADDRESS: '地址(JSON)',
|
||||
DESCRIPTION: '描述(可选)',
|
||||
DESCRIPTION: '描述',
|
||||
INPUT_HIGH_LIMIT: '请输入高限',
|
||||
INPUT_LOW_LIMIT: '请输入低限',
|
||||
INPUT_RATIO: '请输入比例系数',
|
||||
|
@ -1488,7 +1494,7 @@ function config($translateProvider) {
|
|||
SELECT_DISTRIBUTION_SYSTEM: '请选择配电系统',
|
||||
SVG: 'SVG',
|
||||
INPUT_SVG: '请输入SVG',
|
||||
DESCRIPTION: '描述(可选)',
|
||||
DESCRIPTION: '描述',
|
||||
DISTRIBUTION_CIRCUIT: '配电回路',
|
||||
N_S_DISTRIBUTION_CIRCUIT: '所属配电回路',
|
||||
ADD_DISTRIBUTION_CIRCUIT: '添加配电回路',
|
||||
|
@ -1540,7 +1546,7 @@ function config($translateProvider) {
|
|||
SELECT_COMBINED_EQUIPMENT: '请选择组合设备',
|
||||
COST_CENTER: '成本中心',
|
||||
SELECT_COST_CENTER: '请选择成本中心',
|
||||
DESCRIPTION: '描述(可选)',
|
||||
DESCRIPTION: '描述',
|
||||
BIND_EQUIPMENT: '绑定设备',
|
||||
N_S_EQUIPMENT: '绑定的设备',
|
||||
EQUIPMENT_LIST: '设备列表',
|
||||
|
@ -1573,7 +1579,7 @@ function config($translateProvider) {
|
|||
SELECT_EQUIPMENT: '请选择设备',
|
||||
COST_CENTER: '成本中心',
|
||||
SELECT_COST_CENTER: '请选择成本中心',
|
||||
DESCRIPTION: '描述(可选)',
|
||||
DESCRIPTION: '描述',
|
||||
INPUT_METER: '请输入表',
|
||||
INPUT_DESCRIPTION: '请输入描述',
|
||||
OUTPUT_METER: '输出表',
|
||||
|
@ -1608,7 +1614,7 @@ function config($translateProvider) {
|
|||
PARENT_SPACE: '上级',
|
||||
AREA: '面积',
|
||||
INPUT_AREA: '请输入面积',
|
||||
DESCRIPTION: '描述(可选)',
|
||||
DESCRIPTION: '描述',
|
||||
INPUT_DESCRIPTION: '请输入描述',
|
||||
CURRENT_SELECTED_SPACE: '当前选中空间',
|
||||
CHILD_SPACES: '子空间',
|
||||
|
@ -1641,7 +1647,7 @@ function config($translateProvider) {
|
|||
LEASE_START_DATETIME: '租赁开始日期时间',
|
||||
LEASE_END_DATETIME: '租赁结束日期时间',
|
||||
IS_IN_LEASE: '是否在租',
|
||||
DESCRIPTION: '描述(可选)',
|
||||
DESCRIPTION: '描述',
|
||||
INPUT_BUILDINGS: '请输入建筑',
|
||||
INPUT_FLOORS: '请输入楼层',
|
||||
INPUT_ROOMS: '请输入房间',
|
||||
|
@ -1653,7 +1659,7 @@ function config($translateProvider) {
|
|||
LATITUDE: '纬度',
|
||||
LONGITUDE: '经度',
|
||||
TYPE: '门店类型',
|
||||
DESCRIPTION: '描述(可选)',
|
||||
DESCRIPTION: '描述',
|
||||
INPUT_ADDRESS: '请输入地址',
|
||||
INPUT_LATITUDE: '请输入纬度',
|
||||
INPUT_LONGITUDE: '请输入经度',
|
||||
|
@ -1665,7 +1671,7 @@ function config($translateProvider) {
|
|||
SELECT_SHOPFLOOR: '请选择车间',
|
||||
AREA: '面积',
|
||||
INPUT_AREA: '请输入面积',
|
||||
DESCRIPTION: '描述(可选)',
|
||||
DESCRIPTION: '描述',
|
||||
INPUT_DESCRIPTION: '请输入描述',
|
||||
BIND_EQUIPMENT: '绑定设备',
|
||||
N_S_EQUIPMENT: '绑定的设备',
|
||||
|
@ -1676,7 +1682,7 @@ function config($translateProvider) {
|
|||
INPUT_HOURLY_LOW_LIMIT: '请输入每小时最小值',
|
||||
HOURLY_HIGH_LIMIT: '每小时最大值(包含)',
|
||||
INPUT_HOURLY_HIGH_LIMIT: '请输入每小时最大值',
|
||||
DESCRIPTION: '描述(可选)',
|
||||
DESCRIPTION: '描述',
|
||||
INPUT_DESCRIPTION: '请输入描述',
|
||||
MASTER_METER: '上级计量表',
|
||||
SELECT_MASTER_METER: '选择上级计量表',
|
||||
|
@ -1687,7 +1693,7 @@ function config($translateProvider) {
|
|||
ADD_SENSOR: '添加传感器',
|
||||
EDIT_SENSOR: '编辑传感器',
|
||||
DELETE_SENSOR: '删除传感器',
|
||||
DESCRIPTION: '描述(可选)',
|
||||
DESCRIPTION: '描述',
|
||||
INPUT_DESCRIPTION: '请输入描述',
|
||||
SELECT_SENSOR: '选择传感器',
|
||||
},
|
||||
|
@ -2180,7 +2186,7 @@ function config($translateProvider) {
|
|||
}
|
||||
},
|
||||
FDD: {
|
||||
ICH WÜRDE: 'ICH WÜRDE',
|
||||
ID: 'ID',
|
||||
RULE: 'Regel',
|
||||
EMAIL_MESSAGE: 'Mail-Informationen',
|
||||
TEXT_MESSAGE: 'SMS-Nachricht',
|
||||
|
@ -2197,9 +2203,11 @@ function config($translateProvider) {
|
|||
PRIORITY: 'Alarmpriorität',
|
||||
CHANNEL: 'Alarmkanal',
|
||||
IS_ENABLED: 'Alarmschalter',
|
||||
LAST_RUN_DATETIME: 'Letzter Lauf Datetime',
|
||||
NEXT_RUN_DATETIME: 'Nächster Lauf Datetime',
|
||||
EXPRESSION: 'Ausdruck',
|
||||
MESSAGE_TEMPLATE: 'Nachrichtenvorlage',
|
||||
DES_EXPRESSION: 'Klicken Sie auf \"Bearbeiten\',
|
||||
CLICK_EDIT_FOR_DETAILS: 'Klicken Sie auf "Bearbeiten"',
|
||||
|
||||
SMS_ALARM_LIST: 'SMS-Alarmliste',
|
||||
RECIPIENT_NAME: 'Empfänger',
|
||||
|
@ -2304,7 +2312,7 @@ function config($translateProvider) {
|
|||
},
|
||||
SETTING: {
|
||||
KNOWLEDGEFILE: 'Wissensdatei',
|
||||
ICH WÜRDE: 'ICH WÜRDE',
|
||||
ID: 'ID',
|
||||
ACTION: 'Betriebs',
|
||||
ADD: 'Hinzufügen',
|
||||
BIND_PROPERTY: 'Bindungseigenschaften',
|
||||
|
@ -2322,6 +2330,7 @@ function config($translateProvider) {
|
|||
ON: 'anmachen',
|
||||
OFF: 'Herunterfahren',
|
||||
OK: 'bestimmen',
|
||||
OPTIONAL: 'Optional',
|
||||
ADD_SPACE: 'Platz hinzufügen',
|
||||
ADD_TENANT: 'Mieter hinzufügen',
|
||||
ADD_STORE: 'Laden hinzufügen',
|
||||
|
@ -2491,7 +2500,7 @@ function config($translateProvider) {
|
|||
CONTACT: {
|
||||
EMAIL: 'Briefkasten',
|
||||
PHONE: 'Telefon',
|
||||
DESCRIPTION: 'Beschreibung (optional)',
|
||||
DESCRIPTION: 'Beschreibung',
|
||||
INPUT_EMAIL: 'Bitte geben Sie Ihre E-Mail-Adresse ein',
|
||||
INPUT_PHONE: 'Bitte geben Sie das Telefon ein',
|
||||
INPUT_DESCRIPTION: 'Bitte geben Sie eine Beschreibung ein',
|
||||
|
@ -2520,7 +2529,7 @@ function config($translateProvider) {
|
|||
RATIO: 'Skalierungsfaktor',
|
||||
IS_TREND: 'Trend speichern',
|
||||
ADDRESS: 'Adresse (JSON)',
|
||||
DESCRIPTION: 'Beschreibung (optional)',
|
||||
DESCRIPTION: 'Beschreibung',
|
||||
INPUT_HIGH_LIMIT: 'Bitte geben Sie das obere Limit ein',
|
||||
INPUT_LOW_LIMIT: 'Bitte geben Sie die Untergrenze ein',
|
||||
INPUT_RATIO: 'Bitte geben Sie den Skalierungsfaktor ein',
|
||||
|
@ -2535,13 +2544,13 @@ function config($translateProvider) {
|
|||
SELECT_DISTRIBUTION_SYSTEM: 'Bitte wählen Sie das Stromverteilungssystem',
|
||||
SVG: 'SVG',
|
||||
INPUT_SVG: 'Bitte geben Sie SVG ein',
|
||||
DESCRIPTION: 'Beschreibung (optional)',
|
||||
DESCRIPTION: 'Beschreibung',
|
||||
DISTRIBUTION_CIRCUIT: 'Verteilerkreis',
|
||||
N_S_DISTRIBUTION_CIRCUIT: 'Eigener Verteilerkreis',
|
||||
ADD_DISTRIBUTION_CIRCUIT: 'Verteilerkreis hinzufügen',
|
||||
EDIT_DISTRIBUTION_CIRCUIT: 'Stromverteilungskreis bearbeiten',
|
||||
SELECT_DISTRIBUTION_CIRCUIT: 'Bitte wählen Sie den Verteilerkreis',
|
||||
DISTRIBUTION_CIRCUIT_ICH WÜRDE: 'ICH WÜRDE',
|
||||
DISTRIBUTION_CIRCUIT_ID: 'ID',
|
||||
DISTRIBUTION_CIRCUIT_NAME: 'Name',
|
||||
INPUT_DISTRIBUTION_CIRCUIT_NAME: 'Bitte geben Sie einen Namen ein',
|
||||
DISTRIBUTION_CIRCUIT_DISTRIBUTION_ROOM: 'Stromverteilungsraum',
|
||||
|
@ -2587,7 +2596,7 @@ function config($translateProvider) {
|
|||
SELECT_COMBINED_EQUIPMENT: 'Bitte wählen Sie ein Kombinationsgerät',
|
||||
COST_CENTER: 'Kostenstelle',
|
||||
SELECT_COST_CENTER: 'Bitte wählen Sie eine Kostenstelle',
|
||||
DESCRIPTION: 'Beschreibung (optional)',
|
||||
DESCRIPTION: 'Beschreibung',
|
||||
BIND_EQUIPMENT: 'Gerät binden',
|
||||
N_S_EQUIPMENT: 'Gebundenes Gerät',
|
||||
EQUIPMENT_LIST: 'Geräteliste',
|
||||
|
@ -2599,7 +2608,7 @@ function config($translateProvider) {
|
|||
ADD_PARAMETER: 'Parameter hinzufügen',
|
||||
EDIT_PARAMETER: 'Parameter bearbeiten',
|
||||
N_S_PARAMETER: 'Enthaltene Parameter',
|
||||
PARAMETER_ICH WÜRDE: 'ICH WÜRDE',
|
||||
PARAMETER_ID: 'ID',
|
||||
PARAMETER_NAME: 'Name',
|
||||
INPUT_PARAMETER_NAME: 'Bitte geben Sie einen Namen ein',
|
||||
PARAMETER_TYPE: 'Arten von',
|
||||
|
@ -2620,7 +2629,7 @@ function config($translateProvider) {
|
|||
SELECT_EQUIPMENT: 'Bitte wählen Sie ein Gerät',
|
||||
COST_CENTER: 'Kostenstelle',
|
||||
SELECT_COST_CENTER: 'Bitte wählen Sie eine Kostenstelle',
|
||||
DESCRIPTION: 'Beschreibung (optional)',
|
||||
DESCRIPTION: 'Beschreibung',
|
||||
INPUT_METER: 'Bitte geben Sie die Tabelle ein',
|
||||
INPUT_DESCRIPTION: 'Bitte geben Sie eine Beschreibung ein',
|
||||
OUTPUT_METER: 'Ausgabetabelle',
|
||||
|
@ -2629,7 +2638,7 @@ function config($translateProvider) {
|
|||
ADD_PARAMETER: 'Parameter hinzufügen',
|
||||
EDIT_PARAMETER: 'Parameter bearbeiten',
|
||||
N_S_PARAMETER: 'Enthaltene Parameter',
|
||||
PARAMETER_ICH WÜRDE: 'ICH WÜRDE',
|
||||
PARAMETER_ID: 'ID',
|
||||
PARAMETER_NAME: 'Name',
|
||||
INPUT_PARAMETER_NAME: 'Bitte geben Sie einen Namen ein',
|
||||
PARAMETER_TYPE: 'Arten von',
|
||||
|
@ -2655,7 +2664,7 @@ function config($translateProvider) {
|
|||
PARENT_SPACE: 'Überlegen',
|
||||
AREA: 'Bereich',
|
||||
INPUT_AREA: 'Bitte betreten Sie den Bereich',
|
||||
DESCRIPTION: 'Beschreibung (optional)',
|
||||
DESCRIPTION: 'Beschreibung',
|
||||
INPUT_DESCRIPTION: 'Bitte geben Sie eine Beschreibung ein',
|
||||
CURRENT_SELECTED_SPACE: 'Derzeit ausgewählter Platz',
|
||||
CHILD_SPACES: 'Unterraum',
|
||||
|
@ -2688,7 +2697,7 @@ function config($translateProvider) {
|
|||
LEASE_START_DATETIME: 'Datum und Uhrzeit des Mietbeginns',
|
||||
LEASE_END_DATETIME: 'Datum und Uhrzeit des Leasingendes',
|
||||
IS_IN_LEASE: 'Mieten Sie?',
|
||||
DESCRIPTION: 'Beschreibung (optional)',
|
||||
DESCRIPTION: 'Beschreibun',
|
||||
INPUT_BUILDINGS: 'Bitte betreten Sie das Gebäude',
|
||||
INPUT_FLOORS: 'Bitte betreten Sie den Boden',
|
||||
INPUT_ROOMS: 'Bitte betreten Sie den Raum',
|
||||
|
@ -2700,7 +2709,7 @@ function config($translateProvider) {
|
|||
LATITUDE: 'Breite',
|
||||
LONGITUDE: 'Längengrad',
|
||||
TYPE: 'Speichertyp',
|
||||
DESCRIPTION: 'Beschreibung (optional)',
|
||||
DESCRIPTION: 'Beschreibung',
|
||||
INPUT_ADDRESS: 'Bitte geben Sie die Adresse ein',
|
||||
INPUT_LATITUDE: 'Bitte geben Sie den Breitengrad ein',
|
||||
INPUT_LONGITUDE: 'Bitte geben Sie den Längengrad ein',
|
||||
|
@ -2712,7 +2721,7 @@ function config($translateProvider) {
|
|||
SELECT_SHOPFLOOR: 'Bitte Workshop auswählen',
|
||||
AREA: 'Bereich',
|
||||
INPUT_AREA: 'Bitte betreten Sie den Bereich',
|
||||
DESCRIPTION: 'Beschreibung (optional)',
|
||||
DESCRIPTION: 'Beschreibung',
|
||||
INPUT_DESCRIPTION: 'Bitte geben Sie eine Beschreibung ein',
|
||||
BIND_EQUIPMENT: 'Gerät binden',
|
||||
N_S_EQUIPMENT: 'Gebundenes Gerät',
|
||||
|
@ -2723,7 +2732,7 @@ function config($translateProvider) {
|
|||
INPUT_HOURLY_LOW_LIMIT: 'Bitte geben Sie das stündliche Minimum ein',
|
||||
HOURLY_HIGH_LIMIT: 'Stundenmaximum (inklusive)',
|
||||
INPUT_HOURLY_HIGH_LIMIT: 'Bitte geben Sie das Stundenmaximum ein',
|
||||
DESCRIPTION: 'Beschreibung (optional)',
|
||||
DESCRIPTION: 'Beschreibung',
|
||||
INPUT_DESCRIPTION: 'Bitte geben Sie eine Beschreibung ein',
|
||||
MASTER_METER: 'Überlegenes Messgerät',
|
||||
SELECT_MASTER_METER: 'Wählen Sie das übergeordnete Messgerät aus',
|
||||
|
@ -2734,7 +2743,7 @@ function config($translateProvider) {
|
|||
ADD_SENSOR: 'Sensor hinzufügen',
|
||||
EDIT_SENSOR: 'Sensor bearbeiten',
|
||||
DELETE_SENSOR: 'Sensor entfernen',
|
||||
DESCRIPTION: 'Beschreibung (optional)',
|
||||
DESCRIPTION: 'Beschreibung',
|
||||
INPUT_DESCRIPTION: 'Bitte geben Sie eine Beschreibung ein',
|
||||
SELECT_SENSOR: 'Sensor auswählen',
|
||||
},
|
||||
|
@ -3075,7 +3084,7 @@ function config($translateProvider) {
|
|||
INVALID_MAINTENANCE_VALUE: 'Ungültiger Wartungswert',
|
||||
INVALID_MANUFACTURER_VALUE: 'Ungültiger Herstellerwert',
|
||||
INVALID_PERIOD: 'Ungültiger Zeitraum',
|
||||
INVALID_PERIOD_FORMAT: 'Ungültiges Zeitraumformat (erwartetes Format \\'年\',\'月\',\'天\'或\'小时\')',
|
||||
INVALID_PERIOD_FORMAT: 'Ungültiges Zeitraumformat (erwartetes Format \'year\', \'month\', \'day\' or \'hour\')',
|
||||
INVALID_PRIVILEGES_VALUE: 'Ungültiger Zeitraum',
|
||||
INVALID_PRODUCTID_ID: 'Ungültige Produkt-ID',
|
||||
INVALID_REPAIR_VALUE: 'Ungültiger Reparaturwert',
|
||||
|
@ -3154,4 +3163,4 @@ function config($translateProvider) {
|
|||
|
||||
angular
|
||||
.module('inspinia')
|
||||
.config(config)
|
||||
.config(config)
|
|
@ -1,5 +1,5 @@
|
|||
<div class="footer-login">
|
||||
<div>
|
||||
<strong>{{'MY_EMS_NAME' | translate}} v1.0.7 <a href="https://myems.io">https://myems.io</a> </strong>
|
||||
<strong>{{'MY_EMS_NAME' | translate}} v1.1.0 <a href="https://myems.io">https://myems.io</a> </strong>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -3,6 +3,6 @@
|
|||
<strong><a href="https://myems.io">https://myems.io</a></strong>
|
||||
</div>
|
||||
<div>
|
||||
<strong>{{'MY_EMS_NAME' | translate}} V1.0.7</strong>
|
||||
<strong>{{'MY_EMS_NAME' | translate}} v1.1.0</strong>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -11,11 +11,13 @@
|
|||
<tr>
|
||||
<th >{{'SETTING.ID' | translate}}</th>
|
||||
<th >{{'SETTING.NAME' | translate}}</th>
|
||||
<th >{{'FDD.FDD_CODE' | translate}}</th>
|
||||
<th >{{'FDD.CATEGORY' | translate}}</th>
|
||||
<th >{{'FDD.FDD_CODE' | translate}}</th>
|
||||
<th >{{'FDD.PRIORITY' | translate}}</th>
|
||||
<th >{{'FDD.CHANNEL' | translate}}</th>
|
||||
<th >{{'FDD.IS_ENABLED' | translate}}</th>
|
||||
<th >{{'FDD.LAST_RUN_DATETIME' | translate}}</th>
|
||||
<th >{{'FDD.NEXT_RUN_DATETIME' | translate}}</th>
|
||||
<th >{{'FDD.EXPRESSION' | translate}}</th>
|
||||
<th >{{'FDD.MESSAGE_TEMPLATE' | translate}}</th>
|
||||
<th >{{'SETTING.ACTION' | translate}}</th>
|
||||
|
@ -26,13 +28,15 @@
|
|||
<tr ng-repeat="rule in rules">
|
||||
<td >{{ rule.id }}</td>
|
||||
<td >{{ rule.name }}</td>
|
||||
<td >{{ rule.fdd_code }}</td>
|
||||
<td >{{ rule.category }}</td>
|
||||
<td >{{ rule.fdd_code }}</td>
|
||||
<td >{{ rule.priority }}</td>
|
||||
<td >{{ rule.channel }}</td>
|
||||
<td >{{ rule.is_enabled==true?'SETTING.ON':'SETTING.OFF' | translate}}</td>
|
||||
<td > {{'FDD.DES_EXPRESSION' | translate}} </td>
|
||||
<td class="col-lg-5 col-md-5">{{ rule.message_template }}</td>
|
||||
<td >{{ rule.last_run_datetime | date:'yyyy-MM-ddTHH:mm:ss'}}</td>
|
||||
<td >{{ rule.next_run_datetime | date:'yyyy-MM-ddTHH:mm:ss'}}</td>
|
||||
<td > {{'FDD.CLICK_EDIT_FOR_DETAILS' | translate}} </td>
|
||||
<td > {{'FDD.CLICK_EDIT_FOR_DETAILS' | translate}} </td>
|
||||
<td class="text-center">
|
||||
<a class="btn btn-primary btn-rounded btn-xs" ng-click="editRule(rule)" >{{'SETTING.EDIT' | translate}}</a>
|
||||
<a ng-click="deleteRule(rule)" class="btn btn-danger btn-rounded btn-xs" >{{'SETTING.DELETE' | translate}}</a>
|
||||
|
|
|
@ -6,42 +6,18 @@
|
|||
<form role="form" name="form_rule" novalidate class="form-horizontal">
|
||||
<div class="form-group"><label class="col-sm-2 control-label">{{'SETTING.NAME' | translate}}</label>
|
||||
|
||||
<div class="col-sm-10"><input ng-model="rule.name" type="text" name="rulename" class="form-control" required="">
|
||||
<div class="col-sm-5"><input ng-model="rule.name" type="text" name="rulename" class="form-control" required="">
|
||||
<div class="m-t-xs" ng-show="form_rule.rulename.$invalid && form_rule.rulename.$dirty">
|
||||
<small class="text-danger" ng-show="form_rule.rulename.$error.required">{{'SETTING.INPUT_NAME' | translate}}</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group"><label class="col-sm-2 control-label">{{'FDD.FDD_CODE' | translate}}</label>
|
||||
<div class="col-sm-10">
|
||||
<select name="fdd_code" ng-model="rule.fdd_code" class="form-control m-b">
|
||||
<option value="SYSTEM01">SYSTEM01</option>
|
||||
<option value="SYSTEM02">SYSTEM02</option>
|
||||
<option value="SPACE01">SPACE02</option>
|
||||
<option value="SPACE02">SPACE02</option>
|
||||
<option value="METER01">METER01</option>
|
||||
<option value="METER02">METER02</option>
|
||||
<option value="TENANT01">TENANT01</option>
|
||||
<option value="TENANT02">TENANT02</option>
|
||||
<option value="STORE01">STORE01</option>
|
||||
<option value="STORE02">STORE02</option>
|
||||
<option value="SHOPFLOOR01">SHOPFLOOR01</option>
|
||||
<option value="SHOPFLOOR02">SHOPFLOOR02</option>
|
||||
<option value="EQUIPMENT01">EQUIPMENT01</option>
|
||||
<option value="EQUIPMENT02">EQUIPMENT02</option>
|
||||
<option value="COMBINEDEQUIPMENT01">COMBINEDEQUIPMENT01</option>
|
||||
<option value="COMBINEDEQUIPMENT02">COMBINEDEQUIPMENT02</option>
|
||||
</select>
|
||||
<div class="m-t-xs" ng-show="form_rule.fdd_code.$invalid && form_rule.fdd_code.$dirty">
|
||||
<small class="text-danger" ng-show="form_rule.fdd_code.$error.required">-</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group"><label class="col-sm-2 control-label">{{'FDD.CATEGORY' | translate}}</label>
|
||||
<div class="col-sm-10">
|
||||
<div class="col-sm-5">
|
||||
<select name="category" ng-model="rule.category" class="form-control m-b">
|
||||
<option value="SYSTEM">SYSTEM</option>
|
||||
<option value="REALTIME">REALTIME</option>
|
||||
<option value="SPACE">SPACE</option>
|
||||
<option value="METER">METER</option>
|
||||
<option value="TENANT">TENANT</option>
|
||||
|
@ -55,8 +31,49 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group"><label class="col-sm-2 control-label">{{'FDD.FDD_CODE' | translate}}</label>
|
||||
<div class="col-sm-5">
|
||||
<select name="fdd_code" ng-model="rule.fdd_code" class="form-control m-b">
|
||||
<option value="SYSTEM01">SYSTEM01</option>
|
||||
<option value="SYSTEM02">SYSTEM02</option>
|
||||
<option value="REALTIME01">REALTIME01</option>
|
||||
<option value="REALTIME02">REALTIME02</option>
|
||||
<option value="SPACE01">SPACE01</option>
|
||||
<option value="SPACE02">SPACE02</option>
|
||||
<option value="SPACE03">SPACE03</option>
|
||||
<option value="SPACE04">SPACE04</option>
|
||||
<option value="METER01">METER01</option>
|
||||
<option value="METER02">METER02</option>
|
||||
<option value="METER03">METER03</option>
|
||||
<option value="METER04">METER04</option>
|
||||
<option value="TENANT01">TENANT01</option>
|
||||
<option value="TENANT02">TENANT02</option>
|
||||
<option value="TENANT03">TENANT03</option>
|
||||
<option value="TENANT04">TENANT04</option>
|
||||
<option value="STORE01">STORE01</option>
|
||||
<option value="STORE02">STORE02</option>
|
||||
<option value="STORE03">STORE03</option>
|
||||
<option value="STORE04">STORE04</option>
|
||||
<option value="SHOPFLOOR01">SHOPFLOOR01</option>
|
||||
<option value="SHOPFLOOR02">SHOPFLOOR02</option>
|
||||
<option value="SHOPFLOOR03">SHOPFLOOR03</option>
|
||||
<option value="SHOPFLOOR04">SHOPFLOOR04</option>
|
||||
<option value="EQUIPMENT01">EQUIPMENT01</option>
|
||||
<option value="EQUIPMENT02">EQUIPMENT02</option>
|
||||
<option value="EQUIPMENT03">EQUIPMENT03</option>
|
||||
<option value="EQUIPMENT04">EQUIPMENT04</option>
|
||||
<option value="COMBINEDEQUIPMENT01">COMBINEDEQUIPMENT01</option>
|
||||
<option value="COMBINEDEQUIPMENT02">COMBINEDEQUIPMENT02</option>
|
||||
<option value="COMBINEDEQUIPMENT03">COMBINEDEQUIPMENT03</option>
|
||||
<option value="COMBINEDEQUIPMENT04">COMBINEDEQUIPMENT04</option>
|
||||
</select>
|
||||
<div class="m-t-xs" ng-show="form_rule.fdd_code.$invalid && form_rule.fdd_code.$dirty">
|
||||
<small class="text-danger" ng-show="form_rule.fdd_code.$error.required">-</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group"><label class="col-sm-2 control-label">{{'FDD.PRIORITY' | translate}}</label>
|
||||
<div class="col-sm-10">
|
||||
<div class="col-sm-5">
|
||||
<select name="priority" ng-model="rule.priority" class="form-control m-b">
|
||||
<option value="CRITICAL">CRITICAL</option>
|
||||
<option value="HIGH">HIGH</option>
|
||||
|
@ -69,7 +86,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="form-group"><label class="col-sm-2 control-label">{{'FDD.CHANNEL' | translate}}</label>
|
||||
<div class="col-sm-10">
|
||||
<div class="col-sm-5">
|
||||
<select name="channel" ng-model="rule.channel" class="form-control m-b">
|
||||
<option value="WEB">WEB</option>
|
||||
<option value="SMS">SMS</option>
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
<div class="input-group m-x">
|
||||
<span class="input-group-addon"> {{'LANGUAGE' | translate}}</span>
|
||||
<select ng-change="changeLanguage(language)" ng-model="language" class="form-control" >
|
||||
<option value="de">Deutsch</option>
|
||||
<option value="en">English</option>
|
||||
<option value="cn">中 文</option>
|
||||
</select>
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
<th class="text-center">{{'SETTING.IS_INPUT_COUNTED' | translate}}</th>
|
||||
<th class="text-center">{{'SETTING.IS_OUTPUT_COUNTED' | translate}}</th>
|
||||
<th class="text-center">{{'COMBINED_EQUIPMENT.COST_CENTER' | translate}}</th>
|
||||
<th class="text-center">{{'COMBINED_EQUIPMENT.DESCRIPTION' | translate}}</th>
|
||||
<th class="text-center">{{'COMBINED_EQUIPMENT.DESCRIPTION' | translate}} ({{'SETTING.OPTIONAL' | translate}})</th>
|
||||
<th class="text-center">{{'SETTING.ACTION' | translate}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group"><label class="col-sm-4 control-label">{{'COMBINED_EQUIPMENT.DESCRIPTION' | translate}}</label>
|
||||
<div class="form-group"><label class="col-sm-4 control-label">{{'COMBINED_EQUIPMENT.DESCRIPTION' | translate}} ({{'SETTING.OPTIONAL' | translate}})</label>
|
||||
<div class="col-sm-8"><input ng-model="combinedequipment.description" type="text" name="combinedequipmentdescription" class="form-control" >
|
||||
<div class="m-t-xs" ng-show="form_combinedequipment.combinedequipmentdescription.$invalid && form_combinedequipment.combinedequipmentdescription.$dirty">
|
||||
<small class="text-danger" ng-show="form_combinedequipment.combinedequipmentdescription.$error.required">{{'COMBINED_EQUIPMENT.INPUT_DESCRIPTION' | translate}}</small>
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<th class="text-center">{{'SETTING.NAME' | translate}}</th>
|
||||
<th class="text-center">{{'CONTACT.EMAIL' | translate}}</th>
|
||||
<th class="text-center">{{'CONTACT.PHONE' | translate}}</th>
|
||||
<th class="text-center">{{'CONTACT.DESCRIPTION' | translate}}</th>
|
||||
<th class="text-center">{{'CONTACT.DESCRIPTION' | translate}} ({{'SETTING.OPTIONAL' | translate}})</th>
|
||||
<th class="text-center">{{'SETTING.ACTION' | translate}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group"><label class="col-sm-3 control-label">{{'CONTACT.DESCRIPTION' | translate}}</label>
|
||||
<div class="form-group"><label class="col-sm-3 control-label">{{'CONTACT.DESCRIPTION' | translate}} ({{'SETTING.OPTIONAL' | translate}})</label>
|
||||
|
||||
<div class="col-sm-9"><input ng-model="contact.description" type="text" name="contactdescription" class="form-control" >
|
||||
<div class="m-t-xs" ng-show="form_contact.description.$invalid && form_contact.description.$dirty">
|
||||
|
|
|
@ -71,7 +71,7 @@
|
|||
<th class="text-center">{{'POINT.RATIO' | translate}}</th>
|
||||
<th class="text-center">{{'POINT.IS_TREND' | translate}}</th>
|
||||
<th class="text-center">{{'POINT.ADDRESS' | translate}}</th>
|
||||
<th class="text-center">{{'POINT.DESCRIPTION' | translate}}</th>
|
||||
<th class="text-center">{{'POINT.DESCRIPTION' | translate}} ({{'SETTING.OPTIONAL' | translate}})</th>
|
||||
<th class="text-center">{{'SETTING.ACTION' | translate}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
|
@ -82,7 +82,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group"><label class="col-sm-4 control-label">{{'POINT.DESCRIPTION' | translate}}</label>
|
||||
<div class="form-group"><label class="col-sm-4 control-label">{{'POINT.DESCRIPTION' | translate}} ({{'SETTING.OPTIONAL' | translate}})</label>
|
||||
<div class="col-sm-8">
|
||||
<input ng-model="point.description" type="text" name="pointdescription" class="form-control">
|
||||
<div class="m-t-xs" ng-show="form_point.pointdescription.$invalid && form_point.pointdescription.$dirty">
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
<th class="text-center">{{'SETTING.ID' | translate}}</th>
|
||||
<th class="text-center">{{'SETTING.NAME' | translate}}</th>
|
||||
<th class="text-center">{{'DISTRIBUTION_SYSTEM.SVG' | translate}}</th>
|
||||
<th class="text-center">{{'DISTRIBUTION_SYSTEM.DESCRIPTION' | translate}}</th>
|
||||
<th class="text-center">{{'DISTRIBUTION_SYSTEM.DESCRIPTION' | translate}} ({{'SETTING.OPTIONAL' | translate}})</th>
|
||||
<th class="text-center">{{'SETTING.ACTION' | translate}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group"><label class="col-sm-2 control-label">{{'DISTRIBUTION_SYSTEM.DESCRIPTION' | translate}}</label>
|
||||
<div class="form-group"><label class="col-sm-2 control-label">{{'DISTRIBUTION_SYSTEM.DESCRIPTION' | translate}} ({{'SETTING.OPTIONAL' | translate}})</label>
|
||||
<div class="col-sm-10"><input ng-model="distributionsystem.description" type="text" name="distributionsystemdescription" class="form-control" >
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<th class="text-center">{{'SETTING.IS_INPUT_COUNTED' | translate}}</th>
|
||||
<th class="text-center">{{'SETTING.IS_OUTPUT_COUNTED' | translate}}</th>
|
||||
<th class="text-center">{{'EQUIPMENT.COST_CENTER' | translate}}</th>
|
||||
<th class="text-center">{{'EQUIPMENT.DESCRIPTION' | translate}}</th>
|
||||
<th class="text-center">{{'EQUIPMENT.DESCRIPTION' | translate}} ({{'SETTING.OPTIONAL' | translate}})</th>
|
||||
<th class="text-center">{{'SETTING.ACTION' | translate}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group"><label class="col-sm-4 control-label">{{'EQUIPMENT.DESCRIPTION' | translate}}</label>
|
||||
<div class="form-group"><label class="col-sm-4 control-label">{{'EQUIPMENT.DESCRIPTION' | translate}} ({{'SETTING.OPTIONAL' | translate}})</label>
|
||||
<div class="col-sm-8"><input ng-model="equipment.description" type="text" name="equipmentdescription" class="form-control" >
|
||||
<div class="m-t-xs" ng-show="form_equipment.equipmentdescription.$invalid && form_equipment.equipmentdescription.$dirty">
|
||||
<small class="text-danger" ng-show="form_equipment.equipmentdescription.$error.required">{{'EQUIPMENT.INPUT_DESCRIPTION' | translate}}</small>
|
||||
|
|
|
@ -15,13 +15,13 @@
|
|||
<th class="text-center">{{'SETTING.ID' | translate}}</th>
|
||||
<th class="text-center">{{'SETTING.NAME' | translate}}</th>
|
||||
<th class="text-center">{{'SETTING.CATEGORY' | translate}}</th>
|
||||
<th class="text-center">{{'SETTING.ENERGY_ITEM' | translate}}</th>
|
||||
<th class="text-center">{{'SETTING.ENERGY_ITEM' | translate}} ({{'SETTING.OPTIONAL' | translate}})</th>
|
||||
<th class="text-center">{{'SETTING.IS_INPUT_COUNTED' | translate}}</th>
|
||||
<th class="text-center">{{'METER.HOURLY_LOW_LIMIT' | translate}}</th>
|
||||
<th class="text-center">{{'METER.HOURLY_HIGH_LIMIT' | translate}}</th>
|
||||
<th class="text-center">{{'SETTING.COSTCENTER' | translate}}</th>
|
||||
<th class="text-center">{{'METER.MASTER_METER' | translate}}</th>
|
||||
<th class="text-center">{{'METER.DESCRIPTION' | translate}}</th>
|
||||
<th class="text-center">{{'METER.MASTER_METER' | translate}} ({{'SETTING.OPTIONAL' | translate}})</th>
|
||||
<th class="text-center">{{'METER.DESCRIPTION' | translate}} ({{'SETTING.OPTIONAL' | translate}})</th>
|
||||
<th class="text-center">{{'SETTING.ACTION' | translate}}</th>
|
||||
|
||||
</tr>
|
||||
|
@ -167,19 +167,13 @@
|
|||
<th class="text-center">{{'SETTING.ID' | translate}}</th>
|
||||
<th class="text-center">{{'SETTING.NAME' | translate}}</th>
|
||||
<th class="text-center">{{'SETTING.CATEGORY' | translate}}</th>
|
||||
<th class="text-center">{{'SETTING.ENERGY_ITEM' | translate}}
|
||||
</th>
|
||||
<th class="text-center">
|
||||
{{'SETTING.IS_INPUT_COUNTED' | translate}}</th>
|
||||
<th class="text-center">{{'METER.HOURLY_LOW_LIMIT' | translate}}
|
||||
</th>
|
||||
<th class="text-center">
|
||||
{{'METER.HOURLY_HIGH_LIMIT' | translate}}</th>
|
||||
<th class="text-center">{{'SETTING.COSTCENTER' | translate}}
|
||||
</th>
|
||||
<th class="text-center">{{'METER.MASTER_METER' | translate}}
|
||||
</th>
|
||||
<th class="text-center">{{'METER.DESCRIPTION' | translate}}</th>
|
||||
<th class="text-center">{{'SETTING.ENERGY_ITEM' | translate}} ({{'SETTING.OPTIONAL' | translate}})</th>
|
||||
<th class="text-center">{{'SETTING.IS_INPUT_COUNTED' | translate}}</th>
|
||||
<th class="text-center">{{'METER.HOURLY_LOW_LIMIT' | translate}}</th>
|
||||
<th class="text-center">{{'METER.HOURLY_HIGH_LIMIT' | translate}}</th>
|
||||
<th class="text-center">{{'SETTING.COSTCENTER' | translate}}</th>
|
||||
<th class="text-center">{{'METER.MASTER_METER' | translate}}</th>
|
||||
<th class="text-center">{{'METER.DESCRIPTION' | translate}} ({{'SETTING.OPTIONAL' | translate}})</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
@ -218,10 +212,10 @@
|
|||
<th class="text-center">{{'SETTING.ID' | translate}}</th>
|
||||
<th class="text-center">{{'SETTING.NAME' | translate}}</th>
|
||||
<th class="text-center">{{'SETTING.CATEGORY' | translate}}</th>
|
||||
<th class="text-center">{{'SETTING.ENERGY_ITEM' | translate}}</th>
|
||||
<th class="text-center">{{'SETTING.ENERGY_ITEM' | translate}} ({{'SETTING.OPTIONAL' | translate}})</th>
|
||||
<th class="text-center">{{'SETTING.IS_INPUT_COUNTED' | translate}}</th>
|
||||
<th class="text-center">{{'SETTING.COSTCENTER' | translate}}</th>
|
||||
<th class="text-center">{{'METER.DESCRIPTION' | translate}}</th>
|
||||
<th class="text-center">{{'METER.DESCRIPTION' | translate}} ({{'SETTING.OPTIONAL' | translate}})</th>
|
||||
<th class="text-center">{{'SETTING.ACTION' | translate}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
@ -259,12 +253,12 @@
|
|||
<th class="text-center">{{'SETTING.ID' | translate}}</th>
|
||||
<th class="text-center">{{'SETTING.NAME' | translate}}</th>
|
||||
<th class="text-center">{{'SETTING.CATEGORY' | translate}}</th>
|
||||
<th class="text-center">{{'SETTING.ENERGY_ITEM' | translate}}</th>
|
||||
<th class="text-center">{{'SETTING.ENERGY_ITEM' | translate}} ({{'SETTING.OPTIONAL' | translate}})</th>
|
||||
<th class="text-center">{{'SETTING.IS_INPUT_COUNTED' | translate}}</th>
|
||||
<th class="text-center">{{'METER.HOURLY_LOW_LIMIT' | translate}}</th>
|
||||
<th class="text-center">{{'METER.HOURLY_HIGH_LIMIT' | translate}}</th>
|
||||
<th class="text-center">{{'SETTING.COSTCENTER' | translate}}</th>
|
||||
<th class="text-center">{{'METER.DESCRIPTION' | translate}}</th>
|
||||
<th class="text-center">{{'METER.DESCRIPTION' | translate}} ({{'SETTING.OPTIONAL' | translate}})</th>
|
||||
<th class="text-center">{{'SETTING.ACTION' | translate}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group"><label class="col-sm-4 control-label">{{'SETTING.ENERGY_ITEM' | translate}}</label>
|
||||
<div class="form-group"><label class="col-sm-4 control-label">{{'SETTING.ENERGY_ITEM' | translate}} ({{'SETTING.OPTIONAL' | translate}})</label>
|
||||
<div class="col-sm-8">
|
||||
<ui-select ng-model="meter.energy_item.id" name="meter.energy_item_id" theme="bootstrap">
|
||||
<ui-select-match allow-clear="true" placeholder="{{'COMMON.PLACEHOLDER' | translate}}">{{$select.selected.name}}</ui-select-match>
|
||||
|
@ -79,7 +79,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group"><label class="col-sm-4 control-label">{{'METER.MASTER_METER' | translate}}</label>
|
||||
<div class="form-group"><label class="col-sm-4 control-label">{{'METER.MASTER_METER' | translate}} ({{'SETTING.OPTIONAL' | translate}})</label>
|
||||
<div class="col-sm-8">
|
||||
<ui-select ng-model="meter.master_meter.id" name="meter.master_meter_id" theme="bootstrap">
|
||||
<ui-select-match allow-clear="true" placeholder="{{'COMMON.PLACEHOLDER' | translate}}">{{$select.selected.name}}</ui-select-match>
|
||||
|
@ -93,7 +93,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group"><label class="col-sm-4 control-label">{{'METER.DESCRIPTION' | translate}}</label>
|
||||
<div class="form-group"><label class="col-sm-4 control-label">{{'METER.DESCRIPTION' | translate}} ({{'SETTING.OPTIONAL' | translate}})</label>
|
||||
<div class="col-sm-8">
|
||||
<input ng-model="meter.description" type="text" name="meterdescription" class="form-control" >
|
||||
<div class="m-t-xs" ng-show="form_meter.meterdescription.$invalid && form_meter.meterdescription.$dirty">
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group"><label class="col-sm-4 control-label">{{'SETTING.ENERGY_ITEM' | translate}}</label>
|
||||
<div class="form-group"><label class="col-sm-4 control-label">{{'SETTING.ENERGY_ITEM' | translate}} ({{'SETTING.OPTIONAL' | translate}})</label>
|
||||
<div class="col-sm-8">
|
||||
<ui-select ng-model="offlinemeter.energy_item.id" name="offlinemeter.energy_item_id" theme="bootstrap">
|
||||
<ui-select-match allow-clear="true" placeholder="{{'COMMON.PLACEHOLDER' | translate}}">{{$select.selected.name}}</ui-select-match>
|
||||
|
@ -81,7 +81,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group"><label class="col-sm-4 control-label">{{'METER.DESCRIPTION' | translate}}</label>
|
||||
<div class="form-group"><label class="col-sm-4 control-label">{{'METER.DESCRIPTION' | translate}} ({{'SETTING.OPTIONAL' | translate}})</label>
|
||||
<div class="col-sm-8">
|
||||
<input ng-model="offlinemeter.description" type="text" name="offlinemeterdescription" class="form-control" >
|
||||
<div class="m-t-xs" ng-show="form_offlinemeter.meterdescription.$invalid && form_offlinemeter.offlinemeterdescription.$dirty">
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group"><label class="col-sm-5 control-label">{{'SETTING.ENERGY_ITEM' | translate}}</label>
|
||||
<div class="form-group"><label class="col-sm-5 control-label">{{'SETTING.ENERGY_ITEM' | translate}} ({{'SETTING.OPTIONAL' | translate}})</label>
|
||||
<div class="col-sm-7">
|
||||
<ui-select ng-model="virtualmeter.energy_item.id" name="virtualmeter.energy_item_id" theme="bootstrap">
|
||||
<ui-select-match allow-clear="true" placeholder="{{'COMMON.PLACEHOLDER' | translate}}">{{$select.selected.name}}</ui-select-match>
|
||||
|
@ -76,7 +76,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group"><label class="col-sm-5 control-label">{{'METER.DESCRIPTION' | translate}}</label>
|
||||
<div class="form-group"><label class="col-sm-5 control-label">{{'METER.DESCRIPTION' | translate}} ({{'SETTING.OPTIONAL' | translate}})</label>
|
||||
<div class="col-sm-7">
|
||||
<input ng-model="virtualmeter.description" type="text" name="virtualmeterdescription" class="form-control" >
|
||||
<div class="m-t-xs" ng-show="form_virtualmeter.meterdescription.$invalid && form_virtualmeter.virtualmeterdescription.$dirty">
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
<tr>
|
||||
<th class="text-center">{{'SETTING.ID' | translate}}</th>
|
||||
<th class="text-center">{{'SETTING.NAME' | translate}}</th>
|
||||
<th class="text-center">{{'SENSOR.DESCRIPTION' | translate}}</th>
|
||||
<th class="text-center">{{'SENSOR.DESCRIPTION' | translate}} ({{'SETTING.OPTIONAL' | translate}})</th>
|
||||
<th class="text-center">{{'SETTING.ACTION' | translate}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group"><label class="col-sm-4 control-label">{{'SENSOR.DESCRIPTION' | translate}}</label>
|
||||
<div class="form-group"><label class="col-sm-4 control-label">{{'SENSOR.DESCRIPTION' | translate}} ({{'SETTING.OPTIONAL' | translate}})</label>
|
||||
<div class="col-sm-8">
|
||||
<input ng-model="sensor.description" type="text" name="sensordescription" class="form-control" >
|
||||
<div class="m-t-xs" ng-show="form_sensor.sensordescription.$invalid && form_sensor.sensordescription.$dirty">
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
<th class="text-center">{{'SETTING.CONTACT' | translate}}</th>
|
||||
<th class="text-center">{{'SETTING.IS_INPUT_COUNTED' | translate}}</th>
|
||||
<th class="text-center">{{'SETTING.COSTCENTER' | translate}}</th>
|
||||
<th class="text-center">{{'SHOPFLOOR.DESCRIPTION' | translate}}</th>
|
||||
<th class="text-center">{{'SHOPFLOOR.DESCRIPTION' | translate}} ({{'SETTING.OPTIONAL' | translate}})</th>
|
||||
<th class="text-center">{{'SETTING.ACTION' | translate}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
</ui-select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group"><label class="col-sm-2 control-label">{{'SHOPFLOOR.DESCRIPTION' | translate}}</label>
|
||||
<div class="form-group"><label class="col-sm-2 control-label">{{'SHOPFLOOR.DESCRIPTION' | translate}} ({{'SETTING.OPTIONAL' | translate}})</label>
|
||||
<div class="col-sm-10">
|
||||
<input ng-model="shopfloor.description" type="text" name="shopfloordescription" class="form-control">
|
||||
<div class="m-t-xs" ng-show="form_shopfloor.shopfloordescription.$invalid && form_shopfloor.shopfloordescription.$dirty">
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
{{'SETTING.IS_OUTPUT_COUNTED' | translate}}</th>
|
||||
<th class="text-center">{{'SETTING.COSTCENTER' | translate}}
|
||||
</th>
|
||||
<th class="text-center">{{'SPACE.DESCRIPTION' | translate}}</th>
|
||||
<th class="text-center">{{'SPACE.DESCRIPTION' | translate}} ({{'SETTING.OPTIONAL' | translate}})</th>
|
||||
<th class="text-center">{{'SETTING.ACTION' | translate}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
@ -94,7 +94,7 @@
|
|||
{{'SETTING.IS_OUTPUT_COUNTED' | translate}}</th>
|
||||
<th class="text-center">{{'SETTING.COSTCENTER' | translate}}
|
||||
</th>
|
||||
<th class="text-center">{{'SPACE.DESCRIPTION' | translate}}</th>
|
||||
<th class="text-center">{{'SPACE.DESCRIPTION' | translate}} ({{'SETTING.OPTIONAL' | translate}})</th>
|
||||
<th class="text-center">{{'SETTING.ACTION' | translate}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
|
@ -28,10 +28,10 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group"><label class="col-sm-4 control-label">{{'SETTING.CONTACT' | translate}}</label>
|
||||
<div class="form-group"><label class="col-sm-4 control-label">{{'SETTING.CONTACT' | translate}} ({{'SETTING.OPTIONAL' | translate}})</label>
|
||||
<div class="col-sm-8">
|
||||
<ui-select ng-model="space.contact.id" name="spacecontact" theme="bootstrap">
|
||||
<ui-select-match allow-clear="false" placeholder="{{'COMMON.PLACEHOLDER' | translate}}">
|
||||
<ui-select-match allow-clear="true" placeholder="{{'COMMON.PLACEHOLDER' | translate}}">
|
||||
{{$select.selected.name}}</ui-select-match>
|
||||
<ui-select-choices repeat="contact.id as contact in contacts | filter: $select.search">
|
||||
<div ng-bind-html="contact.name | highlight: $select.search"></div>
|
||||
|
@ -101,7 +101,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group"><label class="col-sm-4 control-label">{{'SPACE.DESCRIPTION' | translate}}</label>
|
||||
<div class="form-group"><label class="col-sm-4 control-label">{{'SPACE.DESCRIPTION' | translate}} ({{'SETTING.OPTIONAL' | translate}})</label>
|
||||
<div class="col-sm-8">
|
||||
<input ng-model="space.description" type="text" name="spacedescription" class="form-control">
|
||||
<div class="m-t-xs"
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
<th class="text-center">{{'SETTING.CONTACT' | translate}}</th>
|
||||
<th class="text-center">{{'SETTING.IS_INPUT_COUNTED' | translate}}</th>
|
||||
<th class="text-center">{{'SETTING.COSTCENTER' | translate}}</th>
|
||||
<th class="text-center">{{'STORE.DESCRIPTION' | translate}}</th>
|
||||
<th class="text-center">{{'STORE.DESCRIPTION' | translate}} ({{'SETTING.OPTIONAL' | translate}})</th>
|
||||
<th class="text-center">{{'SETTING.ACTION' | translate}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
|
@ -90,7 +90,7 @@
|
|||
</ui-select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group"><label class="col-sm-2 control-label">{{'STORE.DESCRIPTION' | translate}}</label>
|
||||
<div class="form-group"><label class="col-sm-2 control-label">{{'STORE.DESCRIPTION' | translate}} ({{'SETTING.OPTIONAL' | translate}})</label>
|
||||
<div class="col-sm-10">
|
||||
<input ng-model="store.description" type="text" name="storedescription" class="form-control">
|
||||
<div class="m-t-xs" ng-show="form_store.storedescription.$invalid && form_store.storedescription.$dirty">
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
<th class="text-center">{{'TENANT.LEASE_END_DATETIME' | translate}}</th>
|
||||
<th class="text-center">{{'TENANT.IS_IN_LEASE' | translate}}</th>
|
||||
<th class="text-center">{{'SETTING.COSTCENTER' | translate}}</th>
|
||||
<th class="text-center">{{'TENANT.DESCRIPTION' | translate}}</th>
|
||||
<th class="text-center">{{'TENANT.DESCRIPTION' | translate}} ({{'SETTING.OPTIONAL' | translate}})</th>
|
||||
<th class="text-center">{{'SETTING.ACTION' | translate}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
|
@ -124,7 +124,7 @@
|
|||
</ui-select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group"><label class="col-sm-2 control-label">{{'TENANT.DESCRIPTION' | translate}}</label>
|
||||
<div class="form-group"><label class="col-sm-2 control-label">{{'TENANT.DESCRIPTION' | translate}} ({{'SETTING.OPTIONAL' | translate}})</label>
|
||||
<div class="col-sm-10">
|
||||
<input ng-model="tenant.description" type="text" name="tenantdescription" class="form-control">
|
||||
<div class="m-t-xs" ng-show="form_tenant.tenantdescription.$invalid && form_tenant.tenantdescription.$dirty">
|
||||
|
|
|
@ -72,13 +72,15 @@ CREATE TABLE IF NOT EXISTS `myems_fdd_db`.`tbl_rules` (
|
|||
`id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`name` VARCHAR(128) NOT NULL,
|
||||
`uuid` CHAR(36) NOT NULL,
|
||||
`fdd_code` VARCHAR(128) NOT NULL COMMENT 'SYSTEM01, SYSTEM02, ... SPACE01, SPACE02, ... METER01, METER02, ...',
|
||||
`category` VARCHAR(128) NOT NULL COMMENT 'SYSTEM, SPACE, METER, TENANT, STORE, SHOPFLOOR, EQUIPMENT, COMBINEDEQUIPMENT',
|
||||
`category` VARCHAR(128) NOT NULL COMMENT 'REALTIME, SYSTEM, SPACE, METER, TENANT, STORE, SHOPFLOOR, EQUIPMENT, COMBINEDEQUIPMENT',
|
||||
`fdd_code` VARCHAR(128) NOT NULL COMMENT 'REALTIME01, REALTIME01... SYSTEM01, SYSTEM02, ... SPACE01, SPACE02, ... METER01, METER02, ...',
|
||||
`priority` VARCHAR(128) NOT NULL COMMENT 'CRITICAL, HIGH, MEDIUM, LOW',
|
||||
`channel` VARCHAR(128) NOT NULL COMMENT 'WEB, EMAIL, SMS, WECHAT, CALL',
|
||||
`expression` JSON NOT NULL COMMENT 'JSON string of diagnosed objects, points, values, and recipients',
|
||||
`message_template` TEXT NOT NULL COMMENT 'Plain text template that supports $-substitutions',
|
||||
`is_enabled` BOOL NOT NULL,
|
||||
`last_run_datetime_utc` DATETIME,
|
||||
`next_run_datetime_utc` DATETIME,
|
||||
PRIMARY KEY (`id`));
|
||||
CREATE INDEX `tbl_rules_index_1` ON `myems_fdd_db`.`tbl_rules` (`name`);
|
||||
|
||||
|
|
|
@ -792,7 +792,7 @@ CREATE INDEX `tbl_meters_index_3` ON `myems_system_db`.`tbl_meters` (`energy_
|
|||
-- USE `myems_system_db`;
|
||||
|
||||
-- INSERT INTO `myems_system_db`.`tbl_meters`
|
||||
-- (`id`, `name`, `uuid`, `energy_category_id`, `is_counted`, `max_hourly_value`, `cost_center_id`, `energy_item_id`, `master_meter_id`, `description`)
|
||||
-- (`id`, `name`, `uuid`, `energy_category_id`, `is_counted`, `hourly_low_limit`, `hourly_high_limit`, `cost_center_id`, `energy_item_id`, `master_meter_id`, `description`)
|
||||
-- VALUES
|
||||
-- (1, '示例表1', '5ca47bc5-22c2-47fc-b906-33222191ea40', 1, true, 0.000, 999.999, 1, 1, null, 'meter1'),
|
||||
-- (2, '示例表2', '5ca47bc5-22c2-47fc-b906-33222191ea40', 1, true, 0.000, 999.999, 1, 1, 1, 'meter2'),
|
||||
|
@ -1686,7 +1686,7 @@ USE `myems_system_db`;
|
|||
INSERT INTO `myems_system_db`.`tbl_stores`
|
||||
(`id`, `name`, `uuid`, `address`, `latitude`, `longitude`, `area`, `store_type_id`, `is_input_counted`, `contact_id`, `cost_center_id`, `description`)
|
||||
VALUES
|
||||
(1, '麦当劳(祈年大街得来速店)', 'd8a24322-4bab-4ba2-aedc-5d55a84c3db8', '北京市东城区东打磨厂街7号', 39.899493, 116.412041, 500.000, 1, true, 1, 1, 'MacDonald\'s');
|
||||
(1, '麦当劳(祈年大街得来速店)', 'd8a24322-4bab-4ba2-aedc-5d55a84c3db8', '北京市东城区东打磨厂街7号', 39.899493, 116.412041, 500.000, 1, true, 1, 1, 'MacDonalds');
|
||||
COMMIT;
|
||||
|
||||
-- ---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -2249,6 +2249,6 @@ USE `myems_system_db`;
|
|||
INSERT INTO `myems_system_db`.`tbl_versions`
|
||||
(`id`, `version`, `release_date`)
|
||||
VALUES
|
||||
(1, '1.0.5', '2021-02-23');
|
||||
(1, '1.1.0', '2021-03-18');
|
||||
|
||||
COMMIT;
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
|
||||
-- UPDATE VERSION NUMBER
|
||||
UPDATE myems_system_db.tbl_versions SET version='1.0.8', release_date='2021-03-11' WHERE id=1;
|
|
@ -0,0 +1,3 @@
|
|||
|
||||
-- UPDATE VERSION NUMBER
|
||||
UPDATE myems_system_db.tbl_versions SET version='1.1.0', release_date='2021-03-18' WHERE id=1;
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
-- UPDATE VERSION NUMBER
|
||||
UPDATE myems_system_db.tbl_versions SET version='1.1.1', release_date='2021-03-22' WHERE id=1;
|
||||
|
||||
ALTER TABLE myems_fdd_db.tbl_rules ADD last_run_datetime_utc DATETIME NULL;
|
||||
ALTER TABLE myems_fdd_db.tbl_rules ADD next_run_datetime_utc DATETIME NULL;
|
Binary file not shown.
After Width: | Height: | Size: 2.1 MiB |
Binary file not shown.
After Width: | Height: | Size: 345 KiB |
Binary file not shown.
After Width: | Height: | Size: 4.0 MiB |
Binary file not shown.
After Width: | Height: | Size: 1.3 MiB |
Binary file not shown.
Before Width: | Height: | Size: 616 KiB |
|
@ -207,13 +207,12 @@ def worker(combined_equipment):
|
|||
|
||||
except Exception as e:
|
||||
error_string = "Error in step 3.1 of combined_equipment_energy_input_category.worker " + str(e)
|
||||
print(error_string)
|
||||
return error_string
|
||||
finally:
|
||||
if cursor_system_db:
|
||||
cursor_system_db.close()
|
||||
if cnx_system_db:
|
||||
cnx_system_db.close()
|
||||
print(error_string)
|
||||
return error_string
|
||||
|
||||
####################################################################################################################
|
||||
# Step 4: get all equipments associated with the combined equipment
|
||||
|
|
|
@ -210,13 +210,12 @@ def worker(combined_equipment):
|
|||
|
||||
except Exception as e:
|
||||
error_string = "Error in step 3.1 of combined_equipment_energy_input_item.worker " + str(e)
|
||||
print(error_string)
|
||||
return error_string
|
||||
finally:
|
||||
if cursor_system_db:
|
||||
cursor_system_db.close()
|
||||
if cnx_system_db:
|
||||
cnx_system_db.close()
|
||||
print(error_string)
|
||||
return error_string
|
||||
|
||||
####################################################################################################################
|
||||
# Step 4: get all equipments associated with the combined equipment
|
||||
|
@ -412,7 +411,7 @@ def worker(combined_equipment):
|
|||
try:
|
||||
for equipment in equipment_list:
|
||||
equipment_id = str(equipment['id'])
|
||||
query = (" SELECT start_datetime_utc, energy_category_id, actual_value "
|
||||
query = (" SELECT start_datetime_utc, energy_item_id, actual_value "
|
||||
" FROM tbl_equipment_input_item_hourly "
|
||||
" WHERE equipment_id = %s "
|
||||
" AND start_datetime_utc >= %s "
|
||||
|
@ -428,9 +427,9 @@ def worker(combined_equipment):
|
|||
current_datetime_utc = row_value[0]
|
||||
if current_datetime_utc not in energy_equipment_hourly[equipment_id]:
|
||||
energy_equipment_hourly[equipment_id][current_datetime_utc] = dict()
|
||||
energy_category_id = row_value[1]
|
||||
energy_item_id = row_value[1]
|
||||
actual_value = row_value[2]
|
||||
energy_equipment_hourly[equipment_id][current_datetime_utc][energy_category_id] = \
|
||||
energy_equipment_hourly[equipment_id][current_datetime_utc][energy_item_id] = \
|
||||
actual_value
|
||||
except Exception as e:
|
||||
error_string = "Error in step 9 of combined_equipment_energy_input_item.worker " + str(e)
|
||||
|
@ -564,9 +563,9 @@ def worker(combined_equipment):
|
|||
equipment_id = str(equipment['id'])
|
||||
meta_data_dict = energy_equipment_hourly[equipment_id].get(current_datetime_utc, None)
|
||||
if meta_data_dict is not None and len(meta_data_dict) > 0:
|
||||
for energy_category_id, actual_value in meta_data_dict.items():
|
||||
aggregated_value['meta_data'][energy_category_id] = \
|
||||
aggregated_value['meta_data'].get(energy_category_id, Decimal(0.0)) + actual_value
|
||||
for energy_item_id, actual_value in meta_data_dict.items():
|
||||
aggregated_value['meta_data'][energy_item_id] = \
|
||||
aggregated_value['meta_data'].get(energy_item_id, Decimal(0.0)) + actual_value
|
||||
|
||||
aggregated_values.append(aggregated_value)
|
||||
|
||||
|
|
|
@ -207,13 +207,12 @@ def worker(combined_equipment):
|
|||
|
||||
except Exception as e:
|
||||
error_string = "Error in step 3.1 of combined_equipment_energy_output_category.worker " + str(e)
|
||||
print(error_string)
|
||||
return error_string
|
||||
finally:
|
||||
if cursor_system_db:
|
||||
cursor_system_db.close()
|
||||
if cnx_system_db:
|
||||
cnx_system_db.close()
|
||||
print(error_string)
|
||||
return error_string
|
||||
|
||||
####################################################################################################################
|
||||
# Step 4: get all equipments associated with the combined equipment
|
||||
|
|
|
@ -1164,13 +1164,16 @@ Result in JSON
|
|||
| id | integer | Rule ID |
|
||||
| name | string | Rule Name |
|
||||
| uuid | string | Rule UUID |
|
||||
| fdd_code | string | SYSTEM01, SYSTEM02, ... SPACE01, SPACE02, ... METER01, METER02, ... |
|
||||
| category | string | SYSTEM, SPACE, METER, TENANT, STORE, SHOPFLOOR, EQUIPMENT, COMBINEDEQUIPMENT |
|
||||
| fdd_code | string | SYSTEM01, SYSTEM02, ..., REALTIME01, REALTIME02, ..., SPACE01, SPACE02, ... METER01, METER02, ... |
|
||||
| category | string | SYSTEM, REALTIME, SPACE, METER, TENANT, STORE, SHOPFLOOR, EQUIPMENT, COMBINEDEQUIPMENT |
|
||||
| priority | string | CRITICAL, HIGH, MEDIUM, LOW |
|
||||
| channel | string | WEB, EMAIL, SMS, WECHAT, CALL |
|
||||
| expression | string | JSON string of diagnosed objects, points, values, and recipients |
|
||||
| message_template | string | Plain text template that supports $-substitutions |
|
||||
| is_enabled | boolean | Indicates if this rule is enabled |
|
||||
| last_run_datetime | float | null, or the number of milliseconds since January 1, 1970, 00:00:00, universal time |
|
||||
| next_run_datetime | float | null, or the number of milliseconds since January 1, 1970, 00:00:00, universal time |
|
||||
|
||||
|
||||
```bash
|
||||
$ curl -i -X GET {{base_url}}/rules/{id}
|
||||
|
|
|
@ -208,8 +208,8 @@ class OfflineMeterFileItem:
|
|||
# remove the file from disk
|
||||
os.remove(file_path)
|
||||
except Exception as ex:
|
||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.ERROR',
|
||||
description='API.OFFLINE_METER_FILE_NOT_FOUND')
|
||||
# ignore exception and don't return API.OFFLINE_METER_FILE_NOT_FOUND error
|
||||
pass
|
||||
|
||||
# Note: the energy data imported from the deleted file will not be deleted
|
||||
cursor.execute(" DELETE FROM tbl_offline_meter_files WHERE id = %s ", (id_,))
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import falcon
|
||||
import json
|
||||
import mysql.connector
|
||||
import config
|
||||
import uuid
|
||||
from datetime import datetime, timezone, timedelta
|
||||
import config
|
||||
|
||||
|
||||
class RuleCollection:
|
||||
|
@ -20,9 +21,9 @@ class RuleCollection:
|
|||
cursor = cnx.cursor(dictionary=True)
|
||||
|
||||
query = (" SELECT id, name, uuid, "
|
||||
" fdd_code, category, priority, "
|
||||
" category, fdd_code, priority, "
|
||||
" channel, expression, message_template, "
|
||||
" is_enabled "
|
||||
" is_enabled, last_run_datetime_utc, next_run_datetime_utc "
|
||||
" FROM tbl_rules "
|
||||
" ORDER BY id ")
|
||||
cursor.execute(query)
|
||||
|
@ -33,11 +34,22 @@ class RuleCollection:
|
|||
result = list()
|
||||
if rows is not None and len(rows) > 0:
|
||||
for row in rows:
|
||||
last_run_datetime = None
|
||||
if row['last_run_datetime_utc'] is not None:
|
||||
last_run_datetime = row['last_run_datetime_utc'].replace(tzinfo=timezone.utc).timestamp() * 1000
|
||||
|
||||
next_run_datetime = None
|
||||
if row['next_run_datetime_utc'] is not None:
|
||||
next_run_datetime = row['next_run_datetime_utc'].replace(tzinfo=timezone.utc).timestamp() * 1000
|
||||
|
||||
meta_result = {"id": row['id'], "name": row['name'], "uuid": row['uuid'],
|
||||
"fdd_code": row['fdd_code'], "category": row['category'], "priority": row['priority'],
|
||||
"category": row['category'], "fdd_code": row['fdd_code'], "priority": row['priority'],
|
||||
"channel": row['channel'], "expression": row['expression'],
|
||||
"message_template": row['message_template'].replace("<br>", ""),
|
||||
"is_enabled": bool(row['is_enabled'])}
|
||||
"is_enabled": bool(row['is_enabled']),
|
||||
"last_run_datetime": last_run_datetime,
|
||||
"next_run_datetime": next_run_datetime,
|
||||
}
|
||||
result.append(meta_result)
|
||||
|
||||
resp.body = json.dumps(result)
|
||||
|
@ -58,6 +70,17 @@ class RuleCollection:
|
|||
description='API.INVALID_RULE_NAME')
|
||||
name = str.strip(new_values['data']['name'])
|
||||
|
||||
if 'category' not in new_values['data'].keys() or \
|
||||
not isinstance(new_values['data']['category'], str) or \
|
||||
len(str.strip(new_values['data']['category'])) == 0 or \
|
||||
str.strip(new_values['data']['category']) not in \
|
||||
('SYSTEM', 'REALTIME', 'SPACE', 'METER', 'TENANT', 'STORE', 'SHOPFLOOR', 'EQUIPMENT',
|
||||
'COMBINEDEQUIPMENT'):
|
||||
raise falcon.HTTPError(falcon.HTTP_400,
|
||||
title='API.BAD_REQUEST',
|
||||
description='API.INVALID_CATEGORY')
|
||||
category = str.strip(new_values['data']['category'])
|
||||
|
||||
if 'fdd_code' not in new_values['data'].keys() or \
|
||||
not isinstance(new_values['data']['fdd_code'], str) or \
|
||||
len(str.strip(new_values['data']['fdd_code'])) == 0:
|
||||
|
@ -66,16 +89,6 @@ class RuleCollection:
|
|||
description='API.INVALID_FDD_CODE')
|
||||
fdd_code = str.strip(new_values['data']['fdd_code'])
|
||||
|
||||
if 'category' not in new_values['data'].keys() or \
|
||||
not isinstance(new_values['data']['category'], str) or \
|
||||
len(str.strip(new_values['data']['category'])) == 0 or \
|
||||
str.strip(new_values['data']['category']) not in \
|
||||
('SYSTEM', 'SPACE', 'METER', 'TENANT', 'STORE', 'SHOPFLOOR', 'EQUIPMENT', 'COMBINEDEQUIPMENT'):
|
||||
raise falcon.HTTPError(falcon.HTTP_400,
|
||||
title='API.BAD_REQUEST',
|
||||
description='API.INVALID_CATEGORY')
|
||||
category = str.strip(new_values['data']['category'])
|
||||
|
||||
if 'priority' not in new_values['data'].keys() or \
|
||||
not isinstance(new_values['data']['priority'], str) or \
|
||||
len(str.strip(new_values['data']['priority'])) == 0 or \
|
||||
|
@ -130,13 +143,13 @@ class RuleCollection:
|
|||
description='API.RULE_NAME_IS_ALREADY_IN_USE')
|
||||
|
||||
add_row = (" INSERT INTO tbl_rules "
|
||||
" (name, uuid, fdd_code, category, priority, "
|
||||
" (name, uuid, category, fdd_code, priority, "
|
||||
" channel, expression, message_template, is_enabled) "
|
||||
" VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s) ")
|
||||
cursor.execute(add_row, (name,
|
||||
str(uuid.uuid4()),
|
||||
fdd_code,
|
||||
category,
|
||||
fdd_code,
|
||||
priority,
|
||||
channel,
|
||||
expression,
|
||||
|
@ -170,8 +183,9 @@ class RuleItem:
|
|||
cursor = cnx.cursor(dictionary=True)
|
||||
|
||||
query = (" SELECT id, name, uuid, "
|
||||
" fdd_code, category, priority, "
|
||||
" channel, expression, message_template, is_enabled "
|
||||
" category, fdd_code, priority, "
|
||||
" channel, expression, message_template, "
|
||||
" is_enabled, last_run_datetime_utc, next_run_datetime_utc "
|
||||
" FROM tbl_rules "
|
||||
" WHERE id = %s ")
|
||||
cursor.execute(query, (id_,))
|
||||
|
@ -181,12 +195,22 @@ class RuleItem:
|
|||
if row is None:
|
||||
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND',
|
||||
description='API.RULE_NOT_FOUND')
|
||||
last_run_datetime = None
|
||||
if row['last_run_datetime_utc'] is not None:
|
||||
last_run_datetime = row['last_run_datetime_utc'].replace(tzinfo=timezone.utc).timestamp() * 1000
|
||||
|
||||
next_run_datetime = None
|
||||
if row['next_run_datetime_utc'] is not None:
|
||||
next_run_datetime = row['next_run_datetime_utc'].replace(tzinfo=timezone.utc).timestamp() * 1000
|
||||
|
||||
result = {"id": row['id'], "name": row['name'], "uuid": row['uuid'],
|
||||
"fdd_code": row['fdd_code'], "category": row['category'], "priority": row['priority'],
|
||||
"category": row['category'], "fdd_code": row['fdd_code'], "priority": row['priority'],
|
||||
"channel": row['channel'], "expression": row['expression'],
|
||||
"message_template": row['message_template'].replace("<br>", ""),
|
||||
"is_enabled": bool(row['is_enabled'])}
|
||||
"is_enabled": bool(row['is_enabled']),
|
||||
"last_run_datetime": last_run_datetime,
|
||||
"next_run_datetime": next_run_datetime,
|
||||
}
|
||||
resp.body = json.dumps(result)
|
||||
|
||||
@staticmethod
|
||||
|
@ -236,6 +260,17 @@ class RuleItem:
|
|||
description='API.INVALID_RULE_NAME')
|
||||
name = str.strip(new_values['data']['name'])
|
||||
|
||||
if 'category' not in new_values['data'].keys() or \
|
||||
not isinstance(new_values['data']['category'], str) or \
|
||||
len(str.strip(new_values['data']['category'])) == 0 or \
|
||||
str.strip(new_values['data']['category']) not in \
|
||||
('SYSTEM', 'REALTIME', 'SPACE', 'METER', 'TENANT', 'STORE', 'SHOPFLOOR', 'EQUIPMENT',
|
||||
'COMBINEDEQUIPMENT'):
|
||||
raise falcon.HTTPError(falcon.HTTP_400,
|
||||
title='API.BAD_REQUEST',
|
||||
description='API.INVALID_CATEGORY')
|
||||
category = str.strip(new_values['data']['category'])
|
||||
|
||||
if 'fdd_code' not in new_values['data'].keys() or \
|
||||
not isinstance(new_values['data']['fdd_code'], str) or \
|
||||
len(str.strip(new_values['data']['fdd_code'])) == 0:
|
||||
|
@ -244,16 +279,6 @@ class RuleItem:
|
|||
description='API.INVALID_FDD_CODE')
|
||||
fdd_code = str.strip(new_values['data']['fdd_code'])
|
||||
|
||||
if 'category' not in new_values['data'].keys() or \
|
||||
not isinstance(new_values['data']['category'], str) or \
|
||||
len(str.strip(new_values['data']['category'])) == 0 or \
|
||||
str.strip(new_values['data']['category']) not in \
|
||||
('SYSTEM', 'SPACE', 'METER', 'TENANT', 'STORE', 'SHOPFLOOR', 'EQUIPMENT', 'COMBINEDEQUIPMENT'):
|
||||
raise falcon.HTTPError(falcon.HTTP_400,
|
||||
title='API.BAD_REQUEST',
|
||||
description='API.INVALID_CATEGORY')
|
||||
category = str.strip(new_values['data']['category'])
|
||||
|
||||
if 'priority' not in new_values['data'].keys() or \
|
||||
not isinstance(new_values['data']['priority'], str) or \
|
||||
len(str.strip(new_values['data']['priority'])) == 0 or \
|
||||
|
@ -317,13 +342,13 @@ class RuleItem:
|
|||
description='API.RULE_NAME_IS_ALREADY_IN_USE')
|
||||
|
||||
update_row = (" UPDATE tbl_rules "
|
||||
" SET name = %s, fdd_code = %s, category = %s, priority = %s, "
|
||||
" SET name = %s, category = %s, fdd_code = %s, priority = %s, "
|
||||
" channel = %s, expression = %s, message_template = %s, "
|
||||
" is_enabled = %s "
|
||||
" WHERE id = %s ")
|
||||
cursor.execute(update_row, (name,
|
||||
fdd_code,
|
||||
category,
|
||||
fdd_code,
|
||||
priority,
|
||||
channel,
|
||||
expression,
|
||||
|
|
|
@ -567,7 +567,7 @@ class SpaceItem:
|
|||
description='API.INVALID_IS_OUTPUT_COUNTED_VALUE')
|
||||
is_output_counted = new_values['data']['is_output_counted']
|
||||
|
||||
if 'contact_id' in new_values['data'].keys():
|
||||
if 'contact_id' in new_values['data'].keys() and new_values['data']['contact_id'] is not None:
|
||||
if new_values['data']['contact_id'] <= 0:
|
||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
|
||||
description='API.INVALID_CONTACT_ID')
|
||||
|
@ -608,7 +608,7 @@ class SpaceItem:
|
|||
if cursor.fetchone() is not None:
|
||||
cursor.close()
|
||||
cnx.disconnect()
|
||||
raise falcon.HTTPError(falcon.HTTP_404, title='API.BAD_REQUEST',
|
||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
|
||||
description='API.SPACE_NAME_IS_ALREADY_IN_USE')
|
||||
|
||||
if parent_space_id is not None:
|
||||
|
|
|
@ -432,7 +432,7 @@ class UserLogin:
|
|||
" VALUES (%s, %s, %s) ")
|
||||
user_uuid = result['uuid']
|
||||
token = hashlib.sha1(os.urandom(24)).hexdigest()
|
||||
utc_expires = datetime.utcnow() + timedelta(seconds=1000 * 60 * 60 * 8)
|
||||
utc_expires = datetime.utcnow() + timedelta(seconds=60 * 60 * 8)
|
||||
cursor.execute(add_session, (user_uuid, token, utc_expires))
|
||||
cnx.commit()
|
||||
cursor.close()
|
||||
|
|
|
@ -14,8 +14,8 @@ class VersionItem:
|
|||
@staticmethod
|
||||
def on_get(req, resp):
|
||||
|
||||
result = {"version": 'MyEMS 1.0.7 (Community Edition)',
|
||||
"release-date": '20210307',
|
||||
result = {"version": 'MyEMS 1.1.0 (Community Edition)',
|
||||
"release-date": '202103018',
|
||||
"website": "https://myems.io"}
|
||||
resp.body = json.dumps(result)
|
||||
|
||||
|
|
|
@ -0,0 +1,603 @@
|
|||
import base64
|
||||
import uuid
|
||||
import os
|
||||
from openpyxl.chart import (
|
||||
PieChart,
|
||||
LineChart,
|
||||
BarChart,
|
||||
Reference,
|
||||
)
|
||||
from openpyxl.styles import PatternFill, Border, Side, Alignment, Font
|
||||
from openpyxl.drawing.image import Image
|
||||
from openpyxl import Workbook
|
||||
from openpyxl.chart.label import DataLabelList
|
||||
import openpyxl.utils.cell as format_cell
|
||||
|
||||
|
||||
####################################################################################################################
|
||||
# PROCEDURES
|
||||
# Step 1: Validate the report data
|
||||
# Step 2: Generate excel file
|
||||
# Step 3: Encode the excel file bytes to Base64
|
||||
####################################################################################################################
|
||||
|
||||
|
||||
def export(report,
|
||||
name,
|
||||
reporting_start_datetime_local,
|
||||
reporting_end_datetime_local,
|
||||
period_type):
|
||||
####################################################################################################################
|
||||
# Step 1: Validate the report data
|
||||
####################################################################################################################
|
||||
if report is None:
|
||||
return None
|
||||
print(report)
|
||||
|
||||
####################################################################################################################
|
||||
# Step 2: Generate excel file from the report data
|
||||
####################################################################################################################
|
||||
filename = generate_excel(report,
|
||||
name,
|
||||
reporting_start_datetime_local,
|
||||
reporting_end_datetime_local,
|
||||
period_type)
|
||||
####################################################################################################################
|
||||
# Step 3: Encode the excel file to Base64
|
||||
####################################################################################################################
|
||||
try:
|
||||
with open(filename, 'rb') as binary_file:
|
||||
binary_file_data = binary_file.read()
|
||||
except IOError as ex:
|
||||
pass
|
||||
|
||||
# Base64 encode the bytes
|
||||
base64_encoded_data = base64.b64encode(binary_file_data)
|
||||
# get the Base64 encoded data using human-readable characters.
|
||||
base64_message = base64_encoded_data.decode('utf-8')
|
||||
# delete the file from server
|
||||
try:
|
||||
os.remove(filename)
|
||||
except NotImplementedError as ex:
|
||||
pass
|
||||
return base64_message
|
||||
|
||||
|
||||
def generate_excel(report,
|
||||
name,
|
||||
reporting_start_datetime_local,
|
||||
reporting_end_datetime_local,
|
||||
period_type):
|
||||
wb = Workbook()
|
||||
ws = wb.active
|
||||
|
||||
# Row height
|
||||
ws.row_dimensions[1].height = 102
|
||||
for i in range(2, 2000 + 1):
|
||||
ws.row_dimensions[i].height = 42
|
||||
|
||||
# Col width
|
||||
ws.column_dimensions['A'].width = 1.5
|
||||
|
||||
ws.column_dimensions['B'].width = 25.0
|
||||
|
||||
for i in range(ord('C'), ord('L')):
|
||||
ws.column_dimensions[chr(i)].width = 15.0
|
||||
|
||||
# Font
|
||||
name_font = Font(name='Constantia', size=15, bold=True)
|
||||
title_font = Font(name='宋体', size=15, bold=True)
|
||||
data_font = Font(name='Franklin Gothic Book', size=11)
|
||||
|
||||
table_fill = PatternFill(fill_type='solid', fgColor='1F497D')
|
||||
f_border = Border(left=Side(border_style='medium', color='00000000'),
|
||||
right=Side(border_style='medium', color='00000000'),
|
||||
bottom=Side(border_style='medium', color='00000000'),
|
||||
top=Side(border_style='medium', color='00000000')
|
||||
)
|
||||
b_border = Border(
|
||||
bottom=Side(border_style='medium', color='00000000'),
|
||||
)
|
||||
|
||||
b_c_alignment = Alignment(vertical='bottom',
|
||||
horizontal='center',
|
||||
text_rotation=0,
|
||||
wrap_text=True,
|
||||
shrink_to_fit=False,
|
||||
indent=0)
|
||||
c_c_alignment = Alignment(vertical='center',
|
||||
horizontal='center',
|
||||
text_rotation=0,
|
||||
wrap_text=True,
|
||||
shrink_to_fit=False,
|
||||
indent=0)
|
||||
b_r_alignment = Alignment(vertical='bottom',
|
||||
horizontal='right',
|
||||
text_rotation=0,
|
||||
wrap_text=True,
|
||||
shrink_to_fit=False,
|
||||
indent=0)
|
||||
c_r_alignment = Alignment(vertical='bottom',
|
||||
horizontal='center',
|
||||
text_rotation=0,
|
||||
wrap_text=True,
|
||||
shrink_to_fit=False,
|
||||
indent=0)
|
||||
# Img
|
||||
img = Image("excelexporters/myems.png")
|
||||
img.width = img.width * 0.85
|
||||
img.height = img.height * 0.85
|
||||
# img = Image("myems.png")
|
||||
ws.add_image(img, 'B1')
|
||||
|
||||
# Title
|
||||
ws.row_dimensions[3].height = 60
|
||||
|
||||
ws['B3'].font = name_font
|
||||
ws['B3'].alignment = b_r_alignment
|
||||
ws['B3'] = 'Name:'
|
||||
ws['C3'].border = b_border
|
||||
ws['C3'].alignment = b_c_alignment
|
||||
ws['C3'].font = name_font
|
||||
ws['C3'] = name
|
||||
|
||||
ws['D3'].font = name_font
|
||||
ws['D3'].alignment = b_r_alignment
|
||||
ws['D3'] = 'Period:'
|
||||
ws['E3'].border = b_border
|
||||
ws['E3'].alignment = b_c_alignment
|
||||
ws['E3'].font = name_font
|
||||
ws['E3'] = period_type
|
||||
|
||||
ws['F3'].font = name_font
|
||||
ws['F3'].alignment = b_r_alignment
|
||||
ws['F3'] = 'Date:'
|
||||
ws['G3'].border = b_border
|
||||
ws['G3'].alignment = b_c_alignment
|
||||
ws['G3'].font = name_font
|
||||
ws['G3'] = reporting_start_datetime_local + "__" + reporting_end_datetime_local
|
||||
ws.merge_cells("G3:H3")
|
||||
|
||||
if "reporting_period_efficiency" not in report.keys() or \
|
||||
"names" not in report['reporting_period_efficiency'].keys() or len(
|
||||
report['reporting_period_efficiency']['names']) == 0:
|
||||
filename = str(uuid.uuid4()) + '.xlsx'
|
||||
wb.save(filename)
|
||||
|
||||
return filename
|
||||
|
||||
##################################
|
||||
|
||||
current_row_number = 6
|
||||
|
||||
reporting_period_data = report['reporting_period_efficiency']
|
||||
|
||||
has_names_data_flag = True
|
||||
|
||||
if "names" not in reporting_period_data.keys() or \
|
||||
reporting_period_data['names'] is None or \
|
||||
len(reporting_period_data['names']) == 0:
|
||||
has_names_data_flag = False
|
||||
|
||||
if has_names_data_flag:
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 报告期累积效率'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
category = reporting_period_data['names']
|
||||
ca_len = len(category)
|
||||
|
||||
ws.row_dimensions[current_row_number].height = 80
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '累积效率'
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['cumulations'][i], 2)
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '环比'
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = str(
|
||||
round(reporting_period_data['increment_rates'][i] * 100, 2)) + '%' \
|
||||
if reporting_period_data['increment_rates'][i] is not None else '-'
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 2
|
||||
|
||||
#####################################
|
||||
|
||||
has_parameters_names_and_timestamps_and_values_data = True
|
||||
current_sheet_parameters_row_number = current_row_number
|
||||
|
||||
if 'parameters' not in report.keys() or \
|
||||
report['parameters'] is None or \
|
||||
'names' not in report['parameters'].keys() or \
|
||||
report['parameters']['names'] is None or \
|
||||
len(report['parameters']['names']) == 0 or \
|
||||
'timestamps' not in report['parameters'].keys() or \
|
||||
report['parameters']['timestamps'] is None or \
|
||||
len(report['parameters']['timestamps']) == 0 or \
|
||||
'values' not in report['parameters'].keys() or \
|
||||
report['parameters']['values'] is None or \
|
||||
len(report['parameters']['values']) == 0 or \
|
||||
timestamps_data_all_equal_0(report['parameters']['timestamps']):
|
||||
|
||||
has_parameters_names_and_timestamps_and_values_data = False
|
||||
|
||||
#####################################
|
||||
|
||||
has_values_data = True
|
||||
has_timestamps_data = True
|
||||
|
||||
if 'values' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['values'] is None or \
|
||||
len(reporting_period_data['values']) == 0:
|
||||
has_values_data = False
|
||||
|
||||
if 'timestamps' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['timestamps'] is None or \
|
||||
len(reporting_period_data['timestamps']) == 0 or \
|
||||
len(reporting_period_data['timestamps'][0]) == 0:
|
||||
has_timestamps_data = False
|
||||
|
||||
if has_values_data and has_timestamps_data:
|
||||
ca_len = len(reporting_period_data['names'])
|
||||
time = reporting_period_data['timestamps'][0]
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 报告期累积效率'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
chart_start_row_number = current_row_number
|
||||
|
||||
current_row_number += ca_len * 6 + 1
|
||||
|
||||
if has_parameters_names_and_timestamps_and_values_data:
|
||||
current_sheet_parameters_row_number = current_row_number
|
||||
real_timestamps_len = timestamps_data_not_equal_0(report['parameters']['timestamps'])
|
||||
current_row_number += 6*real_timestamps_len + 2
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 详细数据'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
table_start_row_number = current_row_number
|
||||
|
||||
ws.row_dimensions[current_row_number].height = 85
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '日期时间'
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
for i in range(0, len(time)):
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = time[i]
|
||||
|
||||
col = 'C'
|
||||
for j in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['values'][j][i], 2) \
|
||||
if reporting_period_data['values'][j][i] is not None else 0.00
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
table_end_row_number = current_row_number - 1
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '小计'
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['cumulations'][i], 2)
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 2
|
||||
|
||||
format_time_width_number = 1.0
|
||||
min_len_number = 1.0
|
||||
min_width_number = 11.0 # format_time_width_number * min_len_number + 4 and min_width_number > 11.0
|
||||
|
||||
if period_type == 'hourly':
|
||||
format_time_width_number = 4.0
|
||||
min_len_number = 2
|
||||
min_width_number = 12.0
|
||||
elif period_type == 'daily':
|
||||
format_time_width_number = 2.5
|
||||
min_len_number = 4
|
||||
min_width_number = 14.0
|
||||
elif period_type == 'monthly':
|
||||
format_time_width_number = 2.1
|
||||
min_len_number = 4
|
||||
min_width_number = 12.4
|
||||
elif period_type == 'yearly':
|
||||
format_time_width_number = 1.5
|
||||
min_len_number = 5
|
||||
min_width_number = 11.5
|
||||
|
||||
for i in range(0, ca_len):
|
||||
line = LineChart()
|
||||
line.title = '报告期累积效率 - ' + \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
|
||||
line_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number, max_row=table_end_row_number)
|
||||
line.add_data(line_data, titles_from_data=True)
|
||||
line.set_categories(labels)
|
||||
line_data = line.series[0]
|
||||
line_data.marker.symbol = "circle"
|
||||
line_data.smooth = True
|
||||
line.x_axis.crosses = 'min'
|
||||
line.height = 8.25
|
||||
line.width = format_time_width_number * len(time) if len(time) > min_len_number else min_width_number
|
||||
if line.width > 24:
|
||||
line.width = 24
|
||||
line.dLbls = DataLabelList()
|
||||
line.dLbls.dLblPos = 't'
|
||||
line.dLbls.showVal = True
|
||||
line.dLbls.showPercent = False
|
||||
chart_col = 'B'
|
||||
chart_cell = chart_col + str(chart_start_row_number)
|
||||
chart_start_row_number += 6
|
||||
ws.add_chart(line, chart_cell)
|
||||
|
||||
#####################################################################
|
||||
|
||||
if has_parameters_names_and_timestamps_and_values_data:
|
||||
|
||||
###############################
|
||||
# new worksheet
|
||||
###############################
|
||||
|
||||
parameters_data = report['parameters']
|
||||
parameters_names_len = len(parameters_data['names'])
|
||||
|
||||
parameters_ws = wb.create_sheet('相关参数')
|
||||
|
||||
parameters_timestamps_data_max_len = \
|
||||
get_parameters_timestamps_lists_max_len(list(parameters_data['timestamps']))
|
||||
|
||||
# Row height
|
||||
parameters_ws.row_dimensions[1].height = 102
|
||||
for i in range(2, 7 + 1):
|
||||
parameters_ws.row_dimensions[i].height = 42
|
||||
|
||||
for i in range(8, parameters_timestamps_data_max_len + 10):
|
||||
parameters_ws.row_dimensions[i].height = 60
|
||||
|
||||
# Col width
|
||||
parameters_ws.column_dimensions['A'].width = 1.5
|
||||
|
||||
parameters_ws.column_dimensions['B'].width = 25.0
|
||||
|
||||
for i in range(3, 12+parameters_names_len*3):
|
||||
parameters_ws.column_dimensions[format_cell.get_column_letter(i)].width = 15.0
|
||||
|
||||
# Img
|
||||
img = Image("excelexporters/myems.png")
|
||||
img.width = img.width * 0.85
|
||||
img.height = img.height * 0.85
|
||||
# img = Image("myems.png")
|
||||
parameters_ws.add_image(img, 'B1')
|
||||
|
||||
# Title
|
||||
parameters_ws.row_dimensions[3].height = 60
|
||||
|
||||
parameters_ws['B3'].font = name_font
|
||||
parameters_ws['B3'].alignment = b_r_alignment
|
||||
parameters_ws['B3'] = 'Name:'
|
||||
parameters_ws['C3'].border = b_border
|
||||
parameters_ws['C3'].alignment = b_c_alignment
|
||||
parameters_ws['C3'].font = name_font
|
||||
parameters_ws['C3'] = name
|
||||
|
||||
parameters_ws['D3'].font = name_font
|
||||
parameters_ws['D3'].alignment = b_r_alignment
|
||||
parameters_ws['D3'] = 'Period:'
|
||||
parameters_ws['E3'].border = b_border
|
||||
parameters_ws['E3'].alignment = b_c_alignment
|
||||
parameters_ws['E3'].font = name_font
|
||||
parameters_ws['E3'] = period_type
|
||||
|
||||
parameters_ws['F3'].font = name_font
|
||||
parameters_ws['F3'].alignment = b_r_alignment
|
||||
parameters_ws['F3'] = 'Date:'
|
||||
parameters_ws['G3'].border = b_border
|
||||
parameters_ws['G3'].alignment = b_c_alignment
|
||||
parameters_ws['G3'].font = name_font
|
||||
parameters_ws['G3'] = reporting_start_datetime_local + "__" + reporting_end_datetime_local
|
||||
parameters_ws.merge_cells("G3:H3")
|
||||
|
||||
parameters_ws_current_row_number = 6
|
||||
|
||||
parameters_ws['B' + str(parameters_ws_current_row_number)].font = title_font
|
||||
parameters_ws['B' + str(parameters_ws_current_row_number)] = name + ' 相关参数'
|
||||
|
||||
parameters_ws_current_row_number += 1
|
||||
|
||||
parameters_table_start_row_number = parameters_ws_current_row_number
|
||||
|
||||
parameters_ws.row_dimensions[parameters_ws_current_row_number].height = 80
|
||||
|
||||
parameters_ws_current_row_number += 1
|
||||
|
||||
table_current_col_number = 'B'
|
||||
|
||||
for i in range(0, parameters_names_len):
|
||||
|
||||
if len(parameters_data['timestamps'][i]) == 0:
|
||||
continue
|
||||
|
||||
parameters_ws[table_current_col_number + str(parameters_ws_current_row_number-1)].fill = table_fill
|
||||
parameters_ws[table_current_col_number + str(parameters_ws_current_row_number-1)].border = f_border
|
||||
|
||||
col = chr(ord(table_current_col_number) + 1)
|
||||
|
||||
parameters_ws[col + str(parameters_ws_current_row_number-1)].fill = table_fill
|
||||
parameters_ws[col + str(parameters_ws_current_row_number-1)].border = f_border
|
||||
parameters_ws[col + str(parameters_ws_current_row_number-1)].font = name_font
|
||||
parameters_ws[col + str(parameters_ws_current_row_number-1)].alignment = c_c_alignment
|
||||
parameters_ws[col + str(parameters_ws_current_row_number-1)] = parameters_data['names'][i]
|
||||
|
||||
table_current_row_number = parameters_ws_current_row_number
|
||||
|
||||
for j, value in enumerate(list(parameters_data['timestamps'][i])):
|
||||
col = table_current_col_number
|
||||
|
||||
parameters_ws[col + str(table_current_row_number)].border = f_border
|
||||
parameters_ws[col + str(table_current_row_number)].font = title_font
|
||||
parameters_ws[col + str(table_current_row_number)].alignment = c_c_alignment
|
||||
parameters_ws[col + str(table_current_row_number)] = value
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
parameters_ws[col + str(table_current_row_number)].border = f_border
|
||||
parameters_ws[col + str(table_current_row_number)].font = title_font
|
||||
parameters_ws[col + str(table_current_row_number)].alignment = c_c_alignment
|
||||
parameters_ws[col + str(table_current_row_number)] = round(parameters_data['values'][i][j], 2)
|
||||
|
||||
table_current_row_number += 1
|
||||
|
||||
table_current_col_number = chr(ord(table_current_col_number) + 3)
|
||||
|
||||
########################################################
|
||||
# parameters chart and parameters table
|
||||
########################################################
|
||||
|
||||
ws['B' + str(current_sheet_parameters_row_number)].font = title_font
|
||||
ws['B' + str(current_sheet_parameters_row_number)] = name + ' 相关参数'
|
||||
|
||||
current_sheet_parameters_row_number += 1
|
||||
|
||||
chart_start_row_number = current_sheet_parameters_row_number
|
||||
|
||||
col_index = 0
|
||||
|
||||
for i in range(0, parameters_names_len):
|
||||
|
||||
if len(parameters_data['timestamps'][i]) == 0:
|
||||
continue
|
||||
|
||||
line = LineChart()
|
||||
data_col = 3+col_index*3
|
||||
labels_col = 2+col_index*3
|
||||
col_index += 1
|
||||
line.title = '相关参数 - ' + \
|
||||
parameters_ws.cell(row=parameters_table_start_row_number, column=data_col).value
|
||||
labels = Reference(parameters_ws, min_col=labels_col, min_row=parameters_table_start_row_number + 1,
|
||||
max_row=(len(parameters_data['timestamps'][i])+parameters_table_start_row_number))
|
||||
line_data = Reference(parameters_ws, min_col=data_col, min_row=parameters_table_start_row_number,
|
||||
max_row=(len(parameters_data['timestamps'][i])+parameters_table_start_row_number))
|
||||
line.add_data(line_data, titles_from_data=True)
|
||||
line.set_categories(labels)
|
||||
line_data = line.series[0]
|
||||
line_data.marker.symbol = "circle"
|
||||
line_data.smooth = True
|
||||
line.x_axis.crosses = 'min'
|
||||
line.height = 8.25
|
||||
line.width = 24
|
||||
line.dLbls = DataLabelList()
|
||||
line.dLbls.dLblPos = 't'
|
||||
line.dLbls.showVal = False
|
||||
line.dLbls.showPercent = False
|
||||
chart_col = 'B'
|
||||
chart_cell = chart_col + str(chart_start_row_number)
|
||||
chart_start_row_number += 6
|
||||
ws.add_chart(line, chart_cell)
|
||||
|
||||
current_sheet_parameters_row_number = chart_start_row_number
|
||||
|
||||
current_sheet_parameters_row_number += 1
|
||||
|
||||
filename = str(uuid.uuid4()) + '.xlsx'
|
||||
wb.save(filename)
|
||||
|
||||
return filename
|
||||
|
||||
|
||||
def get_parameters_timestamps_lists_max_len(parameters_timestamps_lists):
|
||||
max_len = 0
|
||||
for i, value in enumerate(list(parameters_timestamps_lists)):
|
||||
if len(value) > max_len:
|
||||
max_len = len(value)
|
||||
|
||||
return max_len
|
||||
|
||||
|
||||
def timestamps_data_all_equal_0(lists):
|
||||
for i, value in enumerate(list(lists)):
|
||||
if len(value) > 0:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def timestamps_data_not_equal_0(lists):
|
||||
number = 0
|
||||
for i, value in enumerate(list(lists)):
|
||||
if len(value) > 0:
|
||||
number += 1
|
||||
return number
|
|
@ -222,23 +222,6 @@ def generate_excel(report,
|
|||
|
||||
current_row_number += 1
|
||||
|
||||
# ws['B' + str(current_row_number)].font = title_font
|
||||
# ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
# ws['B' + str(current_row_number)].border = f_border
|
||||
# ws['B' + str(current_row_number)] = '单位面积值'
|
||||
#
|
||||
# col = 'C'
|
||||
#
|
||||
# for i in range(0, ca_len):
|
||||
# ws[col + str(current_row_number)].font = name_font
|
||||
# ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
# ws[col + str(current_row_number)].border = f_border
|
||||
# ws[col + str(current_row_number)] = round(reporting_period_data['subtotals_per_unit_area'][i], 2)
|
||||
#
|
||||
# col = chr(ord(col) + 1)
|
||||
#
|
||||
# current_row_number += 1
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
|
@ -318,136 +301,136 @@ def generate_excel(report,
|
|||
|
||||
current_row_number += 1
|
||||
|
||||
#####################################
|
||||
#####################################
|
||||
|
||||
has_values_data = True
|
||||
has_timestamps_data = True
|
||||
has_values_data = True
|
||||
has_timestamps_data = True
|
||||
|
||||
if 'values' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['values'] is None or \
|
||||
len(reporting_period_data['values']) == 0:
|
||||
has_values_data = False
|
||||
if 'values' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['values'] is None or \
|
||||
len(reporting_period_data['values']) == 0:
|
||||
has_values_data = False
|
||||
|
||||
if 'timestamps' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['timestamps'] is None or \
|
||||
len(reporting_period_data['timestamps']) == 0 or \
|
||||
len(reporting_period_data['timestamps'][0]) == 0:
|
||||
has_timestamps_data = False
|
||||
if 'timestamps' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['timestamps'] is None or \
|
||||
len(reporting_period_data['timestamps']) == 0 or \
|
||||
len(reporting_period_data['timestamps'][0]) == 0:
|
||||
has_timestamps_data = False
|
||||
|
||||
if has_values_data and has_timestamps_data:
|
||||
ca_len = len(reporting_period_data['names'])
|
||||
time = reporting_period_data['timestamps'][0]
|
||||
if has_values_data and has_timestamps_data:
|
||||
ca_len = len(reporting_period_data['names'])
|
||||
time = reporting_period_data['timestamps'][0]
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 详细数据'
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 详细数据'
|
||||
|
||||
current_row_number += 1
|
||||
current_row_number += 1
|
||||
|
||||
chart_start_row_number = current_row_number
|
||||
chart_start_row_number = current_row_number
|
||||
|
||||
current_row_number += ca_len * 6
|
||||
table_start_row_number = current_row_number
|
||||
current_row_number += ca_len * 6
|
||||
table_start_row_number = current_row_number
|
||||
|
||||
ws.row_dimensions[current_row_number].height = 60
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws.row_dimensions[current_row_number].height = 60
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '日期时间'
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
for i in range(0, len(time)):
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '日期时间'
|
||||
ws['B' + str(current_row_number)] = time[i]
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
for j in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['values'][j][i], 2) \
|
||||
if reporting_period_data['values'][j][i] is not None else 0.00
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
for i in range(0, len(time)):
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = time[i]
|
||||
table_end_row_number = current_row_number - 1
|
||||
|
||||
col = 'C'
|
||||
for j in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['values'][j][i], 2) \
|
||||
if reporting_period_data['values'][j][i] is not None else 0.00
|
||||
col = chr(ord(col) + 1)
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '小计'
|
||||
|
||||
current_row_number += 1
|
||||
col = 'C'
|
||||
|
||||
table_end_row_number = current_row_number - 1
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['subtotals'][i], 2)
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '小计'
|
||||
current_row_number += 2
|
||||
|
||||
col = 'C'
|
||||
format_time_width_number = 1.0
|
||||
min_len_number = 1.0
|
||||
min_width_number = 11.0 # format_time_width_number * min_len_number + 4 and min_width_number > 11.0
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['subtotals'][i], 2)
|
||||
col = chr(ord(col) + 1)
|
||||
if period_type == 'hourly':
|
||||
format_time_width_number = 4.0
|
||||
min_len_number = 2
|
||||
min_width_number = 12.0
|
||||
elif period_type == 'daily':
|
||||
format_time_width_number = 2.5
|
||||
min_len_number = 4
|
||||
min_width_number = 14.0
|
||||
elif period_type == 'monthly':
|
||||
format_time_width_number = 2.1
|
||||
min_len_number = 4
|
||||
min_width_number = 12.4
|
||||
elif period_type == 'yearly':
|
||||
format_time_width_number = 1.5
|
||||
min_len_number = 5
|
||||
min_width_number = 11.5
|
||||
|
||||
current_row_number += 2
|
||||
|
||||
format_time_width_number = 1.0
|
||||
min_len_number = 1.0
|
||||
min_width_number = 11.0 # format_time_width_number * min_len_number + 4 and min_width_number > 11.0
|
||||
|
||||
if period_type == 'hourly':
|
||||
format_time_width_number = 4.0
|
||||
min_len_number = 2
|
||||
min_width_number = 12.0
|
||||
elif period_type == 'daily':
|
||||
format_time_width_number = 2.5
|
||||
min_len_number = 4
|
||||
min_width_number = 14.0
|
||||
elif period_type == 'monthly':
|
||||
format_time_width_number = 2.1
|
||||
min_len_number = 4
|
||||
min_width_number = 12.4
|
||||
elif period_type == 'yearly':
|
||||
format_time_width_number = 1.5
|
||||
min_len_number = 5
|
||||
min_width_number = 11.5
|
||||
|
||||
for i in range(0, ca_len):
|
||||
line = LineChart()
|
||||
line.title = '报告期消耗 - ' + \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
|
||||
line_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number, max_row=table_end_row_number)
|
||||
line.add_data(line_data, titles_from_data=True)
|
||||
line.set_categories(labels)
|
||||
line_data = line.series[0]
|
||||
line_data.marker.symbol = "circle"
|
||||
line_data.smooth = True
|
||||
line.x_axis.crosses = 'min'
|
||||
line.height = 8.25
|
||||
line.width = format_time_width_number * len(time) if len(time) > min_len_number else min_width_number
|
||||
if line.width > 24:
|
||||
line.width = 24
|
||||
line.dLbls = DataLabelList()
|
||||
line.dLbls.dLblPos = 't'
|
||||
line.dLbls.showVal = True
|
||||
line.dLbls.showPercent = False
|
||||
chart_col = 'B'
|
||||
chart_cell = chart_col + str(chart_start_row_number)
|
||||
chart_start_row_number += 6
|
||||
ws.add_chart(line, chart_cell)
|
||||
for i in range(0, ca_len):
|
||||
line = LineChart()
|
||||
line.title = '报告期消耗 - ' + \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
|
||||
line_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number, max_row=table_end_row_number)
|
||||
line.add_data(line_data, titles_from_data=True)
|
||||
line.set_categories(labels)
|
||||
line_data = line.series[0]
|
||||
line_data.marker.symbol = "circle"
|
||||
line_data.smooth = True
|
||||
line.x_axis.crosses = 'min'
|
||||
line.height = 8.25
|
||||
line.width = format_time_width_number * len(time) if len(time) > min_len_number else min_width_number
|
||||
if line.width > 24:
|
||||
line.width = 24
|
||||
line.dLbls = DataLabelList()
|
||||
line.dLbls.dLblPos = 't'
|
||||
line.dLbls.showVal = True
|
||||
line.dLbls.showPercent = False
|
||||
chart_col = 'B'
|
||||
chart_cell = chart_col + str(chart_start_row_number)
|
||||
chart_start_row_number += 6
|
||||
ws.add_chart(line, chart_cell)
|
||||
|
||||
filename = str(uuid.uuid4()) + '.xlsx'
|
||||
wb.save(filename)
|
||||
|
|
|
@ -0,0 +1,463 @@
|
|||
import base64
|
||||
import uuid
|
||||
import os
|
||||
from openpyxl.chart import (
|
||||
PieChart,
|
||||
LineChart,
|
||||
BarChart,
|
||||
Reference,
|
||||
)
|
||||
from openpyxl.styles import PatternFill, Border, Side, Alignment, Font
|
||||
from openpyxl.drawing.image import Image
|
||||
from openpyxl import Workbook
|
||||
from openpyxl.chart.label import DataLabelList
|
||||
|
||||
|
||||
####################################################################################################################
|
||||
# PROCEDURES
|
||||
# Step 1: Validate the report data
|
||||
# Step 2: Generate excel file
|
||||
# Step 3: Encode the excel file bytes to Base64
|
||||
####################################################################################################################
|
||||
|
||||
|
||||
def export(report,
|
||||
name,
|
||||
reporting_start_datetime_local,
|
||||
reporting_end_datetime_local,
|
||||
period_type):
|
||||
####################################################################################################################
|
||||
# Step 1: Validate the report data
|
||||
####################################################################################################################
|
||||
if report is None:
|
||||
return None
|
||||
print(report)
|
||||
|
||||
####################################################################################################################
|
||||
# Step 2: Generate excel file from the report data
|
||||
####################################################################################################################
|
||||
filename = generate_excel(report,
|
||||
name,
|
||||
reporting_start_datetime_local,
|
||||
reporting_end_datetime_local,
|
||||
period_type)
|
||||
####################################################################################################################
|
||||
# Step 3: Encode the excel file to Base64
|
||||
####################################################################################################################
|
||||
try:
|
||||
with open(filename, 'rb') as binary_file:
|
||||
binary_file_data = binary_file.read()
|
||||
except IOError as ex:
|
||||
pass
|
||||
|
||||
# Base64 encode the bytes
|
||||
base64_encoded_data = base64.b64encode(binary_file_data)
|
||||
# get the Base64 encoded data using human-readable characters.
|
||||
base64_message = base64_encoded_data.decode('utf-8')
|
||||
# delete the file from server
|
||||
try:
|
||||
os.remove(filename)
|
||||
except NotImplementedError as ex:
|
||||
pass
|
||||
return base64_message
|
||||
|
||||
|
||||
def generate_excel(report,
|
||||
name,
|
||||
reporting_start_datetime_local,
|
||||
reporting_end_datetime_local,
|
||||
period_type):
|
||||
wb = Workbook()
|
||||
ws = wb.active
|
||||
|
||||
# Row height
|
||||
ws.row_dimensions[1].height = 102
|
||||
for i in range(2, 2000 + 1):
|
||||
ws.row_dimensions[i].height = 42
|
||||
|
||||
# Col width
|
||||
ws.column_dimensions['A'].width = 1.5
|
||||
|
||||
ws.column_dimensions['B'].width = 25.0
|
||||
|
||||
for i in range(ord('C'), ord('L')):
|
||||
ws.column_dimensions[chr(i)].width = 15.0
|
||||
|
||||
# Font
|
||||
name_font = Font(name='Constantia', size=15, bold=True)
|
||||
title_font = Font(name='宋体', size=15, bold=True)
|
||||
data_font = Font(name='Franklin Gothic Book', size=11)
|
||||
|
||||
table_fill = PatternFill(fill_type='solid', fgColor='1F497D')
|
||||
f_border = Border(left=Side(border_style='medium', color='00000000'),
|
||||
right=Side(border_style='medium', color='00000000'),
|
||||
bottom=Side(border_style='medium', color='00000000'),
|
||||
top=Side(border_style='medium', color='00000000')
|
||||
)
|
||||
b_border = Border(
|
||||
bottom=Side(border_style='medium', color='00000000'),
|
||||
)
|
||||
|
||||
b_c_alignment = Alignment(vertical='bottom',
|
||||
horizontal='center',
|
||||
text_rotation=0,
|
||||
wrap_text=True,
|
||||
shrink_to_fit=False,
|
||||
indent=0)
|
||||
c_c_alignment = Alignment(vertical='center',
|
||||
horizontal='center',
|
||||
text_rotation=0,
|
||||
wrap_text=True,
|
||||
shrink_to_fit=False,
|
||||
indent=0)
|
||||
b_r_alignment = Alignment(vertical='bottom',
|
||||
horizontal='right',
|
||||
text_rotation=0,
|
||||
wrap_text=True,
|
||||
shrink_to_fit=False,
|
||||
indent=0)
|
||||
c_r_alignment = Alignment(vertical='bottom',
|
||||
horizontal='center',
|
||||
text_rotation=0,
|
||||
wrap_text=True,
|
||||
shrink_to_fit=False,
|
||||
indent=0)
|
||||
|
||||
# Img
|
||||
img = Image("excelexporters/myems.png")
|
||||
img.width = img.width * 0.85
|
||||
img.height = img.height * 0.85
|
||||
# img = Image("myems.png")
|
||||
ws.add_image(img, 'B1')
|
||||
|
||||
# Title
|
||||
ws.row_dimensions[3].height = 60
|
||||
|
||||
ws['B3'].font = name_font
|
||||
ws['B3'].alignment = b_r_alignment
|
||||
ws['B3'] = 'Name:'
|
||||
ws['C3'].border = b_border
|
||||
ws['C3'].alignment = b_c_alignment
|
||||
ws['C3'].font = name_font
|
||||
ws['C3'] = name
|
||||
|
||||
ws['D3'].font = name_font
|
||||
ws['D3'].alignment = b_r_alignment
|
||||
ws['D3'] = 'Period:'
|
||||
ws['E3'].border = b_border
|
||||
ws['E3'].alignment = b_c_alignment
|
||||
ws['E3'].font = name_font
|
||||
ws['E3'] = period_type
|
||||
|
||||
ws['F3'].font = name_font
|
||||
ws['F3'].alignment = b_r_alignment
|
||||
ws['F3'] = 'Date:'
|
||||
ws['G3'].border = b_border
|
||||
ws['G3'].alignment = b_c_alignment
|
||||
ws['G3'].font = name_font
|
||||
ws['G3'] = reporting_start_datetime_local + "__" + reporting_end_datetime_local
|
||||
ws.merge_cells("G3:H3")
|
||||
|
||||
if "reporting_period" not in report.keys() or \
|
||||
"names" not in report['reporting_period'].keys() or len(report['reporting_period']['names']) == 0:
|
||||
filename = str(uuid.uuid4()) + '.xlsx'
|
||||
wb.save(filename)
|
||||
|
||||
return filename
|
||||
|
||||
##################################
|
||||
|
||||
reporting_period_data = report['reporting_period']
|
||||
|
||||
has_cost_data_flag = True
|
||||
|
||||
if "names" not in reporting_period_data.keys() or \
|
||||
reporting_period_data['names'] is None or \
|
||||
len(reporting_period_data['names']) == 0:
|
||||
has_cost_data_flag = False
|
||||
|
||||
if has_cost_data_flag:
|
||||
ws['B5'].font = title_font
|
||||
ws['B5'] = name + ' 报告期收入'
|
||||
category = reporting_period_data['names']
|
||||
ca_len = len(category)
|
||||
|
||||
ws.row_dimensions[7].height = 60
|
||||
ws['B6'].fill = table_fill
|
||||
ws['B6'].border = f_border
|
||||
|
||||
ws['B7'].font = title_font
|
||||
ws['B7'].alignment = c_c_alignment
|
||||
ws['B7'] = '报告期收入'
|
||||
ws['B7'].border = f_border
|
||||
|
||||
ws['B8'].font = title_font
|
||||
ws['B8'].alignment = c_c_alignment
|
||||
ws['B8'] = '环比'
|
||||
ws['B8'].border = f_border
|
||||
|
||||
col = ''
|
||||
|
||||
for i in range(0, ca_len):
|
||||
col = chr(ord('C') + i)
|
||||
|
||||
ws[col + '6'].fill = table_fill
|
||||
ws[col + '6'].font = name_font
|
||||
ws[col + '6'].alignment = c_c_alignment
|
||||
ws[col + '6'] = reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
ws[col + '6'].border = f_border
|
||||
|
||||
ws[col + '7'].font = name_font
|
||||
ws[col + '7'].alignment = c_c_alignment
|
||||
ws[col + '7'] = round(reporting_period_data['subtotals'][i], 2)
|
||||
ws[col + '7'].border = f_border
|
||||
|
||||
ws[col + '8'].font = name_font
|
||||
ws[col + '8'].alignment = c_c_alignment
|
||||
ws[col + '8'] = str(round(reporting_period_data['increment_rates'][i] * 100, 2)) + "%" \
|
||||
if reporting_period_data['increment_rates'][i] is not None else "-"
|
||||
ws[col + '8'].border = f_border
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
ws[col + '6'].fill = table_fill
|
||||
ws[col + '6'].font = name_font
|
||||
ws[col + '6'].alignment = c_c_alignment
|
||||
ws[col + '6'] = "总计 (" + reporting_period_data['total_unit'] + ")"
|
||||
ws[col + '6'].border = f_border
|
||||
|
||||
ws[col + '7'].font = name_font
|
||||
ws[col + '7'].alignment = c_c_alignment
|
||||
ws[col + '7'] = round(reporting_period_data['total'], 2)
|
||||
ws[col + '7'].border = f_border
|
||||
|
||||
ws[col + '8'].font = name_font
|
||||
ws[col + '8'].alignment = c_c_alignment
|
||||
ws[col + '8'] = str(round(reporting_period_data['total_increment_rate'] * 100, 2)) + "%" \
|
||||
if reporting_period_data['total_increment_rate'] is not None else "-"
|
||||
ws[col + '8'].border = f_border
|
||||
|
||||
else:
|
||||
for i in range(6, 8 + 1):
|
||||
ws.row_dimensions[i].height = 0.1
|
||||
##################################
|
||||
current_row_number = 10
|
||||
has_subtotals_data_flag = True
|
||||
if "subtotals" not in reporting_period_data.keys() or \
|
||||
reporting_period_data['subtotals'] is None or \
|
||||
len(reporting_period_data['subtotals']) == 0:
|
||||
has_subtotals_data_flag = False
|
||||
|
||||
if has_subtotals_data_flag:
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 收入占比'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
table_start_row_number = current_row_number
|
||||
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws['B' + str(current_row_number)].font = name_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
|
||||
ws['C' + str(current_row_number)].fill = table_fill
|
||||
ws['C' + str(current_row_number)].font = name_font
|
||||
ws['C' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['C' + str(current_row_number)].border = f_border
|
||||
ws['C' + str(current_row_number)] = '收入'
|
||||
|
||||
ws['D' + str(current_row_number)].fill = table_fill
|
||||
ws['D' + str(current_row_number)].font = name_font
|
||||
ws['D' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['D' + str(current_row_number)].border = f_border
|
||||
ws['D' + str(current_row_number)] = '收入占比'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
ca_len = len(reporting_period_data['names'])
|
||||
wssum = 0
|
||||
for i in range(0, ca_len):
|
||||
wssum = round(reporting_period_data['subtotals'][i], 2) + wssum
|
||||
for i in range(0, ca_len):
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)] = reporting_period_data['names'][i]
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
|
||||
ws['C' + str(current_row_number)].font = title_font
|
||||
ws['C' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['C' + str(current_row_number)].border = f_border
|
||||
ws['C' + str(current_row_number)] = round(reporting_period_data['subtotals'][i], 2)
|
||||
|
||||
ws['D' + str(current_row_number)].font = title_font
|
||||
ws['D' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['D' + str(current_row_number)].border = f_border
|
||||
ws['D' + str(current_row_number)] = '{:.2%}'.format(round(reporting_period_data['subtotals'][i], 2) / wssum)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
table_end_row_number = current_row_number - 1
|
||||
|
||||
pie = PieChart()
|
||||
pie.title = name + ' 收入占比'
|
||||
labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
|
||||
pie_data = Reference(ws, min_col=3, min_row=table_start_row_number, max_row=table_end_row_number)
|
||||
pie.add_data(pie_data, titles_from_data=True)
|
||||
pie.set_categories(labels)
|
||||
pie.height = 6.6
|
||||
pie.width = 9
|
||||
s1 = pie.series[0]
|
||||
s1.dLbls = DataLabelList()
|
||||
s1.dLbls.showCatName = False
|
||||
s1.dLbls.showVal = True
|
||||
s1.dLbls.showPercent = True
|
||||
table_cell = 'F' + str(table_start_row_number - 1)
|
||||
ws.add_chart(pie, table_cell)
|
||||
|
||||
if ca_len < 4:
|
||||
current_row_number = current_row_number - ca_len + 4
|
||||
|
||||
else:
|
||||
for i in range(13, 22 + 1):
|
||||
ws.row_dimensions[i].height = 0.1
|
||||
|
||||
#############################################
|
||||
current_row_number = 14
|
||||
reporting_period_data = report['reporting_period']
|
||||
times = reporting_period_data['timestamps']
|
||||
has_detail_data_flag = True
|
||||
ca_len = len(report['reporting_period']['names'])
|
||||
table_row = (current_row_number + 1) + ca_len * 6
|
||||
if "timestamps" not in reporting_period_data.keys() or \
|
||||
reporting_period_data['timestamps'] is None or \
|
||||
len(reporting_period_data['timestamps']) == 0:
|
||||
has_detail_data_flag = False
|
||||
|
||||
if has_detail_data_flag:
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 详细数据'
|
||||
|
||||
ws.row_dimensions[table_row].height = 60
|
||||
ws['B' + str(table_row)].fill = table_fill
|
||||
ws['B' + str(table_row)].font = title_font
|
||||
ws['B' + str(table_row)].border = f_border
|
||||
ws['B' + str(table_row)].alignment = c_c_alignment
|
||||
ws['B' + str(table_row)] = '日期时间'
|
||||
time = times[0]
|
||||
has_data = False
|
||||
max_row = 0
|
||||
if len(time) > 0:
|
||||
has_data = True
|
||||
max_row = table_row + len(time)
|
||||
|
||||
if has_data:
|
||||
for i in range(0, len(time)):
|
||||
col = 'B'
|
||||
row = str(table_row + 1 + i)
|
||||
ws[col + row].font = title_font
|
||||
ws[col + row].alignment = c_c_alignment
|
||||
ws[col + row] = time[i]
|
||||
ws[col + row].border = f_border
|
||||
|
||||
for i in range(0, ca_len):
|
||||
|
||||
col = chr(ord('C') + i)
|
||||
|
||||
ws[col + str(table_row)].fill = table_fill
|
||||
ws[col + str(table_row)].font = title_font
|
||||
ws[col + str(table_row)].alignment = c_c_alignment
|
||||
ws[col + str(table_row)] = reporting_period_data['names'][i] + " (" + reporting_period_data['units'][
|
||||
i] + ")"
|
||||
ws[col + str(table_row)].border = f_border
|
||||
|
||||
# 39 data
|
||||
time = times[i]
|
||||
time_len = len(time)
|
||||
|
||||
for j in range(0, time_len):
|
||||
row = str(table_row + 1 + j)
|
||||
ws[col + row].font = title_font
|
||||
ws[col + row].alignment = c_c_alignment
|
||||
ws[col + row] = round(reporting_period_data['values'][i][j], 2)
|
||||
ws[col + row].border = f_border
|
||||
|
||||
line = LineChart()
|
||||
line.title = \
|
||||
'报告期收入 - ' + reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
labels = Reference(ws, min_col=2, min_row=table_row + 1, max_row=max_row)
|
||||
line_data = Reference(ws, min_col=3 + i, min_row=table_row, max_row=max_row)
|
||||
line.add_data(line_data, titles_from_data=True)
|
||||
line.set_categories(labels)
|
||||
line_data = line.series[0]
|
||||
line_data.marker.symbol = "circle"
|
||||
line_data.smooth = True
|
||||
line.x_axis.crosses = 'min'
|
||||
line.height = 8.25
|
||||
line.width = 24
|
||||
line.dLbls = DataLabelList()
|
||||
line.dLbls.dLblPos = 't'
|
||||
line.dLbls.showVal = True
|
||||
line.dLbls.showPercent = False
|
||||
chart_col = 'B'
|
||||
chart_cell = chart_col + str(current_row_number + 1 + 6 * i)
|
||||
ws.add_chart(line, chart_cell)
|
||||
|
||||
row = str(max_row + 1)
|
||||
|
||||
ws['B' + row].font = title_font
|
||||
ws['B' + row].alignment = c_c_alignment
|
||||
ws['B' + row] = '小计'
|
||||
ws['B' + row].border = f_border
|
||||
|
||||
col = ''
|
||||
|
||||
for i in range(0, ca_len):
|
||||
col = chr(ord('C') + i)
|
||||
row = str(max_row + 1)
|
||||
ws[col + row].font = title_font
|
||||
ws[col + row].alignment = c_c_alignment
|
||||
ws[col + row] = round(reporting_period_data['subtotals'][i], 2)
|
||||
ws[col + row].border = f_border
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
ws[col + str(table_row)].fill = table_fill
|
||||
ws[col + str(table_row)].font = title_font
|
||||
ws[col + str(table_row)].alignment = c_c_alignment
|
||||
ws[col + str(table_row)] = '总计 (' + report['reporting_period']['total_unit'] + ')'
|
||||
ws[col + str(table_row)].border = f_border
|
||||
|
||||
total_sum = 0
|
||||
|
||||
for j in range(0, len(time)):
|
||||
row = str(table_row + 1 + j)
|
||||
ws[col + row].font = title_font
|
||||
ws[col + row].alignment = c_c_alignment
|
||||
every_day_sum = reporting_period_values_every_day_sum(reporting_period_data, j, ca_len)
|
||||
total_sum += every_day_sum
|
||||
ws[col + row] = round(every_day_sum, 2)
|
||||
ws[col + row].border = f_border
|
||||
|
||||
row = str(table_row + 1 + len(time))
|
||||
ws[col + row].font = title_font
|
||||
ws[col + row].alignment = c_c_alignment
|
||||
ws[col + row] = round(total_sum, 2)
|
||||
ws[col + row].border = f_border
|
||||
|
||||
else:
|
||||
for i in range(37, 69 + 1):
|
||||
ws.row_dimensions[i].height = 0.1
|
||||
|
||||
filename = str(uuid.uuid4()) + '.xlsx'
|
||||
wb.save(filename)
|
||||
|
||||
return filename
|
||||
|
||||
|
||||
def reporting_period_values_every_day_sum(reporting_period_data, every_day_index, ca_len):
|
||||
every_day_sum = 0
|
||||
for i in range(0, ca_len):
|
||||
every_day_sum += reporting_period_data['values'][i][every_day_index]
|
||||
|
||||
return every_day_sum
|
|
@ -113,12 +113,6 @@ def generate_excel(report,
|
|||
wrap_text=False,
|
||||
shrink_to_fit=False,
|
||||
indent=0)
|
||||
# c_r_alignment = Alignment(vertical='bottom',
|
||||
# horizontal='center',
|
||||
# text_rotation=0,
|
||||
# wrap_text=False,
|
||||
# shrink_to_fit=False,
|
||||
# indent=0)
|
||||
|
||||
# Img
|
||||
img = Image("excelexporters/myems.png")
|
||||
|
@ -262,9 +256,9 @@ def generate_excel(report,
|
|||
|
||||
########################################################
|
||||
# Third: 详细数据
|
||||
# row_sat~ row_sat + 6*cal_len: line
|
||||
# row_da: table title
|
||||
# row_da + 1~: table_data
|
||||
# analysis_end_row_number~ analysis_end_row_number + 6*cal_len: line
|
||||
# detailed_start_row_number: table title
|
||||
# detailed_start_row_number + 1~: table_data
|
||||
########################################################
|
||||
has_timestamps_flag = True
|
||||
if "timestamps" not in reporting_period_data.keys() or \
|
||||
|
@ -277,40 +271,37 @@ def generate_excel(report,
|
|||
names = reporting_period_data['names']
|
||||
ca_len = len(names)
|
||||
time_len = len(timestamps)
|
||||
# row_lines == the number of rows of lines
|
||||
row_lines = 6 * ca_len
|
||||
# row_sat == the number of rows of statistical analysis table
|
||||
row_sat = 9 + 2 * ca_len
|
||||
# row_da == the number of rows of Detailed data
|
||||
row_da = row_sat + row_lines + 1
|
||||
line_charts_row_number = 6 * ca_len
|
||||
analysis_end_row_number = 9 + 2 * ca_len
|
||||
detailed_start_row_number = analysis_end_row_number + line_charts_row_number + 1
|
||||
|
||||
ws['B' + str(row_da)].font = title_font
|
||||
ws['B' + str(row_da)] = name + ' 详细数据'
|
||||
ws['B' + str(detailed_start_row_number)].font = title_font
|
||||
ws['B' + str(detailed_start_row_number)] = name + ' 详细数据'
|
||||
# table_title
|
||||
ws['B' + str(row_da + 1)].fill = table_fill
|
||||
ws['B' + str(row_da + 1)].font = name_font
|
||||
ws['B' + str(row_da + 1)].alignment = c_c_alignment
|
||||
ws['B' + str(row_da + 1)] = "日期时间"
|
||||
ws['B' + str(row_da + 1)].border = f_border
|
||||
ws['B' + str(detailed_start_row_number + 1)].fill = table_fill
|
||||
ws['B' + str(detailed_start_row_number + 1)].font = name_font
|
||||
ws['B' + str(detailed_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['B' + str(detailed_start_row_number + 1)] = "日期时间"
|
||||
ws['B' + str(detailed_start_row_number + 1)].border = f_border
|
||||
|
||||
for i in range(0, ca_len):
|
||||
col_average = chr(ord('C') + 2 * i)
|
||||
col_maximum = chr(ord('D') + 2 * i)
|
||||
|
||||
ws[col_average + str(row_da + 1)].font = name_font
|
||||
ws[col_average + str(row_da + 1)].alignment = c_c_alignment
|
||||
ws[col_average + str(row_da + 1)] = names[i] + " 平均负荷(" + reporting_period_data['units'][
|
||||
ws[col_average + str(detailed_start_row_number + 1)].font = name_font
|
||||
ws[col_average + str(detailed_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws[col_average + str(detailed_start_row_number + 1)] = names[i] + " 平均负荷(" + reporting_period_data['units'][
|
||||
i] + "/H)"
|
||||
ws[col_average + str(row_da + 1)].border = f_border
|
||||
ws[col_average + str(detailed_start_row_number + 1)].border = f_border
|
||||
|
||||
ws[col_maximum + str(row_da + 1)].font = name_font
|
||||
ws[col_maximum + str(row_da + 1)].alignment = c_c_alignment
|
||||
ws[col_maximum + str(row_da + 1)] = names[i] + " 最大负荷(" + reporting_period_data['units'][
|
||||
ws[col_maximum + str(detailed_start_row_number + 1)].font = name_font
|
||||
ws[col_maximum + str(detailed_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws[col_maximum + str(detailed_start_row_number + 1)] = names[i] + " 最大负荷(" + reporting_period_data['units'][
|
||||
i] + "/H)"
|
||||
ws[col_maximum + str(row_da + 1)].border = f_border
|
||||
ws[col_maximum + str(detailed_start_row_number + 1)].border = f_border
|
||||
# table_date
|
||||
for i in range(0, time_len):
|
||||
rows = i + row_da + 2
|
||||
rows = i + detailed_start_row_number + 2
|
||||
|
||||
ws['B' + str(rows)].font = name_font
|
||||
ws['B' + str(rows)].alignment = c_c_alignment
|
||||
|
@ -335,32 +326,36 @@ def generate_excel(report,
|
|||
ws[col_maximum + str(rows)].number_format = '0.00'
|
||||
ws[col_maximum + str(rows)].border = f_border
|
||||
|
||||
# LineChart
|
||||
########################################################
|
||||
# third: LineChart
|
||||
# LineChart requires data from the detailed data table in the Excel file
|
||||
# so print the detailed data table first and then print LineChart
|
||||
########################################################
|
||||
for i in range(0, ca_len):
|
||||
lc = LineChart()
|
||||
lc.title = "报告期 最大负荷"
|
||||
lc.style = 10
|
||||
lc.x_axis.majorTickMark = 'in'
|
||||
lc.y_axis.majorTickMark = 'in'
|
||||
lc.smooth = True
|
||||
lc.x_axis.crosses = 'min'
|
||||
lc.height = 8.25
|
||||
lc.width = 24
|
||||
lc.dLbls = DataLabelList()
|
||||
lc.dLbls.dLblPos = 't'
|
||||
lc.dLbls.showVal = True
|
||||
times = Reference(ws, min_col=2, min_row=row_da + 2,
|
||||
max_row=row_da + 2 + time_len)
|
||||
lc_data = Reference(ws, min_col=2 + 2 * (i+1), min_row=row_da + 1,
|
||||
max_row=row_da + 1 + time_len)
|
||||
lc.add_data(lc_data, titles_from_data=True)
|
||||
lc.set_categories(times)
|
||||
ser = lc.series[0]
|
||||
line = LineChart()
|
||||
line.title = "报告期 最大负荷 - " + names[i] + "(" + reporting_period_data['units'][i] + ")"
|
||||
line.style = 10
|
||||
line.x_axis.majorTickMark = 'in'
|
||||
line.y_axis.majorTickMark = 'in'
|
||||
line.smooth = True
|
||||
line.x_axis.crosses = 'min'
|
||||
line.height = 8.25
|
||||
line.width = 24
|
||||
line.dLbls = DataLabelList()
|
||||
line.dLbls.dLblPos = 't'
|
||||
line.dLbls.showVal = True
|
||||
times = Reference(ws, min_col=2, min_row=detailed_start_row_number + 2,
|
||||
max_row=detailed_start_row_number + 2 + time_len)
|
||||
line_data = Reference(ws, min_col=2 + 2 * (i + 1), min_row=detailed_start_row_number + 1,
|
||||
max_row=detailed_start_row_number + 1 + time_len)
|
||||
line.add_data(line_data, titles_from_data=True)
|
||||
line.set_categories(times)
|
||||
ser = line.series[0]
|
||||
ser.marker.symbol = "diamond"
|
||||
ser.marker.size = 5
|
||||
chart_col = 'B'
|
||||
chart_cell = str(row_sat + 6 * i)
|
||||
ws.add_chart(lc, chart_col + chart_cell)
|
||||
chart_cell = str(analysis_end_row_number + 6 * i)
|
||||
ws.add_chart(line, chart_col + chart_cell)
|
||||
|
||||
filename = str(uuid.uuid4()) + '.xlsx'
|
||||
wb.save(filename)
|
||||
|
|
|
@ -240,136 +240,136 @@ def generate_excel(report,
|
|||
|
||||
current_row_number += 2
|
||||
|
||||
#####################################
|
||||
#####################################
|
||||
|
||||
has_values_data = True
|
||||
has_timestamps_data = True
|
||||
has_values_data = True
|
||||
has_timestamps_data = True
|
||||
|
||||
if 'values' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['values'] is None or \
|
||||
len(reporting_period_data['values']) == 0:
|
||||
has_values_data = False
|
||||
if 'values' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['values'] is None or \
|
||||
len(reporting_period_data['values']) == 0:
|
||||
has_values_data = False
|
||||
|
||||
if 'timestamps' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['timestamps'] is None or \
|
||||
len(reporting_period_data['timestamps']) == 0 or \
|
||||
len(reporting_period_data['timestamps'][0]) == 0:
|
||||
has_timestamps_data = False
|
||||
if 'timestamps' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['timestamps'] is None or \
|
||||
len(reporting_period_data['timestamps']) == 0 or \
|
||||
len(reporting_period_data['timestamps'][0]) == 0:
|
||||
has_timestamps_data = False
|
||||
|
||||
if has_values_data and has_timestamps_data:
|
||||
ca_len = len(reporting_period_data['names'])
|
||||
time = reporting_period_data['timestamps'][0]
|
||||
if has_values_data and has_timestamps_data:
|
||||
ca_len = len(reporting_period_data['names'])
|
||||
time = reporting_period_data['timestamps'][0]
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 详细数据'
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 详细数据'
|
||||
|
||||
current_row_number += 1
|
||||
current_row_number += 1
|
||||
|
||||
chart_start_row_number = current_row_number
|
||||
chart_start_row_number = current_row_number
|
||||
|
||||
current_row_number += ca_len * 6
|
||||
table_start_row_number = current_row_number
|
||||
current_row_number += ca_len * 6
|
||||
table_start_row_number = current_row_number
|
||||
|
||||
ws.row_dimensions[current_row_number].height = 60
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws.row_dimensions[current_row_number].height = 60
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '日期时间'
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
for i in range(0, len(time)):
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '日期时间'
|
||||
ws['B' + str(current_row_number)] = time[i]
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
for j in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['values'][j][i], 2) \
|
||||
if reporting_period_data['values'][j][i] is not None else 0.00
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
for i in range(0, len(time)):
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = time[i]
|
||||
table_end_row_number = current_row_number - 1
|
||||
|
||||
col = 'C'
|
||||
for j in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['values'][j][i], 2) \
|
||||
if reporting_period_data['values'][j][i] is not None else 0.00
|
||||
col = chr(ord(col) + 1)
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '小计'
|
||||
|
||||
current_row_number += 1
|
||||
col = 'C'
|
||||
|
||||
table_end_row_number = current_row_number - 1
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['subtotals'][i], 2)
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '小计'
|
||||
current_row_number += 2
|
||||
|
||||
col = 'C'
|
||||
format_time_width_number = 1.0
|
||||
min_len_number = 1.0
|
||||
min_width_number = 11.0 # format_time_width_number * min_len_number + 4 and min_width_number > 11.0
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['subtotals'][i], 2)
|
||||
col = chr(ord(col) + 1)
|
||||
if period_type == 'hourly':
|
||||
format_time_width_number = 4.0
|
||||
min_len_number = 2
|
||||
min_width_number = 12.0
|
||||
elif period_type == 'daily':
|
||||
format_time_width_number = 2.5
|
||||
min_len_number = 4
|
||||
min_width_number = 14.0
|
||||
elif period_type == 'monthly':
|
||||
format_time_width_number = 2.1
|
||||
min_len_number = 4
|
||||
min_width_number = 12.4
|
||||
elif period_type == 'yearly':
|
||||
format_time_width_number = 1.5
|
||||
min_len_number = 5
|
||||
min_width_number = 11.5
|
||||
|
||||
current_row_number += 2
|
||||
|
||||
format_time_width_number = 1.0
|
||||
min_len_number = 1.0
|
||||
min_width_number = 11.0 # format_time_width_number * min_len_number + 4 and min_width_number > 11.0
|
||||
|
||||
if period_type == 'hourly':
|
||||
format_time_width_number = 4.0
|
||||
min_len_number = 2
|
||||
min_width_number = 12.0
|
||||
elif period_type == 'daily':
|
||||
format_time_width_number = 2.5
|
||||
min_len_number = 4
|
||||
min_width_number = 14.0
|
||||
elif period_type == 'monthly':
|
||||
format_time_width_number = 2.1
|
||||
min_len_number = 4
|
||||
min_width_number = 12.4
|
||||
elif period_type == 'yearly':
|
||||
format_time_width_number = 1.5
|
||||
min_len_number = 5
|
||||
min_width_number = 11.5
|
||||
|
||||
for i in range(0, ca_len):
|
||||
line = LineChart()
|
||||
line.title = '报告期产出 - ' + \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
|
||||
line_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number, max_row=table_end_row_number)
|
||||
line.add_data(line_data, titles_from_data=True)
|
||||
line.set_categories(labels)
|
||||
line_data = line.series[0]
|
||||
line_data.marker.symbol = "circle"
|
||||
line_data.smooth = True
|
||||
line.x_axis.crosses = 'min'
|
||||
line.height = 8.25
|
||||
line.width = format_time_width_number * len(time) if len(time) > min_len_number else min_width_number
|
||||
if line.width > 24:
|
||||
line.width = 24
|
||||
line.dLbls = DataLabelList()
|
||||
line.dLbls.dLblPos = 't'
|
||||
line.dLbls.showVal = True
|
||||
line.dLbls.showPercent = False
|
||||
chart_col = 'B'
|
||||
chart_cell = chart_col + str(chart_start_row_number)
|
||||
chart_start_row_number += 6
|
||||
ws.add_chart(line, chart_cell)
|
||||
for i in range(0, ca_len):
|
||||
line = LineChart()
|
||||
line.title = '报告期产出 - ' + \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
|
||||
line_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number, max_row=table_end_row_number)
|
||||
line.add_data(line_data, titles_from_data=True)
|
||||
line.set_categories(labels)
|
||||
line_data = line.series[0]
|
||||
line_data.marker.symbol = "circle"
|
||||
line_data.smooth = True
|
||||
line.x_axis.crosses = 'min'
|
||||
line.height = 8.25
|
||||
line.width = format_time_width_number * len(time) if len(time) > min_len_number else min_width_number
|
||||
if line.width > 24:
|
||||
line.width = 24
|
||||
line.dLbls = DataLabelList()
|
||||
line.dLbls.dLblPos = 't'
|
||||
line.dLbls.showVal = True
|
||||
line.dLbls.showPercent = False
|
||||
chart_col = 'B'
|
||||
chart_cell = chart_col + str(chart_start_row_number)
|
||||
chart_start_row_number += 6
|
||||
ws.add_chart(line, chart_cell)
|
||||
|
||||
filename = str(uuid.uuid4()) + '.xlsx'
|
||||
wb.save(filename)
|
||||
|
|
|
@ -0,0 +1,414 @@
|
|||
import base64
|
||||
import uuid
|
||||
import os
|
||||
from openpyxl.chart import (
|
||||
LineChart,
|
||||
Reference,
|
||||
)
|
||||
from openpyxl.chart.label import DataLabelList
|
||||
from openpyxl.styles import PatternFill, Border, Side, Alignment, Font
|
||||
from openpyxl.drawing.image import Image
|
||||
from openpyxl import Workbook
|
||||
|
||||
|
||||
####################################################################################################################
|
||||
# PROCEDURES
|
||||
# Step 1: Validate the report data
|
||||
# Step 2: Generate excel file
|
||||
# Step 3: Encode the excel file bytes to Base64
|
||||
####################################################################################################################
|
||||
|
||||
|
||||
def export(report,
|
||||
name,
|
||||
reporting_start_datetime_local,
|
||||
reporting_end_datetime_local,
|
||||
period_type):
|
||||
####################################################################################################################
|
||||
# Step 1: Validate the report data
|
||||
####################################################################################################################
|
||||
if report is None:
|
||||
return None
|
||||
print(report)
|
||||
|
||||
####################################################################################################################
|
||||
# Step 2: Generate excel file from the report data
|
||||
####################################################################################################################
|
||||
filename = generate_excel(report,
|
||||
name,
|
||||
reporting_start_datetime_local,
|
||||
reporting_end_datetime_local,
|
||||
period_type)
|
||||
####################################################################################################################
|
||||
# Step 3: Encode the excel file to Base64
|
||||
####################################################################################################################
|
||||
try:
|
||||
with open(filename, 'rb') as binary_file:
|
||||
binary_file_data = binary_file.read()
|
||||
except IOError as ex:
|
||||
pass
|
||||
|
||||
# Base64 encode the bytes
|
||||
base64_encoded_data = base64.b64encode(binary_file_data)
|
||||
# get the Base64 encoded data using human-readable characters.
|
||||
base64_message = base64_encoded_data.decode('utf-8')
|
||||
# delete the file from server
|
||||
try:
|
||||
os.remove(filename)
|
||||
except NotImplementedError as ex:
|
||||
pass
|
||||
return base64_message
|
||||
|
||||
|
||||
def generate_excel(report,
|
||||
name,
|
||||
reporting_start_datetime_local,
|
||||
reporting_end_datetime_local,
|
||||
period_type):
|
||||
wb = Workbook()
|
||||
ws = wb.active
|
||||
|
||||
# Row height
|
||||
ws.row_dimensions[1].height = 102
|
||||
|
||||
for i in range(2, 2000 + 1):
|
||||
ws.row_dimensions[i].height = 42
|
||||
|
||||
# Col width
|
||||
ws.column_dimensions['A'].width = 1.5
|
||||
ws.column_dimensions['B'].width = 25.0
|
||||
|
||||
for i in range(ord('C'), ord('L')):
|
||||
ws.column_dimensions[chr(i)].width = 15.0
|
||||
|
||||
# Font
|
||||
name_font = Font(name='Constantia', size=15, bold=True)
|
||||
title_font = Font(name='宋体', size=15, bold=True)
|
||||
# data_font = Font(name='Franklin Gothic Book', size=11)
|
||||
|
||||
table_fill = PatternFill(fill_type='solid', fgColor='1F497D')
|
||||
f_border = Border(left=Side(border_style='medium', color='00000000'),
|
||||
right=Side(border_style='medium', color='00000000'),
|
||||
bottom=Side(border_style='medium', color='00000000'),
|
||||
top=Side(border_style='medium', color='00000000')
|
||||
)
|
||||
b_border = Border(
|
||||
bottom=Side(border_style='medium', color='00000000'),
|
||||
)
|
||||
|
||||
b_c_alignment = Alignment(vertical='bottom',
|
||||
horizontal='center',
|
||||
text_rotation=0,
|
||||
wrap_text=False,
|
||||
shrink_to_fit=False,
|
||||
indent=0)
|
||||
c_c_alignment = Alignment(vertical='center',
|
||||
horizontal='center',
|
||||
text_rotation=0,
|
||||
wrap_text=False,
|
||||
shrink_to_fit=False,
|
||||
indent=0)
|
||||
b_r_alignment = Alignment(vertical='bottom',
|
||||
horizontal='right',
|
||||
text_rotation=0,
|
||||
wrap_text=False,
|
||||
shrink_to_fit=False,
|
||||
indent=0)
|
||||
|
||||
# Img
|
||||
img = Image("excelexporters/myems.png")
|
||||
# img = Image("myems.png")
|
||||
img.width = img.width * 0.85
|
||||
img.height = img.height * 0.85
|
||||
ws.add_image(img, 'B1')
|
||||
|
||||
# Title
|
||||
ws['B3'].font = name_font
|
||||
ws['B3'].alignment = b_r_alignment
|
||||
ws['B3'] = 'Name:'
|
||||
ws['C3'].border = b_border
|
||||
ws['C3'].alignment = b_c_alignment
|
||||
ws['C3'].font = name_font
|
||||
ws['C3'] = name
|
||||
|
||||
ws['D3'].font = name_font
|
||||
ws['D3'].alignment = b_r_alignment
|
||||
ws['D3'] = 'Period:'
|
||||
ws['E3'].border = b_border
|
||||
ws['E3'].alignment = b_c_alignment
|
||||
ws['E3'].font = name_font
|
||||
ws['E3'] = period_type
|
||||
|
||||
ws['F3'].font = name_font
|
||||
ws['F3'].alignment = b_r_alignment
|
||||
ws['F3'] = 'Date:'
|
||||
ws['G3'].border = b_border
|
||||
ws['G3'].alignment = b_c_alignment
|
||||
ws['G3'].font = name_font
|
||||
ws['G3'] = reporting_start_datetime_local + "__" + reporting_end_datetime_local
|
||||
ws.merge_cells("G3:H3")
|
||||
|
||||
if "reporting_period" not in report.keys() or \
|
||||
"names" not in report['reporting_period'].keys() or len(report['reporting_period']['names']) == 0:
|
||||
filename = str(uuid.uuid4()) + '.xlsx'
|
||||
wb.save(filename)
|
||||
|
||||
return filename
|
||||
#################################################
|
||||
# First: 统计分析
|
||||
# 6: title
|
||||
# 7: table title
|
||||
# 8~ca_len table_data
|
||||
#################################################
|
||||
reporting_period_data = report['reporting_period']
|
||||
|
||||
has_energy_data_flag = True
|
||||
|
||||
if "names" not in reporting_period_data.keys() or \
|
||||
reporting_period_data['names'] is None or \
|
||||
len(reporting_period_data['names']) == 0:
|
||||
has_energy_data_flag = False
|
||||
|
||||
filename = str(uuid.uuid4()) + '.xlsx'
|
||||
wb.save(filename)
|
||||
|
||||
return filename
|
||||
|
||||
if has_energy_data_flag:
|
||||
ws['B6'].font = title_font
|
||||
ws['B6'] = name + ' 统计分析'
|
||||
|
||||
category = reporting_period_data['names']
|
||||
|
||||
# table_title
|
||||
ws['B7'].fill = table_fill
|
||||
ws['B7'].font = title_font
|
||||
ws['B7'].alignment = c_c_alignment
|
||||
ws['B7'] = '报告期'
|
||||
ws['B7'].border = f_border
|
||||
|
||||
ws['C7'].font = title_font
|
||||
ws['C7'].alignment = c_c_alignment
|
||||
ws['C7'] = '算术平均数'
|
||||
ws['C7'].border = f_border
|
||||
|
||||
ws['D7'].font = title_font
|
||||
ws['D7'].alignment = c_c_alignment
|
||||
ws['D7'] = '中位数'
|
||||
ws['D7'].border = f_border
|
||||
|
||||
ws['E7'].font = title_font
|
||||
ws['E7'].alignment = c_c_alignment
|
||||
ws['E7'] = '最小值'
|
||||
ws['E7'].border = f_border
|
||||
|
||||
ws['F7'].font = title_font
|
||||
ws['F7'].alignment = c_c_alignment
|
||||
ws['F7'] = '最大值'
|
||||
ws['F7'].border = f_border
|
||||
|
||||
ws['G7'].font = title_font
|
||||
ws['G7'].alignment = c_c_alignment
|
||||
ws['G7'] = '样本标准差'
|
||||
ws['G7'].border = f_border
|
||||
|
||||
ws['H7'].font = title_font
|
||||
ws['H7'].alignment = c_c_alignment
|
||||
ws['H7'] = '样本方差'
|
||||
ws['H7'].border = f_border
|
||||
|
||||
# table_data
|
||||
|
||||
for i, value in enumerate(category):
|
||||
row = i * 2 + 8
|
||||
ws['B' + str(row)].font = name_font
|
||||
ws['B' + str(row)].alignment = c_c_alignment
|
||||
ws['B' + str(row)] = reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + " )"
|
||||
ws['B' + str(row)].border = f_border
|
||||
|
||||
ws['B' + str(row + 1)].font = name_font
|
||||
ws['B' + str(row + 1)].alignment = c_c_alignment
|
||||
ws['B' + str(row + 1)] = "环比"
|
||||
ws['B' + str(row + 1)].border = f_border
|
||||
|
||||
ws['C' + str(row)].font = name_font
|
||||
ws['C' + str(row)].alignment = c_c_alignment
|
||||
ws['C' + str(row)] = reporting_period_data['means'][i] \
|
||||
if reporting_period_data['means'][i] is not None else ''
|
||||
ws['C' + str(row)].border = f_border
|
||||
ws['C' + str(row)].number_format = '0.00'
|
||||
|
||||
ws['C' + str(row + 1)].font = name_font
|
||||
ws['C' + str(row + 1)].alignment = c_c_alignment
|
||||
ws['C' + str(row + 1)] = str(round(reporting_period_data['means_increment_rate'][i] * 100, 2)) + "%" \
|
||||
if reporting_period_data['means_increment_rate'][i] is not None else '0.00%'
|
||||
ws['C' + str(row + 1)].border = f_border
|
||||
|
||||
ws['D' + str(row)].font = name_font
|
||||
ws['D' + str(row)].alignment = c_c_alignment
|
||||
ws['D' + str(row)] = reporting_period_data['medians'][i] \
|
||||
if reporting_period_data['medians'][i] is not None else ''
|
||||
ws['D' + str(row)].border = f_border
|
||||
ws['D' + str(row)].number_format = '0.00'
|
||||
|
||||
ws['D' + str(row + 1)].font = name_font
|
||||
ws['D' + str(row + 1)].alignment = c_c_alignment
|
||||
ws['D' + str(row + 1)] = str(round(reporting_period_data['medians_increment_rate'][i] * 100, 2)) + "%" \
|
||||
if reporting_period_data['medians_increment_rate'][i] is not None else '0.00%'
|
||||
ws['D' + str(row + 1)].border = f_border
|
||||
|
||||
ws['E' + str(row)].font = name_font
|
||||
ws['E' + str(row)].alignment = c_c_alignment
|
||||
ws['E' + str(row)] = reporting_period_data['minimums'][i] \
|
||||
if reporting_period_data['minimums'][i] is not None else ''
|
||||
ws['E' + str(row)].border = f_border
|
||||
ws['E' + str(row)].number_format = '0.00'
|
||||
|
||||
ws['E' + str(row + 1)].font = name_font
|
||||
ws['E' + str(row + 1)].alignment = c_c_alignment
|
||||
ws['E' + str(row + 1)] = str(round(reporting_period_data['minimums_increment_rate'][i] * 100, 2)) + "%" \
|
||||
if reporting_period_data['minimums_increment_rate'][i] is not None else '0.00%'
|
||||
ws['E' + str(row + 1)].border = f_border
|
||||
|
||||
ws['F' + str(row)].font = name_font
|
||||
ws['F' + str(row)].alignment = c_c_alignment
|
||||
ws['F' + str(row)] = reporting_period_data['maximums'][i] \
|
||||
if reporting_period_data['maximums'][i] is not None else ''
|
||||
ws['F' + str(row)].border = f_border
|
||||
ws['F' + str(row)].number_format = '0.00'
|
||||
|
||||
ws['F' + str(row + 1)].font = name_font
|
||||
ws['F' + str(row + 1)].alignment = c_c_alignment
|
||||
ws['F' + str(row + 1)] = str(round(reporting_period_data['maximums_increment_rate'][i] * 100, 2)) + "%" \
|
||||
if reporting_period_data['maximums_increment_rate'][i] is not None else '0.00%'
|
||||
ws['F' + str(row + 1)].border = f_border
|
||||
|
||||
ws['G' + str(row)].font = name_font
|
||||
ws['G' + str(row)].alignment = c_c_alignment
|
||||
ws['G' + str(row)] = reporting_period_data['stdevs'][i] \
|
||||
if reporting_period_data['stdevs'][i] is not None else ''
|
||||
ws['G' + str(row)].border = f_border
|
||||
ws['G' + str(row)].number_format = '0.00'
|
||||
|
||||
ws['G' + str(row + 1)].font = name_font
|
||||
ws['G' + str(row + 1)].alignment = c_c_alignment
|
||||
ws['G' + str(row + 1)] = str(round(reporting_period_data['stdevs_increment_rate'][i] * 100, 2)) + "%" \
|
||||
if reporting_period_data['stdevs_increment_rate'][i] is not None else '0.00%'
|
||||
ws['G' + str(row + 1)].border = f_border
|
||||
|
||||
ws['H' + str(row)].font = name_font
|
||||
ws['H' + str(row)].alignment = c_c_alignment
|
||||
ws['H' + str(row)] = reporting_period_data['variances'][i] \
|
||||
if reporting_period_data['variances'][i] is not None else ''
|
||||
ws['H' + str(row)].border = f_border
|
||||
ws['H' + str(row)].number_format = '0.00'
|
||||
|
||||
ws['H' + str(row + 1)].font = name_font
|
||||
ws['H' + str(row + 1)].alignment = c_c_alignment
|
||||
ws['H' + str(row + 1)] = str(round(reporting_period_data['variances_increment_rate'][i] * 100, 2)) + "%" \
|
||||
if reporting_period_data['variances_increment_rate'][i] is not None else '0.00%'
|
||||
ws['H' + str(row + 1)].border = f_border
|
||||
|
||||
########################################################
|
||||
# Second: 详细数据
|
||||
# analysis_end_row_number+1~ analysis_end_row_number+1+line_charts_row_number+: line
|
||||
# detailed_start_row_number~ : the detailed data table
|
||||
########################################################
|
||||
has_timestamps_flag = True
|
||||
if "timestamps" not in reporting_period_data.keys() or \
|
||||
reporting_period_data['timestamps'] is None or \
|
||||
len(reporting_period_data['timestamps']) == 0:
|
||||
has_timestamps_flag = False
|
||||
|
||||
if has_timestamps_flag:
|
||||
timestamps = reporting_period_data['timestamps'][0]
|
||||
values = reporting_period_data['values']
|
||||
names = reporting_period_data['names']
|
||||
ca_len = len(names)
|
||||
time_len = len(timestamps)
|
||||
# the detailed title
|
||||
line_charts_row_number = 6 * ca_len + 1
|
||||
analysis_end_row_number = 9 + 2 * ca_len
|
||||
detailed_start_row_number = analysis_end_row_number + line_charts_row_number
|
||||
|
||||
ws['B' + str(detailed_start_row_number)].font = title_font
|
||||
ws['B' + str(detailed_start_row_number)] = name + ' 详细数据'
|
||||
# the detailed table_title
|
||||
ws['B' + str(detailed_start_row_number + 1)].fill = table_fill
|
||||
ws['B' + str(detailed_start_row_number + 1)].font = name_font
|
||||
ws['B' + str(detailed_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['B' + str(detailed_start_row_number + 1)] = "时间"
|
||||
ws['B' + str(detailed_start_row_number + 1)].border = f_border
|
||||
|
||||
for i in range(0, ca_len):
|
||||
col = chr(ord('C') + i)
|
||||
|
||||
ws[col + str(detailed_start_row_number + 1)].font = name_font
|
||||
ws[col + str(detailed_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws[col + str(detailed_start_row_number + 1)] = names[i] + " - (" + reporting_period_data['units'][i] + ")"
|
||||
ws[col + str(detailed_start_row_number + 1)].border = f_border
|
||||
# the detailed table_date
|
||||
for i in range(0, time_len):
|
||||
rows = i + detailed_start_row_number + 2
|
||||
|
||||
ws['B' + str(rows)].font = name_font
|
||||
ws['B' + str(rows)].alignment = c_c_alignment
|
||||
ws['B' + str(rows)] = timestamps[i]
|
||||
ws['B' + str(rows)].border = f_border
|
||||
|
||||
for index in range(0, ca_len):
|
||||
col = chr(ord('C') + index)
|
||||
|
||||
ws[col + str(rows)].font = name_font
|
||||
ws[col + str(rows)].alignment = c_c_alignment
|
||||
ws[col + str(rows)] = values[index][i]
|
||||
ws[col + str(rows)].number_format = '0.00'
|
||||
ws[col + str(rows)].border = f_border
|
||||
|
||||
# 小计
|
||||
row_subtotals = detailed_start_row_number + 2 + time_len
|
||||
ws['B' + str(row_subtotals)].font = name_font
|
||||
ws['B' + str(row_subtotals)].alignment = c_c_alignment
|
||||
ws['B' + str(row_subtotals)] = "小计"
|
||||
ws['B' + str(row_subtotals)].border = f_border
|
||||
|
||||
for i in range(0, ca_len):
|
||||
col = chr(ord('C') + i)
|
||||
|
||||
ws[col + str(row_subtotals)].font = name_font
|
||||
ws[col + str(row_subtotals)].alignment = c_c_alignment
|
||||
ws[col + str(row_subtotals)] = reporting_period_data['subtotals'][i]
|
||||
ws[col + str(row_subtotals)].border = f_border
|
||||
ws[col + str(row_subtotals)].number_format = '0.00'
|
||||
|
||||
########################################################
|
||||
# third: LineChart
|
||||
# LineChart requires data from the detailed data table in the Excel file
|
||||
# so print the detailed data table first and then print LineChart
|
||||
########################################################
|
||||
for i in range(0, ca_len):
|
||||
line = LineChart()
|
||||
line.title = "报告期消耗" + " - " + names[i] + "(" + reporting_period_data['units'][i] + ")"
|
||||
line.style = 10
|
||||
line.height = 8.40 # cm 1.05*8 1.05cm = 30 pt
|
||||
line.width = 24
|
||||
line.x_axis.majorTickMark = 'in'
|
||||
line.y_axis.majorTickMark = 'in'
|
||||
line.dLbls = DataLabelList()
|
||||
line.dLbls.dLblPos = 't'
|
||||
line.dLbls.showVal = True
|
||||
times = Reference(ws, min_col=2, min_row=detailed_start_row_number + 2,
|
||||
max_row=detailed_start_row_number + 2 + time_len)
|
||||
line_data = Reference(ws, min_col=3 + i, min_row=detailed_start_row_number + 1,
|
||||
max_row=detailed_start_row_number + 1 + time_len)
|
||||
line.add_data(line_data, titles_from_data=True)
|
||||
line.set_categories(times)
|
||||
ser = line.series[0]
|
||||
ser.marker.symbol = "diamond"
|
||||
ser.marker.size = 5
|
||||
ws.add_chart(line, 'B' + str(analysis_end_row_number + 6 * i))
|
||||
|
||||
filename = str(uuid.uuid4()) + '.xlsx'
|
||||
wb.save(filename)
|
||||
|
||||
return filename
|
|
@ -0,0 +1,603 @@
|
|||
import base64
|
||||
import uuid
|
||||
import os
|
||||
from openpyxl.chart import (
|
||||
PieChart,
|
||||
LineChart,
|
||||
BarChart,
|
||||
Reference,
|
||||
)
|
||||
from openpyxl.styles import PatternFill, Border, Side, Alignment, Font
|
||||
from openpyxl.drawing.image import Image
|
||||
from openpyxl import Workbook
|
||||
from openpyxl.chart.label import DataLabelList
|
||||
import openpyxl.utils.cell as format_cell
|
||||
|
||||
|
||||
####################################################################################################################
|
||||
# PROCEDURES
|
||||
# Step 1: Validate the report data
|
||||
# Step 2: Generate excel file
|
||||
# Step 3: Encode the excel file bytes to Base64
|
||||
####################################################################################################################
|
||||
|
||||
|
||||
def export(report,
|
||||
name,
|
||||
reporting_start_datetime_local,
|
||||
reporting_end_datetime_local,
|
||||
period_type):
|
||||
####################################################################################################################
|
||||
# Step 1: Validate the report data
|
||||
####################################################################################################################
|
||||
if report is None:
|
||||
return None
|
||||
print(report)
|
||||
|
||||
####################################################################################################################
|
||||
# Step 2: Generate excel file from the report data
|
||||
####################################################################################################################
|
||||
filename = generate_excel(report,
|
||||
name,
|
||||
reporting_start_datetime_local,
|
||||
reporting_end_datetime_local,
|
||||
period_type)
|
||||
####################################################################################################################
|
||||
# Step 3: Encode the excel file to Base64
|
||||
####################################################################################################################
|
||||
try:
|
||||
with open(filename, 'rb') as binary_file:
|
||||
binary_file_data = binary_file.read()
|
||||
except IOError as ex:
|
||||
pass
|
||||
|
||||
# Base64 encode the bytes
|
||||
base64_encoded_data = base64.b64encode(binary_file_data)
|
||||
# get the Base64 encoded data using human-readable characters.
|
||||
base64_message = base64_encoded_data.decode('utf-8')
|
||||
# delete the file from server
|
||||
try:
|
||||
os.remove(filename)
|
||||
except NotImplementedError as ex:
|
||||
pass
|
||||
return base64_message
|
||||
|
||||
|
||||
def generate_excel(report,
|
||||
name,
|
||||
reporting_start_datetime_local,
|
||||
reporting_end_datetime_local,
|
||||
period_type):
|
||||
wb = Workbook()
|
||||
ws = wb.active
|
||||
|
||||
# Row height
|
||||
ws.row_dimensions[1].height = 102
|
||||
for i in range(2, 2000 + 1):
|
||||
ws.row_dimensions[i].height = 42
|
||||
|
||||
# Col width
|
||||
ws.column_dimensions['A'].width = 1.5
|
||||
|
||||
ws.column_dimensions['B'].width = 25.0
|
||||
|
||||
for i in range(ord('C'), ord('L')):
|
||||
ws.column_dimensions[chr(i)].width = 15.0
|
||||
|
||||
# Font
|
||||
name_font = Font(name='Constantia', size=15, bold=True)
|
||||
title_font = Font(name='宋体', size=15, bold=True)
|
||||
data_font = Font(name='Franklin Gothic Book', size=11)
|
||||
|
||||
table_fill = PatternFill(fill_type='solid', fgColor='1F497D')
|
||||
f_border = Border(left=Side(border_style='medium', color='00000000'),
|
||||
right=Side(border_style='medium', color='00000000'),
|
||||
bottom=Side(border_style='medium', color='00000000'),
|
||||
top=Side(border_style='medium', color='00000000')
|
||||
)
|
||||
b_border = Border(
|
||||
bottom=Side(border_style='medium', color='00000000'),
|
||||
)
|
||||
|
||||
b_c_alignment = Alignment(vertical='bottom',
|
||||
horizontal='center',
|
||||
text_rotation=0,
|
||||
wrap_text=True,
|
||||
shrink_to_fit=False,
|
||||
indent=0)
|
||||
c_c_alignment = Alignment(vertical='center',
|
||||
horizontal='center',
|
||||
text_rotation=0,
|
||||
wrap_text=True,
|
||||
shrink_to_fit=False,
|
||||
indent=0)
|
||||
b_r_alignment = Alignment(vertical='bottom',
|
||||
horizontal='right',
|
||||
text_rotation=0,
|
||||
wrap_text=True,
|
||||
shrink_to_fit=False,
|
||||
indent=0)
|
||||
c_r_alignment = Alignment(vertical='bottom',
|
||||
horizontal='center',
|
||||
text_rotation=0,
|
||||
wrap_text=True,
|
||||
shrink_to_fit=False,
|
||||
indent=0)
|
||||
# Img
|
||||
img = Image("excelexporters/myems.png")
|
||||
img.width = img.width * 0.85
|
||||
img.height = img.height * 0.85
|
||||
# img = Image("myems.png")
|
||||
ws.add_image(img, 'B1')
|
||||
|
||||
# Title
|
||||
ws.row_dimensions[3].height = 60
|
||||
|
||||
ws['B3'].font = name_font
|
||||
ws['B3'].alignment = b_r_alignment
|
||||
ws['B3'] = 'Name:'
|
||||
ws['C3'].border = b_border
|
||||
ws['C3'].alignment = b_c_alignment
|
||||
ws['C3'].font = name_font
|
||||
ws['C3'] = name
|
||||
|
||||
ws['D3'].font = name_font
|
||||
ws['D3'].alignment = b_r_alignment
|
||||
ws['D3'] = 'Period:'
|
||||
ws['E3'].border = b_border
|
||||
ws['E3'].alignment = b_c_alignment
|
||||
ws['E3'].font = name_font
|
||||
ws['E3'] = period_type
|
||||
|
||||
ws['F3'].font = name_font
|
||||
ws['F3'].alignment = b_r_alignment
|
||||
ws['F3'] = 'Date:'
|
||||
ws['G3'].border = b_border
|
||||
ws['G3'].alignment = b_c_alignment
|
||||
ws['G3'].font = name_font
|
||||
ws['G3'] = reporting_start_datetime_local + "__" + reporting_end_datetime_local
|
||||
ws.merge_cells("G3:H3")
|
||||
|
||||
if "reporting_period_efficiency" not in report.keys() or \
|
||||
"names" not in report['reporting_period_efficiency'].keys() or len(
|
||||
report['reporting_period_efficiency']['names']) == 0:
|
||||
filename = str(uuid.uuid4()) + '.xlsx'
|
||||
wb.save(filename)
|
||||
|
||||
return filename
|
||||
|
||||
##################################
|
||||
|
||||
current_row_number = 6
|
||||
|
||||
reporting_period_data = report['reporting_period_efficiency']
|
||||
|
||||
has_names_data_flag = True
|
||||
|
||||
if "names" not in reporting_period_data.keys() or \
|
||||
reporting_period_data['names'] is None or \
|
||||
len(reporting_period_data['names']) == 0:
|
||||
has_names_data_flag = False
|
||||
|
||||
if has_names_data_flag:
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 报告期累积效率'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
category = reporting_period_data['names']
|
||||
ca_len = len(category)
|
||||
|
||||
ws.row_dimensions[current_row_number].height = 80
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '累积效率'
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['cumulations'][i], 2)
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '环比'
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = str(
|
||||
round(reporting_period_data['increment_rates'][i] * 100, 2)) + '%' \
|
||||
if reporting_period_data['increment_rates'][i] is not None else '-'
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 2
|
||||
|
||||
#####################################
|
||||
|
||||
has_parameters_names_and_timestamps_and_values_data = True
|
||||
current_sheet_parameters_row_number = current_row_number
|
||||
|
||||
if 'parameters' not in report.keys() or \
|
||||
report['parameters'] is None or \
|
||||
'names' not in report['parameters'].keys() or \
|
||||
report['parameters']['names'] is None or \
|
||||
len(report['parameters']['names']) == 0 or \
|
||||
'timestamps' not in report['parameters'].keys() or \
|
||||
report['parameters']['timestamps'] is None or \
|
||||
len(report['parameters']['timestamps']) == 0 or \
|
||||
'values' not in report['parameters'].keys() or \
|
||||
report['parameters']['values'] is None or \
|
||||
len(report['parameters']['values']) == 0 or \
|
||||
timestamps_data_all_equal_0(report['parameters']['timestamps']):
|
||||
|
||||
has_parameters_names_and_timestamps_and_values_data = False
|
||||
|
||||
#####################################
|
||||
|
||||
has_values_data = True
|
||||
has_timestamps_data = True
|
||||
|
||||
if 'values' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['values'] is None or \
|
||||
len(reporting_period_data['values']) == 0:
|
||||
has_values_data = False
|
||||
|
||||
if 'timestamps' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['timestamps'] is None or \
|
||||
len(reporting_period_data['timestamps']) == 0 or \
|
||||
len(reporting_period_data['timestamps'][0]) == 0:
|
||||
has_timestamps_data = False
|
||||
|
||||
if has_values_data and has_timestamps_data:
|
||||
ca_len = len(reporting_period_data['names'])
|
||||
time = reporting_period_data['timestamps'][0]
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 报告期累积效率'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
chart_start_row_number = current_row_number
|
||||
|
||||
current_row_number += ca_len * 6 + 1
|
||||
|
||||
if has_parameters_names_and_timestamps_and_values_data:
|
||||
current_sheet_parameters_row_number = current_row_number
|
||||
real_timestamps_len = timestamps_data_not_equal_0(report['parameters']['timestamps'])
|
||||
current_row_number += 6*real_timestamps_len + 2
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 详细数据'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
table_start_row_number = current_row_number
|
||||
|
||||
ws.row_dimensions[current_row_number].height = 85
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '日期时间'
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
for i in range(0, len(time)):
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = time[i]
|
||||
|
||||
col = 'C'
|
||||
for j in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['values'][j][i], 2) \
|
||||
if reporting_period_data['values'][j][i] is not None else 0.00
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
table_end_row_number = current_row_number - 1
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '小计'
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['cumulations'][i], 2)
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 2
|
||||
|
||||
format_time_width_number = 1.0
|
||||
min_len_number = 1.0
|
||||
min_width_number = 11.0 # format_time_width_number * min_len_number + 4 and min_width_number > 11.0
|
||||
|
||||
if period_type == 'hourly':
|
||||
format_time_width_number = 4.0
|
||||
min_len_number = 2
|
||||
min_width_number = 12.0
|
||||
elif period_type == 'daily':
|
||||
format_time_width_number = 2.5
|
||||
min_len_number = 4
|
||||
min_width_number = 14.0
|
||||
elif period_type == 'monthly':
|
||||
format_time_width_number = 2.1
|
||||
min_len_number = 4
|
||||
min_width_number = 12.4
|
||||
elif period_type == 'yearly':
|
||||
format_time_width_number = 1.5
|
||||
min_len_number = 5
|
||||
min_width_number = 11.5
|
||||
|
||||
for i in range(0, ca_len):
|
||||
line = LineChart()
|
||||
line.title = '报告期累积效率 - ' + \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
|
||||
line_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number, max_row=table_end_row_number)
|
||||
line.add_data(line_data, titles_from_data=True)
|
||||
line.set_categories(labels)
|
||||
line_data = line.series[0]
|
||||
line_data.marker.symbol = "circle"
|
||||
line_data.smooth = True
|
||||
line.x_axis.crosses = 'min'
|
||||
line.height = 8.25
|
||||
line.width = format_time_width_number * len(time) if len(time) > min_len_number else min_width_number
|
||||
if line.width > 24:
|
||||
line.width = 24
|
||||
line.dLbls = DataLabelList()
|
||||
line.dLbls.dLblPos = 't'
|
||||
line.dLbls.showVal = True
|
||||
line.dLbls.showPercent = False
|
||||
chart_col = 'B'
|
||||
chart_cell = chart_col + str(chart_start_row_number)
|
||||
chart_start_row_number += 6
|
||||
ws.add_chart(line, chart_cell)
|
||||
|
||||
#####################################################################
|
||||
|
||||
if has_parameters_names_and_timestamps_and_values_data:
|
||||
|
||||
###############################
|
||||
# new worksheet
|
||||
###############################
|
||||
|
||||
parameters_data = report['parameters']
|
||||
parameters_names_len = len(parameters_data['names'])
|
||||
|
||||
parameters_ws = wb.create_sheet('相关参数')
|
||||
|
||||
parameters_timestamps_data_max_len = \
|
||||
get_parameters_timestamps_lists_max_len(list(parameters_data['timestamps']))
|
||||
|
||||
# Row height
|
||||
parameters_ws.row_dimensions[1].height = 102
|
||||
for i in range(2, 7 + 1):
|
||||
parameters_ws.row_dimensions[i].height = 42
|
||||
|
||||
for i in range(8, parameters_timestamps_data_max_len + 10):
|
||||
parameters_ws.row_dimensions[i].height = 60
|
||||
|
||||
# Col width
|
||||
parameters_ws.column_dimensions['A'].width = 1.5
|
||||
|
||||
parameters_ws.column_dimensions['B'].width = 25.0
|
||||
|
||||
for i in range(3, 12+parameters_names_len*3):
|
||||
parameters_ws.column_dimensions[format_cell.get_column_letter(i)].width = 15.0
|
||||
|
||||
# Img
|
||||
img = Image("excelexporters/myems.png")
|
||||
img.width = img.width * 0.85
|
||||
img.height = img.height * 0.85
|
||||
# img = Image("myems.png")
|
||||
parameters_ws.add_image(img, 'B1')
|
||||
|
||||
# Title
|
||||
parameters_ws.row_dimensions[3].height = 60
|
||||
|
||||
parameters_ws['B3'].font = name_font
|
||||
parameters_ws['B3'].alignment = b_r_alignment
|
||||
parameters_ws['B3'] = 'Name:'
|
||||
parameters_ws['C3'].border = b_border
|
||||
parameters_ws['C3'].alignment = b_c_alignment
|
||||
parameters_ws['C3'].font = name_font
|
||||
parameters_ws['C3'] = name
|
||||
|
||||
parameters_ws['D3'].font = name_font
|
||||
parameters_ws['D3'].alignment = b_r_alignment
|
||||
parameters_ws['D3'] = 'Period:'
|
||||
parameters_ws['E3'].border = b_border
|
||||
parameters_ws['E3'].alignment = b_c_alignment
|
||||
parameters_ws['E3'].font = name_font
|
||||
parameters_ws['E3'] = period_type
|
||||
|
||||
parameters_ws['F3'].font = name_font
|
||||
parameters_ws['F3'].alignment = b_r_alignment
|
||||
parameters_ws['F3'] = 'Date:'
|
||||
parameters_ws['G3'].border = b_border
|
||||
parameters_ws['G3'].alignment = b_c_alignment
|
||||
parameters_ws['G3'].font = name_font
|
||||
parameters_ws['G3'] = reporting_start_datetime_local + "__" + reporting_end_datetime_local
|
||||
parameters_ws.merge_cells("G3:H3")
|
||||
|
||||
parameters_ws_current_row_number = 6
|
||||
|
||||
parameters_ws['B' + str(parameters_ws_current_row_number)].font = title_font
|
||||
parameters_ws['B' + str(parameters_ws_current_row_number)] = name + ' 相关参数'
|
||||
|
||||
parameters_ws_current_row_number += 1
|
||||
|
||||
parameters_table_start_row_number = parameters_ws_current_row_number
|
||||
|
||||
parameters_ws.row_dimensions[parameters_ws_current_row_number].height = 80
|
||||
|
||||
parameters_ws_current_row_number += 1
|
||||
|
||||
table_current_col_number = 'B'
|
||||
|
||||
for i in range(0, parameters_names_len):
|
||||
|
||||
if len(parameters_data['timestamps'][i]) == 0:
|
||||
continue
|
||||
|
||||
parameters_ws[table_current_col_number + str(parameters_ws_current_row_number-1)].fill = table_fill
|
||||
parameters_ws[table_current_col_number + str(parameters_ws_current_row_number-1)].border = f_border
|
||||
|
||||
col = chr(ord(table_current_col_number) + 1)
|
||||
|
||||
parameters_ws[col + str(parameters_ws_current_row_number-1)].fill = table_fill
|
||||
parameters_ws[col + str(parameters_ws_current_row_number-1)].border = f_border
|
||||
parameters_ws[col + str(parameters_ws_current_row_number-1)].font = name_font
|
||||
parameters_ws[col + str(parameters_ws_current_row_number-1)].alignment = c_c_alignment
|
||||
parameters_ws[col + str(parameters_ws_current_row_number-1)] = parameters_data['names'][i]
|
||||
|
||||
table_current_row_number = parameters_ws_current_row_number
|
||||
|
||||
for j, value in enumerate(list(parameters_data['timestamps'][i])):
|
||||
col = table_current_col_number
|
||||
|
||||
parameters_ws[col + str(table_current_row_number)].border = f_border
|
||||
parameters_ws[col + str(table_current_row_number)].font = title_font
|
||||
parameters_ws[col + str(table_current_row_number)].alignment = c_c_alignment
|
||||
parameters_ws[col + str(table_current_row_number)] = value
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
parameters_ws[col + str(table_current_row_number)].border = f_border
|
||||
parameters_ws[col + str(table_current_row_number)].font = title_font
|
||||
parameters_ws[col + str(table_current_row_number)].alignment = c_c_alignment
|
||||
parameters_ws[col + str(table_current_row_number)] = round(parameters_data['values'][i][j], 2)
|
||||
|
||||
table_current_row_number += 1
|
||||
|
||||
table_current_col_number = chr(ord(table_current_col_number) + 3)
|
||||
|
||||
########################################################
|
||||
# parameters chart and parameters table
|
||||
########################################################
|
||||
|
||||
ws['B' + str(current_sheet_parameters_row_number)].font = title_font
|
||||
ws['B' + str(current_sheet_parameters_row_number)] = name + ' 相关参数'
|
||||
|
||||
current_sheet_parameters_row_number += 1
|
||||
|
||||
chart_start_row_number = current_sheet_parameters_row_number
|
||||
|
||||
col_index = 0
|
||||
|
||||
for i in range(0, parameters_names_len):
|
||||
|
||||
if len(parameters_data['timestamps'][i]) == 0:
|
||||
continue
|
||||
|
||||
line = LineChart()
|
||||
data_col = 3+col_index*3
|
||||
labels_col = 2+col_index*3
|
||||
col_index += 1
|
||||
line.title = '相关参数 - ' + \
|
||||
parameters_ws.cell(row=parameters_table_start_row_number, column=data_col).value
|
||||
labels = Reference(parameters_ws, min_col=labels_col, min_row=parameters_table_start_row_number + 1,
|
||||
max_row=(len(parameters_data['timestamps'][i])+parameters_table_start_row_number))
|
||||
line_data = Reference(parameters_ws, min_col=data_col, min_row=parameters_table_start_row_number,
|
||||
max_row=(len(parameters_data['timestamps'][i])+parameters_table_start_row_number))
|
||||
line.add_data(line_data, titles_from_data=True)
|
||||
line.set_categories(labels)
|
||||
line_data = line.series[0]
|
||||
line_data.marker.symbol = "circle"
|
||||
line_data.smooth = True
|
||||
line.x_axis.crosses = 'min'
|
||||
line.height = 8.25
|
||||
line.width = 24
|
||||
line.dLbls = DataLabelList()
|
||||
line.dLbls.dLblPos = 't'
|
||||
line.dLbls.showVal = False
|
||||
line.dLbls.showPercent = False
|
||||
chart_col = 'B'
|
||||
chart_cell = chart_col + str(chart_start_row_number)
|
||||
chart_start_row_number += 6
|
||||
ws.add_chart(line, chart_cell)
|
||||
|
||||
current_sheet_parameters_row_number = chart_start_row_number
|
||||
|
||||
current_sheet_parameters_row_number += 1
|
||||
|
||||
filename = str(uuid.uuid4()) + '.xlsx'
|
||||
wb.save(filename)
|
||||
|
||||
return filename
|
||||
|
||||
|
||||
def get_parameters_timestamps_lists_max_len(parameters_timestamps_lists):
|
||||
max_len = 0
|
||||
for i, value in enumerate(list(parameters_timestamps_lists)):
|
||||
if len(value) > max_len:
|
||||
max_len = len(value)
|
||||
|
||||
return max_len
|
||||
|
||||
|
||||
def timestamps_data_all_equal_0(lists):
|
||||
for i, value in enumerate(list(lists)):
|
||||
if len(value) > 0:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def timestamps_data_not_equal_0(lists):
|
||||
number = 0
|
||||
for i, value in enumerate(list(lists)):
|
||||
if len(value) > 0:
|
||||
number += 1
|
||||
return number
|
|
@ -222,23 +222,6 @@ def generate_excel(report,
|
|||
|
||||
current_row_number += 1
|
||||
|
||||
# ws['B' + str(current_row_number)].font = title_font
|
||||
# ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
# ws['B' + str(current_row_number)].border = f_border
|
||||
# ws['B' + str(current_row_number)] = '单位面积值'
|
||||
#
|
||||
# col = 'C'
|
||||
#
|
||||
# for i in range(0, ca_len):
|
||||
# ws[col + str(current_row_number)].font = name_font
|
||||
# ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
# ws[col + str(current_row_number)].border = f_border
|
||||
# ws[col + str(current_row_number)] = round(reporting_period_data['subtotals_per_unit_area'][i], 2)
|
||||
#
|
||||
# col = chr(ord(col) + 1)
|
||||
#
|
||||
# current_row_number += 1
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
|
@ -318,136 +301,136 @@ def generate_excel(report,
|
|||
|
||||
current_row_number += 1
|
||||
|
||||
####################################
|
||||
####################################
|
||||
|
||||
has_values_data = True
|
||||
has_timestamps_data = True
|
||||
has_values_data = True
|
||||
has_timestamps_data = True
|
||||
|
||||
if 'values' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['values'] is None or \
|
||||
len(reporting_period_data['values']) == 0:
|
||||
has_values_data = False
|
||||
if 'values' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['values'] is None or \
|
||||
len(reporting_period_data['values']) == 0:
|
||||
has_values_data = False
|
||||
|
||||
if 'timestamps' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['timestamps'] is None or \
|
||||
len(reporting_period_data['timestamps']) == 0 or \
|
||||
len(reporting_period_data['timestamps'][0]) == 0:
|
||||
has_timestamps_data = False
|
||||
if 'timestamps' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['timestamps'] is None or \
|
||||
len(reporting_period_data['timestamps']) == 0 or \
|
||||
len(reporting_period_data['timestamps'][0]) == 0:
|
||||
has_timestamps_data = False
|
||||
|
||||
if has_values_data and has_timestamps_data:
|
||||
ca_len = len(reporting_period_data['names'])
|
||||
time = reporting_period_data['timestamps'][0]
|
||||
if has_values_data and has_timestamps_data:
|
||||
ca_len = len(reporting_period_data['names'])
|
||||
time = reporting_period_data['timestamps'][0]
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 详细数据'
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 详细数据'
|
||||
|
||||
current_row_number += 1
|
||||
current_row_number += 1
|
||||
|
||||
chart_start_row_number = current_row_number
|
||||
chart_start_row_number = current_row_number
|
||||
|
||||
current_row_number += ca_len * 6
|
||||
table_start_row_number = current_row_number
|
||||
current_row_number += ca_len * 6
|
||||
table_start_row_number = current_row_number
|
||||
|
||||
ws.row_dimensions[current_row_number].height = 60
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws.row_dimensions[current_row_number].height = 60
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '日期时间'
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
for i in range(0, len(time)):
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '日期时间'
|
||||
ws['B' + str(current_row_number)] = time[i]
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
for j in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['values'][j][i], 2) \
|
||||
if reporting_period_data['values'][j][i] is not None else 0.00
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
for i in range(0, len(time)):
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = time[i]
|
||||
table_end_row_number = current_row_number - 1
|
||||
|
||||
col = 'C'
|
||||
for j in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['values'][j][i], 2) \
|
||||
if reporting_period_data['values'][j][i] is not None else 0.00
|
||||
col = chr(ord(col) + 1)
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '小计'
|
||||
|
||||
current_row_number += 1
|
||||
col = 'C'
|
||||
|
||||
table_end_row_number = current_row_number - 1
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['subtotals'][i], 2)
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '小计'
|
||||
current_row_number += 2
|
||||
|
||||
col = 'C'
|
||||
format_time_width_number = 1.0
|
||||
min_len_number = 1.0
|
||||
min_width_number = 11.0 # format_time_width_number * min_len_number + 4 and min_width_number > 11.0
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['subtotals'][i], 2)
|
||||
col = chr(ord(col) + 1)
|
||||
if period_type == 'hourly':
|
||||
format_time_width_number = 4.0
|
||||
min_len_number = 2
|
||||
min_width_number = 12.0
|
||||
elif period_type == 'daily':
|
||||
format_time_width_number = 2.5
|
||||
min_len_number = 4
|
||||
min_width_number = 14.0
|
||||
elif period_type == 'monthly':
|
||||
format_time_width_number = 2.1
|
||||
min_len_number = 4
|
||||
min_width_number = 12.4
|
||||
elif period_type == 'yearly':
|
||||
format_time_width_number = 1.5
|
||||
min_len_number = 5
|
||||
min_width_number = 11.5
|
||||
|
||||
current_row_number += 2
|
||||
|
||||
format_time_width_number = 1.0
|
||||
min_len_number = 1.0
|
||||
min_width_number = 11.0 # format_time_width_number * min_len_number + 4 and min_width_number > 11.0
|
||||
|
||||
if period_type == 'hourly':
|
||||
format_time_width_number = 4.0
|
||||
min_len_number = 2
|
||||
min_width_number = 12.0
|
||||
elif period_type == 'daily':
|
||||
format_time_width_number = 2.5
|
||||
min_len_number = 4
|
||||
min_width_number = 14.0
|
||||
elif period_type == 'monthly':
|
||||
format_time_width_number = 2.1
|
||||
min_len_number = 4
|
||||
min_width_number = 12.4
|
||||
elif period_type == 'yearly':
|
||||
format_time_width_number = 1.5
|
||||
min_len_number = 5
|
||||
min_width_number = 11.5
|
||||
|
||||
for i in range(0, ca_len):
|
||||
line = LineChart()
|
||||
line.title = '报告期消耗 - ' + \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
|
||||
line_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number, max_row=table_end_row_number)
|
||||
line.add_data(line_data, titles_from_data=True)
|
||||
line.set_categories(labels)
|
||||
line_data = line.series[0]
|
||||
line_data.marker.symbol = "circle"
|
||||
line_data.smooth = True
|
||||
line.x_axis.crosses = 'min'
|
||||
line.height = 8.25
|
||||
line.width = format_time_width_number * len(time) if len(time) > min_len_number else min_width_number
|
||||
if line.width > 24:
|
||||
line.width = 24
|
||||
line.dLbls = DataLabelList()
|
||||
line.dLbls.dLblPos = 't'
|
||||
line.dLbls.showVal = True
|
||||
line.dLbls.showPercent = False
|
||||
chart_col = 'B'
|
||||
chart_cell = chart_col + str(chart_start_row_number)
|
||||
chart_start_row_number += 6
|
||||
ws.add_chart(line, chart_cell)
|
||||
for i in range(0, ca_len):
|
||||
line = LineChart()
|
||||
line.title = '报告期消耗 - ' + \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
|
||||
line_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number, max_row=table_end_row_number)
|
||||
line.add_data(line_data, titles_from_data=True)
|
||||
line.set_categories(labels)
|
||||
line_data = line.series[0]
|
||||
line_data.marker.symbol = "circle"
|
||||
line_data.smooth = True
|
||||
line.x_axis.crosses = 'min'
|
||||
line.height = 8.25
|
||||
line.width = format_time_width_number * len(time) if len(time) > min_len_number else min_width_number
|
||||
if line.width > 24:
|
||||
line.width = 24
|
||||
line.dLbls = DataLabelList()
|
||||
line.dLbls.dLblPos = 't'
|
||||
line.dLbls.showVal = True
|
||||
line.dLbls.showPercent = False
|
||||
chart_col = 'B'
|
||||
chart_cell = chart_col + str(chart_start_row_number)
|
||||
chart_start_row_number += 6
|
||||
ws.add_chart(line, chart_cell)
|
||||
|
||||
filename = str(uuid.uuid4()) + '.xlsx'
|
||||
wb.save(filename)
|
||||
|
|
|
@ -0,0 +1,463 @@
|
|||
import base64
|
||||
import uuid
|
||||
import os
|
||||
from openpyxl.chart import (
|
||||
PieChart,
|
||||
LineChart,
|
||||
BarChart,
|
||||
Reference,
|
||||
)
|
||||
from openpyxl.styles import PatternFill, Border, Side, Alignment, Font
|
||||
from openpyxl.drawing.image import Image
|
||||
from openpyxl import Workbook
|
||||
from openpyxl.chart.label import DataLabelList
|
||||
|
||||
|
||||
####################################################################################################################
|
||||
# PROCEDURES
|
||||
# Step 1: Validate the report data
|
||||
# Step 2: Generate excel file
|
||||
# Step 3: Encode the excel file bytes to Base64
|
||||
####################################################################################################################
|
||||
|
||||
|
||||
def export(report,
|
||||
name,
|
||||
reporting_start_datetime_local,
|
||||
reporting_end_datetime_local,
|
||||
period_type):
|
||||
####################################################################################################################
|
||||
# Step 1: Validate the report data
|
||||
####################################################################################################################
|
||||
if report is None:
|
||||
return None
|
||||
print(report)
|
||||
|
||||
####################################################################################################################
|
||||
# Step 2: Generate excel file from the report data
|
||||
####################################################################################################################
|
||||
filename = generate_excel(report,
|
||||
name,
|
||||
reporting_start_datetime_local,
|
||||
reporting_end_datetime_local,
|
||||
period_type)
|
||||
####################################################################################################################
|
||||
# Step 3: Encode the excel file to Base64
|
||||
####################################################################################################################
|
||||
try:
|
||||
with open(filename, 'rb') as binary_file:
|
||||
binary_file_data = binary_file.read()
|
||||
except IOError as ex:
|
||||
pass
|
||||
|
||||
# Base64 encode the bytes
|
||||
base64_encoded_data = base64.b64encode(binary_file_data)
|
||||
# get the Base64 encoded data using human-readable characters.
|
||||
base64_message = base64_encoded_data.decode('utf-8')
|
||||
# delete the file from server
|
||||
try:
|
||||
os.remove(filename)
|
||||
except NotImplementedError as ex:
|
||||
pass
|
||||
return base64_message
|
||||
|
||||
|
||||
def generate_excel(report,
|
||||
name,
|
||||
reporting_start_datetime_local,
|
||||
reporting_end_datetime_local,
|
||||
period_type):
|
||||
wb = Workbook()
|
||||
ws = wb.active
|
||||
|
||||
# Row height
|
||||
ws.row_dimensions[1].height = 102
|
||||
for i in range(2, 2000 + 1):
|
||||
ws.row_dimensions[i].height = 42
|
||||
|
||||
# Col width
|
||||
ws.column_dimensions['A'].width = 1.5
|
||||
|
||||
ws.column_dimensions['B'].width = 25.0
|
||||
|
||||
for i in range(ord('C'), ord('L')):
|
||||
ws.column_dimensions[chr(i)].width = 15.0
|
||||
|
||||
# Font
|
||||
name_font = Font(name='Constantia', size=15, bold=True)
|
||||
title_font = Font(name='宋体', size=15, bold=True)
|
||||
data_font = Font(name='Franklin Gothic Book', size=11)
|
||||
|
||||
table_fill = PatternFill(fill_type='solid', fgColor='1F497D')
|
||||
f_border = Border(left=Side(border_style='medium', color='00000000'),
|
||||
right=Side(border_style='medium', color='00000000'),
|
||||
bottom=Side(border_style='medium', color='00000000'),
|
||||
top=Side(border_style='medium', color='00000000')
|
||||
)
|
||||
b_border = Border(
|
||||
bottom=Side(border_style='medium', color='00000000'),
|
||||
)
|
||||
|
||||
b_c_alignment = Alignment(vertical='bottom',
|
||||
horizontal='center',
|
||||
text_rotation=0,
|
||||
wrap_text=True,
|
||||
shrink_to_fit=False,
|
||||
indent=0)
|
||||
c_c_alignment = Alignment(vertical='center',
|
||||
horizontal='center',
|
||||
text_rotation=0,
|
||||
wrap_text=True,
|
||||
shrink_to_fit=False,
|
||||
indent=0)
|
||||
b_r_alignment = Alignment(vertical='bottom',
|
||||
horizontal='right',
|
||||
text_rotation=0,
|
||||
wrap_text=True,
|
||||
shrink_to_fit=False,
|
||||
indent=0)
|
||||
c_r_alignment = Alignment(vertical='bottom',
|
||||
horizontal='center',
|
||||
text_rotation=0,
|
||||
wrap_text=True,
|
||||
shrink_to_fit=False,
|
||||
indent=0)
|
||||
|
||||
# Img
|
||||
img = Image("excelexporters/myems.png")
|
||||
img.width = img.width * 0.85
|
||||
img.height = img.height * 0.85
|
||||
# img = Image("myems.png")
|
||||
ws.add_image(img, 'B1')
|
||||
|
||||
# Title
|
||||
ws.row_dimensions[3].height = 60
|
||||
|
||||
ws['B3'].font = name_font
|
||||
ws['B3'].alignment = b_r_alignment
|
||||
ws['B3'] = 'Name:'
|
||||
ws['C3'].border = b_border
|
||||
ws['C3'].alignment = b_c_alignment
|
||||
ws['C3'].font = name_font
|
||||
ws['C3'] = name
|
||||
|
||||
ws['D3'].font = name_font
|
||||
ws['D3'].alignment = b_r_alignment
|
||||
ws['D3'] = 'Period:'
|
||||
ws['E3'].border = b_border
|
||||
ws['E3'].alignment = b_c_alignment
|
||||
ws['E3'].font = name_font
|
||||
ws['E3'] = period_type
|
||||
|
||||
ws['F3'].font = name_font
|
||||
ws['F3'].alignment = b_r_alignment
|
||||
ws['F3'] = 'Date:'
|
||||
ws['G3'].border = b_border
|
||||
ws['G3'].alignment = b_c_alignment
|
||||
ws['G3'].font = name_font
|
||||
ws['G3'] = reporting_start_datetime_local + "__" + reporting_end_datetime_local
|
||||
ws.merge_cells("G3:H3")
|
||||
|
||||
if "reporting_period" not in report.keys() or \
|
||||
"names" not in report['reporting_period'].keys() or len(report['reporting_period']['names']) == 0:
|
||||
filename = str(uuid.uuid4()) + '.xlsx'
|
||||
wb.save(filename)
|
||||
|
||||
return filename
|
||||
|
||||
##################################
|
||||
|
||||
reporting_period_data = report['reporting_period']
|
||||
|
||||
has_cost_data_flag = True
|
||||
|
||||
if "names" not in reporting_period_data.keys() or \
|
||||
reporting_period_data['names'] is None or \
|
||||
len(reporting_period_data['names']) == 0:
|
||||
has_cost_data_flag = False
|
||||
|
||||
if has_cost_data_flag:
|
||||
ws['B5'].font = title_font
|
||||
ws['B5'] = name + ' 报告期收入'
|
||||
category = reporting_period_data['names']
|
||||
ca_len = len(category)
|
||||
|
||||
ws.row_dimensions[7].height = 60
|
||||
ws['B6'].fill = table_fill
|
||||
ws['B6'].border = f_border
|
||||
|
||||
ws['B7'].font = title_font
|
||||
ws['B7'].alignment = c_c_alignment
|
||||
ws['B7'] = '报告期收入'
|
||||
ws['B7'].border = f_border
|
||||
|
||||
ws['B8'].font = title_font
|
||||
ws['B8'].alignment = c_c_alignment
|
||||
ws['B8'] = '环比'
|
||||
ws['B8'].border = f_border
|
||||
|
||||
col = ''
|
||||
|
||||
for i in range(0, ca_len):
|
||||
col = chr(ord('C') + i)
|
||||
|
||||
ws[col + '6'].fill = table_fill
|
||||
ws[col + '6'].font = name_font
|
||||
ws[col + '6'].alignment = c_c_alignment
|
||||
ws[col + '6'] = reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
ws[col + '6'].border = f_border
|
||||
|
||||
ws[col + '7'].font = name_font
|
||||
ws[col + '7'].alignment = c_c_alignment
|
||||
ws[col + '7'] = round(reporting_period_data['subtotals'][i], 2)
|
||||
ws[col + '7'].border = f_border
|
||||
|
||||
ws[col + '8'].font = name_font
|
||||
ws[col + '8'].alignment = c_c_alignment
|
||||
ws[col + '8'] = str(round(reporting_period_data['increment_rates'][i] * 100, 2)) + "%" \
|
||||
if reporting_period_data['increment_rates'][i] is not None else "-"
|
||||
ws[col + '8'].border = f_border
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
ws[col + '6'].fill = table_fill
|
||||
ws[col + '6'].font = name_font
|
||||
ws[col + '6'].alignment = c_c_alignment
|
||||
ws[col + '6'] = "总计 (" + reporting_period_data['total_unit'] + ")"
|
||||
ws[col + '6'].border = f_border
|
||||
|
||||
ws[col + '7'].font = name_font
|
||||
ws[col + '7'].alignment = c_c_alignment
|
||||
ws[col + '7'] = round(reporting_period_data['total'], 2)
|
||||
ws[col + '7'].border = f_border
|
||||
|
||||
ws[col + '8'].font = name_font
|
||||
ws[col + '8'].alignment = c_c_alignment
|
||||
ws[col + '8'] = str(round(reporting_period_data['total_increment_rate'] * 100, 2)) + "%" \
|
||||
if reporting_period_data['total_increment_rate'] is not None else "-"
|
||||
ws[col + '8'].border = f_border
|
||||
|
||||
else:
|
||||
for i in range(6, 8 + 1):
|
||||
ws.row_dimensions[i].height = 0.1
|
||||
##################################
|
||||
current_row_number = 10
|
||||
has_subtotals_data_flag = True
|
||||
if "subtotals" not in reporting_period_data.keys() or \
|
||||
reporting_period_data['subtotals'] is None or \
|
||||
len(reporting_period_data['subtotals']) == 0:
|
||||
has_subtotals_data_flag = False
|
||||
|
||||
if has_subtotals_data_flag:
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 收入占比'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
table_start_row_number = current_row_number
|
||||
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws['B' + str(current_row_number)].font = name_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
|
||||
ws['C' + str(current_row_number)].fill = table_fill
|
||||
ws['C' + str(current_row_number)].font = name_font
|
||||
ws['C' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['C' + str(current_row_number)].border = f_border
|
||||
ws['C' + str(current_row_number)] = '收入'
|
||||
|
||||
ws['D' + str(current_row_number)].fill = table_fill
|
||||
ws['D' + str(current_row_number)].font = name_font
|
||||
ws['D' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['D' + str(current_row_number)].border = f_border
|
||||
ws['D' + str(current_row_number)] = '收入占比'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
ca_len = len(reporting_period_data['names'])
|
||||
wssum = 0
|
||||
for i in range(0, ca_len):
|
||||
wssum = round(reporting_period_data['subtotals'][i], 2) + wssum
|
||||
for i in range(0, ca_len):
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)] = reporting_period_data['names'][i]
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
|
||||
ws['C' + str(current_row_number)].font = title_font
|
||||
ws['C' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['C' + str(current_row_number)].border = f_border
|
||||
ws['C' + str(current_row_number)] = round(reporting_period_data['subtotals'][i], 2)
|
||||
|
||||
ws['D' + str(current_row_number)].font = title_font
|
||||
ws['D' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['D' + str(current_row_number)].border = f_border
|
||||
ws['D' + str(current_row_number)] = '{:.2%}'.format(round(reporting_period_data['subtotals'][i], 2) / wssum)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
table_end_row_number = current_row_number - 1
|
||||
|
||||
pie = PieChart()
|
||||
pie.title = name + ' 收入占比'
|
||||
labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
|
||||
pie_data = Reference(ws, min_col=3, min_row=table_start_row_number, max_row=table_end_row_number)
|
||||
pie.add_data(pie_data, titles_from_data=True)
|
||||
pie.set_categories(labels)
|
||||
pie.height = 6.6
|
||||
pie.width = 9
|
||||
s1 = pie.series[0]
|
||||
s1.dLbls = DataLabelList()
|
||||
s1.dLbls.showCatName = False
|
||||
s1.dLbls.showVal = True
|
||||
s1.dLbls.showPercent = True
|
||||
table_cell = 'F' + str(table_start_row_number - 1)
|
||||
ws.add_chart(pie, table_cell)
|
||||
|
||||
if ca_len < 4:
|
||||
current_row_number = current_row_number - ca_len + 4
|
||||
|
||||
else:
|
||||
for i in range(13, 22 + 1):
|
||||
ws.row_dimensions[i].height = 0.1
|
||||
|
||||
#############################################
|
||||
current_row_number = 14
|
||||
reporting_period_data = report['reporting_period']
|
||||
times = reporting_period_data['timestamps']
|
||||
has_detail_data_flag = True
|
||||
ca_len = len(report['reporting_period']['names'])
|
||||
table_row = (current_row_number + 1) + ca_len * 6
|
||||
if "timestamps" not in reporting_period_data.keys() or \
|
||||
reporting_period_data['timestamps'] is None or \
|
||||
len(reporting_period_data['timestamps']) == 0:
|
||||
has_detail_data_flag = False
|
||||
|
||||
if has_detail_data_flag:
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 详细数据'
|
||||
|
||||
ws.row_dimensions[table_row].height = 60
|
||||
ws['B' + str(table_row)].fill = table_fill
|
||||
ws['B' + str(table_row)].font = title_font
|
||||
ws['B' + str(table_row)].border = f_border
|
||||
ws['B' + str(table_row)].alignment = c_c_alignment
|
||||
ws['B' + str(table_row)] = '日期时间'
|
||||
time = times[0]
|
||||
has_data = False
|
||||
max_row = 0
|
||||
if len(time) > 0:
|
||||
has_data = True
|
||||
max_row = table_row + len(time)
|
||||
|
||||
if has_data:
|
||||
for i in range(0, len(time)):
|
||||
col = 'B'
|
||||
row = str(table_row + 1 + i)
|
||||
ws[col + row].font = title_font
|
||||
ws[col + row].alignment = c_c_alignment
|
||||
ws[col + row] = time[i]
|
||||
ws[col + row].border = f_border
|
||||
|
||||
for i in range(0, ca_len):
|
||||
|
||||
col = chr(ord('C') + i)
|
||||
|
||||
ws[col + str(table_row)].fill = table_fill
|
||||
ws[col + str(table_row)].font = title_font
|
||||
ws[col + str(table_row)].alignment = c_c_alignment
|
||||
ws[col + str(table_row)] = reporting_period_data['names'][i] + " (" + reporting_period_data['units'][
|
||||
i] + ")"
|
||||
ws[col + str(table_row)].border = f_border
|
||||
|
||||
# 39 data
|
||||
time = times[i]
|
||||
time_len = len(time)
|
||||
|
||||
for j in range(0, time_len):
|
||||
row = str(table_row + 1 + j)
|
||||
ws[col + row].font = title_font
|
||||
ws[col + row].alignment = c_c_alignment
|
||||
ws[col + row] = round(reporting_period_data['values'][i][j], 2)
|
||||
ws[col + row].border = f_border
|
||||
|
||||
line = LineChart()
|
||||
line.title = \
|
||||
'报告期收入 - ' + reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
labels = Reference(ws, min_col=2, min_row=table_row + 1, max_row=max_row)
|
||||
line_data = Reference(ws, min_col=3 + i, min_row=table_row, max_row=max_row)
|
||||
line.add_data(line_data, titles_from_data=True)
|
||||
line.set_categories(labels)
|
||||
line_data = line.series[0]
|
||||
line_data.marker.symbol = "circle"
|
||||
line_data.smooth = True
|
||||
line.x_axis.crosses = 'min'
|
||||
line.height = 8.25
|
||||
line.width = 24
|
||||
line.dLbls = DataLabelList()
|
||||
line.dLbls.dLblPos = 't'
|
||||
line.dLbls.showVal = True
|
||||
line.dLbls.showPercent = False
|
||||
chart_col = 'B'
|
||||
chart_cell = chart_col + str(current_row_number + 1 + 6 * i)
|
||||
ws.add_chart(line, chart_cell)
|
||||
|
||||
row = str(max_row + 1)
|
||||
|
||||
ws['B' + row].font = title_font
|
||||
ws['B' + row].alignment = c_c_alignment
|
||||
ws['B' + row] = '小计'
|
||||
ws['B' + row].border = f_border
|
||||
|
||||
col = ''
|
||||
|
||||
for i in range(0, ca_len):
|
||||
col = chr(ord('C') + i)
|
||||
row = str(max_row + 1)
|
||||
ws[col + row].font = title_font
|
||||
ws[col + row].alignment = c_c_alignment
|
||||
ws[col + row] = round(reporting_period_data['subtotals'][i], 2)
|
||||
ws[col + row].border = f_border
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
ws[col + str(table_row)].fill = table_fill
|
||||
ws[col + str(table_row)].font = title_font
|
||||
ws[col + str(table_row)].alignment = c_c_alignment
|
||||
ws[col + str(table_row)] = '总计 (' + report['reporting_period']['total_unit'] + ')'
|
||||
ws[col + str(table_row)].border = f_border
|
||||
|
||||
total_sum = 0
|
||||
|
||||
for j in range(0, len(time)):
|
||||
row = str(table_row + 1 + j)
|
||||
ws[col + row].font = title_font
|
||||
ws[col + row].alignment = c_c_alignment
|
||||
every_day_sum = reporting_period_values_every_day_sum(reporting_period_data, j, ca_len)
|
||||
total_sum += every_day_sum
|
||||
ws[col + row] = round(every_day_sum, 2)
|
||||
ws[col + row].border = f_border
|
||||
|
||||
row = str(table_row + 1 + len(time))
|
||||
ws[col + row].font = title_font
|
||||
ws[col + row].alignment = c_c_alignment
|
||||
ws[col + row] = round(total_sum, 2)
|
||||
ws[col + row].border = f_border
|
||||
|
||||
else:
|
||||
for i in range(37, 69 + 1):
|
||||
ws.row_dimensions[i].height = 0.1
|
||||
|
||||
filename = str(uuid.uuid4()) + '.xlsx'
|
||||
wb.save(filename)
|
||||
|
||||
return filename
|
||||
|
||||
|
||||
def reporting_period_values_every_day_sum(reporting_period_data, every_day_index, ca_len):
|
||||
every_day_sum = 0
|
||||
for i in range(0, ca_len):
|
||||
every_day_sum += reporting_period_data['values'][i][every_day_index]
|
||||
|
||||
return every_day_sum
|
|
@ -221,23 +221,6 @@ def generate_excel(report,
|
|||
|
||||
current_row_number += 1
|
||||
|
||||
# ws['B' + str(current_row_number)].font = title_font
|
||||
# ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
# ws['B' + str(current_row_number)].border = f_border
|
||||
# ws['B' + str(current_row_number)] = '单位面积值'
|
||||
#
|
||||
# col = 'C'
|
||||
#
|
||||
# for i in range(0, ca_len):
|
||||
# ws[col + str(current_row_number)].font = name_font
|
||||
# ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
# ws[col + str(current_row_number)].border = f_border
|
||||
# ws[col + str(current_row_number)] = round(reporting_period_data['subtotals_per_unit_area'][i], 2)
|
||||
#
|
||||
# col = chr(ord(col) + 1)
|
||||
#
|
||||
# current_row_number += 1
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
|
@ -257,136 +240,136 @@ def generate_excel(report,
|
|||
|
||||
current_row_number += 2
|
||||
|
||||
####################################
|
||||
####################################
|
||||
|
||||
has_values_data = True
|
||||
has_timestamps_data = True
|
||||
has_values_data = True
|
||||
has_timestamps_data = True
|
||||
|
||||
if 'values' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['values'] is None or \
|
||||
len(reporting_period_data['values']) == 0:
|
||||
has_values_data = False
|
||||
if 'values' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['values'] is None or \
|
||||
len(reporting_period_data['values']) == 0:
|
||||
has_values_data = False
|
||||
|
||||
if 'timestamps' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['timestamps'] is None or \
|
||||
len(reporting_period_data['timestamps']) == 0 or \
|
||||
len(reporting_period_data['timestamps'][0]) == 0:
|
||||
has_timestamps_data = False
|
||||
if 'timestamps' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['timestamps'] is None or \
|
||||
len(reporting_period_data['timestamps']) == 0 or \
|
||||
len(reporting_period_data['timestamps'][0]) == 0:
|
||||
has_timestamps_data = False
|
||||
|
||||
if has_values_data and has_timestamps_data:
|
||||
ca_len = len(reporting_period_data['names'])
|
||||
time = reporting_period_data['timestamps'][0]
|
||||
if has_values_data and has_timestamps_data:
|
||||
ca_len = len(reporting_period_data['names'])
|
||||
time = reporting_period_data['timestamps'][0]
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 详细数据'
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 详细数据'
|
||||
|
||||
current_row_number += 1
|
||||
current_row_number += 1
|
||||
|
||||
chart_start_row_number = current_row_number
|
||||
chart_start_row_number = current_row_number
|
||||
|
||||
current_row_number += ca_len * 6
|
||||
table_start_row_number = current_row_number
|
||||
current_row_number += ca_len * 6
|
||||
table_start_row_number = current_row_number
|
||||
|
||||
ws.row_dimensions[current_row_number].height = 60
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws.row_dimensions[current_row_number].height = 60
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '日期时间'
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
for i in range(0, len(time)):
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '日期时间'
|
||||
ws['B' + str(current_row_number)] = time[i]
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
for j in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['values'][j][i], 2) \
|
||||
if reporting_period_data['values'][j][i] is not None else 0.00
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
for i in range(0, len(time)):
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = time[i]
|
||||
table_end_row_number = current_row_number - 1
|
||||
|
||||
col = 'C'
|
||||
for j in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['values'][j][i], 2) \
|
||||
if reporting_period_data['values'][j][i] is not None else 0.00
|
||||
col = chr(ord(col) + 1)
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '小计'
|
||||
|
||||
current_row_number += 1
|
||||
col = 'C'
|
||||
|
||||
table_end_row_number = current_row_number - 1
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['subtotals'][i], 2)
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '小计'
|
||||
current_row_number += 2
|
||||
|
||||
col = 'C'
|
||||
format_time_width_number = 1.0
|
||||
min_len_number = 1.0
|
||||
min_width_number = 11.0 # format_time_width_number * min_len_number + 4 and min_width_number > 11.0
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['subtotals'][i], 2)
|
||||
col = chr(ord(col) + 1)
|
||||
if period_type == 'hourly':
|
||||
format_time_width_number = 4.0
|
||||
min_len_number = 2
|
||||
min_width_number = 12.0
|
||||
elif period_type == 'daily':
|
||||
format_time_width_number = 2.5
|
||||
min_len_number = 4
|
||||
min_width_number = 14.0
|
||||
elif period_type == 'monthly':
|
||||
format_time_width_number = 2.1
|
||||
min_len_number = 4
|
||||
min_width_number = 12.4
|
||||
elif period_type == 'yearly':
|
||||
format_time_width_number = 1.5
|
||||
min_len_number = 5
|
||||
min_width_number = 11.5
|
||||
|
||||
current_row_number += 2
|
||||
|
||||
format_time_width_number = 1.0
|
||||
min_len_number = 1.0
|
||||
min_width_number = 11.0 # format_time_width_number * min_len_number + 4 and min_width_number > 11.0
|
||||
|
||||
if period_type == 'hourly':
|
||||
format_time_width_number = 4.0
|
||||
min_len_number = 2
|
||||
min_width_number = 12.0
|
||||
elif period_type == 'daily':
|
||||
format_time_width_number = 2.5
|
||||
min_len_number = 4
|
||||
min_width_number = 14.0
|
||||
elif period_type == 'monthly':
|
||||
format_time_width_number = 2.1
|
||||
min_len_number = 4
|
||||
min_width_number = 12.4
|
||||
elif period_type == 'yearly':
|
||||
format_time_width_number = 1.5
|
||||
min_len_number = 5
|
||||
min_width_number = 11.5
|
||||
|
||||
for i in range(0, ca_len):
|
||||
line = LineChart()
|
||||
line.title = '报告期产出 - ' + \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
|
||||
line_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number, max_row=table_end_row_number)
|
||||
line.add_data(line_data, titles_from_data=True)
|
||||
line.set_categories(labels)
|
||||
line_data = line.series[0]
|
||||
line_data.marker.symbol = "circle"
|
||||
line_data.smooth = True
|
||||
line.x_axis.crosses = 'min'
|
||||
line.height = 8.25
|
||||
line.width = format_time_width_number * len(time) if len(time) > min_len_number else min_width_number
|
||||
if line.width > 24:
|
||||
line.width = 24
|
||||
line.dLbls = DataLabelList()
|
||||
line.dLbls.dLblPos = 't'
|
||||
line.dLbls.showVal = True
|
||||
line.dLbls.showPercent = False
|
||||
chart_col = 'B'
|
||||
chart_cell = chart_col + str(chart_start_row_number)
|
||||
chart_start_row_number += 6
|
||||
ws.add_chart(line, chart_cell)
|
||||
for i in range(0, ca_len):
|
||||
line = LineChart()
|
||||
line.title = '报告期产出 - ' + \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
|
||||
line_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number, max_row=table_end_row_number)
|
||||
line.add_data(line_data, titles_from_data=True)
|
||||
line.set_categories(labels)
|
||||
line_data = line.series[0]
|
||||
line_data.marker.symbol = "circle"
|
||||
line_data.smooth = True
|
||||
line.x_axis.crosses = 'min'
|
||||
line.height = 8.25
|
||||
line.width = format_time_width_number * len(time) if len(time) > min_len_number else min_width_number
|
||||
if line.width > 24:
|
||||
line.width = 24
|
||||
line.dLbls = DataLabelList()
|
||||
line.dLbls.dLblPos = 't'
|
||||
line.dLbls.showVal = True
|
||||
line.dLbls.showPercent = False
|
||||
chart_col = 'B'
|
||||
chart_cell = chart_col + str(chart_start_row_number)
|
||||
chart_start_row_number += 6
|
||||
ws.add_chart(line, chart_cell)
|
||||
|
||||
filename = str(uuid.uuid4()) + '.xlsx'
|
||||
wb.save(filename)
|
||||
|
|
|
@ -5,6 +5,7 @@ from openpyxl.chart import (
|
|||
LineChart,
|
||||
Reference,
|
||||
)
|
||||
from openpyxl.chart.label import DataLabelList
|
||||
from openpyxl.styles import PatternFill, Border, Side, Alignment, Font
|
||||
from openpyxl.drawing.image import Image
|
||||
from openpyxl import Workbook
|
||||
|
@ -68,19 +69,16 @@ def generate_excel(report,
|
|||
ws = wb.active
|
||||
|
||||
# Row height
|
||||
ws.row_dimensions[1].height = 121
|
||||
ws.row_dimensions[1].height = 102
|
||||
|
||||
for i in range(2, 37 + 1):
|
||||
ws.row_dimensions[i].height = 30
|
||||
|
||||
for i in range(38, 90 + 1):
|
||||
ws.row_dimensions[i].height = 30
|
||||
for i in range(2, 2000 + 1):
|
||||
ws.row_dimensions[i].height = 42
|
||||
|
||||
# Col width
|
||||
ws.column_dimensions['A'].width = 1.5
|
||||
ws.column_dimensions['B'].width = 20.0
|
||||
ws.column_dimensions['B'].width = 25.0
|
||||
|
||||
for i in range(ord('C'), ord('I')):
|
||||
for i in range(ord('C'), ord('L')):
|
||||
ws.column_dimensions[chr(i)].width = 15.0
|
||||
|
||||
# Font
|
||||
|
@ -116,12 +114,6 @@ def generate_excel(report,
|
|||
wrap_text=False,
|
||||
shrink_to_fit=False,
|
||||
indent=0)
|
||||
# c_r_alignment = Alignment(vertical='bottom',
|
||||
# horizontal='center',
|
||||
# text_rotation=0,
|
||||
# wrap_text=False,
|
||||
# shrink_to_fit=False,
|
||||
# indent=0)
|
||||
|
||||
# Img
|
||||
img = Image("excelexporters/myems.png")
|
||||
|
@ -317,11 +309,8 @@ def generate_excel(report,
|
|||
|
||||
########################################################
|
||||
# Second: 详细数据
|
||||
# row_sat+1~ row_sat+1+row_lines+: line
|
||||
# row_ddt~ : the detailed data table
|
||||
# row_sat : the number of rows of the analysis table
|
||||
# row_lines : the number of rows of all line charts
|
||||
# row_ddt : The number of rows in which the detailed data table header resides
|
||||
# a+1~ analysis_end_row_number+1+line_charts_row_number+: line
|
||||
# detailed_start_row_number~ : the detailed data table
|
||||
########################################################
|
||||
has_timestamps_flag = True
|
||||
if "timestamps" not in reporting_period_data.keys() or \
|
||||
|
@ -336,29 +325,29 @@ def generate_excel(report,
|
|||
ca_len = len(names)
|
||||
time_len = len(timestamps)
|
||||
# the detailed title
|
||||
row_lines = 9 * ca_len
|
||||
row_sat = 7 + 2 * ca_len
|
||||
row_ddt = row_sat + row_lines + 2
|
||||
line_charts_row_number = 6 * ca_len + 1
|
||||
analysis_end_row_number = 7 + 2 * ca_len
|
||||
detailed_start_row_number = analysis_end_row_number + line_charts_row_number + 2
|
||||
|
||||
ws['B' + str(row_ddt)].font = title_font
|
||||
ws['B' + str(row_ddt)] = name + ' 详细数据'
|
||||
ws['B' + str(detailed_start_row_number)].font = title_font
|
||||
ws['B' + str(detailed_start_row_number)] = name + ' 详细数据'
|
||||
# the detailed table_title
|
||||
ws['B' + str(row_ddt+1)].fill = table_fill
|
||||
ws['B' + str(row_ddt+1)].font = name_font
|
||||
ws['B' + str(row_ddt+1)].alignment = c_c_alignment
|
||||
ws['B' + str(row_ddt+1)] = "时间"
|
||||
ws['B' + str(row_ddt+1)].border = f_border
|
||||
ws['B' + str(detailed_start_row_number + 1)].fill = table_fill
|
||||
ws['B' + str(detailed_start_row_number + 1)].font = name_font
|
||||
ws['B' + str(detailed_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['B' + str(detailed_start_row_number + 1)] = "时间"
|
||||
ws['B' + str(detailed_start_row_number + 1)].border = f_border
|
||||
|
||||
for i in range(0, ca_len):
|
||||
col = chr(ord('C') + i)
|
||||
|
||||
ws[col + str(row_ddt+1)].font = name_font
|
||||
ws[col + str(row_ddt+1)].alignment = c_c_alignment
|
||||
ws[col + str(row_ddt+1)] = names[i] + " - (" + reporting_period_data['units'][i] + ")"
|
||||
ws[col + str(row_ddt+1)].border = f_border
|
||||
ws[col + str(detailed_start_row_number + 1)].font = name_font
|
||||
ws[col + str(detailed_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws[col + str(detailed_start_row_number + 1)] = names[i] + " - (" + reporting_period_data['units'][i] + ")"
|
||||
ws[col + str(detailed_start_row_number + 1)].border = f_border
|
||||
# the detailed table_date
|
||||
for i in range(0, time_len):
|
||||
rows = i + row_ddt + 2
|
||||
rows = i + detailed_start_row_number + 2
|
||||
|
||||
ws['B' + str(rows)].font = name_font
|
||||
ws['B' + str(rows)].alignment = c_c_alignment
|
||||
|
@ -375,7 +364,7 @@ def generate_excel(report,
|
|||
ws[col + str(rows)].border = f_border
|
||||
|
||||
# 小计
|
||||
row_subtotals = row_ddt + 2 + time_len
|
||||
row_subtotals = detailed_start_row_number + 2 + time_len
|
||||
ws['B' + str(row_subtotals)].font = name_font
|
||||
ws['B' + str(row_subtotals)].alignment = c_c_alignment
|
||||
ws['B' + str(row_subtotals)] = "小计"
|
||||
|
@ -390,26 +379,32 @@ def generate_excel(report,
|
|||
ws[col + str(row_subtotals)].border = f_border
|
||||
ws[col + str(row_subtotals)].number_format = '0.00'
|
||||
|
||||
# LineChart
|
||||
########################################################
|
||||
# third: LineChart
|
||||
# LineChart requires data from the detailed data table in the Excel file
|
||||
# so print the detailed data table first and then print LineChart
|
||||
########################################################
|
||||
for i in range(0, ca_len):
|
||||
|
||||
lc = LineChart()
|
||||
lc.title = "报告期消耗" + " - " + names[i] + "(" + reporting_period_data['units'][i] + ")"
|
||||
lc.style = 10
|
||||
lc.height = 8.40 # cm 1.05*8 1.05cm = 30 pt
|
||||
lc.width = 23.28
|
||||
lc.x_axis.majorTickMark = 'in'
|
||||
lc.y_axis.majorTickMark = 'in'
|
||||
times = Reference(ws, min_col=2, min_row=row_ddt + 2,
|
||||
max_row=row_ddt + 2 + time_len)
|
||||
lc_data = Reference(ws, min_col=3 + i, min_row=row_ddt + 1,
|
||||
max_row=row_ddt + 1 + time_len)
|
||||
lc.add_data(lc_data, titles_from_data=True)
|
||||
lc.set_categories(times)
|
||||
ser = lc.series[0]
|
||||
line = LineChart()
|
||||
line.title = "报告期消耗" + " - " + names[i] + "(" + reporting_period_data['units'][i] + ")"
|
||||
line.style = 10
|
||||
line.height = 8.40 # cm 1.05*8 1.05cm = 30 pt
|
||||
line.width = 24
|
||||
line.x_axis.majorTickMark = 'in'
|
||||
line.y_axis.majorTickMark = 'in'
|
||||
line.dLbls = DataLabelList()
|
||||
line.dLbls.dLblPos = 't'
|
||||
line.dLbls.showVal = True
|
||||
times = Reference(ws, min_col=2, min_row=detailed_start_row_number + 2,
|
||||
max_row=detailed_start_row_number + 2 + time_len)
|
||||
line_data = Reference(ws, min_col=3 + i, min_row=detailed_start_row_number + 1,
|
||||
max_row=detailed_start_row_number + 1 + time_len)
|
||||
line.add_data(line_data, titles_from_data=True)
|
||||
line.set_categories(times)
|
||||
ser = line.series[0]
|
||||
ser.marker.symbol = "diamond"
|
||||
ser.marker.size = 5
|
||||
ws.add_chart(lc, 'B' + str(row_sat + 2 + 9 * i))
|
||||
ws.add_chart(line, 'B' + str(analysis_end_row_number + 2 + 6 * i))
|
||||
|
||||
filename = str(uuid.uuid4()) + '.xlsx'
|
||||
wb.save(filename)
|
||||
|
|
|
@ -318,136 +318,136 @@ def generate_excel(report,
|
|||
|
||||
current_row_number += 1
|
||||
|
||||
#####################################
|
||||
#####################################
|
||||
|
||||
has_values_data = True
|
||||
has_timestamps_data = True
|
||||
has_values_data = True
|
||||
has_timestamps_data = True
|
||||
|
||||
if 'values' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['values'] is None or \
|
||||
len(reporting_period_data['values']) == 0:
|
||||
has_values_data = False
|
||||
if 'values' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['values'] is None or \
|
||||
len(reporting_period_data['values']) == 0:
|
||||
has_values_data = False
|
||||
|
||||
if 'timestamps' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['timestamps'] is None or \
|
||||
len(reporting_period_data['timestamps']) == 0 or \
|
||||
len(reporting_period_data['timestamps'][0]) == 0:
|
||||
has_timestamps_data = False
|
||||
if 'timestamps' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['timestamps'] is None or \
|
||||
len(reporting_period_data['timestamps']) == 0 or \
|
||||
len(reporting_period_data['timestamps'][0]) == 0:
|
||||
has_timestamps_data = False
|
||||
|
||||
if has_values_data and has_timestamps_data:
|
||||
ca_len = len(reporting_period_data['names'])
|
||||
time = reporting_period_data['timestamps'][0]
|
||||
if has_values_data and has_timestamps_data:
|
||||
ca_len = len(reporting_period_data['names'])
|
||||
time = reporting_period_data['timestamps'][0]
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 详细数据'
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 详细数据'
|
||||
|
||||
current_row_number += 1
|
||||
current_row_number += 1
|
||||
|
||||
chart_start_row_number = current_row_number
|
||||
chart_start_row_number = current_row_number
|
||||
|
||||
current_row_number += ca_len * 6
|
||||
table_start_row_number = current_row_number
|
||||
current_row_number += ca_len * 6
|
||||
table_start_row_number = current_row_number
|
||||
|
||||
ws.row_dimensions[current_row_number].height = 60
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws.row_dimensions[current_row_number].height = 60
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '日期时间'
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
for i in range(0, len(time)):
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '日期时间'
|
||||
ws['B' + str(current_row_number)] = time[i]
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
for j in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['values'][j][i], 2) \
|
||||
if reporting_period_data['values'][j][i] is not None else 0.00
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
for i in range(0, len(time)):
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = time[i]
|
||||
table_end_row_number = current_row_number - 1
|
||||
|
||||
col = 'C'
|
||||
for j in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['values'][j][i], 2) \
|
||||
if reporting_period_data['values'][j][i] is not None else 0.00
|
||||
col = chr(ord(col) + 1)
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '小计'
|
||||
|
||||
current_row_number += 1
|
||||
col = 'C'
|
||||
|
||||
table_end_row_number = current_row_number - 1
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['subtotals'][i], 2)
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '小计'
|
||||
current_row_number += 2
|
||||
|
||||
col = 'C'
|
||||
format_time_width_number = 1.0
|
||||
min_len_number = 1.0
|
||||
min_width_number = 11.0 # format_time_width_number * min_len_number + 4 and min_width_number > 11.0
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['subtotals'][i], 2)
|
||||
col = chr(ord(col) + 1)
|
||||
if period_type == 'hourly':
|
||||
format_time_width_number = 4.0
|
||||
min_len_number = 2
|
||||
min_width_number = 12.0
|
||||
elif period_type == 'daily':
|
||||
format_time_width_number = 2.5
|
||||
min_len_number = 4
|
||||
min_width_number = 14.0
|
||||
elif period_type == 'monthly':
|
||||
format_time_width_number = 2.1
|
||||
min_len_number = 4
|
||||
min_width_number = 12.4
|
||||
elif period_type == 'yearly':
|
||||
format_time_width_number = 1.5
|
||||
min_len_number = 5
|
||||
min_width_number = 11.5
|
||||
|
||||
current_row_number += 2
|
||||
|
||||
format_time_width_number = 1.0
|
||||
min_len_number = 1.0
|
||||
min_width_number = 11.0 # format_time_width_number * min_len_number + 4 and min_width_number > 11.0
|
||||
|
||||
if period_type == 'hourly':
|
||||
format_time_width_number = 4.0
|
||||
min_len_number = 2
|
||||
min_width_number = 12.0
|
||||
elif period_type == 'daily':
|
||||
format_time_width_number = 2.5
|
||||
min_len_number = 4
|
||||
min_width_number = 14.0
|
||||
elif period_type == 'monthly':
|
||||
format_time_width_number = 2.1
|
||||
min_len_number = 4
|
||||
min_width_number = 12.4
|
||||
elif period_type == 'yearly':
|
||||
format_time_width_number = 1.5
|
||||
min_len_number = 5
|
||||
min_width_number = 11.5
|
||||
|
||||
for i in range(0, ca_len):
|
||||
line = LineChart()
|
||||
line.title = '报告期消耗 - ' + \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
|
||||
line_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number, max_row=table_end_row_number)
|
||||
line.add_data(line_data, titles_from_data=True)
|
||||
line.set_categories(labels)
|
||||
line_data = line.series[0]
|
||||
line_data.marker.symbol = "circle"
|
||||
line_data.smooth = True
|
||||
line.x_axis.crosses = 'min'
|
||||
line.height = 8.25
|
||||
line.width = format_time_width_number * len(time) if len(time) > min_len_number else min_width_number
|
||||
if line.width > 24:
|
||||
line.width = 24
|
||||
line.dLbls = DataLabelList()
|
||||
line.dLbls.dLblPos = 't'
|
||||
line.dLbls.showVal = True
|
||||
line.dLbls.showPercent = False
|
||||
chart_col = 'B'
|
||||
chart_cell = chart_col + str(chart_start_row_number)
|
||||
chart_start_row_number += 6
|
||||
ws.add_chart(line, chart_cell)
|
||||
for i in range(0, ca_len):
|
||||
line = LineChart()
|
||||
line.title = '报告期消耗 - ' + \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
|
||||
line_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number, max_row=table_end_row_number)
|
||||
line.add_data(line_data, titles_from_data=True)
|
||||
line.set_categories(labels)
|
||||
line_data = line.series[0]
|
||||
line_data.marker.symbol = "circle"
|
||||
line_data.smooth = True
|
||||
line.x_axis.crosses = 'min'
|
||||
line.height = 8.25
|
||||
line.width = format_time_width_number * len(time) if len(time) > min_len_number else min_width_number
|
||||
if line.width > 24:
|
||||
line.width = 24
|
||||
line.dLbls = DataLabelList()
|
||||
line.dLbls.dLblPos = 't'
|
||||
line.dLbls.showVal = True
|
||||
line.dLbls.showPercent = False
|
||||
chart_col = 'B'
|
||||
chart_cell = chart_col + str(chart_start_row_number)
|
||||
chart_start_row_number += 6
|
||||
ws.add_chart(line, chart_cell)
|
||||
|
||||
filename = str(uuid.uuid4()) + '.xlsx'
|
||||
wb.save(filename)
|
||||
|
|
|
@ -113,12 +113,6 @@ def generate_excel(report,
|
|||
wrap_text=False,
|
||||
shrink_to_fit=False,
|
||||
indent=0)
|
||||
# c_r_alignment = Alignment(vertical='bottom',
|
||||
# horizontal='center',
|
||||
# text_rotation=0,
|
||||
# wrap_text=False,
|
||||
# shrink_to_fit=False,
|
||||
# indent=0)
|
||||
|
||||
# Img
|
||||
img = Image("excelexporters/myems.png")
|
||||
|
@ -264,40 +258,40 @@ def generate_excel(report,
|
|||
# Second: 报告期单位面积消耗
|
||||
# 9 + ca_len * 2: title
|
||||
# 10 + ca_len * 2: table title
|
||||
# row_title + 2 ~ row_title + 2 + ca_len : table_data
|
||||
# per_unit_area_start_row_number + 2 ~ per_unit_area_start_row_number + 2 + ca_len : table_data
|
||||
#################################################
|
||||
|
||||
if has_energy_data_flag:
|
||||
names = reporting_period_data['names']
|
||||
ca_len = len(names)
|
||||
row_title = 9 + ca_len * 2
|
||||
per_unit_area_start_row_number = 9 + ca_len * 2
|
||||
|
||||
ws['B' + str(row_title)].font = title_font
|
||||
ws['B' + str(row_title)] = name + ' 单位面积值' + str(report['shopfloor']['area']) + 'M²'
|
||||
ws['B' + str(per_unit_area_start_row_number)].font = title_font
|
||||
ws['B' + str(per_unit_area_start_row_number)] = name + ' 单位面积值' + str(report['shopfloor']['area']) + 'M²'
|
||||
|
||||
category = reporting_period_data['names']
|
||||
|
||||
# table_title
|
||||
ws['B' + str(row_title + 1)].fill = table_fill
|
||||
ws['B' + str(row_title + 1)].font = title_font
|
||||
ws['B' + str(row_title + 1)].alignment = c_c_alignment
|
||||
ws['B' + str(row_title + 1)] = '报告期'
|
||||
ws['B' + str(row_title + 1)].border = f_border
|
||||
ws['B' + str(per_unit_area_start_row_number + 1)].fill = table_fill
|
||||
ws['B' + str(per_unit_area_start_row_number + 1)].font = title_font
|
||||
ws['B' + str(per_unit_area_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['B' + str(per_unit_area_start_row_number + 1)] = '报告期'
|
||||
ws['B' + str(per_unit_area_start_row_number + 1)].border = f_border
|
||||
|
||||
ws['C' + str(row_title + 1)].font = title_font
|
||||
ws['C' + str(row_title + 1)].alignment = c_c_alignment
|
||||
ws['C' + str(row_title + 1)] = '平均负荷'
|
||||
ws['C' + str(row_title + 1)].border = f_border
|
||||
ws['C' + str(per_unit_area_start_row_number + 1)].font = title_font
|
||||
ws['C' + str(per_unit_area_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['C' + str(per_unit_area_start_row_number + 1)] = '平均负荷'
|
||||
ws['C' + str(per_unit_area_start_row_number + 1)].border = f_border
|
||||
|
||||
ws['D' + str(row_title + 1)].font = title_font
|
||||
ws['D' + str(row_title + 1)].alignment = c_c_alignment
|
||||
ws['D' + str(row_title + 1)] = '最大负荷'
|
||||
ws['D' + str(row_title + 1)].border = f_border
|
||||
ws['D' + str(per_unit_area_start_row_number + 1)].font = title_font
|
||||
ws['D' + str(per_unit_area_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['D' + str(per_unit_area_start_row_number + 1)] = '最大负荷'
|
||||
ws['D' + str(per_unit_area_start_row_number + 1)].border = f_border
|
||||
|
||||
# table_data
|
||||
|
||||
for i, value in enumerate(category):
|
||||
row_data = row_title + 2 + i
|
||||
row_data = per_unit_area_start_row_number + 2 + i
|
||||
ws['B' + str(row_data)].font = name_font
|
||||
ws['B' + str(row_data)].alignment = c_c_alignment
|
||||
ws['B' + str(row_data)] = reporting_period_data['names'][i] + " (" + reporting_period_data['units'][
|
||||
|
@ -322,9 +316,9 @@ def generate_excel(report,
|
|||
|
||||
########################################################
|
||||
# Third: 详细数据
|
||||
# row_sat~ row_sat + 6*cal_len: line
|
||||
# row_da: table title
|
||||
# row_da + 1~: table_data
|
||||
# analysis_end_row_number~ analysis_end_row_number + 6*cal_len: line
|
||||
# detailed_start_row_number: table title
|
||||
# detailed_start_row_number + 1~: table_data
|
||||
########################################################
|
||||
has_timestamps_flag = True
|
||||
if "timestamps" not in reporting_period_data.keys() or \
|
||||
|
@ -337,40 +331,37 @@ def generate_excel(report,
|
|||
names = reporting_period_data['names']
|
||||
ca_len = len(names)
|
||||
time_len = len(timestamps)
|
||||
# row_lines == the number of rows of lines
|
||||
row_lines = 6 * ca_len
|
||||
# row_sat == the number of rows of statistical analysis table
|
||||
row_sat = 12 + 3 * ca_len
|
||||
# row_da == the number of rows of Detailed data
|
||||
row_da = row_sat + row_lines + 1
|
||||
line_charts_row_number = 6 * ca_len
|
||||
analysis_end_row_number = 12 + 3 * ca_len
|
||||
detailed_start_row_number = analysis_end_row_number + line_charts_row_number + 1
|
||||
|
||||
ws['B' + str(row_da)].font = title_font
|
||||
ws['B' + str(row_da)] = name + ' 详细数据'
|
||||
ws['B' + str(detailed_start_row_number)].font = title_font
|
||||
ws['B' + str(detailed_start_row_number)] = name + ' 详细数据'
|
||||
# table_title
|
||||
ws['B' + str(row_da + 1)].fill = table_fill
|
||||
ws['B' + str(row_da + 1)].font = name_font
|
||||
ws['B' + str(row_da + 1)].alignment = c_c_alignment
|
||||
ws['B' + str(row_da + 1)] = "日期时间"
|
||||
ws['B' + str(row_da + 1)].border = f_border
|
||||
ws['B' + str(detailed_start_row_number + 1)].fill = table_fill
|
||||
ws['B' + str(detailed_start_row_number + 1)].font = name_font
|
||||
ws['B' + str(detailed_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['B' + str(detailed_start_row_number + 1)] = "日期时间"
|
||||
ws['B' + str(detailed_start_row_number + 1)].border = f_border
|
||||
|
||||
for i in range(0, ca_len):
|
||||
col_average = chr(ord('C') + 2 * i)
|
||||
col_maximum = chr(ord('D') + 2 * i)
|
||||
|
||||
ws[col_average + str(row_da + 1)].font = name_font
|
||||
ws[col_average + str(row_da + 1)].alignment = c_c_alignment
|
||||
ws[col_average + str(row_da + 1)] = names[i] + " 平均负荷(" + reporting_period_data['units'][
|
||||
ws[col_average + str(detailed_start_row_number + 1)].font = name_font
|
||||
ws[col_average + str(detailed_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws[col_average + str(detailed_start_row_number + 1)] = names[i] + " 平均负荷(" + reporting_period_data['units'][
|
||||
i] + "/H)"
|
||||
ws[col_average + str(row_da + 1)].border = f_border
|
||||
ws[col_average + str(detailed_start_row_number + 1)].border = f_border
|
||||
|
||||
ws[col_maximum + str(row_da + 1)].font = name_font
|
||||
ws[col_maximum + str(row_da + 1)].alignment = c_c_alignment
|
||||
ws[col_maximum + str(row_da + 1)] = names[i] + " 最大负荷(" + reporting_period_data['units'][
|
||||
ws[col_maximum + str(detailed_start_row_number + 1)].font = name_font
|
||||
ws[col_maximum + str(detailed_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws[col_maximum + str(detailed_start_row_number + 1)] = names[i] + " 最大负荷(" + reporting_period_data['units'][
|
||||
i] + "/H)"
|
||||
ws[col_maximum + str(row_da + 1)].border = f_border
|
||||
ws[col_maximum + str(detailed_start_row_number + 1)].border = f_border
|
||||
# table_date
|
||||
for i in range(0, time_len):
|
||||
rows = i + row_da + 2
|
||||
rows = i + detailed_start_row_number + 2
|
||||
|
||||
ws['B' + str(rows)].font = name_font
|
||||
ws['B' + str(rows)].alignment = c_c_alignment
|
||||
|
@ -395,32 +386,36 @@ def generate_excel(report,
|
|||
ws[col_maximum + str(rows)].number_format = '0.00'
|
||||
ws[col_maximum + str(rows)].border = f_border
|
||||
|
||||
# LineChart
|
||||
########################################################
|
||||
# third: LineChart
|
||||
# LineChart requires data from the detailed data table in the Excel file
|
||||
# so print the detailed data table first and then print LineChart
|
||||
########################################################
|
||||
for i in range(0, ca_len):
|
||||
lc = LineChart()
|
||||
lc.title = "报告期 最大负荷"
|
||||
lc.style = 10
|
||||
lc.x_axis.majorTickMark = 'in'
|
||||
lc.y_axis.majorTickMark = 'in'
|
||||
lc.smooth = True
|
||||
lc.x_axis.crosses = 'min'
|
||||
lc.height = 8.25
|
||||
lc.width = 24
|
||||
lc.dLbls = DataLabelList()
|
||||
lc.dLbls.dLblPos = 't'
|
||||
lc.dLbls.showVal = True
|
||||
times = Reference(ws, min_col=2, min_row=row_da + 2,
|
||||
max_row=row_da + 2 + time_len)
|
||||
lc_data = Reference(ws, min_col=2 + 2 * (i+1), min_row=row_da + 1,
|
||||
max_row=row_da + 1 + time_len)
|
||||
lc.add_data(lc_data, titles_from_data=True)
|
||||
lc.set_categories(times)
|
||||
ser = lc.series[0]
|
||||
line = LineChart()
|
||||
line.title = "报告期 最大负荷 - " + names[i] + "(" + reporting_period_data['units'][i] + ")"
|
||||
line.style = 10
|
||||
line.x_axis.majorTickMark = 'in'
|
||||
line.y_axis.majorTickMark = 'in'
|
||||
line.smooth = True
|
||||
line.x_axis.crosses = 'min'
|
||||
line.height = 8.25
|
||||
line.width = 24
|
||||
line.dLbls = DataLabelList()
|
||||
line.dLbls.dLblPos = 't'
|
||||
line.dLbls.showVal = True
|
||||
times = Reference(ws, min_col=2, min_row=detailed_start_row_number + 2,
|
||||
max_row=detailed_start_row_number + 2 + time_len)
|
||||
line_data = Reference(ws, min_col=2 + 2 * (i + 1), min_row=detailed_start_row_number + 1,
|
||||
max_row=detailed_start_row_number + 1 + time_len)
|
||||
line.add_data(line_data, titles_from_data=True)
|
||||
line.set_categories(times)
|
||||
ser = line.series[0]
|
||||
ser.marker.symbol = "diamond"
|
||||
ser.marker.size = 5
|
||||
chart_col = 'B'
|
||||
chart_cell = str(row_sat + 6 * i)
|
||||
ws.add_chart(lc, chart_col + chart_cell)
|
||||
chart_cell = str(analysis_end_row_number + 6 * i)
|
||||
ws.add_chart(line, chart_col + chart_cell)
|
||||
|
||||
filename = str(uuid.uuid4()) + '.xlsx'
|
||||
wb.save(filename)
|
||||
|
|
|
@ -0,0 +1,604 @@
|
|||
import base64
|
||||
import uuid
|
||||
import os
|
||||
from openpyxl.chart import (
|
||||
PieChart,
|
||||
LineChart,
|
||||
BarChart,
|
||||
Reference,
|
||||
)
|
||||
from openpyxl.styles import PatternFill, Border, Side, Alignment, Font
|
||||
from openpyxl.drawing.image import Image
|
||||
from openpyxl import Workbook
|
||||
from openpyxl.chart.label import DataLabelList
|
||||
|
||||
####################################################################################################################
|
||||
# PROCEDURES
|
||||
# Step 1: Validate the report data
|
||||
# Step 2: Generate excel file
|
||||
# Step 3: Encode the excel file bytes to Base64
|
||||
####################################################################################################################
|
||||
|
||||
|
||||
def export(report,
|
||||
name,
|
||||
reporting_start_datetime_local,
|
||||
reporting_end_datetime_local,
|
||||
period_type):
|
||||
####################################################################################################################
|
||||
# Step 1: Validate the report data
|
||||
####################################################################################################################
|
||||
if report is None:
|
||||
return None
|
||||
print(report)
|
||||
|
||||
####################################################################################################################
|
||||
# Step 2: Generate excel file from the report data
|
||||
####################################################################################################################
|
||||
filename = generate_excel(report,
|
||||
name,
|
||||
reporting_start_datetime_local,
|
||||
reporting_end_datetime_local,
|
||||
period_type)
|
||||
####################################################################################################################
|
||||
# Step 3: Encode the excel file to Base64
|
||||
####################################################################################################################
|
||||
try:
|
||||
with open(filename, 'rb') as binary_file:
|
||||
binary_file_data = binary_file.read()
|
||||
except IOError as ex:
|
||||
pass
|
||||
|
||||
# Base64 encode the bytes
|
||||
base64_encoded_data = base64.b64encode(binary_file_data)
|
||||
# get the Base64 encoded data using human-readable characters.
|
||||
base64_message = base64_encoded_data.decode('utf-8')
|
||||
# delete the file from server
|
||||
try:
|
||||
os.remove(filename)
|
||||
except NotImplementedError as ex:
|
||||
pass
|
||||
return base64_message
|
||||
|
||||
|
||||
def generate_excel(report,
|
||||
name,
|
||||
reporting_start_datetime_local,
|
||||
reporting_end_datetime_local,
|
||||
period_type):
|
||||
wb = Workbook()
|
||||
ws = wb.active
|
||||
|
||||
# Row height
|
||||
ws.row_dimensions[1].height = 102
|
||||
for i in range(2, 2000 + 1):
|
||||
ws.row_dimensions[i].height = 42
|
||||
|
||||
# Col width
|
||||
ws.column_dimensions['A'].width = 1.5
|
||||
|
||||
ws.column_dimensions['B'].width = 25.0
|
||||
|
||||
for i in range(ord('C'), ord('L')):
|
||||
ws.column_dimensions[chr(i)].width = 15.0
|
||||
|
||||
# Font
|
||||
name_font = Font(name='Constantia', size=15, bold=True)
|
||||
title_font = Font(name='宋体', size=15, bold=True)
|
||||
data_font = Font(name='Franklin Gothic Book', size=11)
|
||||
|
||||
table_fill = PatternFill(fill_type='solid', fgColor='1F497D')
|
||||
f_border = Border(left=Side(border_style='medium', color='00000000'),
|
||||
right=Side(border_style='medium', color='00000000'),
|
||||
bottom=Side(border_style='medium', color='00000000'),
|
||||
top=Side(border_style='medium', color='00000000')
|
||||
)
|
||||
b_border = Border(
|
||||
bottom=Side(border_style='medium', color='00000000'),
|
||||
)
|
||||
|
||||
b_c_alignment = Alignment(vertical='bottom',
|
||||
horizontal='center',
|
||||
text_rotation=0,
|
||||
wrap_text=True,
|
||||
shrink_to_fit=False,
|
||||
indent=0)
|
||||
c_c_alignment = Alignment(vertical='center',
|
||||
horizontal='center',
|
||||
text_rotation=0,
|
||||
wrap_text=True,
|
||||
shrink_to_fit=False,
|
||||
indent=0)
|
||||
b_r_alignment = Alignment(vertical='bottom',
|
||||
horizontal='right',
|
||||
text_rotation=0,
|
||||
wrap_text=True,
|
||||
shrink_to_fit=False,
|
||||
indent=0)
|
||||
c_r_alignment = Alignment(vertical='bottom',
|
||||
horizontal='center',
|
||||
text_rotation=0,
|
||||
wrap_text=True,
|
||||
shrink_to_fit=False,
|
||||
indent=0)
|
||||
|
||||
# Img
|
||||
img = Image("excelexporters/myems.png")
|
||||
img.width = img.width * 0.85
|
||||
img.height = img.height * 0.85
|
||||
# img = Image("myems.png")
|
||||
ws.add_image(img, 'B1')
|
||||
|
||||
# Title
|
||||
ws.row_dimensions[3].height = 60
|
||||
|
||||
ws['B3'].font = name_font
|
||||
ws['B3'].alignment = b_r_alignment
|
||||
ws['B3'] = 'Name:'
|
||||
ws['C3'].border = b_border
|
||||
ws['C3'].alignment = b_c_alignment
|
||||
ws['C3'].font = name_font
|
||||
ws['C3'] = name
|
||||
|
||||
ws['D3'].font = name_font
|
||||
ws['D3'].alignment = b_r_alignment
|
||||
ws['D3'] = 'Period:'
|
||||
ws['E3'].border = b_border
|
||||
ws['E3'].alignment = b_c_alignment
|
||||
ws['E3'].font = name_font
|
||||
ws['E3'] = period_type
|
||||
|
||||
ws['F3'].font = name_font
|
||||
ws['F3'].alignment = b_r_alignment
|
||||
ws['F3'] = 'Date:'
|
||||
ws['G3'].alignment = b_c_alignment
|
||||
ws['G3'].font = name_font
|
||||
ws['G3'] = reporting_start_datetime_local + "__" + reporting_end_datetime_local
|
||||
ws['G3'].border = b_border
|
||||
ws.merge_cells("G3:H3")
|
||||
|
||||
if "reporting_period" not in report.keys() or \
|
||||
"names" not in report['reporting_period'].keys() or len(report['reporting_period']['names']) == 0:
|
||||
filename = str(uuid.uuid4()) + '.xlsx'
|
||||
wb.save(filename)
|
||||
|
||||
return filename
|
||||
|
||||
##################################
|
||||
|
||||
current_row_number = 6
|
||||
|
||||
reporting_period_data = report['reporting_period']
|
||||
|
||||
has_names_data_flag = True
|
||||
|
||||
if "names" not in reporting_period_data.keys() or \
|
||||
reporting_period_data['names'] is None or \
|
||||
len(reporting_period_data['names']) == 0:
|
||||
has_names_data_flag = False
|
||||
|
||||
if has_names_data_flag:
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 报告期节约'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
category = reporting_period_data['names']
|
||||
ca_len = len(category)
|
||||
|
||||
ws.row_dimensions[current_row_number].height = 75
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = \
|
||||
reporting_period_data['names'][i] + " (基线-实际) (" + reporting_period_data['units'][i] + ")"
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = '吨标准煤 (基线-实际) (TCE)'
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = '吨二氧化碳排放 (基线-实际) (TCO2E)'
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '节约'
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['subtotals_saving'][i], 2)
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['total_in_kgce_saving'] / 1000, 2)
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['total_in_kgco2e_saving'] / 1000, 2)
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '单位面积值'
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['subtotals_per_unit_area_saving'][i], 2)
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['total_in_kgce_per_unit_area_saving'] / 1000, 2)
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = \
|
||||
round(reporting_period_data['total_in_kgco2e_per_unit_area_saving'] / 1000, 2)
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '环比'
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = str(
|
||||
round(reporting_period_data['increment_rates_saving'][i] * 100, 2)) + '%' \
|
||||
if reporting_period_data['increment_rates_saving'][i] is not None else '-'
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = str(
|
||||
round(reporting_period_data['increment_rate_in_kgce_saving'] * 100, 2)) + '%' \
|
||||
if reporting_period_data['increment_rate_in_kgce_saving'] is not None else '-'
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = str(
|
||||
round(reporting_period_data['increment_rate_in_kgco2e_saving'] * 100, 2)) + '%' \
|
||||
if reporting_period_data['increment_rate_in_kgco2e_saving'] is not None else '-'
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 2
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 吨标准煤(TCE)占比'
|
||||
|
||||
current_row_number += 1
|
||||
table_start_row_number = current_row_number
|
||||
chart_start_row_number = current_row_number
|
||||
|
||||
ws.row_dimensions[current_row_number].height = 60
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
|
||||
ws['C' + str(current_row_number)].fill = table_fill
|
||||
ws['C' + str(current_row_number)].font = name_font
|
||||
ws['C' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['C' + str(current_row_number)].border = f_border
|
||||
ws['C' + str(current_row_number)] = '节约'
|
||||
|
||||
ws['D' + str(current_row_number)].fill = table_fill
|
||||
ws['D' + str(current_row_number)].font = name_font
|
||||
ws['D' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['D' + str(current_row_number)].border = f_border
|
||||
ws['D' + str(current_row_number)] = '吨标准煤(TCE) 节约占比'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
subtotals_in_kgce_saving_sum = sum_list(reporting_period_data['subtotals_in_kgce_saving'])
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = reporting_period_data['names'][i]
|
||||
|
||||
ws['C' + str(current_row_number)].font = name_font
|
||||
ws['C' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['C' + str(current_row_number)].border = f_border
|
||||
ws['C' + str(current_row_number)] = round(reporting_period_data['subtotals_in_kgce_saving'][i] / 1000, 3)
|
||||
|
||||
ws['D' + str(current_row_number)].font = name_font
|
||||
ws['D' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['D' + str(current_row_number)].border = f_border
|
||||
ws['D' + str(current_row_number)] = str(round(reporting_period_data['subtotals_in_kgce_saving'][i] /
|
||||
subtotals_in_kgce_saving_sum * 100, 2)) + '%'\
|
||||
if abs(subtotals_in_kgce_saving_sum) > 0 else '-'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
table_end_row_number = current_row_number - 1
|
||||
|
||||
if ca_len < 4:
|
||||
current_row_number = current_row_number - ca_len + 4
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
pie = PieChart()
|
||||
pie.title = name + ' 吨标准煤(TCE)占比'
|
||||
labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
|
||||
pie_data = Reference(ws, min_col=3, min_row=table_start_row_number, max_row=table_end_row_number)
|
||||
pie.add_data(pie_data, titles_from_data=True)
|
||||
pie.set_categories(labels)
|
||||
pie.height = 7.25
|
||||
pie.width = 9
|
||||
s1 = pie.series[0]
|
||||
s1.dLbls = DataLabelList()
|
||||
s1.dLbls.showCatName = False
|
||||
s1.dLbls.showVal = True
|
||||
s1.dLbls.showPercent = True
|
||||
ws.add_chart(pie, 'E' + str(chart_start_row_number))
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 吨二氧化碳排放(TCO2E)占比'
|
||||
|
||||
current_row_number += 1
|
||||
table_start_row_number = current_row_number
|
||||
chart_start_row_number = current_row_number
|
||||
|
||||
ws.row_dimensions[current_row_number].height = 60
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
|
||||
ws['C' + str(current_row_number)].fill = table_fill
|
||||
ws['C' + str(current_row_number)].font = name_font
|
||||
ws['C' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['C' + str(current_row_number)].border = f_border
|
||||
ws['C' + str(current_row_number)] = '节约'
|
||||
|
||||
ws['D' + str(current_row_number)].fill = table_fill
|
||||
ws['D' + str(current_row_number)].font = name_font
|
||||
ws['D' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['D' + str(current_row_number)].border = f_border
|
||||
ws['D' + str(current_row_number)] = '吨二氧化碳排放(TCO2E) 节约占比'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
subtotals_in_kgco2e_saving_sum = sum_list(reporting_period_data['subtotals_in_kgco2e_saving'])
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = reporting_period_data['names'][i]
|
||||
|
||||
ws['C' + str(current_row_number)].font = name_font
|
||||
ws['C' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['C' + str(current_row_number)].border = f_border
|
||||
ws['C' + str(current_row_number)] = round(reporting_period_data['subtotals_in_kgco2e_saving'][i] / 1000, 3)
|
||||
|
||||
ws['D' + str(current_row_number)].font = name_font
|
||||
ws['D' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['D' + str(current_row_number)].border = f_border
|
||||
ws['D' + str(current_row_number)] = str(round(reporting_period_data['subtotals_in_kgco2e_saving'][i] /
|
||||
subtotals_in_kgco2e_saving_sum * 100, 2)) + '%'\
|
||||
if abs(subtotals_in_kgco2e_saving_sum) > 0 else '-'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
table_end_row_number = current_row_number - 1
|
||||
|
||||
if ca_len < 4:
|
||||
current_row_number = current_row_number - ca_len + 4
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
pie = PieChart()
|
||||
pie.title = name + ' 吨二氧化碳排放(TCO2E)占比'
|
||||
labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
|
||||
pie_data = Reference(ws, min_col=3, min_row=table_start_row_number, max_row=table_end_row_number)
|
||||
pie.add_data(pie_data, titles_from_data=True)
|
||||
pie.set_categories(labels)
|
||||
pie.height = 7.25
|
||||
pie.width = 9
|
||||
s1 = pie.series[0]
|
||||
s1.dLbls = DataLabelList()
|
||||
s1.dLbls.showCatName = False
|
||||
s1.dLbls.showVal = True
|
||||
s1.dLbls.showPercent = True
|
||||
ws.add_chart(pie, 'E' + str(chart_start_row_number))
|
||||
|
||||
#############################################
|
||||
|
||||
has_values_saving_data = True
|
||||
has_timestamps_data = True
|
||||
|
||||
if 'values_saving' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['values_saving'] is None or \
|
||||
len(reporting_period_data['values_saving']) == 0:
|
||||
has_values_saving_data = False
|
||||
|
||||
if 'timestamps' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['timestamps'] is None or \
|
||||
len(reporting_period_data['timestamps']) == 0 or \
|
||||
len(reporting_period_data['timestamps'][0]) == 0:
|
||||
has_timestamps_data = False
|
||||
|
||||
if has_values_saving_data and has_timestamps_data:
|
||||
ca_len = len(reporting_period_data['names'])
|
||||
time = reporting_period_data['timestamps'][0]
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 详细数据'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
chart_start_row_number = current_row_number
|
||||
|
||||
current_row_number += ca_len * 6
|
||||
table_start_row_number = current_row_number
|
||||
|
||||
ws.row_dimensions[current_row_number].height = 60
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '日期时间'
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
for i in range(0, len(time)):
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = time[i]
|
||||
|
||||
col = 'C'
|
||||
for j in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['values_saving'][j][i], 2) \
|
||||
if reporting_period_data['values_saving'][j][i] is not None else 0.00
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
table_end_row_number = current_row_number - 1
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '小计'
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['subtotals_saving'][i], 2)
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 2
|
||||
|
||||
format_time_width_number = 1.0
|
||||
min_len_number = 1.0
|
||||
min_width_number = 11.0 # format_time_width_number * min_len_number + 4 and min_width_number > 11.0
|
||||
|
||||
if period_type == 'hourly':
|
||||
format_time_width_number = 4.0
|
||||
min_len_number = 2
|
||||
min_width_number = 12.0
|
||||
elif period_type == 'daily':
|
||||
format_time_width_number = 2.5
|
||||
min_len_number = 4
|
||||
min_width_number = 14.0
|
||||
elif period_type == 'monthly':
|
||||
format_time_width_number = 2.1
|
||||
min_len_number = 4
|
||||
min_width_number = 12.4
|
||||
elif period_type == 'yearly':
|
||||
format_time_width_number = 1.5
|
||||
min_len_number = 5
|
||||
min_width_number = 11.5
|
||||
|
||||
for i in range(0, ca_len):
|
||||
line = LineChart()
|
||||
line.title = '报告期节约 - ' + \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
|
||||
line_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number, max_row=table_end_row_number)
|
||||
line.add_data(line_data, titles_from_data=True)
|
||||
line.set_categories(labels)
|
||||
line_data = line.series[0]
|
||||
line_data.marker.symbol = "circle"
|
||||
line_data.smooth = True
|
||||
line.height = 8.25
|
||||
line.width = format_time_width_number * len(time) if len(time) > min_len_number else min_width_number
|
||||
if line.width > 24:
|
||||
line.width = 24
|
||||
line.x_axis.crosses = 'min'
|
||||
line.dLbls = DataLabelList()
|
||||
line.dLbls.dLblPos = 't'
|
||||
line.dLbls.showVal = True
|
||||
line.dLbls.showPercent = False
|
||||
chart_col = 'B'
|
||||
chart_cell = chart_col + str(chart_start_row_number)
|
||||
chart_start_row_number += 6
|
||||
ws.add_chart(line, chart_cell)
|
||||
|
||||
filename = str(uuid.uuid4()) + '.xlsx'
|
||||
wb.save(filename)
|
||||
|
||||
return filename
|
||||
|
||||
|
||||
def sum_list(lists):
|
||||
total = 0
|
||||
|
||||
for i in range(0, len(lists)):
|
||||
total += lists[i]
|
||||
|
||||
return total
|
|
@ -5,6 +5,7 @@ from openpyxl.chart import (
|
|||
LineChart,
|
||||
Reference,
|
||||
)
|
||||
from openpyxl.chart.label import DataLabelList
|
||||
from openpyxl.styles import PatternFill, Border, Side, Alignment, Font
|
||||
from openpyxl.drawing.image import Image
|
||||
from openpyxl import Workbook
|
||||
|
@ -68,19 +69,16 @@ def generate_excel(report,
|
|||
ws = wb.active
|
||||
|
||||
# Row height
|
||||
ws.row_dimensions[1].height = 121
|
||||
ws.row_dimensions[1].height = 102
|
||||
|
||||
for i in range(2, 37 + 1):
|
||||
ws.row_dimensions[i].height = 30
|
||||
|
||||
for i in range(38, 90 + 1):
|
||||
ws.row_dimensions[i].height = 30
|
||||
for i in range(2, 2000 + 1):
|
||||
ws.row_dimensions[i].height = 42
|
||||
|
||||
# Col width
|
||||
ws.column_dimensions['A'].width = 1.5
|
||||
ws.column_dimensions['B'].width = 20.0
|
||||
ws.column_dimensions['B'].width = 25.0
|
||||
|
||||
for i in range(ord('C'), ord('I')):
|
||||
for i in range(ord('C'), ord('L')):
|
||||
ws.column_dimensions[chr(i)].width = 15.0
|
||||
|
||||
# Font
|
||||
|
@ -116,12 +114,6 @@ def generate_excel(report,
|
|||
wrap_text=False,
|
||||
shrink_to_fit=False,
|
||||
indent=0)
|
||||
# c_r_alignment = Alignment(vertical='bottom',
|
||||
# horizontal='center',
|
||||
# text_rotation=0,
|
||||
# wrap_text=False,
|
||||
# shrink_to_fit=False,
|
||||
# indent=0)
|
||||
|
||||
# Img
|
||||
img = Image("excelexporters/myems.png")
|
||||
|
@ -318,63 +310,61 @@ def generate_excel(report,
|
|||
# Second: 报告期消耗
|
||||
# 9 + ca_len * 2: title
|
||||
# 10 + ca_len * 2: table title
|
||||
# row_title + 2 ~ row_title + 2 + ca_len : table_data
|
||||
# per_unit_area_start_row_number + 2 ~ per_unit_area_start_row_number + 2 + ca_len : table_data
|
||||
#################################################
|
||||
|
||||
if has_energy_data_flag:
|
||||
names = reporting_period_data['names']
|
||||
ca_len = len(names)
|
||||
|
||||
row_title = 9 + ca_len * 2
|
||||
per_unit_area_start_row_number = 9 + ca_len * 2
|
||||
|
||||
ws['B' + str(row_title)].font = title_font
|
||||
ws['B' + str(row_title)] = name + ' 单位面积值'
|
||||
ws['D' + str(row_title)].font = title_font
|
||||
ws['D' + str(row_title)] = str(report['shopfloor']['area']) + 'M²'
|
||||
ws['B' + str(per_unit_area_start_row_number)].font = title_font
|
||||
ws['B' + str(per_unit_area_start_row_number)] = name + ' 单位面积值' + str(report['shopfloor']['area']) + 'M²'
|
||||
|
||||
category = reporting_period_data['names']
|
||||
|
||||
# table_title
|
||||
ws['B' + str(row_title + 1)].fill = table_fill
|
||||
ws['B' + str(row_title + 1)].font = title_font
|
||||
ws['B' + str(row_title + 1)].alignment = c_c_alignment
|
||||
ws['B' + str(row_title + 1)] = '报告期'
|
||||
ws['B' + str(row_title + 1)].border = f_border
|
||||
ws['B' + str(per_unit_area_start_row_number + 1)].fill = table_fill
|
||||
ws['B' + str(per_unit_area_start_row_number + 1)].font = title_font
|
||||
ws['B' + str(per_unit_area_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['B' + str(per_unit_area_start_row_number + 1)] = '报告期'
|
||||
ws['B' + str(per_unit_area_start_row_number + 1)].border = f_border
|
||||
|
||||
ws['C' + str(row_title + 1)].font = title_font
|
||||
ws['C' + str(row_title + 1)].alignment = c_c_alignment
|
||||
ws['C' + str(row_title + 1)] = '算术平均数'
|
||||
ws['C' + str(row_title + 1)].border = f_border
|
||||
ws['C' + str(per_unit_area_start_row_number + 1)].font = title_font
|
||||
ws['C' + str(per_unit_area_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['C' + str(per_unit_area_start_row_number + 1)] = '算术平均数'
|
||||
ws['C' + str(per_unit_area_start_row_number + 1)].border = f_border
|
||||
|
||||
ws['D' + str(row_title + 1)].font = title_font
|
||||
ws['D' + str(row_title + 1)].alignment = c_c_alignment
|
||||
ws['D' + str(row_title + 1)] = '中位数'
|
||||
ws['D' + str(row_title + 1)].border = f_border
|
||||
ws['D' + str(per_unit_area_start_row_number + 1)].font = title_font
|
||||
ws['D' + str(per_unit_area_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['D' + str(per_unit_area_start_row_number + 1)] = '中位数'
|
||||
ws['D' + str(per_unit_area_start_row_number + 1)].border = f_border
|
||||
|
||||
ws['E' + str(row_title + 1)].font = title_font
|
||||
ws['E' + str(row_title + 1)].alignment = c_c_alignment
|
||||
ws['E' + str(row_title + 1)] = '最小值'
|
||||
ws['E' + str(row_title + 1)].border = f_border
|
||||
ws['E' + str(per_unit_area_start_row_number + 1)].font = title_font
|
||||
ws['E' + str(per_unit_area_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['E' + str(per_unit_area_start_row_number + 1)] = '最小值'
|
||||
ws['E' + str(per_unit_area_start_row_number + 1)].border = f_border
|
||||
|
||||
ws['F' + str(row_title + 1)].font = title_font
|
||||
ws['F' + str(row_title + 1)].alignment = c_c_alignment
|
||||
ws['F' + str(row_title + 1)] = '最大值'
|
||||
ws['F' + str(row_title + 1)].border = f_border
|
||||
ws['F' + str(per_unit_area_start_row_number + 1)].font = title_font
|
||||
ws['F' + str(per_unit_area_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['F' + str(per_unit_area_start_row_number + 1)] = '最大值'
|
||||
ws['F' + str(per_unit_area_start_row_number + 1)].border = f_border
|
||||
|
||||
ws['G' + str(row_title + 1)].font = title_font
|
||||
ws['G' + str(row_title + 1)].alignment = c_c_alignment
|
||||
ws['G' + str(row_title + 1)] = '样本标准差'
|
||||
ws['G' + str(row_title + 1)].border = f_border
|
||||
ws['G' + str(per_unit_area_start_row_number + 1)].font = title_font
|
||||
ws['G' + str(per_unit_area_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['G' + str(per_unit_area_start_row_number + 1)] = '样本标准差'
|
||||
ws['G' + str(per_unit_area_start_row_number + 1)].border = f_border
|
||||
|
||||
ws['H' + str(row_title + 1)].font = title_font
|
||||
ws['H' + str(row_title + 1)].alignment = c_c_alignment
|
||||
ws['H' + str(row_title + 1)] = '样本方差'
|
||||
ws['H' + str(row_title + 1)].border = f_border
|
||||
ws['H' + str(per_unit_area_start_row_number + 1)].font = title_font
|
||||
ws['H' + str(per_unit_area_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['H' + str(per_unit_area_start_row_number + 1)] = '样本方差'
|
||||
ws['H' + str(per_unit_area_start_row_number + 1)].border = f_border
|
||||
|
||||
# table_data
|
||||
|
||||
for i, value in enumerate(category):
|
||||
row_data = row_title + 2 + i
|
||||
row_data = per_unit_area_start_row_number + 2 + i
|
||||
ws['B' + str(row_data)].font = name_font
|
||||
ws['B' + str(row_data)].alignment = c_c_alignment
|
||||
ws['B' + str(row_data)] = reporting_period_data['names'][i] + " (" + reporting_period_data['units'][
|
||||
|
@ -431,9 +421,9 @@ def generate_excel(report,
|
|||
|
||||
########################################################
|
||||
# Third: 详细数据
|
||||
# row_sat+row_title~ row_sat+row_title+time_len: line
|
||||
# row_sat+1+row_title: table title
|
||||
# i + row_sat + 2 + 9 * ca_len~: table_data
|
||||
# detailed_start_row_number~ detailed_start_row_number+time_len: line
|
||||
# detailed_start_row_number+1: table title
|
||||
# i + analysis_end_row_number + 2 + 6 * ca_len~: table_data
|
||||
########################################################
|
||||
has_timestamps_flag = True
|
||||
if "timestamps" not in reporting_period_data.keys() or \
|
||||
|
@ -448,29 +438,29 @@ def generate_excel(report,
|
|||
ca_len = len(names)
|
||||
time_len = len(timestamps)
|
||||
# title
|
||||
row_title = 9 * ca_len
|
||||
# row_st == row_statistical analysis table
|
||||
row_sat = 12 + 3 * ca_len
|
||||
line_charts_row_number = 6 * ca_len
|
||||
analysis_end_row_number = 12 + 3 * ca_len
|
||||
detailed_start_row_number = analysis_end_row_number + line_charts_row_number + 1
|
||||
|
||||
ws['B' + str(row_sat+row_title)].font = title_font
|
||||
ws['B' + str(row_sat+row_title)] = name + ' 详细数据'
|
||||
ws['B' + str(detailed_start_row_number)].font = title_font
|
||||
ws['B' + str(detailed_start_row_number)] = name + ' 详细数据'
|
||||
# table_title
|
||||
ws['B' + str(row_sat+1+row_title)].fill = table_fill
|
||||
ws['B' + str(row_sat+1+row_title)].font = name_font
|
||||
ws['B' + str(row_sat+1+row_title)].alignment = c_c_alignment
|
||||
ws['B' + str(row_sat+1+row_title)] = "时间"
|
||||
ws['B' + str(row_sat+1+row_title)].border = f_border
|
||||
ws['B' + str(detailed_start_row_number+1)].fill = table_fill
|
||||
ws['B' + str(detailed_start_row_number+1)].font = name_font
|
||||
ws['B' + str(detailed_start_row_number+1)].alignment = c_c_alignment
|
||||
ws['B' + str(detailed_start_row_number+1)] = "时间"
|
||||
ws['B' + str(detailed_start_row_number+1)].border = f_border
|
||||
|
||||
for i in range(0, ca_len):
|
||||
col = chr(ord('C') + i)
|
||||
|
||||
ws[col + str(row_sat+1+row_title)].font = name_font
|
||||
ws[col + str(row_sat+1+row_title)].alignment = c_c_alignment
|
||||
ws[col + str(row_sat+1+row_title)] = names[i] + " - (" + reporting_period_data['units'][i] + ")"
|
||||
ws[col + str(row_sat+1+row_title)].border = f_border
|
||||
ws[col + str(detailed_start_row_number+1)].font = name_font
|
||||
ws[col + str(detailed_start_row_number+1)].alignment = c_c_alignment
|
||||
ws[col + str(detailed_start_row_number+1)] = names[i] + " - (" + reporting_period_data['units'][i] + ")"
|
||||
ws[col + str(detailed_start_row_number+1)].border = f_border
|
||||
# table_date
|
||||
for i in range(0, time_len):
|
||||
rows = i + row_sat + 2 + 9 * ca_len
|
||||
rows = i + detailed_start_row_number + 2
|
||||
|
||||
ws['B' + str(rows)].font = name_font
|
||||
ws['B' + str(rows)].alignment = c_c_alignment
|
||||
|
@ -487,7 +477,7 @@ def generate_excel(report,
|
|||
ws[col + str(rows)].border = f_border
|
||||
|
||||
# 小计
|
||||
row_subtotals = row_sat + 2 + time_len + 9 * ca_len
|
||||
row_subtotals = detailed_start_row_number + 2 + time_len
|
||||
ws['B' + str(row_subtotals)].font = name_font
|
||||
ws['B' + str(row_subtotals)].alignment = c_c_alignment
|
||||
ws['B' + str(row_subtotals)] = "小计"
|
||||
|
@ -502,26 +492,36 @@ def generate_excel(report,
|
|||
ws[col + str(row_subtotals)].border = f_border
|
||||
ws[col + str(row_subtotals)].number_format = '0.00'
|
||||
|
||||
# LineChart
|
||||
########################################################
|
||||
# third: LineChart
|
||||
# LineChart requires data from the detailed data table in the Excel file
|
||||
# so print the detailed data table first and then print LineChart
|
||||
########################################################
|
||||
for i in range(0, ca_len):
|
||||
|
||||
lc = LineChart()
|
||||
lc.title = "报告期消耗" + " - " + names[i] + "(" + reporting_period_data['units'][i] + ")"
|
||||
lc.style = 10
|
||||
lc.height = 8.40 # cm 1.05*8 1.05cm = 30 pt
|
||||
lc.width = 31
|
||||
lc.x_axis.majorTickMark = 'in'
|
||||
lc.y_axis.majorTickMark = 'in'
|
||||
times = Reference(ws, min_col=2, min_row=row_sat + 2 + row_title,
|
||||
max_row=row_sat + 2 + row_title + time_len)
|
||||
lc_data = Reference(ws, min_col=3 + i, min_row=row_sat + 1 + row_title,
|
||||
max_row=row_sat + 1 + row_title + time_len)
|
||||
lc.add_data(lc_data, titles_from_data=True)
|
||||
lc.set_categories(times)
|
||||
ser = lc.series[0]
|
||||
line = LineChart()
|
||||
line.title = "报告期消耗" + " - " + names[i] + "(" + reporting_period_data['units'][i] + ")"
|
||||
line.style = 10
|
||||
line.x_axis.majorTickMark = 'in'
|
||||
line.y_axis.majorTickMark = 'in'
|
||||
line.smooth = True
|
||||
line.x_axis.crosses = 'min'
|
||||
line.height = 8.25
|
||||
line.width = 24
|
||||
line.dLbls = DataLabelList()
|
||||
line.dLbls.dLblPos = 't'
|
||||
line.dLbls.showVal = True
|
||||
times = Reference(ws, min_col=2, min_row=detailed_start_row_number + 2,
|
||||
max_row=detailed_start_row_number + 2 + time_len)
|
||||
line_data = Reference(ws, min_col=3 + i, min_row=detailed_start_row_number + 1,
|
||||
max_row=detailed_start_row_number + 1 + time_len)
|
||||
line.add_data(line_data, titles_from_data=True)
|
||||
line.set_categories(times)
|
||||
ser = line.series[0]
|
||||
ser.marker.symbol = "diamond"
|
||||
ser.marker.size = 5
|
||||
ws.add_chart(lc, 'B' + str(row_sat + 9 * i))
|
||||
chart_col = 'B'
|
||||
chart_cell = str(analysis_end_row_number + 6 * i)
|
||||
ws.add_chart(line, chart_col + chart_cell)
|
||||
|
||||
filename = str(uuid.uuid4()) + '.xlsx'
|
||||
wb.save(filename)
|
||||
|
|
|
@ -560,7 +560,10 @@ def generate_excel(report,
|
|||
|
||||
ws.row_dimensions[current_row_number].height = 60
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws['B' + str(current_row_number)].font = name_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '子空间'
|
||||
ca_len = len(child['energy_category_names'])
|
||||
|
||||
col = ''
|
||||
|
@ -568,14 +571,14 @@ def generate_excel(report,
|
|||
for i in range(0, ca_len):
|
||||
col = chr(ord('C') + i)
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = child['energy_category_names'][i] + ' (' + child['units'][i] + ')'
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = '总计 (' + report['reporting_period']['total_unit'] + ')'
|
||||
|
@ -586,7 +589,7 @@ def generate_excel(report,
|
|||
current_row_number += 1
|
||||
row = str(current_row_number)
|
||||
|
||||
ws['B' + row].font = name_font
|
||||
ws['B' + row].font = title_font
|
||||
ws['B' + row].alignment = c_c_alignment
|
||||
ws['B' + row] = child['child_space_names_array'][0][i]
|
||||
ws['B' + row].border = f_border
|
||||
|
|
|
@ -622,7 +622,10 @@ def generate_excel(report,
|
|||
|
||||
ws.row_dimensions[current_row_number].height = 60
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws['B' + str(current_row_number)].font = name_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '子空间'
|
||||
ca_len = len(child['energy_category_names'])
|
||||
|
||||
col = ''
|
||||
|
@ -630,7 +633,7 @@ def generate_excel(report,
|
|||
for i in range(0, ca_len):
|
||||
col = chr(ord('C') + i)
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = child['energy_category_names'][i] + ' (' + child['units'][i] + ')'
|
||||
|
@ -641,7 +644,7 @@ def generate_excel(report,
|
|||
current_row_number += 1
|
||||
row = str(current_row_number)
|
||||
|
||||
ws['B' + row].font = name_font
|
||||
ws['B' + row].font = title_font
|
||||
ws['B' + row].alignment = c_c_alignment
|
||||
ws['B' + row] = child['child_space_names_array'][0][i]
|
||||
ws['B' + row].border = f_border
|
||||
|
|
|
@ -472,7 +472,10 @@ def generate_excel(report,
|
|||
|
||||
ws.row_dimensions[current_row_number].height = 60
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws['B' + str(current_row_number)].font = name_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '子空间'
|
||||
ca_len = len(child['energy_item_names'])
|
||||
|
||||
for i in range(0, ca_len):
|
||||
|
@ -490,7 +493,7 @@ def generate_excel(report,
|
|||
current_row_number += 1
|
||||
row = str(current_row_number)
|
||||
|
||||
ws['B' + row].font = name_font
|
||||
ws['B' + row].font = title_font
|
||||
ws['B' + row].alignment = c_c_alignment
|
||||
ws['B' + row] = child['child_space_names_array'][0][i]
|
||||
ws['B' + row].border = f_border
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import base64
|
||||
import uuid
|
||||
import os
|
||||
from decimal import Decimal
|
||||
from openpyxl.chart import (
|
||||
PieChart,
|
||||
LineChart,
|
||||
|
@ -291,9 +292,10 @@ def generate_excel(report,
|
|||
current_row_number += 1
|
||||
|
||||
ca_len = len(reporting_period_data['names'])
|
||||
wssum = 0
|
||||
total = Decimal(0.0)
|
||||
for i in range(0, ca_len):
|
||||
wssum = round(reporting_period_data['subtotals'][i], 2) + wssum
|
||||
total = reporting_period_data['subtotals'][i] + total
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
|
@ -308,7 +310,8 @@ def generate_excel(report,
|
|||
ws['D' + str(current_row_number)].font = title_font
|
||||
ws['D' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['D' + str(current_row_number)].border = f_border
|
||||
ws['D' + str(current_row_number)] = '{:.2%}'.format(round(reporting_period_data['subtotals'][i], 2) / wssum)
|
||||
ws['D' + str(current_row_number)] = '{:.2%}'.format(reporting_period_data['subtotals'][i] / total) \
|
||||
if total > Decimal(0.0) else '-'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
|
@ -327,103 +330,29 @@ def generate_excel(report,
|
|||
s1.dLbls.showCatName = False
|
||||
s1.dLbls.showVal = True
|
||||
s1.dLbls.showPercent = True
|
||||
table_cell = 'E' + str(table_start_row_number - 1)
|
||||
table_cell = 'E' + str(table_start_row_number)
|
||||
ws.add_chart(pie, table_cell)
|
||||
|
||||
if ca_len < 4:
|
||||
current_row_number = current_row_number - ca_len + 4
|
||||
|
||||
else:
|
||||
for i in range(13, 22 + 1):
|
||||
ws.row_dimensions[i].height = 0.1
|
||||
|
||||
##################################
|
||||
current_row_number = 15
|
||||
|
||||
has_child_flag = True
|
||||
|
||||
if "child_space" not in report.keys() or "energy_category_names" not in report['child_space'].keys() or \
|
||||
len(report['child_space']["energy_category_names"]) == 0 \
|
||||
or 'child_space_names_array' not in report['child_space'].keys() \
|
||||
or report['child_space']['energy_category_names'] is None \
|
||||
or len(report['child_space']['child_space_names_array']) == 0 \
|
||||
or len(report['child_space']['child_space_names_array'][0]) == 0:
|
||||
has_child_flag = False
|
||||
|
||||
if has_child_flag:
|
||||
child = report['child_space']
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 子空间数据'
|
||||
|
||||
current_row_number += 1
|
||||
table_start_row_number = current_row_number
|
||||
|
||||
ws.row_dimensions[current_row_number].height = 60
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ca_len = len(child['energy_category_names'])
|
||||
|
||||
col = ''
|
||||
|
||||
for i in range(0, ca_len):
|
||||
col = chr(ord('C') + i)
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = child['energy_category_names'][i] + ' (' + child['units'][i] + ')'
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = '总计 (' + report['reporting_period']['total_unit'] + ')'
|
||||
|
||||
space_len = len(child['child_space_names_array'][0])
|
||||
|
||||
for i in range(0, space_len):
|
||||
current_row_number += 1
|
||||
row = str(current_row_number)
|
||||
|
||||
ws['B' + row].font = name_font
|
||||
ws['B' + row].alignment = c_c_alignment
|
||||
ws['B' + row] = child['child_space_names_array'][0][i]
|
||||
ws['B' + row].border = f_border
|
||||
|
||||
col = ''
|
||||
every_day_sum = 0
|
||||
|
||||
for j in range(0, ca_len):
|
||||
col = chr(ord('C') + j)
|
||||
ws[col + row].font = name_font
|
||||
ws[col + row].alignment = c_c_alignment
|
||||
every_day_sum += child['subtotals_array'][j][i]
|
||||
ws[col + row] = round(child['subtotals_array'][j][i], 2)
|
||||
ws[col + row].border = f_border
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
ws[col + row].font = name_font
|
||||
ws[col + row].alignment = c_c_alignment
|
||||
ws[col + row] = round(every_day_sum, 2)
|
||||
ws[col + row].border = f_border
|
||||
current_row_number += 1
|
||||
|
||||
current_row_number += 1
|
||||
#################################################
|
||||
|
||||
#############################################
|
||||
reporting_period_data = report['reporting_period']
|
||||
times = reporting_period_data['timestamps']
|
||||
has_detail_data_flag = True
|
||||
ca_len = len(report['reporting_period']['names'])
|
||||
table_row = (current_row_number + 1) + ca_len * 6
|
||||
current_end_row_number = current_row_number
|
||||
if "timestamps" not in reporting_period_data.keys() or \
|
||||
reporting_period_data['timestamps'] is None or \
|
||||
len(reporting_period_data['timestamps']) == 0:
|
||||
has_detail_data_flag = False
|
||||
|
||||
if has_detail_data_flag:
|
||||
current_end_row_number += ca_len * 6 + 1
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 详细数据'
|
||||
|
||||
|
@ -439,6 +368,7 @@ def generate_excel(report,
|
|||
if len(time) > 0:
|
||||
has_data = True
|
||||
max_row = table_row + len(time)
|
||||
current_end_row_number += (len(time) + 3)
|
||||
|
||||
if has_data:
|
||||
for i in range(0, len(time)):
|
||||
|
@ -517,7 +447,7 @@ def generate_excel(report,
|
|||
ws[col + str(table_row)] = '总计 (' + report['reporting_period']['total_unit'] + ')'
|
||||
ws[col + str(table_row)].border = f_border
|
||||
|
||||
total_sum = 0
|
||||
total_sum = Decimal(0.0)
|
||||
|
||||
for j in range(0, len(time)):
|
||||
row = str(table_row + 1 + j)
|
||||
|
@ -534,9 +464,120 @@ def generate_excel(report,
|
|||
ws[col + row] = round(total_sum, 2)
|
||||
ws[col + row].border = f_border
|
||||
|
||||
else:
|
||||
for i in range(37, 69 + 1):
|
||||
ws.row_dimensions[i].height = 0.1
|
||||
current_row_number = current_end_row_number
|
||||
|
||||
##################################
|
||||
|
||||
has_child_flag = True
|
||||
|
||||
if "child_space" not in report.keys() or "energy_category_names" not in report['child_space'].keys() or \
|
||||
len(report['child_space']["energy_category_names"]) == 0 \
|
||||
or 'child_space_names_array' not in report['child_space'].keys() \
|
||||
or report['child_space']['energy_category_names'] is None \
|
||||
or len(report['child_space']['child_space_names_array']) == 0 \
|
||||
or len(report['child_space']['child_space_names_array'][0]) == 0:
|
||||
has_child_flag = False
|
||||
|
||||
if has_child_flag:
|
||||
child = report['child_space']
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 子空间数据'
|
||||
|
||||
current_row_number += 1
|
||||
table_start_row_number = current_row_number
|
||||
|
||||
ws.row_dimensions[current_row_number].height = 60
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws['B' + str(current_row_number)].font = name_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '子空间'
|
||||
ca_len = len(child['energy_category_names'])
|
||||
|
||||
col = ''
|
||||
|
||||
for i in range(0, ca_len):
|
||||
col = chr(ord('C') + i)
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = child['energy_category_names'][i] + ' (' + child['units'][i] + ')'
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = '总计 (' + report['reporting_period']['total_unit'] + ')'
|
||||
|
||||
space_len = len(child['child_space_names_array'][0])
|
||||
|
||||
for i in range(0, space_len):
|
||||
current_row_number += 1
|
||||
row = str(current_row_number)
|
||||
|
||||
ws['B' + row].font = title_font
|
||||
ws['B' + row].alignment = c_c_alignment
|
||||
ws['B' + row] = child['child_space_names_array'][0][i]
|
||||
ws['B' + row].border = f_border
|
||||
|
||||
col = ''
|
||||
every_day_sum = Decimal(0.0)
|
||||
|
||||
for j in range(0, ca_len):
|
||||
col = chr(ord('C') + j)
|
||||
ws[col + row].font = name_font
|
||||
ws[col + row].alignment = c_c_alignment
|
||||
every_day_sum += child['subtotals_array'][j][i]
|
||||
ws[col + row] = round(child['subtotals_array'][j][i], 2)
|
||||
ws[col + row].border = f_border
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
ws[col + row].font = name_font
|
||||
ws[col + row].alignment = c_c_alignment
|
||||
ws[col + row] = round(every_day_sum, 2)
|
||||
ws[col + row].border = f_border
|
||||
|
||||
table_end_row_number = current_row_number
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
chart_start_row_number = current_row_number
|
||||
|
||||
# Pie
|
||||
for i in range(0, ca_len):
|
||||
pie = PieChart()
|
||||
labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
|
||||
pie_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number,
|
||||
max_row=table_end_row_number)
|
||||
pie.add_data(pie_data, titles_from_data=True)
|
||||
pie.set_categories(labels)
|
||||
pie.height = 6.6
|
||||
pie.width = 8
|
||||
pie.title = ws.cell(column=3 + i, row=table_start_row_number).value
|
||||
s1 = pie.series[0]
|
||||
s1.dLbls = DataLabelList()
|
||||
s1.dLbls.showCatName = False
|
||||
s1.dLbls.showVal = True
|
||||
s1.dLbls.showPercent = True
|
||||
chart_cell = ''
|
||||
if i % 2 == 0:
|
||||
chart_cell = 'B' + str(chart_start_row_number)
|
||||
else:
|
||||
chart_cell = 'E' + str(chart_start_row_number)
|
||||
chart_start_row_number += 5
|
||||
ws.add_chart(pie, chart_cell)
|
||||
|
||||
current_row_number = chart_start_row_number
|
||||
|
||||
if ca_len % 2 == 1:
|
||||
current_row_number += 5
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
#############################################
|
||||
|
||||
filename = str(uuid.uuid4()) + '.xlsx'
|
||||
wb.save(filename)
|
||||
|
@ -545,7 +586,7 @@ def generate_excel(report,
|
|||
|
||||
|
||||
def reporting_period_values_every_day_sum(reporting_period_data, every_day_index, ca_len):
|
||||
every_day_sum = 0
|
||||
every_day_sum = Decimal(0.0)
|
||||
for i in range(0, ca_len):
|
||||
every_day_sum += reporting_period_data['values'][i][every_day_index]
|
||||
|
||||
|
|
|
@ -204,7 +204,8 @@ def generate_excel(report, name, reporting_start_datetime_local, reporting_end_d
|
|||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['averages'][i], 2)
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['averages'][i], 2) \
|
||||
if reporting_period_data['averages'][i] is not None else 'N/A'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
|
@ -218,7 +219,8 @@ def generate_excel(report, name, reporting_start_datetime_local, reporting_end_d
|
|||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['averages_per_unit_area'][i], 2)
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['averages_per_unit_area'][i], 2) \
|
||||
if reporting_period_data['averages_per_unit_area'][i] is not None else 'N/A'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
|
@ -267,7 +269,8 @@ def generate_excel(report, name, reporting_start_datetime_local, reporting_end_d
|
|||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['maximums'][i], 2)
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['maximums'][i], 2) \
|
||||
if reporting_period_data['maximums'][i] is not None else 'N/A'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
|
@ -281,7 +284,8 @@ def generate_excel(report, name, reporting_start_datetime_local, reporting_end_d
|
|||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['maximums_per_unit_area'][i], 2)
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['maximums_per_unit_area'][i], 2) \
|
||||
if reporting_period_data['maximums_per_unit_area'][i] is not None else 'N/A'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
|
|
|
@ -257,224 +257,224 @@ def generate_excel(report,
|
|||
|
||||
current_row_number += 2
|
||||
|
||||
#######################
|
||||
#######################
|
||||
|
||||
has_values_data = True
|
||||
has_timestamps_data = True
|
||||
has_values_data = True
|
||||
has_timestamps_data = True
|
||||
|
||||
if 'values' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['values'] is None or \
|
||||
len(reporting_period_data['values']) == 0:
|
||||
has_values_data = False
|
||||
if 'values' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['values'] is None or \
|
||||
len(reporting_period_data['values']) == 0:
|
||||
has_values_data = False
|
||||
|
||||
if 'timestamps' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['timestamps'] is None or \
|
||||
len(reporting_period_data['timestamps']) == 0 or \
|
||||
len(reporting_period_data['timestamps'][0]) == 0:
|
||||
has_timestamps_data = False
|
||||
if 'timestamps' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['timestamps'] is None or \
|
||||
len(reporting_period_data['timestamps']) == 0 or \
|
||||
len(reporting_period_data['timestamps'][0]) == 0:
|
||||
has_timestamps_data = False
|
||||
|
||||
if has_values_data and has_timestamps_data:
|
||||
ca_len = len(reporting_period_data['names'])
|
||||
time = reporting_period_data['timestamps'][0]
|
||||
if has_values_data and has_timestamps_data:
|
||||
ca_len = len(reporting_period_data['names'])
|
||||
time = reporting_period_data['timestamps'][0]
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 详细数据'
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 详细数据'
|
||||
|
||||
current_row_number += 1
|
||||
current_row_number += 1
|
||||
|
||||
chart_start_row_number = current_row_number
|
||||
chart_start_row_number = current_row_number
|
||||
|
||||
current_row_number += ca_len * 6
|
||||
table_start_row_number = current_row_number
|
||||
current_row_number += ca_len * 6
|
||||
table_start_row_number = current_row_number
|
||||
|
||||
ws.row_dimensions[current_row_number].height = 60
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws.row_dimensions[current_row_number].height = 60
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '日期时间'
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
for i in range(0, len(time)):
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '日期时间'
|
||||
ws['B' + str(current_row_number)] = time[i]
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
for j in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['values'][j][i], 2) \
|
||||
if reporting_period_data['values'][j][i] is not None else 0.00
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
for i in range(0, len(time)):
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = time[i]
|
||||
table_end_row_number = current_row_number - 1
|
||||
|
||||
col = 'C'
|
||||
for j in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['values'][j][i], 2) \
|
||||
if reporting_period_data['values'][j][i] is not None else 0.00
|
||||
col = chr(ord(col) + 1)
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '小计'
|
||||
|
||||
current_row_number += 1
|
||||
col = 'C'
|
||||
|
||||
table_end_row_number = current_row_number - 1
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['subtotals'][i], 2)
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '小计'
|
||||
current_row_number += 2
|
||||
|
||||
col = 'C'
|
||||
format_time_width_number = 1.0
|
||||
min_len_number = 1.0
|
||||
min_width_number = 11.0 # format_time_width_number * min_len_number + 4 and min_width_number > 11.0
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['subtotals'][i], 2)
|
||||
col = chr(ord(col) + 1)
|
||||
if period_type == 'hourly':
|
||||
format_time_width_number = 4.0
|
||||
min_len_number = 2
|
||||
min_width_number = 12.0
|
||||
elif period_type == 'daily':
|
||||
format_time_width_number = 2.5
|
||||
min_len_number = 4
|
||||
min_width_number = 14.0
|
||||
elif period_type == 'monthly':
|
||||
format_time_width_number = 2.1
|
||||
min_len_number = 4
|
||||
min_width_number = 12.4
|
||||
elif period_type == 'yearly':
|
||||
format_time_width_number = 1.5
|
||||
min_len_number = 5
|
||||
min_width_number = 11.5
|
||||
|
||||
current_row_number += 2
|
||||
for i in range(0, ca_len):
|
||||
line = LineChart()
|
||||
line.title = '报告期产出 - ' + \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
|
||||
line_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number, max_row=table_end_row_number)
|
||||
line.add_data(line_data, titles_from_data=True)
|
||||
line.set_categories(labels)
|
||||
line_data = line.series[0]
|
||||
line_data.marker.symbol = "circle"
|
||||
line_data.smooth = True
|
||||
line.x_axis.crosses = 'min'
|
||||
line.height = 8.25
|
||||
line.width = format_time_width_number * len(time) if len(time) > min_len_number else min_width_number
|
||||
if line.width > 24:
|
||||
line.width = 24
|
||||
line.dLbls = DataLabelList()
|
||||
line.dLbls.dLblPos = 't'
|
||||
line.dLbls.showVal = True
|
||||
line.dLbls.showPercent = False
|
||||
chart_col = 'B'
|
||||
chart_cell = chart_col + str(chart_start_row_number)
|
||||
chart_start_row_number += 6
|
||||
ws.add_chart(line, chart_cell)
|
||||
|
||||
format_time_width_number = 1.0
|
||||
min_len_number = 1.0
|
||||
min_width_number = 11.0 # format_time_width_number * min_len_number + 4 and min_width_number > 11.0
|
||||
#####################################
|
||||
|
||||
if period_type == 'hourly':
|
||||
format_time_width_number = 4.0
|
||||
min_len_number = 2
|
||||
min_width_number = 12.0
|
||||
elif period_type == 'daily':
|
||||
format_time_width_number = 2.5
|
||||
min_len_number = 4
|
||||
min_width_number = 14.0
|
||||
elif period_type == 'monthly':
|
||||
format_time_width_number = 2.1
|
||||
min_len_number = 4
|
||||
min_width_number = 12.4
|
||||
elif period_type == 'yearly':
|
||||
format_time_width_number = 1.5
|
||||
min_len_number = 5
|
||||
min_width_number = 11.5
|
||||
has_child_flag = True
|
||||
|
||||
for i in range(0, ca_len):
|
||||
line = LineChart()
|
||||
line.title = '报告期产出 - ' + \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
|
||||
line_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number, max_row=table_end_row_number)
|
||||
line.add_data(line_data, titles_from_data=True)
|
||||
line.set_categories(labels)
|
||||
line_data = line.series[0]
|
||||
line_data.marker.symbol = "circle"
|
||||
line_data.smooth = True
|
||||
line.x_axis.crosses = 'min'
|
||||
line.height = 8.25
|
||||
line.width = format_time_width_number * len(time) if len(time) > min_len_number else min_width_number
|
||||
if line.width > 24:
|
||||
line.width = 24
|
||||
line.dLbls = DataLabelList()
|
||||
line.dLbls.dLblPos = 't'
|
||||
line.dLbls.showVal = True
|
||||
line.dLbls.showPercent = False
|
||||
chart_col = 'B'
|
||||
chart_cell = chart_col + str(chart_start_row_number)
|
||||
chart_start_row_number += 6
|
||||
ws.add_chart(line, chart_cell)
|
||||
if "child_space" not in report.keys() or "energy_category_names" not in report['child_space'].keys() or \
|
||||
len(report['child_space']["energy_category_names"]) == 0 \
|
||||
or 'child_space_names_array' not in report['child_space'].keys() \
|
||||
or report['child_space']['child_space_names_array'] is None \
|
||||
or len(report['child_space']['child_space_names_array']) == 0 \
|
||||
or len(report['child_space']['child_space_names_array'][0]) == 0:
|
||||
has_child_flag = False
|
||||
|
||||
#####################################
|
||||
if has_child_flag:
|
||||
child = report['child_space']
|
||||
|
||||
has_child_flag = True
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 子空间数据'
|
||||
|
||||
if "child_space" not in report.keys() or "energy_category_names" not in report['child_space'].keys() or \
|
||||
len(report['child_space']["energy_category_names"]) == 0 \
|
||||
or 'child_space_names_array' not in report['child_space'].keys() \
|
||||
or report['child_space']['child_space_names_array'] is None \
|
||||
or len(report['child_space']['child_space_names_array']) == 0 \
|
||||
or len(report['child_space']['child_space_names_array'][0]) == 0:
|
||||
has_child_flag = False
|
||||
current_row_number += 1
|
||||
table_start_row_number = current_row_number
|
||||
|
||||
if has_child_flag:
|
||||
child = report['child_space']
|
||||
ws.row_dimensions[current_row_number].height = 60
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ca_len = len(child['energy_category_names'])
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 子空间数据'
|
||||
for i in range(0, ca_len):
|
||||
row = chr(ord('C') + i)
|
||||
ws[row + str(current_row_number)].fill = table_fill
|
||||
ws[row + str(current_row_number)].font = name_font
|
||||
ws[row + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[row + str(current_row_number)].border = f_border
|
||||
ws[row + str(current_row_number)] = \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
|
||||
space_len = len(child['child_space_names_array'][0])
|
||||
|
||||
for i in range(0, space_len):
|
||||
current_row_number += 1
|
||||
table_start_row_number = current_row_number
|
||||
row = str(current_row_number)
|
||||
|
||||
ws.row_dimensions[current_row_number].height = 60
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ca_len = len(child['energy_category_names'])
|
||||
ws['B' + row].font = name_font
|
||||
ws['B' + row].alignment = c_c_alignment
|
||||
ws['B' + row] = child['child_space_names_array'][0][i]
|
||||
ws['B' + row].border = f_border
|
||||
|
||||
for i in range(0, ca_len):
|
||||
row = chr(ord('C') + i)
|
||||
ws[row + str(current_row_number)].fill = table_fill
|
||||
ws[row + str(current_row_number)].font = name_font
|
||||
ws[row + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[row + str(current_row_number)].border = f_border
|
||||
ws[row + str(current_row_number)] = \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
for j in range(0, ca_len):
|
||||
col = chr(ord('C') + j)
|
||||
ws[col + row].font = name_font
|
||||
ws[col + row].alignment = c_c_alignment
|
||||
ws[col + row] = round(child['subtotals_array'][j][i], 2)
|
||||
ws[col + row].border = f_border
|
||||
|
||||
space_len = len(child['child_space_names_array'][0])
|
||||
table_end_row_number = current_row_number
|
||||
current_row_number += 1
|
||||
pie_start_row_number = current_row_number
|
||||
|
||||
for i in range(0, space_len):
|
||||
current_row_number += 1
|
||||
row = str(current_row_number)
|
||||
# Pie
|
||||
for i in range(0, ca_len):
|
||||
pie = PieChart()
|
||||
labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1,
|
||||
max_row=table_end_row_number)
|
||||
pie_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number,
|
||||
max_row=table_end_row_number)
|
||||
pie.add_data(pie_data, titles_from_data=True)
|
||||
pie.set_categories(labels)
|
||||
pie.height = 6.6
|
||||
pie.width = 8
|
||||
pie.title = ws.cell(column=3 + i, row=table_start_row_number).value
|
||||
s1 = pie.series[0]
|
||||
s1.dLbls = DataLabelList()
|
||||
s1.dLbls.showCatName = False
|
||||
s1.dLbls.showVal = True
|
||||
s1.dLbls.showPercent = True
|
||||
chart_cell = ''
|
||||
if i % 2 == 0:
|
||||
chart_cell = 'B' + str(pie_start_row_number)
|
||||
else:
|
||||
chart_cell = 'E' + str(pie_start_row_number)
|
||||
pie_start_row_number += 5
|
||||
ws.add_chart(pie, chart_cell)
|
||||
|
||||
ws['B' + row].font = name_font
|
||||
ws['B' + row].alignment = c_c_alignment
|
||||
ws['B' + row] = child['child_space_names_array'][0][i]
|
||||
ws['B' + row].border = f_border
|
||||
current_row_number = pie_start_row_number
|
||||
if ca_len % 2 == 1:
|
||||
current_row_number += 5
|
||||
|
||||
for j in range(0, ca_len):
|
||||
col = chr(ord('C') + j)
|
||||
ws[col + row].font = name_font
|
||||
ws[col + row].alignment = c_c_alignment
|
||||
ws[col + row] = round(child['subtotals_array'][j][i], 2)
|
||||
ws[col + row].border = f_border
|
||||
|
||||
table_end_row_number = current_row_number
|
||||
current_row_number += 1
|
||||
pie_start_row_number = current_row_number
|
||||
|
||||
# Pie
|
||||
for i in range(0, ca_len):
|
||||
pie = PieChart()
|
||||
labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1,
|
||||
max_row=table_end_row_number)
|
||||
pie_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number,
|
||||
max_row=table_end_row_number)
|
||||
pie.add_data(pie_data, titles_from_data=True)
|
||||
pie.set_categories(labels)
|
||||
pie.height = 6.6
|
||||
pie.width = 8
|
||||
pie.title = ws.cell(column=3 + i, row=table_start_row_number).value
|
||||
s1 = pie.series[0]
|
||||
s1.dLbls = DataLabelList()
|
||||
s1.dLbls.showCatName = False
|
||||
s1.dLbls.showVal = True
|
||||
s1.dLbls.showPercent = True
|
||||
chart_cell = ''
|
||||
if i % 2 == 0:
|
||||
chart_cell = 'B' + str(pie_start_row_number)
|
||||
else:
|
||||
chart_cell = 'E' + str(pie_start_row_number)
|
||||
pie_start_row_number += 5
|
||||
ws.add_chart(pie, chart_cell)
|
||||
|
||||
current_row_number = pie_start_row_number
|
||||
if ca_len % 2 == 1:
|
||||
current_row_number += 5
|
||||
|
||||
current_row_number += 1
|
||||
current_row_number += 1
|
||||
|
||||
filename = str(uuid.uuid4()) + '.xlsx'
|
||||
wb.save(filename)
|
||||
|
|
|
@ -152,6 +152,7 @@ def generate_excel(report,
|
|||
ws['F3'].font = name_font
|
||||
ws['F3'].alignment = b_r_alignment
|
||||
ws['F3'] = 'Date:'
|
||||
ws['G3'].border = b_border
|
||||
ws['G3'].alignment = b_c_alignment
|
||||
ws['G3'].font = name_font
|
||||
ws['G3'] = reporting_start_datetime_local + "__" + reporting_end_datetime_local
|
||||
|
@ -335,10 +336,18 @@ def generate_excel(report,
|
|||
ws['C' + str(current_row_number)].font = name_font
|
||||
ws['C' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['C' + str(current_row_number)].border = f_border
|
||||
ws['C' + str(current_row_number)] = '吨标准煤(TCE)占比'
|
||||
ws['C' + str(current_row_number)] = '节约'
|
||||
|
||||
ws['D' + str(current_row_number)].fill = table_fill
|
||||
ws['D' + str(current_row_number)].font = name_font
|
||||
ws['D' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['D' + str(current_row_number)].border = f_border
|
||||
ws['D' + str(current_row_number)] = '吨标准煤(TCE) 节约占比'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
subtotals_in_kgce_saving_sum = sum_list(reporting_period_data['subtotals_in_kgce_saving'])
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
|
@ -350,6 +359,13 @@ def generate_excel(report,
|
|||
ws['C' + str(current_row_number)].border = f_border
|
||||
ws['C' + str(current_row_number)] = round(reporting_period_data['subtotals_in_kgce_saving'][i] / 1000, 3)
|
||||
|
||||
ws['D' + str(current_row_number)].font = name_font
|
||||
ws['D' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['D' + str(current_row_number)].border = f_border
|
||||
ws['D' + str(current_row_number)] = str(round(reporting_period_data['subtotals_in_kgce_saving'][i] /
|
||||
subtotals_in_kgce_saving_sum * 100, 2)) + '%'\
|
||||
if abs(subtotals_in_kgce_saving_sum) > 0 else '-'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
table_end_row_number = current_row_number - 1
|
||||
|
@ -372,7 +388,7 @@ def generate_excel(report,
|
|||
s1.dLbls.showCatName = False
|
||||
s1.dLbls.showVal = True
|
||||
s1.dLbls.showPercent = True
|
||||
ws.add_chart(pie, 'D' + str(chart_start_row_number))
|
||||
ws.add_chart(pie, 'E' + str(chart_start_row_number))
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 吨二氧化碳排放(TCO2E)占比'
|
||||
|
@ -389,10 +405,18 @@ def generate_excel(report,
|
|||
ws['C' + str(current_row_number)].font = name_font
|
||||
ws['C' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['C' + str(current_row_number)].border = f_border
|
||||
ws['C' + str(current_row_number)] = '吨二氧化碳排放(TCO2E)占比'
|
||||
ws['C' + str(current_row_number)] = '节约'
|
||||
|
||||
ws['D' + str(current_row_number)].fill = table_fill
|
||||
ws['D' + str(current_row_number)].font = name_font
|
||||
ws['D' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['D' + str(current_row_number)].border = f_border
|
||||
ws['D' + str(current_row_number)] = '吨二氧化碳排放(TCO2E) 节约占比'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
subtotals_in_kgco2e_saving_sum = sum_list(reporting_period_data['subtotals_in_kgco2e_saving'])
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
|
@ -404,6 +428,13 @@ def generate_excel(report,
|
|||
ws['C' + str(current_row_number)].border = f_border
|
||||
ws['C' + str(current_row_number)] = round(reporting_period_data['subtotals_in_kgco2e_saving'][i] / 1000, 3)
|
||||
|
||||
ws['D' + str(current_row_number)].font = name_font
|
||||
ws['D' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['D' + str(current_row_number)].border = f_border
|
||||
ws['D' + str(current_row_number)] = str(round(reporting_period_data['subtotals_in_kgco2e_saving'][i] /
|
||||
subtotals_in_kgco2e_saving_sum * 100, 2)) + '%'\
|
||||
if abs(subtotals_in_kgco2e_saving_sum) > 0 else '-'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
table_end_row_number = current_row_number - 1
|
||||
|
@ -426,7 +457,7 @@ def generate_excel(report,
|
|||
s1.dLbls.showCatName = False
|
||||
s1.dLbls.showVal = True
|
||||
s1.dLbls.showPercent = True
|
||||
ws.add_chart(pie, 'D' + str(chart_start_row_number))
|
||||
ws.add_chart(pie, 'E' + str(chart_start_row_number))
|
||||
|
||||
################################
|
||||
|
||||
|
@ -657,3 +688,13 @@ def generate_excel(report,
|
|||
wb.save(filename)
|
||||
|
||||
return filename
|
||||
|
||||
|
||||
def sum_list(lists):
|
||||
total = 0
|
||||
|
||||
for i in range(0, len(lists)):
|
||||
total += lists[i]
|
||||
|
||||
return total
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ from openpyxl.chart import (
|
|||
LineChart,
|
||||
Reference,
|
||||
)
|
||||
from openpyxl.chart.label import DataLabelList
|
||||
from openpyxl.styles import PatternFill, Border, Side, Alignment, Font
|
||||
from openpyxl.drawing.image import Image
|
||||
from openpyxl import Workbook
|
||||
|
@ -68,19 +69,16 @@ def generate_excel(report,
|
|||
ws = wb.active
|
||||
|
||||
# Row height
|
||||
ws.row_dimensions[1].height = 121
|
||||
ws.row_dimensions[1].height = 102
|
||||
|
||||
for i in range(2, 37 + 1):
|
||||
ws.row_dimensions[i].height = 30
|
||||
|
||||
for i in range(38, 90 + 1):
|
||||
ws.row_dimensions[i].height = 30
|
||||
for i in range(2, 2000 + 1):
|
||||
ws.row_dimensions[i].height = 42
|
||||
|
||||
# Col width
|
||||
ws.column_dimensions['A'].width = 1.5
|
||||
ws.column_dimensions['B'].width = 20.0
|
||||
ws.column_dimensions['B'].width = 25.0
|
||||
|
||||
for i in range(ord('C'), ord('I')):
|
||||
for i in range(ord('C'), ord('L')):
|
||||
ws.column_dimensions[chr(i)].width = 15.0
|
||||
|
||||
# Font
|
||||
|
@ -116,12 +114,6 @@ def generate_excel(report,
|
|||
wrap_text=False,
|
||||
shrink_to_fit=False,
|
||||
indent=0)
|
||||
# c_r_alignment = Alignment(vertical='bottom',
|
||||
# horizontal='center',
|
||||
# text_rotation=0,
|
||||
# wrap_text=False,
|
||||
# shrink_to_fit=False,
|
||||
# indent=0)
|
||||
|
||||
# Img
|
||||
img = Image("excelexporters/myems.png")
|
||||
|
@ -320,63 +312,63 @@ def generate_excel(report,
|
|||
# Second: 报告期消耗
|
||||
# 9 + ca_len * 2: title
|
||||
# 10 + ca_len * 2: table title
|
||||
# row_title + 2 ~ row_title + 2 + ca_len : table_data
|
||||
# per_unit_area_start_row_number + 2 ~ per_unit_area_start_row_number + 2 + ca_len : table_data
|
||||
#################################################
|
||||
|
||||
if has_energy_data_flag:
|
||||
names = reporting_period_data['names']
|
||||
ca_len = len(names)
|
||||
|
||||
row_title = 9 + ca_len * 2
|
||||
per_unit_area_start_row_number = 9 + ca_len * 2
|
||||
|
||||
ws['B' + str(row_title)].font = title_font
|
||||
ws['B' + str(row_title)] = name + ' 单位面积值'
|
||||
ws['D' + str(row_title)].font = title_font
|
||||
ws['D' + str(row_title)] = str(report['space']['area']) + 'M²'
|
||||
ws['B' + str(per_unit_area_start_row_number)].font = title_font
|
||||
ws['B' + str(per_unit_area_start_row_number)] = name + ' 单位面积值'
|
||||
ws['D' + str(per_unit_area_start_row_number)].font = title_font
|
||||
ws['D' + str(per_unit_area_start_row_number)] = str(report['space']['area']) + 'M²'
|
||||
|
||||
category = reporting_period_data['names']
|
||||
|
||||
# table_title
|
||||
ws['B' + str(row_title + 1)].fill = table_fill
|
||||
ws['B' + str(row_title + 1)].font = title_font
|
||||
ws['B' + str(row_title + 1)].alignment = c_c_alignment
|
||||
ws['B' + str(row_title + 1)] = '报告期'
|
||||
ws['B' + str(row_title + 1)].border = f_border
|
||||
ws['B' + str(per_unit_area_start_row_number + 1)].fill = table_fill
|
||||
ws['B' + str(per_unit_area_start_row_number + 1)].font = title_font
|
||||
ws['B' + str(per_unit_area_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['B' + str(per_unit_area_start_row_number + 1)] = '报告期'
|
||||
ws['B' + str(per_unit_area_start_row_number + 1)].border = f_border
|
||||
|
||||
ws['C' + str(row_title + 1)].font = title_font
|
||||
ws['C' + str(row_title + 1)].alignment = c_c_alignment
|
||||
ws['C' + str(row_title + 1)] = '算术平均数'
|
||||
ws['C' + str(row_title + 1)].border = f_border
|
||||
ws['C' + str(per_unit_area_start_row_number + 1)].font = title_font
|
||||
ws['C' + str(per_unit_area_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['C' + str(per_unit_area_start_row_number + 1)] = '算术平均数'
|
||||
ws['C' + str(per_unit_area_start_row_number + 1)].border = f_border
|
||||
|
||||
ws['D' + str(row_title + 1)].font = title_font
|
||||
ws['D' + str(row_title + 1)].alignment = c_c_alignment
|
||||
ws['D' + str(row_title + 1)] = '中位数'
|
||||
ws['D' + str(row_title + 1)].border = f_border
|
||||
ws['D' + str(per_unit_area_start_row_number + 1)].font = title_font
|
||||
ws['D' + str(per_unit_area_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['D' + str(per_unit_area_start_row_number + 1)] = '中位数'
|
||||
ws['D' + str(per_unit_area_start_row_number + 1)].border = f_border
|
||||
|
||||
ws['E' + str(row_title + 1)].font = title_font
|
||||
ws['E' + str(row_title + 1)].alignment = c_c_alignment
|
||||
ws['E' + str(row_title + 1)] = '最小值'
|
||||
ws['E' + str(row_title + 1)].border = f_border
|
||||
ws['E' + str(per_unit_area_start_row_number + 1)].font = title_font
|
||||
ws['E' + str(per_unit_area_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['E' + str(per_unit_area_start_row_number + 1)] = '最小值'
|
||||
ws['E' + str(per_unit_area_start_row_number + 1)].border = f_border
|
||||
|
||||
ws['F' + str(row_title + 1)].font = title_font
|
||||
ws['F' + str(row_title + 1)].alignment = c_c_alignment
|
||||
ws['F' + str(row_title + 1)] = '最大值'
|
||||
ws['F' + str(row_title + 1)].border = f_border
|
||||
ws['F' + str(per_unit_area_start_row_number + 1)].font = title_font
|
||||
ws['F' + str(per_unit_area_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['F' + str(per_unit_area_start_row_number + 1)] = '最大值'
|
||||
ws['F' + str(per_unit_area_start_row_number + 1)].border = f_border
|
||||
|
||||
ws['G' + str(row_title + 1)].font = title_font
|
||||
ws['G' + str(row_title + 1)].alignment = c_c_alignment
|
||||
ws['G' + str(row_title + 1)] = '样本标准差'
|
||||
ws['G' + str(row_title + 1)].border = f_border
|
||||
ws['G' + str(per_unit_area_start_row_number + 1)].font = title_font
|
||||
ws['G' + str(per_unit_area_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['G' + str(per_unit_area_start_row_number + 1)] = '样本标准差'
|
||||
ws['G' + str(per_unit_area_start_row_number + 1)].border = f_border
|
||||
|
||||
ws['H' + str(row_title + 1)].font = title_font
|
||||
ws['H' + str(row_title + 1)].alignment = c_c_alignment
|
||||
ws['H' + str(row_title + 1)] = '样本方差'
|
||||
ws['H' + str(row_title + 1)].border = f_border
|
||||
ws['H' + str(per_unit_area_start_row_number + 1)].font = title_font
|
||||
ws['H' + str(per_unit_area_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['H' + str(per_unit_area_start_row_number + 1)] = '样本方差'
|
||||
ws['H' + str(per_unit_area_start_row_number + 1)].border = f_border
|
||||
|
||||
# table_data
|
||||
|
||||
for i, value in enumerate(category):
|
||||
row_data = row_title + 2 + i
|
||||
row_data = per_unit_area_start_row_number + 2 + i
|
||||
ws['B' + str(row_data)].font = name_font
|
||||
ws['B' + str(row_data)].alignment = c_c_alignment
|
||||
ws['B' + str(row_data)] = reporting_period_data['names'][i] + " (" + reporting_period_data['units'][
|
||||
|
@ -433,9 +425,9 @@ def generate_excel(report,
|
|||
|
||||
########################################################
|
||||
# Third: 详细数据
|
||||
# row_sat+row_title~ row_sat+row_title+time_len: line
|
||||
# row_sat+1+row_title: table title
|
||||
# i + row_sat + 2 + 10 * ca_len~: table_data
|
||||
# analysis_end_row_number~ analysis_end_row_number+time_len: line
|
||||
# analysis_end_row_number+1+line_charts_row_number: table title
|
||||
# i + analysis_end_row_number + 2 + 10 * ca_len~: table_data
|
||||
########################################################
|
||||
has_timestamps_flag = True
|
||||
if "timestamps" not in reporting_period_data.keys() or \
|
||||
|
@ -450,29 +442,29 @@ def generate_excel(report,
|
|||
ca_len = len(names)
|
||||
time_len = len(timestamps)
|
||||
# title
|
||||
row_title = 10 * ca_len
|
||||
# row_st == row_statistical analysis table
|
||||
row_sat = 12 + 3 * ca_len
|
||||
|
||||
ws['B' + str(row_sat+row_title)].font = title_font
|
||||
ws['B' + str(row_sat+row_title)] = name + ' 详细数据'
|
||||
line_charts_row_number = 6 * ca_len
|
||||
analysis_end_row_number = 12 + 3 * ca_len
|
||||
detailed_start_row_number = analysis_end_row_number + line_charts_row_number + 1
|
||||
|
||||
ws['B' + str(detailed_start_row_number)].font = title_font
|
||||
ws['B' + str(detailed_start_row_number)] = name + ' 详细数据'
|
||||
# table_title
|
||||
ws['B' + str(row_sat+1+row_title)].fill = table_fill
|
||||
ws['B' + str(row_sat+1+row_title)].font = name_font
|
||||
ws['B' + str(row_sat+1+row_title)].alignment = c_c_alignment
|
||||
ws['B' + str(row_sat+1+row_title)] = "时间"
|
||||
ws['B' + str(row_sat+1+row_title)].border = f_border
|
||||
ws['B' + str(detailed_start_row_number + 1)].fill = table_fill
|
||||
ws['B' + str(detailed_start_row_number + 1)].font = name_font
|
||||
ws['B' + str(detailed_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['B' + str(detailed_start_row_number + 1)] = "时间"
|
||||
ws['B' + str(detailed_start_row_number + 1)].border = f_border
|
||||
|
||||
for i in range(0, ca_len):
|
||||
col = chr(ord('C') + i)
|
||||
|
||||
ws[col + str(row_sat+1+row_title)].font = name_font
|
||||
ws[col + str(row_sat+1+row_title)].alignment = c_c_alignment
|
||||
ws[col + str(row_sat+1+row_title)] = names[i] + " - (" + reporting_period_data['units'][i] + ")"
|
||||
ws[col + str(row_sat+1+row_title)].border = f_border
|
||||
ws[col + str(detailed_start_row_number + 1)].font = name_font
|
||||
ws[col + str(detailed_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws[col + str(detailed_start_row_number + 1)] = names[i] + " - (" + reporting_period_data['units'][i] + ")"
|
||||
ws[col + str(detailed_start_row_number + 1)].border = f_border
|
||||
# table_date
|
||||
for i in range(0, time_len):
|
||||
rows = i + row_sat + 2 + 10 * ca_len
|
||||
rows = i + detailed_start_row_number + 2
|
||||
|
||||
ws['B' + str(rows)].font = name_font
|
||||
ws['B' + str(rows)].alignment = c_c_alignment
|
||||
|
@ -489,7 +481,7 @@ def generate_excel(report,
|
|||
ws[col + str(rows)].border = f_border
|
||||
|
||||
# 小计
|
||||
row_subtotals = row_sat + 2 + time_len + 10 * ca_len
|
||||
row_subtotals = detailed_start_row_number + 2 + time_len
|
||||
ws['B' + str(row_subtotals)].font = name_font
|
||||
ws['B' + str(row_subtotals)].alignment = c_c_alignment
|
||||
ws['B' + str(row_subtotals)] = "小计"
|
||||
|
@ -504,26 +496,35 @@ def generate_excel(report,
|
|||
ws[col + str(row_subtotals)].border = f_border
|
||||
ws[col + str(row_subtotals)].number_format = '0.00'
|
||||
|
||||
# LineChart
|
||||
########################################################
|
||||
# third: LineChart
|
||||
# LineChart requires data from the detailed data table in the Excel file
|
||||
# so print the detailed data table first and then print LineChart
|
||||
########################################################
|
||||
for i in range(0, ca_len):
|
||||
|
||||
lc = LineChart()
|
||||
lc.title = "报告期消耗" + " - " + names[i] + "(" + reporting_period_data['units'][i] + ")"
|
||||
lc.style = 10
|
||||
lc.height = 8.40 # cm 1.05*8 1.05cm = 30 pt
|
||||
lc.width = 31
|
||||
lc.x_axis.majorTickMark = 'in'
|
||||
lc.y_axis.majorTickMark = 'in'
|
||||
times = Reference(ws, min_col=2, min_row=row_sat + 2 + row_title,
|
||||
max_row=row_sat + 2 + row_title + time_len)
|
||||
lc_data = Reference(ws, min_col=3 + i, min_row=row_sat + 1 + row_title,
|
||||
max_row=row_sat + 1 + row_title + time_len)
|
||||
lc.add_data(lc_data, titles_from_data=True)
|
||||
lc.set_categories(times)
|
||||
ser = lc.series[0]
|
||||
line = LineChart()
|
||||
line.title = "报告期消耗" + " - " + names[i] + "(" + reporting_period_data['units'][i] + ")"
|
||||
line.style = 10
|
||||
line.x_axis.majorTickMark = 'in'
|
||||
line.y_axis.majorTickMark = 'in'
|
||||
line.smooth = True
|
||||
line.x_axis.crosses = 'min'
|
||||
line.height = 8.25
|
||||
line.width = 24
|
||||
line.dLbls = DataLabelList()
|
||||
line.dLbls.dLblPos = 't'
|
||||
line.dLbls.showVal = True
|
||||
times = Reference(ws, min_col=2, min_row=detailed_start_row_number + 2,
|
||||
max_row=detailed_start_row_number + 2 + time_len)
|
||||
line_data = Reference(ws, min_col=3 + i, min_row=detailed_start_row_number + 1,
|
||||
max_row=detailed_start_row_number + 1 + time_len)
|
||||
line.add_data(line_data, titles_from_data=True)
|
||||
line.set_categories(times)
|
||||
ser = line.series[0]
|
||||
ser.marker.symbol = "diamond"
|
||||
ser.marker.size = 5
|
||||
ws.add_chart(lc, 'B' + str(row_sat + 10 * i))
|
||||
ws.add_chart(line, 'B' + str(analysis_end_row_number + 6 * i))
|
||||
|
||||
filename = str(uuid.uuid4()) + '.xlsx'
|
||||
wb.save(filename)
|
||||
|
|
|
@ -318,136 +318,136 @@ def generate_excel(report,
|
|||
|
||||
current_row_number += 1
|
||||
|
||||
#######################
|
||||
#######################
|
||||
|
||||
has_values_data = True
|
||||
has_timestamps_data = True
|
||||
has_values_data = True
|
||||
has_timestamps_data = True
|
||||
|
||||
if 'values' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['values'] is None or \
|
||||
len(reporting_period_data['values']) == 0:
|
||||
has_values_data = False
|
||||
if 'values' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['values'] is None or \
|
||||
len(reporting_period_data['values']) == 0:
|
||||
has_values_data = False
|
||||
|
||||
if 'timestamps' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['timestamps'] is None or \
|
||||
len(reporting_period_data['timestamps']) == 0 or \
|
||||
len(reporting_period_data['timestamps'][0]) == 0:
|
||||
has_timestamps_data = False
|
||||
if 'timestamps' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['timestamps'] is None or \
|
||||
len(reporting_period_data['timestamps']) == 0 or \
|
||||
len(reporting_period_data['timestamps'][0]) == 0:
|
||||
has_timestamps_data = False
|
||||
|
||||
if has_values_data and has_timestamps_data:
|
||||
ca_len = len(reporting_period_data['names'])
|
||||
time = reporting_period_data['timestamps'][0]
|
||||
if has_values_data and has_timestamps_data:
|
||||
ca_len = len(reporting_period_data['names'])
|
||||
time = reporting_period_data['timestamps'][0]
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 详细数据'
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 详细数据'
|
||||
|
||||
current_row_number += 1
|
||||
current_row_number += 1
|
||||
|
||||
chart_start_row_number = current_row_number
|
||||
chart_start_row_number = current_row_number
|
||||
|
||||
current_row_number += ca_len * 6
|
||||
table_start_row_number = current_row_number
|
||||
current_row_number += ca_len * 6
|
||||
table_start_row_number = current_row_number
|
||||
|
||||
ws.row_dimensions[current_row_number].height = 60
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws.row_dimensions[current_row_number].height = 60
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '日期时间'
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
for i in range(0, len(time)):
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '日期时间'
|
||||
ws['B' + str(current_row_number)] = time[i]
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
for j in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['values'][j][i], 2) \
|
||||
if reporting_period_data['values'][j][i] is not None else 0.00
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
for i in range(0, len(time)):
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = time[i]
|
||||
table_end_row_number = current_row_number - 1
|
||||
|
||||
col = 'C'
|
||||
for j in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['values'][j][i], 2) \
|
||||
if reporting_period_data['values'][j][i] is not None else 0.00
|
||||
col = chr(ord(col) + 1)
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '小计'
|
||||
|
||||
current_row_number += 1
|
||||
col = 'C'
|
||||
|
||||
table_end_row_number = current_row_number - 1
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['subtotals'][i], 2)
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '小计'
|
||||
current_row_number += 2
|
||||
|
||||
col = 'C'
|
||||
format_time_width_number = 1.0
|
||||
min_len_number = 1.0
|
||||
min_width_number = 11.0 # format_time_width_number * min_len_number + 4 and min_width_number > 11.0
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['subtotals'][i], 2)
|
||||
col = chr(ord(col) + 1)
|
||||
if period_type == 'hourly':
|
||||
format_time_width_number = 4.0
|
||||
min_len_number = 2
|
||||
min_width_number = 12.0
|
||||
elif period_type == 'daily':
|
||||
format_time_width_number = 2.5
|
||||
min_len_number = 4
|
||||
min_width_number = 14.0
|
||||
elif period_type == 'monthly':
|
||||
format_time_width_number = 2.1
|
||||
min_len_number = 4
|
||||
min_width_number = 12.4
|
||||
elif period_type == 'yearly':
|
||||
format_time_width_number = 1.5
|
||||
min_len_number = 5
|
||||
min_width_number = 11.5
|
||||
|
||||
current_row_number += 2
|
||||
|
||||
format_time_width_number = 1.0
|
||||
min_len_number = 1.0
|
||||
min_width_number = 11.0 # format_time_width_number * min_len_number + 4 and min_width_number > 11.0
|
||||
|
||||
if period_type == 'hourly':
|
||||
format_time_width_number = 4.0
|
||||
min_len_number = 2
|
||||
min_width_number = 12.0
|
||||
elif period_type == 'daily':
|
||||
format_time_width_number = 2.5
|
||||
min_len_number = 4
|
||||
min_width_number = 14.0
|
||||
elif period_type == 'monthly':
|
||||
format_time_width_number = 2.1
|
||||
min_len_number = 4
|
||||
min_width_number = 12.4
|
||||
elif period_type == 'yearly':
|
||||
format_time_width_number = 1.5
|
||||
min_len_number = 5
|
||||
min_width_number = 11.5
|
||||
|
||||
for i in range(0, ca_len):
|
||||
line = LineChart()
|
||||
line.title = '报告期消耗 - ' + \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
|
||||
line_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number, max_row=table_end_row_number)
|
||||
line.add_data(line_data, titles_from_data=True)
|
||||
line.set_categories(labels)
|
||||
line_data = line.series[0]
|
||||
line_data.marker.symbol = "circle"
|
||||
line_data.smooth = True
|
||||
line.x_axis.crosses = 'min'
|
||||
line.height = 8.25
|
||||
line.width = format_time_width_number * len(time) if len(time) > min_len_number else min_width_number
|
||||
if line.width > 24:
|
||||
line.width = 24
|
||||
line.dLbls = DataLabelList()
|
||||
line.dLbls.dLblPos = 't'
|
||||
line.dLbls.showVal = True
|
||||
line.dLbls.showPercent = False
|
||||
chart_col = 'B'
|
||||
chart_cell = chart_col + str(chart_start_row_number)
|
||||
chart_start_row_number += 6
|
||||
ws.add_chart(line, chart_cell)
|
||||
for i in range(0, ca_len):
|
||||
line = LineChart()
|
||||
line.title = '报告期消耗 - ' + \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
|
||||
line_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number, max_row=table_end_row_number)
|
||||
line.add_data(line_data, titles_from_data=True)
|
||||
line.set_categories(labels)
|
||||
line_data = line.series[0]
|
||||
line_data.marker.symbol = "circle"
|
||||
line_data.smooth = True
|
||||
line.x_axis.crosses = 'min'
|
||||
line.height = 8.25
|
||||
line.width = format_time_width_number * len(time) if len(time) > min_len_number else min_width_number
|
||||
if line.width > 24:
|
||||
line.width = 24
|
||||
line.dLbls = DataLabelList()
|
||||
line.dLbls.dLblPos = 't'
|
||||
line.dLbls.showVal = True
|
||||
line.dLbls.showPercent = False
|
||||
chart_col = 'B'
|
||||
chart_cell = chart_col + str(chart_start_row_number)
|
||||
chart_start_row_number += 6
|
||||
ws.add_chart(line, chart_cell)
|
||||
|
||||
filename = str(uuid.uuid4()) + '.xlsx'
|
||||
wb.save(filename)
|
||||
|
|
|
@ -113,12 +113,6 @@ def generate_excel(report,
|
|||
wrap_text=False,
|
||||
shrink_to_fit=False,
|
||||
indent=0)
|
||||
# c_r_alignment = Alignment(vertical='bottom',
|
||||
# horizontal='center',
|
||||
# text_rotation=0,
|
||||
# wrap_text=False,
|
||||
# shrink_to_fit=False,
|
||||
# indent=0)
|
||||
|
||||
# Img
|
||||
img = Image("excelexporters/myems.png")
|
||||
|
@ -264,40 +258,40 @@ def generate_excel(report,
|
|||
# Second: 报告期单位面积消耗
|
||||
# 9 + ca_len * 2: title
|
||||
# 10 + ca_len * 2: table title
|
||||
# row_title + 2 ~ row_title + 2 + ca_len : table_data
|
||||
# per_unit_area_start_row_number + 2 ~ per_unit_area_start_row_number + 2 + ca_len : table_data
|
||||
#################################################
|
||||
|
||||
if has_energy_data_flag:
|
||||
names = reporting_period_data['names']
|
||||
ca_len = len(names)
|
||||
row_title = 9 + ca_len * 2
|
||||
per_unit_area_start_row_number = 9 + ca_len * 2
|
||||
|
||||
ws['B' + str(row_title)].font = title_font
|
||||
ws['B' + str(row_title)] = name + ' 单位面积值' + str(report['store']['area']) + 'M²'
|
||||
ws['B' + str(per_unit_area_start_row_number)].font = title_font
|
||||
ws['B' + str(per_unit_area_start_row_number)] = name + ' 单位面积值' + str(report['store']['area']) + 'M²'
|
||||
|
||||
category = reporting_period_data['names']
|
||||
|
||||
# table_title
|
||||
ws['B' + str(row_title + 1)].fill = table_fill
|
||||
ws['B' + str(row_title + 1)].font = title_font
|
||||
ws['B' + str(row_title + 1)].alignment = c_c_alignment
|
||||
ws['B' + str(row_title + 1)] = '报告期'
|
||||
ws['B' + str(row_title + 1)].border = f_border
|
||||
ws['B' + str(per_unit_area_start_row_number + 1)].fill = table_fill
|
||||
ws['B' + str(per_unit_area_start_row_number + 1)].font = title_font
|
||||
ws['B' + str(per_unit_area_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['B' + str(per_unit_area_start_row_number + 1)] = '报告期'
|
||||
ws['B' + str(per_unit_area_start_row_number + 1)].border = f_border
|
||||
|
||||
ws['C' + str(row_title + 1)].font = title_font
|
||||
ws['C' + str(row_title + 1)].alignment = c_c_alignment
|
||||
ws['C' + str(row_title + 1)] = '平均负荷'
|
||||
ws['C' + str(row_title + 1)].border = f_border
|
||||
ws['C' + str(per_unit_area_start_row_number + 1)].font = title_font
|
||||
ws['C' + str(per_unit_area_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['C' + str(per_unit_area_start_row_number + 1)] = '平均负荷'
|
||||
ws['C' + str(per_unit_area_start_row_number + 1)].border = f_border
|
||||
|
||||
ws['D' + str(row_title + 1)].font = title_font
|
||||
ws['D' + str(row_title + 1)].alignment = c_c_alignment
|
||||
ws['D' + str(row_title + 1)] = '最大负荷'
|
||||
ws['D' + str(row_title + 1)].border = f_border
|
||||
ws['D' + str(per_unit_area_start_row_number + 1)].font = title_font
|
||||
ws['D' + str(per_unit_area_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['D' + str(per_unit_area_start_row_number + 1)] = '最大负荷'
|
||||
ws['D' + str(per_unit_area_start_row_number + 1)].border = f_border
|
||||
|
||||
# table_data
|
||||
|
||||
for i, value in enumerate(category):
|
||||
row_data = row_title + 2 + i
|
||||
row_data = per_unit_area_start_row_number + 2 + i
|
||||
ws['B' + str(row_data)].font = name_font
|
||||
ws['B' + str(row_data)].alignment = c_c_alignment
|
||||
ws['B' + str(row_data)] = reporting_period_data['names'][i] + " (" + reporting_period_data['units'][
|
||||
|
@ -322,9 +316,9 @@ def generate_excel(report,
|
|||
|
||||
########################################################
|
||||
# Third: 详细数据
|
||||
# row_sat~ row_sat + 6*cal_len: line
|
||||
# row_da: table title
|
||||
# row_da + 1~: table_data
|
||||
# analysis_end_row_number~ analysis_end_row_number + 6*cal_len: line
|
||||
# detailed_start_row_number: table title
|
||||
# detailed_start_row_number + 1~: table_data
|
||||
########################################################
|
||||
has_timestamps_flag = True
|
||||
if "timestamps" not in reporting_period_data.keys() or \
|
||||
|
@ -337,40 +331,37 @@ def generate_excel(report,
|
|||
names = reporting_period_data['names']
|
||||
ca_len = len(names)
|
||||
time_len = len(timestamps)
|
||||
# row_lines == the number of rows of lines
|
||||
row_lines = 6 * ca_len
|
||||
# row_sat == the number of rows of statistical analysis table
|
||||
row_sat = 12 + 3 * ca_len
|
||||
# row_da == the number of rows of Detailed data
|
||||
row_da = row_sat + row_lines + 1
|
||||
line_charts_row_number = 6 * ca_len
|
||||
analysis_end_row_number = 12 + 3 * ca_len
|
||||
detailed_start_row_number = analysis_end_row_number + line_charts_row_number + 1
|
||||
|
||||
ws['B' + str(row_da)].font = title_font
|
||||
ws['B' + str(row_da)] = name + ' 详细数据'
|
||||
ws['B' + str(detailed_start_row_number)].font = title_font
|
||||
ws['B' + str(detailed_start_row_number)] = name + ' 详细数据'
|
||||
# table_title
|
||||
ws['B' + str(row_da + 1)].fill = table_fill
|
||||
ws['B' + str(row_da + 1)].font = name_font
|
||||
ws['B' + str(row_da + 1)].alignment = c_c_alignment
|
||||
ws['B' + str(row_da + 1)] = "日期时间"
|
||||
ws['B' + str(row_da + 1)].border = f_border
|
||||
ws['B' + str(detailed_start_row_number + 1)].fill = table_fill
|
||||
ws['B' + str(detailed_start_row_number + 1)].font = name_font
|
||||
ws['B' + str(detailed_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['B' + str(detailed_start_row_number + 1)] = "日期时间"
|
||||
ws['B' + str(detailed_start_row_number + 1)].border = f_border
|
||||
|
||||
for i in range(0, ca_len):
|
||||
col_average = chr(ord('C') + 2 * i)
|
||||
col_maximum = chr(ord('D') + 2 * i)
|
||||
|
||||
ws[col_average + str(row_da + 1)].font = name_font
|
||||
ws[col_average + str(row_da + 1)].alignment = c_c_alignment
|
||||
ws[col_average + str(row_da + 1)] = names[i] + " 平均负荷(" + reporting_period_data['units'][
|
||||
ws[col_average + str(detailed_start_row_number + 1)].font = name_font
|
||||
ws[col_average + str(detailed_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws[col_average + str(detailed_start_row_number + 1)] = names[i] + " 平均负荷(" + reporting_period_data['units'][
|
||||
i] + "/H)"
|
||||
ws[col_average + str(row_da + 1)].border = f_border
|
||||
ws[col_average + str(detailed_start_row_number + 1)].border = f_border
|
||||
|
||||
ws[col_maximum + str(row_da + 1)].font = name_font
|
||||
ws[col_maximum + str(row_da + 1)].alignment = c_c_alignment
|
||||
ws[col_maximum + str(row_da + 1)] = names[i] + " 最大负荷(" + reporting_period_data['units'][
|
||||
ws[col_maximum + str(detailed_start_row_number + 1)].font = name_font
|
||||
ws[col_maximum + str(detailed_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws[col_maximum + str(detailed_start_row_number + 1)] = names[i] + " 最大负荷(" + reporting_period_data['units'][
|
||||
i] + "/H)"
|
||||
ws[col_maximum + str(row_da + 1)].border = f_border
|
||||
ws[col_maximum + str(detailed_start_row_number + 1)].border = f_border
|
||||
# table_date
|
||||
for i in range(0, time_len):
|
||||
rows = i + row_da + 2
|
||||
rows = i + detailed_start_row_number + 2
|
||||
|
||||
ws['B' + str(rows)].font = name_font
|
||||
ws['B' + str(rows)].alignment = c_c_alignment
|
||||
|
@ -395,32 +386,36 @@ def generate_excel(report,
|
|||
ws[col_maximum + str(rows)].number_format = '0.00'
|
||||
ws[col_maximum + str(rows)].border = f_border
|
||||
|
||||
# LineChart
|
||||
########################################################
|
||||
# third: LineChart
|
||||
# LineChart requires data from the detailed data table in the Excel file
|
||||
# so print the detailed data table first and then print LineChart
|
||||
########################################################
|
||||
for i in range(0, ca_len):
|
||||
lc = LineChart()
|
||||
lc.title = "报告期 最大负荷"
|
||||
lc.style = 10
|
||||
lc.x_axis.majorTickMark = 'in'
|
||||
lc.y_axis.majorTickMark = 'in'
|
||||
lc.smooth = True
|
||||
lc.x_axis.crosses = 'min'
|
||||
lc.height = 8.25
|
||||
lc.width = 24
|
||||
lc.dLbls = DataLabelList()
|
||||
lc.dLbls.dLblPos = 't'
|
||||
lc.dLbls.showVal = True
|
||||
times = Reference(ws, min_col=2, min_row=row_da + 2,
|
||||
max_row=row_da + 2 + time_len)
|
||||
lc_data = Reference(ws, min_col=2 + 2 * (i+1), min_row=row_da + 1,
|
||||
max_row=row_da + 1 + time_len)
|
||||
lc.add_data(lc_data, titles_from_data=True)
|
||||
lc.set_categories(times)
|
||||
ser = lc.series[0]
|
||||
line = LineChart()
|
||||
line.title = "报告期 最大负荷 - " + names[i] + "(" + reporting_period_data['units'][i] + ")"
|
||||
line.style = 10
|
||||
line.x_axis.majorTickMark = 'in'
|
||||
line.y_axis.majorTickMark = 'in'
|
||||
line.smooth = True
|
||||
line.x_axis.crosses = 'min'
|
||||
line.height = 8.25
|
||||
line.width = 24
|
||||
line.dLbls = DataLabelList()
|
||||
line.dLbls.dLblPos = 't'
|
||||
line.dLbls.showVal = True
|
||||
times = Reference(ws, min_col=2, min_row=detailed_start_row_number + 2,
|
||||
max_row=detailed_start_row_number + 2 + time_len)
|
||||
line_data = Reference(ws, min_col=2 + 2 * (i+1), min_row=detailed_start_row_number + 1,
|
||||
max_row=detailed_start_row_number + 1 + time_len)
|
||||
line.add_data(line_data, titles_from_data=True)
|
||||
line.set_categories(times)
|
||||
ser = line.series[0]
|
||||
ser.marker.symbol = "diamond"
|
||||
ser.marker.size = 5
|
||||
chart_col = 'B'
|
||||
chart_cell = str(row_sat + 6 * i)
|
||||
ws.add_chart(lc, chart_col + chart_cell)
|
||||
chart_cell = str(analysis_end_row_number + 6 * i)
|
||||
ws.add_chart(line, chart_col + chart_cell)
|
||||
|
||||
filename = str(uuid.uuid4()) + '.xlsx'
|
||||
wb.save(filename)
|
||||
|
|
|
@ -0,0 +1,604 @@
|
|||
import base64
|
||||
import uuid
|
||||
import os
|
||||
from openpyxl.chart import (
|
||||
PieChart,
|
||||
LineChart,
|
||||
BarChart,
|
||||
Reference,
|
||||
)
|
||||
from openpyxl.styles import PatternFill, Border, Side, Alignment, Font
|
||||
from openpyxl.drawing.image import Image
|
||||
from openpyxl import Workbook
|
||||
from openpyxl.chart.label import DataLabelList
|
||||
|
||||
####################################################################################################################
|
||||
# PROCEDURES
|
||||
# Step 1: Validate the report data
|
||||
# Step 2: Generate excel file
|
||||
# Step 3: Encode the excel file bytes to Base64
|
||||
####################################################################################################################
|
||||
|
||||
|
||||
def export(report,
|
||||
name,
|
||||
reporting_start_datetime_local,
|
||||
reporting_end_datetime_local,
|
||||
period_type):
|
||||
####################################################################################################################
|
||||
# Step 1: Validate the report data
|
||||
####################################################################################################################
|
||||
if report is None:
|
||||
return None
|
||||
print(report)
|
||||
|
||||
####################################################################################################################
|
||||
# Step 2: Generate excel file from the report data
|
||||
####################################################################################################################
|
||||
filename = generate_excel(report,
|
||||
name,
|
||||
reporting_start_datetime_local,
|
||||
reporting_end_datetime_local,
|
||||
period_type)
|
||||
####################################################################################################################
|
||||
# Step 3: Encode the excel file to Base64
|
||||
####################################################################################################################
|
||||
try:
|
||||
with open(filename, 'rb') as binary_file:
|
||||
binary_file_data = binary_file.read()
|
||||
except IOError as ex:
|
||||
pass
|
||||
|
||||
# Base64 encode the bytes
|
||||
base64_encoded_data = base64.b64encode(binary_file_data)
|
||||
# get the Base64 encoded data using human-readable characters.
|
||||
base64_message = base64_encoded_data.decode('utf-8')
|
||||
# delete the file from server
|
||||
try:
|
||||
os.remove(filename)
|
||||
except NotImplementedError as ex:
|
||||
pass
|
||||
return base64_message
|
||||
|
||||
|
||||
def generate_excel(report,
|
||||
name,
|
||||
reporting_start_datetime_local,
|
||||
reporting_end_datetime_local,
|
||||
period_type):
|
||||
wb = Workbook()
|
||||
ws = wb.active
|
||||
|
||||
# Row height
|
||||
ws.row_dimensions[1].height = 102
|
||||
for i in range(2, 2000 + 1):
|
||||
ws.row_dimensions[i].height = 42
|
||||
|
||||
# Col width
|
||||
ws.column_dimensions['A'].width = 1.5
|
||||
|
||||
ws.column_dimensions['B'].width = 25.0
|
||||
|
||||
for i in range(ord('C'), ord('L')):
|
||||
ws.column_dimensions[chr(i)].width = 15.0
|
||||
|
||||
# Font
|
||||
name_font = Font(name='Constantia', size=15, bold=True)
|
||||
title_font = Font(name='宋体', size=15, bold=True)
|
||||
data_font = Font(name='Franklin Gothic Book', size=11)
|
||||
|
||||
table_fill = PatternFill(fill_type='solid', fgColor='1F497D')
|
||||
f_border = Border(left=Side(border_style='medium', color='00000000'),
|
||||
right=Side(border_style='medium', color='00000000'),
|
||||
bottom=Side(border_style='medium', color='00000000'),
|
||||
top=Side(border_style='medium', color='00000000')
|
||||
)
|
||||
b_border = Border(
|
||||
bottom=Side(border_style='medium', color='00000000'),
|
||||
)
|
||||
|
||||
b_c_alignment = Alignment(vertical='bottom',
|
||||
horizontal='center',
|
||||
text_rotation=0,
|
||||
wrap_text=True,
|
||||
shrink_to_fit=False,
|
||||
indent=0)
|
||||
c_c_alignment = Alignment(vertical='center',
|
||||
horizontal='center',
|
||||
text_rotation=0,
|
||||
wrap_text=True,
|
||||
shrink_to_fit=False,
|
||||
indent=0)
|
||||
b_r_alignment = Alignment(vertical='bottom',
|
||||
horizontal='right',
|
||||
text_rotation=0,
|
||||
wrap_text=True,
|
||||
shrink_to_fit=False,
|
||||
indent=0)
|
||||
c_r_alignment = Alignment(vertical='bottom',
|
||||
horizontal='center',
|
||||
text_rotation=0,
|
||||
wrap_text=True,
|
||||
shrink_to_fit=False,
|
||||
indent=0)
|
||||
|
||||
# Img
|
||||
img = Image("excelexporters/myems.png")
|
||||
img.width = img.width * 0.85
|
||||
img.height = img.height * 0.85
|
||||
# img = Image("myems.png")
|
||||
ws.add_image(img, 'B1')
|
||||
|
||||
# Title
|
||||
ws.row_dimensions[3].height = 60
|
||||
|
||||
ws['B3'].font = name_font
|
||||
ws['B3'].alignment = b_r_alignment
|
||||
ws['B3'] = 'Name:'
|
||||
ws['C3'].border = b_border
|
||||
ws['C3'].alignment = b_c_alignment
|
||||
ws['C3'].font = name_font
|
||||
ws['C3'] = name
|
||||
|
||||
ws['D3'].font = name_font
|
||||
ws['D3'].alignment = b_r_alignment
|
||||
ws['D3'] = 'Period:'
|
||||
ws['E3'].border = b_border
|
||||
ws['E3'].alignment = b_c_alignment
|
||||
ws['E3'].font = name_font
|
||||
ws['E3'] = period_type
|
||||
|
||||
ws['F3'].font = name_font
|
||||
ws['F3'].alignment = b_r_alignment
|
||||
ws['F3'] = 'Date:'
|
||||
ws['G3'].alignment = b_c_alignment
|
||||
ws['G3'].font = name_font
|
||||
ws['G3'] = reporting_start_datetime_local + "__" + reporting_end_datetime_local
|
||||
ws['G3'].border = b_border
|
||||
ws.merge_cells("G3:H3")
|
||||
|
||||
if "reporting_period" not in report.keys() or \
|
||||
"names" not in report['reporting_period'].keys() or len(report['reporting_period']['names']) == 0:
|
||||
filename = str(uuid.uuid4()) + '.xlsx'
|
||||
wb.save(filename)
|
||||
|
||||
return filename
|
||||
|
||||
##################################
|
||||
|
||||
current_row_number = 6
|
||||
|
||||
reporting_period_data = report['reporting_period']
|
||||
|
||||
has_names_data_flag = True
|
||||
|
||||
if "names" not in reporting_period_data.keys() or \
|
||||
reporting_period_data['names'] is None or \
|
||||
len(reporting_period_data['names']) == 0:
|
||||
has_names_data_flag = False
|
||||
|
||||
if has_names_data_flag:
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 报告期节约'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
category = reporting_period_data['names']
|
||||
ca_len = len(category)
|
||||
|
||||
ws.row_dimensions[current_row_number].height = 75
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = \
|
||||
reporting_period_data['names'][i] + " (基线-实际) (" + reporting_period_data['units'][i] + ")"
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = '吨标准煤 (基线-实际) (TCE)'
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = '吨二氧化碳排放 (基线-实际) (TCO2E)'
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '节约'
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['subtotals_saving'][i], 2)
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['total_in_kgce_saving'] / 1000, 2)
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['total_in_kgco2e_saving'] / 1000, 2)
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '单位面积值'
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['subtotals_per_unit_area_saving'][i], 2)
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['total_in_kgce_per_unit_area_saving'] / 1000, 2)
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = \
|
||||
round(reporting_period_data['total_in_kgco2e_per_unit_area_saving'] / 1000, 2)
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '环比'
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = str(
|
||||
round(reporting_period_data['increment_rates_saving'][i] * 100, 2)) + '%' \
|
||||
if reporting_period_data['increment_rates_saving'][i] is not None else '-'
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = str(
|
||||
round(reporting_period_data['increment_rate_in_kgce_saving'] * 100, 2)) + '%' \
|
||||
if reporting_period_data['increment_rate_in_kgce_saving'] is not None else '-'
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = str(
|
||||
round(reporting_period_data['increment_rate_in_kgco2e_saving'] * 100, 2)) + '%' \
|
||||
if reporting_period_data['increment_rate_in_kgco2e_saving'] is not None else '-'
|
||||
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 2
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 吨标准煤(TCE)占比'
|
||||
|
||||
current_row_number += 1
|
||||
table_start_row_number = current_row_number
|
||||
chart_start_row_number = current_row_number
|
||||
|
||||
ws.row_dimensions[current_row_number].height = 60
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
|
||||
ws['C' + str(current_row_number)].fill = table_fill
|
||||
ws['C' + str(current_row_number)].font = name_font
|
||||
ws['C' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['C' + str(current_row_number)].border = f_border
|
||||
ws['C' + str(current_row_number)] = '节约'
|
||||
|
||||
ws['D' + str(current_row_number)].fill = table_fill
|
||||
ws['D' + str(current_row_number)].font = name_font
|
||||
ws['D' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['D' + str(current_row_number)].border = f_border
|
||||
ws['D' + str(current_row_number)] = '吨标准煤(TCE) 节约占比'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
subtotals_in_kgce_saving_sum = sum_list(reporting_period_data['subtotals_in_kgce_saving'])
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = reporting_period_data['names'][i]
|
||||
|
||||
ws['C' + str(current_row_number)].font = name_font
|
||||
ws['C' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['C' + str(current_row_number)].border = f_border
|
||||
ws['C' + str(current_row_number)] = round(reporting_period_data['subtotals_in_kgce_saving'][i] / 1000, 3)
|
||||
|
||||
ws['D' + str(current_row_number)].font = name_font
|
||||
ws['D' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['D' + str(current_row_number)].border = f_border
|
||||
ws['D' + str(current_row_number)] = str(round(reporting_period_data['subtotals_in_kgce_saving'][i] /
|
||||
subtotals_in_kgce_saving_sum * 100, 2)) + '%'\
|
||||
if abs(subtotals_in_kgce_saving_sum) > 0 else '-'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
table_end_row_number = current_row_number - 1
|
||||
|
||||
if ca_len < 4:
|
||||
current_row_number = current_row_number - ca_len + 4
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
pie = PieChart()
|
||||
pie.title = name + ' 吨标准煤(TCE)占比'
|
||||
labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
|
||||
pie_data = Reference(ws, min_col=3, min_row=table_start_row_number, max_row=table_end_row_number)
|
||||
pie.add_data(pie_data, titles_from_data=True)
|
||||
pie.set_categories(labels)
|
||||
pie.height = 7.25
|
||||
pie.width = 9
|
||||
s1 = pie.series[0]
|
||||
s1.dLbls = DataLabelList()
|
||||
s1.dLbls.showCatName = False
|
||||
s1.dLbls.showVal = True
|
||||
s1.dLbls.showPercent = True
|
||||
ws.add_chart(pie, 'E' + str(chart_start_row_number))
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 吨二氧化碳排放(TCO2E)占比'
|
||||
|
||||
current_row_number += 1
|
||||
table_start_row_number = current_row_number
|
||||
chart_start_row_number = current_row_number
|
||||
|
||||
ws.row_dimensions[current_row_number].height = 60
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
|
||||
ws['C' + str(current_row_number)].fill = table_fill
|
||||
ws['C' + str(current_row_number)].font = name_font
|
||||
ws['C' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['C' + str(current_row_number)].border = f_border
|
||||
ws['C' + str(current_row_number)] = '节约'
|
||||
|
||||
ws['D' + str(current_row_number)].fill = table_fill
|
||||
ws['D' + str(current_row_number)].font = name_font
|
||||
ws['D' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['D' + str(current_row_number)].border = f_border
|
||||
ws['D' + str(current_row_number)] = '吨二氧化碳排放(TCO2E) 节约占比'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
subtotals_in_kgco2e_saving_sum = sum_list(reporting_period_data['subtotals_in_kgco2e_saving'])
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = reporting_period_data['names'][i]
|
||||
|
||||
ws['C' + str(current_row_number)].font = name_font
|
||||
ws['C' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['C' + str(current_row_number)].border = f_border
|
||||
ws['C' + str(current_row_number)] = round(reporting_period_data['subtotals_in_kgco2e_saving'][i] / 1000, 3)
|
||||
|
||||
ws['D' + str(current_row_number)].font = name_font
|
||||
ws['D' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['D' + str(current_row_number)].border = f_border
|
||||
ws['D' + str(current_row_number)] = str(round(reporting_period_data['subtotals_in_kgco2e_saving'][i] /
|
||||
subtotals_in_kgco2e_saving_sum * 100, 2)) + '%'\
|
||||
if abs(subtotals_in_kgco2e_saving_sum) > 0 else '-'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
table_end_row_number = current_row_number - 1
|
||||
|
||||
if ca_len < 4:
|
||||
current_row_number = current_row_number - ca_len + 4
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
pie = PieChart()
|
||||
pie.title = name + ' 吨二氧化碳排放(TCO2E)占比'
|
||||
labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
|
||||
pie_data = Reference(ws, min_col=3, min_row=table_start_row_number, max_row=table_end_row_number)
|
||||
pie.add_data(pie_data, titles_from_data=True)
|
||||
pie.set_categories(labels)
|
||||
pie.height = 7.25
|
||||
pie.width = 9
|
||||
s1 = pie.series[0]
|
||||
s1.dLbls = DataLabelList()
|
||||
s1.dLbls.showCatName = False
|
||||
s1.dLbls.showVal = True
|
||||
s1.dLbls.showPercent = True
|
||||
ws.add_chart(pie, 'E' + str(chart_start_row_number))
|
||||
|
||||
#############################################
|
||||
|
||||
has_values_saving_data = True
|
||||
has_timestamps_data = True
|
||||
|
||||
if 'values_saving' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['values_saving'] is None or \
|
||||
len(reporting_period_data['values_saving']) == 0:
|
||||
has_values_saving_data = False
|
||||
|
||||
if 'timestamps' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['timestamps'] is None or \
|
||||
len(reporting_period_data['timestamps']) == 0 or \
|
||||
len(reporting_period_data['timestamps'][0]) == 0:
|
||||
has_timestamps_data = False
|
||||
|
||||
if has_values_saving_data and has_timestamps_data:
|
||||
ca_len = len(reporting_period_data['names'])
|
||||
time = reporting_period_data['timestamps'][0]
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 详细数据'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
chart_start_row_number = current_row_number
|
||||
|
||||
current_row_number += ca_len * 6
|
||||
table_start_row_number = current_row_number
|
||||
|
||||
ws.row_dimensions[current_row_number].height = 60
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '日期时间'
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
for i in range(0, len(time)):
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = time[i]
|
||||
|
||||
col = 'C'
|
||||
for j in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['values_saving'][j][i], 2) \
|
||||
if reporting_period_data['values_saving'][j][i] is not None else 0.00
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
table_end_row_number = current_row_number - 1
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '小计'
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['subtotals_saving'][i], 2)
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 2
|
||||
|
||||
format_time_width_number = 1.0
|
||||
min_len_number = 1.0
|
||||
min_width_number = 11.0 # format_time_width_number * min_len_number + 4 and min_width_number > 11.0
|
||||
|
||||
if period_type == 'hourly':
|
||||
format_time_width_number = 4.0
|
||||
min_len_number = 2
|
||||
min_width_number = 12.0
|
||||
elif period_type == 'daily':
|
||||
format_time_width_number = 2.5
|
||||
min_len_number = 4
|
||||
min_width_number = 14.0
|
||||
elif period_type == 'monthly':
|
||||
format_time_width_number = 2.1
|
||||
min_len_number = 4
|
||||
min_width_number = 12.4
|
||||
elif period_type == 'yearly':
|
||||
format_time_width_number = 1.5
|
||||
min_len_number = 5
|
||||
min_width_number = 11.5
|
||||
|
||||
for i in range(0, ca_len):
|
||||
line = LineChart()
|
||||
line.title = '报告期节约 - ' + \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
|
||||
line_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number, max_row=table_end_row_number)
|
||||
line.add_data(line_data, titles_from_data=True)
|
||||
line.set_categories(labels)
|
||||
line_data = line.series[0]
|
||||
line_data.marker.symbol = "circle"
|
||||
line_data.smooth = True
|
||||
line.height = 8.25
|
||||
line.width = format_time_width_number * len(time) if len(time) > min_len_number else min_width_number
|
||||
if line.width > 24:
|
||||
line.width = 24
|
||||
line.x_axis.crosses = 'min'
|
||||
line.dLbls = DataLabelList()
|
||||
line.dLbls.dLblPos = 't'
|
||||
line.dLbls.showVal = True
|
||||
line.dLbls.showPercent = False
|
||||
chart_col = 'B'
|
||||
chart_cell = chart_col + str(chart_start_row_number)
|
||||
chart_start_row_number += 6
|
||||
ws.add_chart(line, chart_cell)
|
||||
|
||||
filename = str(uuid.uuid4()) + '.xlsx'
|
||||
wb.save(filename)
|
||||
|
||||
return filename
|
||||
|
||||
|
||||
def sum_list(lists):
|
||||
total = 0
|
||||
|
||||
for i in range(0, len(lists)):
|
||||
total += lists[i]
|
||||
|
||||
return total
|
|
@ -7,6 +7,7 @@ from openpyxl.chart import (
|
|||
LineChart,
|
||||
Reference,
|
||||
)
|
||||
from openpyxl.chart.label import DataLabelList
|
||||
from openpyxl.drawing.image import Image
|
||||
from openpyxl.styles import PatternFill, Border, Side, Alignment, Font
|
||||
|
||||
|
@ -69,19 +70,16 @@ def generate_excel(report,
|
|||
ws = wb.active
|
||||
|
||||
# Row height
|
||||
ws.row_dimensions[1].height = 121
|
||||
ws.row_dimensions[1].height = 102
|
||||
|
||||
for i in range(2, 37 + 1):
|
||||
ws.row_dimensions[i].height = 30
|
||||
|
||||
for i in range(38, 90 + 1):
|
||||
ws.row_dimensions[i].height = 30
|
||||
for i in range(2, 2000 + 1):
|
||||
ws.row_dimensions[i].height = 42
|
||||
|
||||
# Col width
|
||||
ws.column_dimensions['A'].width = 1.5
|
||||
ws.column_dimensions['B'].width = 20.0
|
||||
ws.column_dimensions['B'].width = 25.0
|
||||
|
||||
for i in range(ord('C'), ord('I')):
|
||||
for i in range(ord('C'), ord('L')):
|
||||
ws.column_dimensions[chr(i)].width = 15.0
|
||||
|
||||
# Font
|
||||
|
@ -117,12 +115,6 @@ def generate_excel(report,
|
|||
wrap_text=False,
|
||||
shrink_to_fit=False,
|
||||
indent=0)
|
||||
# c_r_alignment = Alignment(vertical='bottom',
|
||||
# horizontal='center',
|
||||
# text_rotation=0,
|
||||
# wrap_text=False,
|
||||
# shrink_to_fit=False,
|
||||
# indent=0)
|
||||
|
||||
# Img
|
||||
img = Image("excelexporters/myems.png")
|
||||
|
@ -319,63 +311,61 @@ def generate_excel(report,
|
|||
# Second: 报告期消耗
|
||||
# 9 + ca_len * 2: title
|
||||
# 10 + ca_len * 2: table title
|
||||
# row_title + 2 ~ row_title + 2 + ca_len : table_data
|
||||
# per_unit_area_start_row_number + 2 ~ per_unit_area_start_row_number + 2 + ca_len : table_data
|
||||
#################################################
|
||||
|
||||
if has_energy_data_flag:
|
||||
names = reporting_period_data['names']
|
||||
ca_len = len(names)
|
||||
|
||||
row_title = 9 + ca_len * 2
|
||||
per_unit_area_start_row_number = 9 + ca_len * 2
|
||||
|
||||
ws['B' + str(row_title)].font = title_font
|
||||
ws['B' + str(row_title)] = name + ' 单位面积值'
|
||||
ws['D' + str(row_title)].font = title_font
|
||||
ws['D' + str(row_title)] = str(report['store']['area']) + 'M²'
|
||||
ws['B' + str(per_unit_area_start_row_number)].font = title_font
|
||||
ws['B' + str(per_unit_area_start_row_number)] = name + ' 单位面积值' + str(report['store']['area']) + 'M²'
|
||||
|
||||
category = reporting_period_data['names']
|
||||
|
||||
# table_title
|
||||
ws['B' + str(row_title + 1)].fill = table_fill
|
||||
ws['B' + str(row_title + 1)].font = title_font
|
||||
ws['B' + str(row_title + 1)].alignment = c_c_alignment
|
||||
ws['B' + str(row_title + 1)] = '报告期'
|
||||
ws['B' + str(row_title + 1)].border = f_border
|
||||
ws['B' + str(per_unit_area_start_row_number + 1)].fill = table_fill
|
||||
ws['B' + str(per_unit_area_start_row_number + 1)].font = title_font
|
||||
ws['B' + str(per_unit_area_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['B' + str(per_unit_area_start_row_number + 1)] = '报告期'
|
||||
ws['B' + str(per_unit_area_start_row_number + 1)].border = f_border
|
||||
|
||||
ws['C' + str(row_title + 1)].font = title_font
|
||||
ws['C' + str(row_title + 1)].alignment = c_c_alignment
|
||||
ws['C' + str(row_title + 1)] = '算术平均数'
|
||||
ws['C' + str(row_title + 1)].border = f_border
|
||||
ws['C' + str(per_unit_area_start_row_number + 1)].font = title_font
|
||||
ws['C' + str(per_unit_area_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['C' + str(per_unit_area_start_row_number + 1)] = '算术平均数'
|
||||
ws['C' + str(per_unit_area_start_row_number + 1)].border = f_border
|
||||
|
||||
ws['D' + str(row_title + 1)].font = title_font
|
||||
ws['D' + str(row_title + 1)].alignment = c_c_alignment
|
||||
ws['D' + str(row_title + 1)] = '中位数'
|
||||
ws['D' + str(row_title + 1)].border = f_border
|
||||
ws['D' + str(per_unit_area_start_row_number + 1)].font = title_font
|
||||
ws['D' + str(per_unit_area_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['D' + str(per_unit_area_start_row_number + 1)] = '中位数'
|
||||
ws['D' + str(per_unit_area_start_row_number + 1)].border = f_border
|
||||
|
||||
ws['E' + str(row_title + 1)].font = title_font
|
||||
ws['E' + str(row_title + 1)].alignment = c_c_alignment
|
||||
ws['E' + str(row_title + 1)] = '最小值'
|
||||
ws['E' + str(row_title + 1)].border = f_border
|
||||
ws['E' + str(per_unit_area_start_row_number + 1)].font = title_font
|
||||
ws['E' + str(per_unit_area_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['E' + str(per_unit_area_start_row_number + 1)] = '最小值'
|
||||
ws['E' + str(per_unit_area_start_row_number + 1)].border = f_border
|
||||
|
||||
ws['F' + str(row_title + 1)].font = title_font
|
||||
ws['F' + str(row_title + 1)].alignment = c_c_alignment
|
||||
ws['F' + str(row_title + 1)] = '最大值'
|
||||
ws['F' + str(row_title + 1)].border = f_border
|
||||
ws['F' + str(per_unit_area_start_row_number + 1)].font = title_font
|
||||
ws['F' + str(per_unit_area_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['F' + str(per_unit_area_start_row_number + 1)] = '最大值'
|
||||
ws['F' + str(per_unit_area_start_row_number + 1)].border = f_border
|
||||
|
||||
ws['G' + str(row_title + 1)].font = title_font
|
||||
ws['G' + str(row_title + 1)].alignment = c_c_alignment
|
||||
ws['G' + str(row_title + 1)] = '样本标准差'
|
||||
ws['G' + str(row_title + 1)].border = f_border
|
||||
ws['G' + str(per_unit_area_start_row_number + 1)].font = title_font
|
||||
ws['G' + str(per_unit_area_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['G' + str(per_unit_area_start_row_number + 1)] = '样本标准差'
|
||||
ws['G' + str(per_unit_area_start_row_number + 1)].border = f_border
|
||||
|
||||
ws['H' + str(row_title + 1)].font = title_font
|
||||
ws['H' + str(row_title + 1)].alignment = c_c_alignment
|
||||
ws['H' + str(row_title + 1)] = '样本方差'
|
||||
ws['H' + str(row_title + 1)].border = f_border
|
||||
ws['H' + str(per_unit_area_start_row_number + 1)].font = title_font
|
||||
ws['H' + str(per_unit_area_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['H' + str(per_unit_area_start_row_number + 1)] = '样本方差'
|
||||
ws['H' + str(per_unit_area_start_row_number + 1)].border = f_border
|
||||
|
||||
# table_data
|
||||
|
||||
for i, value in enumerate(category):
|
||||
row_data = row_title + 2 + i
|
||||
row_data = per_unit_area_start_row_number + 2 + i
|
||||
ws['B' + str(row_data)].font = name_font
|
||||
ws['B' + str(row_data)].alignment = c_c_alignment
|
||||
ws['B' + str(row_data)] = reporting_period_data['names'][i] + " (" + reporting_period_data['units'][
|
||||
|
@ -432,9 +422,9 @@ def generate_excel(report,
|
|||
|
||||
########################################################
|
||||
# Third: 详细数据
|
||||
# row_sat+row_title~ row_sat+row_title+time_len: line
|
||||
# row_sat+1+row_title: table title
|
||||
# i + row_sat + 2 + 10 * ca_len~: table_data
|
||||
# detailed_start_row_number~ detailed_start_row_number+time_len: line
|
||||
# detailed_start_row_number+1: table title
|
||||
# i + analysis_end_row_number + 2 + 6 * ca_len~: table_data
|
||||
########################################################
|
||||
has_timestamps_flag = True
|
||||
if "timestamps" not in reporting_period_data.keys() or \
|
||||
|
@ -449,29 +439,29 @@ def generate_excel(report,
|
|||
ca_len = len(names)
|
||||
time_len = len(timestamps)
|
||||
# title
|
||||
row_title = 10 * ca_len
|
||||
# row_st == row_statistical analysis table
|
||||
row_sat = 12 + 3 * ca_len
|
||||
line_charts_row_number = 6 * ca_len
|
||||
analysis_end_row_number = 12 + 3 * ca_len
|
||||
detailed_start_row_number = analysis_end_row_number + line_charts_row_number + 1
|
||||
|
||||
ws['B' + str(row_sat + row_title)].font = title_font
|
||||
ws['B' + str(row_sat + row_title)] = name + ' 详细数据'
|
||||
ws['B' + str(detailed_start_row_number)].font = title_font
|
||||
ws['B' + str(detailed_start_row_number)] = name + ' 详细数据'
|
||||
# table_title
|
||||
ws['B' + str(row_sat + 1 + row_title)].fill = table_fill
|
||||
ws['B' + str(row_sat + 1 + row_title)].font = name_font
|
||||
ws['B' + str(row_sat + 1 + row_title)].alignment = c_c_alignment
|
||||
ws['B' + str(row_sat + 1 + row_title)] = "时间"
|
||||
ws['B' + str(row_sat + 1 + row_title)].border = f_border
|
||||
ws['B' + str(detailed_start_row_number + 1)].fill = table_fill
|
||||
ws['B' + str(detailed_start_row_number + 1)].font = name_font
|
||||
ws['B' + str(detailed_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['B' + str(detailed_start_row_number + 1)] = "时间"
|
||||
ws['B' + str(detailed_start_row_number + 1)].border = f_border
|
||||
|
||||
for i in range(0, ca_len):
|
||||
col = chr(ord('C') + i)
|
||||
|
||||
ws[col + str(row_sat + 1 + row_title)].font = name_font
|
||||
ws[col + str(row_sat + 1 + row_title)].alignment = c_c_alignment
|
||||
ws[col + str(row_sat + 1 + row_title)] = names[i] + " - (" + reporting_period_data['units'][i] + ")"
|
||||
ws[col + str(row_sat + 1 + row_title)].border = f_border
|
||||
ws[col + str(detailed_start_row_number + 1)].font = name_font
|
||||
ws[col + str(detailed_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws[col + str(detailed_start_row_number + 1)] = names[i] + " - (" + reporting_period_data['units'][i] + ")"
|
||||
ws[col + str(detailed_start_row_number + 1)].border = f_border
|
||||
# table_date
|
||||
for i in range(0, time_len):
|
||||
rows = i + row_sat + 2 + 10 * ca_len
|
||||
rows = i + detailed_start_row_number + 2
|
||||
|
||||
ws['B' + str(rows)].font = name_font
|
||||
ws['B' + str(rows)].alignment = c_c_alignment
|
||||
|
@ -488,7 +478,7 @@ def generate_excel(report,
|
|||
ws[col + str(rows)].border = f_border
|
||||
|
||||
# 小计
|
||||
row_subtotals = row_sat + 2 + time_len + 10 * ca_len
|
||||
row_subtotals = detailed_start_row_number + 2 + time_len
|
||||
ws['B' + str(row_subtotals)].font = name_font
|
||||
ws['B' + str(row_subtotals)].alignment = c_c_alignment
|
||||
ws['B' + str(row_subtotals)] = "小计"
|
||||
|
@ -503,25 +493,34 @@ def generate_excel(report,
|
|||
ws[col + str(row_subtotals)].border = f_border
|
||||
ws[col + str(row_subtotals)].number_format = '0.00'
|
||||
|
||||
# LineChart
|
||||
########################################################
|
||||
# third: LineChart
|
||||
# LineChart requires data from the detailed data table in the Excel file
|
||||
# so print the detailed data table first and then print LineChart
|
||||
########################################################
|
||||
for i in range(0, ca_len):
|
||||
lc = LineChart()
|
||||
lc.title = "报告期消耗" + " - " + names[i] + "(" + reporting_period_data['units'][i] + ")"
|
||||
lc.style = 10
|
||||
lc.height = 8.40 # cm 1.05*8 1.05cm = 30 pt
|
||||
lc.width = 31
|
||||
lc.x_axis.majorTickMark = 'in'
|
||||
lc.y_axis.majorTickMark = 'in'
|
||||
times = Reference(ws, min_col=2, min_row=row_sat + 2 + row_title,
|
||||
max_row=row_sat + 2 + row_title + time_len)
|
||||
lc_data = Reference(ws, min_col=3 + i, min_row=row_sat + 1 + row_title,
|
||||
max_row=row_sat + 1 + row_title + time_len)
|
||||
lc.add_data(lc_data, titles_from_data=True)
|
||||
lc.set_categories(times)
|
||||
ser = lc.series[0]
|
||||
line = LineChart()
|
||||
line.title = "报告期消耗" + " - " + names[i] + "(" + reporting_period_data['units'][i] + ")"
|
||||
line.style = 10
|
||||
line.x_axis.majorTickMark = 'in'
|
||||
line.y_axis.majorTickMark = 'in'
|
||||
line.smooth = True
|
||||
line.x_axis.crosses = 'min'
|
||||
line.height = 8.25
|
||||
line.width = 24
|
||||
line.dLbls = DataLabelList()
|
||||
line.dLbls.dLblPos = 't'
|
||||
line.dLbls.showVal = True
|
||||
times = Reference(ws, min_col=2, min_row=detailed_start_row_number + 2,
|
||||
max_row=detailed_start_row_number + 2 + time_len)
|
||||
line_data = Reference(ws, min_col=3 + i, min_row=detailed_start_row_number + 1,
|
||||
max_row=detailed_start_row_number + 1 + time_len)
|
||||
line.add_data(line_data, titles_from_data=True)
|
||||
line.set_categories(times)
|
||||
ser = line.series[0]
|
||||
ser.marker.symbol = "diamond"
|
||||
ser.marker.size = 5
|
||||
ws.add_chart(lc, 'B' + str(row_sat + 10 * i))
|
||||
ws.add_chart(line, 'B' + str(analysis_end_row_number + 6 * i))
|
||||
|
||||
filename = str(uuid.uuid4()) + '.xlsx'
|
||||
wb.save(filename)
|
||||
|
|
|
@ -318,136 +318,136 @@ def generate_excel(report,
|
|||
|
||||
current_row_number += 1
|
||||
|
||||
#######################
|
||||
#######################
|
||||
|
||||
has_values_data = True
|
||||
has_timestamps_data = True
|
||||
has_values_data = True
|
||||
has_timestamps_data = True
|
||||
|
||||
if 'values' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['values'] is None or \
|
||||
len(reporting_period_data['values']) == 0:
|
||||
has_values_data = False
|
||||
if 'values' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['values'] is None or \
|
||||
len(reporting_period_data['values']) == 0:
|
||||
has_values_data = False
|
||||
|
||||
if 'timestamps' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['timestamps'] is None or \
|
||||
len(reporting_period_data['timestamps']) == 0 or \
|
||||
len(reporting_period_data['timestamps'][0]) == 0:
|
||||
has_timestamps_data = False
|
||||
if 'timestamps' not in reporting_period_data.keys() or \
|
||||
reporting_period_data['timestamps'] is None or \
|
||||
len(reporting_period_data['timestamps']) == 0 or \
|
||||
len(reporting_period_data['timestamps'][0]) == 0:
|
||||
has_timestamps_data = False
|
||||
|
||||
if has_values_data and has_timestamps_data:
|
||||
ca_len = len(reporting_period_data['names'])
|
||||
time = reporting_period_data['timestamps'][0]
|
||||
if has_values_data and has_timestamps_data:
|
||||
ca_len = len(reporting_period_data['names'])
|
||||
time = reporting_period_data['timestamps'][0]
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 详细数据'
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 详细数据'
|
||||
|
||||
current_row_number += 1
|
||||
current_row_number += 1
|
||||
|
||||
chart_start_row_number = current_row_number
|
||||
chart_start_row_number = current_row_number
|
||||
|
||||
current_row_number += ca_len * 6
|
||||
table_start_row_number = current_row_number
|
||||
current_row_number += ca_len * 6
|
||||
table_start_row_number = current_row_number
|
||||
|
||||
ws.row_dimensions[current_row_number].height = 60
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws.row_dimensions[current_row_number].height = 60
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '日期时间'
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
for i in range(0, len(time)):
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '日期时间'
|
||||
ws['B' + str(current_row_number)] = time[i]
|
||||
|
||||
col = 'C'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].fill = table_fill
|
||||
for j in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['values'][j][i], 2) \
|
||||
if reporting_period_data['values'][j][i] is not None else 0.00
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
for i in range(0, len(time)):
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = time[i]
|
||||
table_end_row_number = current_row_number - 1
|
||||
|
||||
col = 'C'
|
||||
for j in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['values'][j][i], 2) \
|
||||
if reporting_period_data['values'][j][i] is not None else 0.00
|
||||
col = chr(ord(col) + 1)
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '小计'
|
||||
|
||||
current_row_number += 1
|
||||
col = 'C'
|
||||
|
||||
table_end_row_number = current_row_number - 1
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['subtotals'][i], 2)
|
||||
col = chr(ord(col) + 1)
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '小计'
|
||||
current_row_number += 2
|
||||
|
||||
col = 'C'
|
||||
format_time_width_number = 1.0
|
||||
min_len_number = 1.0
|
||||
min_width_number = 11.0 # format_time_width_number * min_len_number + 4 and min_width_number > 11.0
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['subtotals'][i], 2)
|
||||
col = chr(ord(col) + 1)
|
||||
if period_type == 'hourly':
|
||||
format_time_width_number = 4.0
|
||||
min_len_number = 2
|
||||
min_width_number = 12.0
|
||||
elif period_type == 'daily':
|
||||
format_time_width_number = 2.5
|
||||
min_len_number = 4
|
||||
min_width_number = 14.0
|
||||
elif period_type == 'monthly':
|
||||
format_time_width_number = 2.1
|
||||
min_len_number = 4
|
||||
min_width_number = 12.4
|
||||
elif period_type == 'yearly':
|
||||
format_time_width_number = 1.5
|
||||
min_len_number = 5
|
||||
min_width_number = 11.5
|
||||
|
||||
current_row_number += 2
|
||||
|
||||
format_time_width_number = 1.0
|
||||
min_len_number = 1.0
|
||||
min_width_number = 11.0 # format_time_width_number * min_len_number + 4 and min_width_number > 11.0
|
||||
|
||||
if period_type == 'hourly':
|
||||
format_time_width_number = 4.0
|
||||
min_len_number = 2
|
||||
min_width_number = 12.0
|
||||
elif period_type == 'daily':
|
||||
format_time_width_number = 2.5
|
||||
min_len_number = 4
|
||||
min_width_number = 14.0
|
||||
elif period_type == 'monthly':
|
||||
format_time_width_number = 2.1
|
||||
min_len_number = 4
|
||||
min_width_number = 12.4
|
||||
elif period_type == 'yearly':
|
||||
format_time_width_number = 1.5
|
||||
min_len_number = 5
|
||||
min_width_number = 11.5
|
||||
|
||||
for i in range(0, ca_len):
|
||||
line = LineChart()
|
||||
line.title = '报告期消耗 - ' + \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
|
||||
line_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number, max_row=table_end_row_number)
|
||||
line.add_data(line_data, titles_from_data=True)
|
||||
line.set_categories(labels)
|
||||
line_data = line.series[0]
|
||||
line_data.marker.symbol = "circle"
|
||||
line_data.smooth = True
|
||||
line.x_axis.crosses = 'min'
|
||||
line.height = 8.25
|
||||
line.width = format_time_width_number * len(time) if len(time) > min_len_number else min_width_number
|
||||
if line.width > 24:
|
||||
line.width = 24
|
||||
line.dLbls = DataLabelList()
|
||||
line.dLbls.dLblPos = 't'
|
||||
line.dLbls.showVal = True
|
||||
line.dLbls.showPercent = False
|
||||
chart_col = 'B'
|
||||
chart_cell = chart_col + str(chart_start_row_number)
|
||||
chart_start_row_number += 6
|
||||
ws.add_chart(line, chart_cell)
|
||||
for i in range(0, ca_len):
|
||||
line = LineChart()
|
||||
line.title = '报告期消耗 - ' + \
|
||||
reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
|
||||
labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
|
||||
line_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number, max_row=table_end_row_number)
|
||||
line.add_data(line_data, titles_from_data=True)
|
||||
line.set_categories(labels)
|
||||
line_data = line.series[0]
|
||||
line_data.marker.symbol = "circle"
|
||||
line_data.smooth = True
|
||||
line.x_axis.crosses = 'min'
|
||||
line.height = 8.25
|
||||
line.width = format_time_width_number * len(time) if len(time) > min_len_number else min_width_number
|
||||
if line.width > 24:
|
||||
line.width = 24
|
||||
line.dLbls = DataLabelList()
|
||||
line.dLbls.dLblPos = 't'
|
||||
line.dLbls.showVal = True
|
||||
line.dLbls.showPercent = False
|
||||
chart_col = 'B'
|
||||
chart_cell = chart_col + str(chart_start_row_number)
|
||||
chart_start_row_number += 6
|
||||
ws.add_chart(line, chart_cell)
|
||||
|
||||
filename = str(uuid.uuid4()) + '.xlsx'
|
||||
wb.save(filename)
|
||||
|
|
|
@ -205,7 +205,8 @@ def generate_excel(report, name, reporting_start_datetime_local, reporting_end_d
|
|||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['averages'][i], 2)
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['averages'][i], 2) \
|
||||
if reporting_period_data['averages'][i] is not None else 'N/A'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
|
@ -219,7 +220,8 @@ def generate_excel(report, name, reporting_start_datetime_local, reporting_end_d
|
|||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['averages_per_unit_area'][i], 2)
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['averages_per_unit_area'][i], 2) \
|
||||
if reporting_period_data['averages_per_unit_area'][i] is not None else 'N/A'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
|
@ -268,7 +270,8 @@ def generate_excel(report, name, reporting_start_datetime_local, reporting_end_d
|
|||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['maximums'][i], 2)
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['maximums'][i], 2) \
|
||||
if reporting_period_data['maximums'][i] is not None else 'N/A'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
|
@ -282,7 +285,8 @@ def generate_excel(report, name, reporting_start_datetime_local, reporting_end_d
|
|||
ws[col + str(current_row_number)].font = name_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['maximums_per_unit_area'][i], 2)
|
||||
ws[col + str(current_row_number)] = round(reporting_period_data['maximums_per_unit_area'][i], 2) \
|
||||
if reporting_period_data['maximums_per_unit_area'][i] is not None else 'N/A'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
|
|
|
@ -152,6 +152,7 @@ def generate_excel(report,
|
|||
ws['F3'].font = name_font
|
||||
ws['F3'].alignment = b_r_alignment
|
||||
ws['F3'] = 'Date:'
|
||||
ws['G3'].border = b_border
|
||||
ws['G3'].alignment = b_c_alignment
|
||||
ws['G3'].font = name_font
|
||||
ws['G3'] = reporting_start_datetime_local + "__" + reporting_end_datetime_local
|
||||
|
@ -335,10 +336,18 @@ def generate_excel(report,
|
|||
ws['C' + str(current_row_number)].font = name_font
|
||||
ws['C' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['C' + str(current_row_number)].border = f_border
|
||||
ws['C' + str(current_row_number)] = '吨标准煤(TCE)占比'
|
||||
ws['C' + str(current_row_number)] = '节约'
|
||||
|
||||
ws['D' + str(current_row_number)].fill = table_fill
|
||||
ws['D' + str(current_row_number)].font = name_font
|
||||
ws['D' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['D' + str(current_row_number)].border = f_border
|
||||
ws['D' + str(current_row_number)] = '吨标准煤(TCE) 节约占比'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
subtotals_in_kgce_saving_sum = sum_list(reporting_period_data['subtotals_in_kgce_saving'])
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
|
@ -350,6 +359,13 @@ def generate_excel(report,
|
|||
ws['C' + str(current_row_number)].border = f_border
|
||||
ws['C' + str(current_row_number)] = round(reporting_period_data['subtotals_in_kgce_saving'][i] / 1000, 3)
|
||||
|
||||
ws['D' + str(current_row_number)].font = name_font
|
||||
ws['D' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['D' + str(current_row_number)].border = f_border
|
||||
ws['D' + str(current_row_number)] = str(round(reporting_period_data['subtotals_in_kgce_saving'][i] /
|
||||
subtotals_in_kgce_saving_sum * 100, 2)) + '%'\
|
||||
if abs(subtotals_in_kgce_saving_sum) > 0 else '-'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
table_end_row_number = current_row_number - 1
|
||||
|
@ -372,7 +388,7 @@ def generate_excel(report,
|
|||
s1.dLbls.showCatName = False
|
||||
s1.dLbls.showVal = True
|
||||
s1.dLbls.showPercent = True
|
||||
ws.add_chart(pie, 'D' + str(chart_start_row_number))
|
||||
ws.add_chart(pie, 'E' + str(chart_start_row_number))
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name + ' 吨二氧化碳排放(TCO2E)占比'
|
||||
|
@ -389,10 +405,18 @@ def generate_excel(report,
|
|||
ws['C' + str(current_row_number)].font = name_font
|
||||
ws['C' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['C' + str(current_row_number)].border = f_border
|
||||
ws['C' + str(current_row_number)] = '吨二氧化碳排放(TCO2E)占比'
|
||||
ws['C' + str(current_row_number)] = '节约'
|
||||
|
||||
ws['D' + str(current_row_number)].fill = table_fill
|
||||
ws['D' + str(current_row_number)].font = name_font
|
||||
ws['D' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['D' + str(current_row_number)].border = f_border
|
||||
ws['D' + str(current_row_number)] = '吨二氧化碳排放(TCO2E) 节约占比'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
subtotals_in_kgco2e_saving_sum = sum_list(reporting_period_data['subtotals_in_kgco2e_saving'])
|
||||
|
||||
for i in range(0, ca_len):
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
|
@ -404,6 +428,13 @@ def generate_excel(report,
|
|||
ws['C' + str(current_row_number)].border = f_border
|
||||
ws['C' + str(current_row_number)] = round(reporting_period_data['subtotals_in_kgco2e_saving'][i] / 1000, 3)
|
||||
|
||||
ws['D' + str(current_row_number)].font = name_font
|
||||
ws['D' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['D' + str(current_row_number)].border = f_border
|
||||
ws['D' + str(current_row_number)] = str(round(reporting_period_data['subtotals_in_kgco2e_saving'][i] /
|
||||
subtotals_in_kgco2e_saving_sum * 100, 2)) + '%'\
|
||||
if abs(subtotals_in_kgco2e_saving_sum) > 0 else '-'
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
table_end_row_number = current_row_number - 1
|
||||
|
@ -426,7 +457,7 @@ def generate_excel(report,
|
|||
s1.dLbls.showCatName = False
|
||||
s1.dLbls.showVal = True
|
||||
s1.dLbls.showPercent = True
|
||||
ws.add_chart(pie, 'D' + str(chart_start_row_number))
|
||||
ws.add_chart(pie, 'E' + str(chart_start_row_number))
|
||||
|
||||
#############################################
|
||||
|
||||
|
@ -563,3 +594,12 @@ def generate_excel(report,
|
|||
wb.save(filename)
|
||||
|
||||
return filename
|
||||
|
||||
|
||||
def sum_list(lists):
|
||||
total = 0
|
||||
|
||||
for i in range(0, len(lists)):
|
||||
total += lists[i]
|
||||
|
||||
return total
|
||||
|
|
|
@ -5,6 +5,7 @@ from openpyxl.chart import (
|
|||
LineChart,
|
||||
Reference,
|
||||
)
|
||||
from openpyxl.chart.label import DataLabelList
|
||||
from openpyxl.styles import PatternFill, Border, Side, Alignment, Font
|
||||
from openpyxl.drawing.image import Image
|
||||
from openpyxl import Workbook
|
||||
|
@ -68,19 +69,16 @@ def generate_excel(report,
|
|||
ws = wb.active
|
||||
|
||||
# Row height
|
||||
ws.row_dimensions[1].height = 121
|
||||
ws.row_dimensions[1].height = 102
|
||||
|
||||
for i in range(2, 37 + 1):
|
||||
ws.row_dimensions[i].height = 30
|
||||
|
||||
for i in range(38, 90 + 1):
|
||||
ws.row_dimensions[i].height = 30
|
||||
for i in range(2, 2000 + 1):
|
||||
ws.row_dimensions[i].height = 42
|
||||
|
||||
# Col width
|
||||
ws.column_dimensions['A'].width = 1.5
|
||||
ws.column_dimensions['B'].width = 20.0
|
||||
ws.column_dimensions['B'].width = 25.0
|
||||
|
||||
for i in range(ord('C'), ord('I')):
|
||||
for i in range(ord('C'), ord('L')):
|
||||
ws.column_dimensions[chr(i)].width = 15.0
|
||||
|
||||
# Font
|
||||
|
@ -116,12 +114,6 @@ def generate_excel(report,
|
|||
wrap_text=False,
|
||||
shrink_to_fit=False,
|
||||
indent=0)
|
||||
# c_r_alignment = Alignment(vertical='bottom',
|
||||
# horizontal='center',
|
||||
# text_rotation=0,
|
||||
# wrap_text=False,
|
||||
# shrink_to_fit=False,
|
||||
# indent=0)
|
||||
|
||||
# Img
|
||||
img = Image("excelexporters/myems.png")
|
||||
|
@ -183,8 +175,6 @@ def generate_excel(report,
|
|||
if has_energy_data_flag:
|
||||
ws['B6'].font = title_font
|
||||
ws['B6'] = name + ' 统计分析'
|
||||
# ws['D6'].font = title_font
|
||||
# ws['D6'] = '面积' +report['space']['area']
|
||||
|
||||
category = reporting_period_data['names']
|
||||
|
||||
|
@ -320,63 +310,61 @@ def generate_excel(report,
|
|||
# Second: 报告期消耗
|
||||
# 9 + ca_len * 2: title
|
||||
# 10 + ca_len * 2: table title
|
||||
# row_title + 2 ~ row_title + 2 + ca_len : table_data
|
||||
# per_unit_area_start_row_number + 2 ~ per_unit_area_start_row_number + 2 + ca_len : table_data
|
||||
#################################################
|
||||
|
||||
if has_energy_data_flag:
|
||||
names = reporting_period_data['names']
|
||||
ca_len = len(names)
|
||||
|
||||
row_title = 9 + ca_len * 2
|
||||
per_unit_area_start_row_number = 9 + ca_len * 2
|
||||
|
||||
ws['B' + str(row_title)].font = title_font
|
||||
ws['B' + str(row_title)] = name + ' 单位面积值'
|
||||
ws['D' + str(row_title)].font = title_font
|
||||
ws['D' + str(row_title)] = str(report['tenant']['area']) + 'M²'
|
||||
ws['B' + str(per_unit_area_start_row_number)].font = title_font
|
||||
ws['B' + str(per_unit_area_start_row_number)] = name + ' 单位面积值' + str(report['tenant']['area']) + 'M²'
|
||||
|
||||
category = reporting_period_data['names']
|
||||
|
||||
# table_title
|
||||
ws['B' + str(row_title + 1)].fill = table_fill
|
||||
ws['B' + str(row_title + 1)].font = title_font
|
||||
ws['B' + str(row_title + 1)].alignment = c_c_alignment
|
||||
ws['B' + str(row_title + 1)] = '报告期'
|
||||
ws['B' + str(row_title + 1)].border = f_border
|
||||
ws['B' + str(per_unit_area_start_row_number + 1)].fill = table_fill
|
||||
ws['B' + str(per_unit_area_start_row_number + 1)].font = title_font
|
||||
ws['B' + str(per_unit_area_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['B' + str(per_unit_area_start_row_number + 1)] = '报告期'
|
||||
ws['B' + str(per_unit_area_start_row_number + 1)].border = f_border
|
||||
|
||||
ws['C' + str(row_title + 1)].font = title_font
|
||||
ws['C' + str(row_title + 1)].alignment = c_c_alignment
|
||||
ws['C' + str(row_title + 1)] = '算术平均数'
|
||||
ws['C' + str(row_title + 1)].border = f_border
|
||||
ws['C' + str(per_unit_area_start_row_number + 1)].font = title_font
|
||||
ws['C' + str(per_unit_area_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['C' + str(per_unit_area_start_row_number + 1)] = '算术平均数'
|
||||
ws['C' + str(per_unit_area_start_row_number + 1)].border = f_border
|
||||
|
||||
ws['D' + str(row_title + 1)].font = title_font
|
||||
ws['D' + str(row_title + 1)].alignment = c_c_alignment
|
||||
ws['D' + str(row_title + 1)] = '中位数'
|
||||
ws['D' + str(row_title + 1)].border = f_border
|
||||
ws['D' + str(per_unit_area_start_row_number + 1)].font = title_font
|
||||
ws['D' + str(per_unit_area_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['D' + str(per_unit_area_start_row_number + 1)] = '中位数'
|
||||
ws['D' + str(per_unit_area_start_row_number + 1)].border = f_border
|
||||
|
||||
ws['E' + str(row_title + 1)].font = title_font
|
||||
ws['E' + str(row_title + 1)].alignment = c_c_alignment
|
||||
ws['E' + str(row_title + 1)] = '最小值'
|
||||
ws['E' + str(row_title + 1)].border = f_border
|
||||
ws['E' + str(per_unit_area_start_row_number + 1)].font = title_font
|
||||
ws['E' + str(per_unit_area_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['E' + str(per_unit_area_start_row_number + 1)] = '最小值'
|
||||
ws['E' + str(per_unit_area_start_row_number + 1)].border = f_border
|
||||
|
||||
ws['F' + str(row_title + 1)].font = title_font
|
||||
ws['F' + str(row_title + 1)].alignment = c_c_alignment
|
||||
ws['F' + str(row_title + 1)] = '最大值'
|
||||
ws['F' + str(row_title + 1)].border = f_border
|
||||
ws['F' + str(per_unit_area_start_row_number + 1)].font = title_font
|
||||
ws['F' + str(per_unit_area_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['F' + str(per_unit_area_start_row_number + 1)] = '最大值'
|
||||
ws['F' + str(per_unit_area_start_row_number + 1)].border = f_border
|
||||
|
||||
ws['G' + str(row_title + 1)].font = title_font
|
||||
ws['G' + str(row_title + 1)].alignment = c_c_alignment
|
||||
ws['G' + str(row_title + 1)] = '样本标准差'
|
||||
ws['G' + str(row_title + 1)].border = f_border
|
||||
ws['G' + str(per_unit_area_start_row_number + 1)].font = title_font
|
||||
ws['G' + str(per_unit_area_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['G' + str(per_unit_area_start_row_number + 1)] = '样本标准差'
|
||||
ws['G' + str(per_unit_area_start_row_number + 1)].border = f_border
|
||||
|
||||
ws['H' + str(row_title + 1)].font = title_font
|
||||
ws['H' + str(row_title + 1)].alignment = c_c_alignment
|
||||
ws['H' + str(row_title + 1)] = '样本方差'
|
||||
ws['H' + str(row_title + 1)].border = f_border
|
||||
ws['H' + str(per_unit_area_start_row_number + 1)].font = title_font
|
||||
ws['H' + str(per_unit_area_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['H' + str(per_unit_area_start_row_number + 1)] = '样本方差'
|
||||
ws['H' + str(per_unit_area_start_row_number + 1)].border = f_border
|
||||
|
||||
# table_data
|
||||
|
||||
for i, value in enumerate(category):
|
||||
row_data = row_title + 2 + i
|
||||
row_data = per_unit_area_start_row_number + 2 + i
|
||||
ws['B' + str(row_data)].font = name_font
|
||||
ws['B' + str(row_data)].alignment = c_c_alignment
|
||||
ws['B' + str(row_data)] = reporting_period_data['names'][i] + " (" + reporting_period_data['units'][
|
||||
|
@ -433,9 +421,9 @@ def generate_excel(report,
|
|||
|
||||
########################################################
|
||||
# Third: 详细数据
|
||||
# row_sat+row_title~ row_sat+row_title+time_len: line
|
||||
# row_sat+1+row_title: table title
|
||||
# i + row_sat + 2 + 10 * ca_len~: table_data
|
||||
# detailed_start_row_number~ detailed_start_row_number+time_len: line
|
||||
# detailed_start_row_number + 1: table title
|
||||
# i + analysis_end_row_number + 2 + 6 * ca_len~: table_data
|
||||
########################################################
|
||||
has_timestamps_flag = True
|
||||
if "timestamps" not in reporting_period_data.keys() or \
|
||||
|
@ -450,29 +438,29 @@ def generate_excel(report,
|
|||
ca_len = len(names)
|
||||
time_len = len(timestamps)
|
||||
# title
|
||||
row_title = 10 * ca_len
|
||||
# row_st == row_statistical analysis table
|
||||
row_sat = 12 + 3 * ca_len
|
||||
line_charts_row_number = 6 * ca_len
|
||||
analysis_end_row_number = 12 + 3 * ca_len
|
||||
detailed_start_row_number = analysis_end_row_number + line_charts_row_number + 1
|
||||
|
||||
ws['B' + str(row_sat+row_title)].font = title_font
|
||||
ws['B' + str(row_sat+row_title)] = name + ' 详细数据'
|
||||
ws['B' + str(detailed_start_row_number)].font = title_font
|
||||
ws['B' + str(detailed_start_row_number)] = name + ' 详细数据'
|
||||
# table_title
|
||||
ws['B' + str(row_sat+1+row_title)].fill = table_fill
|
||||
ws['B' + str(row_sat+1+row_title)].font = name_font
|
||||
ws['B' + str(row_sat+1+row_title)].alignment = c_c_alignment
|
||||
ws['B' + str(row_sat+1+row_title)] = "时间"
|
||||
ws['B' + str(row_sat+1+row_title)].border = f_border
|
||||
ws['B' + str(detailed_start_row_number + 1)].fill = table_fill
|
||||
ws['B' + str(detailed_start_row_number + 1)].font = name_font
|
||||
ws['B' + str(detailed_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws['B' + str(detailed_start_row_number + 1)] = "时间"
|
||||
ws['B' + str(detailed_start_row_number + 1)].border = f_border
|
||||
|
||||
for i in range(0, ca_len):
|
||||
col = chr(ord('C') + i)
|
||||
|
||||
ws[col + str(row_sat+1+row_title)].font = name_font
|
||||
ws[col + str(row_sat+1+row_title)].alignment = c_c_alignment
|
||||
ws[col + str(row_sat+1+row_title)] = names[i] + " - (" + reporting_period_data['units'][i] + ")"
|
||||
ws[col + str(row_sat+1+row_title)].border = f_border
|
||||
ws[col + str(detailed_start_row_number + 1)].font = name_font
|
||||
ws[col + str(detailed_start_row_number + 1)].alignment = c_c_alignment
|
||||
ws[col + str(detailed_start_row_number + 1)] = names[i] + " - (" + reporting_period_data['units'][i] + ")"
|
||||
ws[col + str(detailed_start_row_number + 1)].border = f_border
|
||||
# table_date
|
||||
for i in range(0, time_len):
|
||||
rows = i + row_sat + 2 + 10 * ca_len
|
||||
rows = i + detailed_start_row_number + 2
|
||||
|
||||
ws['B' + str(rows)].font = name_font
|
||||
ws['B' + str(rows)].alignment = c_c_alignment
|
||||
|
@ -489,7 +477,7 @@ def generate_excel(report,
|
|||
ws[col + str(rows)].border = f_border
|
||||
|
||||
# 小计
|
||||
row_subtotals = row_sat + 2 + time_len + 10 * ca_len
|
||||
row_subtotals = detailed_start_row_number + 2 + time_len
|
||||
ws['B' + str(row_subtotals)].font = name_font
|
||||
ws['B' + str(row_subtotals)].alignment = c_c_alignment
|
||||
ws['B' + str(row_subtotals)] = "小计"
|
||||
|
@ -504,26 +492,35 @@ def generate_excel(report,
|
|||
ws[col + str(row_subtotals)].border = f_border
|
||||
ws[col + str(row_subtotals)].number_format = '0.00'
|
||||
|
||||
# LineChart
|
||||
########################################################
|
||||
# third: LineChart
|
||||
# LineChart requires data from the detailed data table in the Excel file
|
||||
# so print the detailed data table first and then print LineChart
|
||||
########################################################
|
||||
for i in range(0, ca_len):
|
||||
|
||||
lc = LineChart()
|
||||
lc.title = "报告期消耗" + " - " + names[i] + "(" + reporting_period_data['units'][i] + ")"
|
||||
lc.style = 10
|
||||
lc.height = 8.40 # cm 1.05*8 1.05cm = 30 pt
|
||||
lc.width = 31
|
||||
lc.x_axis.majorTickMark = 'in'
|
||||
lc.y_axis.majorTickMark = 'in'
|
||||
times = Reference(ws, min_col=2, min_row=row_sat + 2 + row_title,
|
||||
max_row=row_sat + 2 + row_title + time_len)
|
||||
lc_data = Reference(ws, min_col=3 + i, min_row=row_sat + 1 + row_title,
|
||||
max_row=row_sat + 1 + row_title + time_len)
|
||||
lc.add_data(lc_data, titles_from_data=True)
|
||||
lc.set_categories(times)
|
||||
ser = lc.series[0]
|
||||
line = LineChart()
|
||||
line.title = "报告期消耗" + " - " + names[i] + "(" + reporting_period_data['units'][i] + ")"
|
||||
line.style = 10
|
||||
line.x_axis.majorTickMark = 'in'
|
||||
line.y_axis.majorTickMark = 'in'
|
||||
line.smooth = True
|
||||
line.x_axis.crosses = 'min'
|
||||
line.height = 8.25
|
||||
line.width = 24
|
||||
line.dLbls = DataLabelList()
|
||||
line.dLbls.dLblPos = 't'
|
||||
line.dLbls.showVal = True
|
||||
times = Reference(ws, min_col=2, min_row=detailed_start_row_number + 2,
|
||||
max_row=detailed_start_row_number + 2 + time_len)
|
||||
line_data = Reference(ws, min_col=3 + i, min_row=detailed_start_row_number + 1,
|
||||
max_row=detailed_start_row_number + 1 + time_len)
|
||||
line.add_data(line_data, titles_from_data=True)
|
||||
line.set_categories(times)
|
||||
ser = line.series[0]
|
||||
ser.marker.symbol = "diamond"
|
||||
ser.marker.size = 5
|
||||
ws.add_chart(lc, 'B' + str(row_sat + 10 * i))
|
||||
ws.add_chart(line, 'B' + str(analysis_end_row_number + 6 * i))
|
||||
|
||||
filename = str(uuid.uuid4()) + '.xlsx'
|
||||
wb.save(filename)
|
||||
|
|
|
@ -148,10 +148,10 @@ class Reporting:
|
|||
if cnx_billing:
|
||||
cnx_billing.disconnect()
|
||||
|
||||
if cnx_historical:
|
||||
cnx_historical.close()
|
||||
if cursor_historical:
|
||||
cursor_historical.disconnect()
|
||||
cursor_historical.close()
|
||||
if cnx_historical:
|
||||
cnx_historical.disconnect()
|
||||
raise falcon.HTTPError(falcon.HTTP_404,
|
||||
title='API.NOT_FOUND',
|
||||
description='API.COMBINED_EQUIPMENT_NOT_FOUND')
|
||||
|
@ -205,10 +205,10 @@ class Reporting:
|
|||
if cnx_billing:
|
||||
cnx_billing.disconnect()
|
||||
|
||||
if cnx_historical:
|
||||
cnx_historical.close()
|
||||
if cursor_historical:
|
||||
cursor_historical.disconnect()
|
||||
cursor_historical.close()
|
||||
if cnx_historical:
|
||||
cnx_historical.disconnect()
|
||||
raise falcon.HTTPError(falcon.HTTP_404,
|
||||
title='API.NOT_FOUND',
|
||||
description='API.ENERGY_CATEGORY_NOT_FOUND')
|
||||
|
@ -452,6 +452,11 @@ class Reporting:
|
|||
if cnx_billing:
|
||||
cnx_billing.disconnect()
|
||||
|
||||
if cursor_historical:
|
||||
cursor_historical.close()
|
||||
if cnx_historical:
|
||||
cnx_historical.disconnect()
|
||||
|
||||
result = dict()
|
||||
|
||||
result['combined_equipment'] = dict()
|
||||
|
|
|
@ -5,6 +5,7 @@ import config
|
|||
from datetime import datetime, timedelta, timezone
|
||||
from core import utilities
|
||||
from decimal import Decimal
|
||||
import excelexporters.combinedequipmentefficiency
|
||||
|
||||
|
||||
class Reporting:
|
||||
|
@ -20,16 +21,13 @@ class Reporting:
|
|||
# PROCEDURES
|
||||
# Step 1: valid parameters
|
||||
# Step 2: query the combined equipment
|
||||
# Step 3: query associated equipments
|
||||
# Step 4: query energy categories
|
||||
# Step 5: query associated points
|
||||
# Step 6: query base period energy input
|
||||
# Step 7: query base period energy output
|
||||
# Step 8: query reporting period energy input
|
||||
# Step 9: query reporting period energy output
|
||||
# Step 10: query tariff data
|
||||
# Step 11: query associated points data
|
||||
# Step 12: construct the report
|
||||
# Step 3: query associated points
|
||||
# Step 4: query associated fractions
|
||||
# Step 5: query fractions' numerator and denominator
|
||||
# Step 6: calculate base period fractions
|
||||
# Step 7: calculate reporting period fractions
|
||||
# Step 8: query associated points data
|
||||
# Step 9: construct the report
|
||||
####################################################################################################################
|
||||
@staticmethod
|
||||
def on_get(req, resp):
|
||||
|
@ -45,14 +43,12 @@ class Reporting:
|
|||
# Step 1: valid parameters
|
||||
################################################################################################################
|
||||
if combined_equipment_id is None:
|
||||
raise falcon.HTTPError(falcon.HTTP_400,
|
||||
title='API.BAD_REQUEST',
|
||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
|
||||
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
||||
else:
|
||||
combined_equipment_id = str.strip(combined_equipment_id)
|
||||
if not combined_equipment_id.isdigit() or int(combined_equipment_id) <= 0:
|
||||
raise falcon.HTTPError(falcon.HTTP_400,
|
||||
title='API.BAD_REQUEST',
|
||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
|
||||
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
||||
|
||||
if period_type is None:
|
||||
|
@ -72,7 +68,7 @@ class Reporting:
|
|||
try:
|
||||
base_start_datetime_utc = datetime.strptime(base_start_datetime_local,
|
||||
'%Y-%m-%dT%H:%M:%S').replace(tzinfo=timezone.utc) - \
|
||||
timedelta(minutes=timezone_offset)
|
||||
timedelta(minutes=timezone_offset)
|
||||
except ValueError:
|
||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
|
||||
description="API.INVALID_BASE_PERIOD_START_DATETIME")
|
||||
|
@ -83,7 +79,7 @@ class Reporting:
|
|||
try:
|
||||
base_end_datetime_utc = datetime.strptime(base_end_datetime_local,
|
||||
'%Y-%m-%dT%H:%M:%S').replace(tzinfo=timezone.utc) - \
|
||||
timedelta(minutes=timezone_offset)
|
||||
timedelta(minutes=timezone_offset)
|
||||
except ValueError:
|
||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
|
||||
description="API.INVALID_BASE_PERIOD_END_DATETIME")
|
||||
|
@ -101,7 +97,7 @@ class Reporting:
|
|||
try:
|
||||
reporting_start_datetime_utc = datetime.strptime(reporting_start_datetime_local,
|
||||
'%Y-%m-%dT%H:%M:%S').replace(tzinfo=timezone.utc) - \
|
||||
timedelta(minutes=timezone_offset)
|
||||
timedelta(minutes=timezone_offset)
|
||||
except ValueError:
|
||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
|
||||
description="API.INVALID_REPORTING_PERIOD_START_DATETIME")
|
||||
|
@ -114,7 +110,7 @@ class Reporting:
|
|||
try:
|
||||
reporting_end_datetime_utc = datetime.strptime(reporting_end_datetime_local,
|
||||
'%Y-%m-%dT%H:%M:%S').replace(tzinfo=timezone.utc) - \
|
||||
timedelta(minutes=timezone_offset)
|
||||
timedelta(minutes=timezone_offset)
|
||||
except ValueError:
|
||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
|
||||
description="API.INVALID_REPORTING_PERIOD_END_DATETIME")
|
||||
|
@ -150,110 +146,20 @@ class Reporting:
|
|||
if cnx_energy:
|
||||
cnx_energy.disconnect()
|
||||
|
||||
if cnx_historical:
|
||||
cnx_historical.close()
|
||||
if cursor_historical:
|
||||
cursor_historical.disconnect()
|
||||
raise falcon.HTTPError(falcon.HTTP_404,
|
||||
title='API.NOT_FOUND',
|
||||
cursor_historical.close()
|
||||
if cnx_historical:
|
||||
cnx_historical.disconnect()
|
||||
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND',
|
||||
description='API.COMBINED_EQUIPMENT_NOT_FOUND')
|
||||
|
||||
combined_equipment = dict()
|
||||
combined_equipment['id'] = row_combined_equipment[0]
|
||||
combined_equipment['name'] = row_combined_equipment[1]
|
||||
combined_equipment['cost_center_id'] = row_combined_equipment[2]
|
||||
################################################################################################################
|
||||
# Step 3: query associated equipments
|
||||
################################################################################################################
|
||||
# todo
|
||||
|
||||
################################################################################################################
|
||||
# Step 4: query input energy categories and output energy categories
|
||||
################################################################################################################
|
||||
energy_category_set_input = set()
|
||||
energy_category_set_output = set()
|
||||
# query input energy categories in base period
|
||||
cursor_energy.execute(" SELECT DISTINCT(energy_category_id) "
|
||||
" FROM tbl_combined_equipment_input_category_hourly "
|
||||
" WHERE combined_equipment_id = %s "
|
||||
" AND start_datetime_utc >= %s "
|
||||
" AND start_datetime_utc < %s ",
|
||||
(combined_equipment['id'], base_start_datetime_utc, base_end_datetime_utc))
|
||||
rows_energy_categories = cursor_energy.fetchall()
|
||||
if rows_energy_categories is not None or len(rows_energy_categories) > 0:
|
||||
for row_energy_category in rows_energy_categories:
|
||||
energy_category_set_input.add(row_energy_category[0])
|
||||
|
||||
# query input energy categories in reporting period
|
||||
cursor_energy.execute(" SELECT DISTINCT(energy_category_id) "
|
||||
" FROM tbl_combined_equipment_input_category_hourly "
|
||||
" WHERE combined_equipment_id = %s "
|
||||
" AND start_datetime_utc >= %s "
|
||||
" AND start_datetime_utc < %s ",
|
||||
(combined_equipment['id'], reporting_start_datetime_utc, reporting_end_datetime_utc))
|
||||
rows_energy_categories = cursor_energy.fetchall()
|
||||
if rows_energy_categories is not None or len(rows_energy_categories) > 0:
|
||||
for row_energy_category in rows_energy_categories:
|
||||
energy_category_set_input.add(row_energy_category[0])
|
||||
|
||||
# query output energy categories in base period
|
||||
cursor_energy.execute(" SELECT DISTINCT(energy_category_id) "
|
||||
" FROM tbl_combined_equipment_output_category_hourly "
|
||||
" WHERE combined_equipment_id = %s "
|
||||
" AND start_datetime_utc >= %s "
|
||||
" AND start_datetime_utc < %s ",
|
||||
(combined_equipment['id'], base_start_datetime_utc, base_end_datetime_utc))
|
||||
rows_energy_categories = cursor_energy.fetchall()
|
||||
if rows_energy_categories is not None or len(rows_energy_categories) > 0:
|
||||
for row_energy_category in rows_energy_categories:
|
||||
energy_category_set_output.add(row_energy_category[0])
|
||||
|
||||
# query output energy categories in reporting period
|
||||
cursor_energy.execute(" SELECT DISTINCT(energy_category_id) "
|
||||
" FROM tbl_combined_equipment_output_category_hourly "
|
||||
" WHERE combined_equipment_id = %s "
|
||||
" AND start_datetime_utc >= %s "
|
||||
" AND start_datetime_utc < %s ",
|
||||
(combined_equipment['id'], reporting_start_datetime_utc, reporting_end_datetime_utc))
|
||||
rows_energy_categories = cursor_energy.fetchall()
|
||||
if rows_energy_categories is not None or len(rows_energy_categories) > 0:
|
||||
for row_energy_category in rows_energy_categories:
|
||||
energy_category_set_output.add(row_energy_category[0])
|
||||
|
||||
# query properties of all energy categories above
|
||||
cursor_system.execute(" SELECT id, name, unit_of_measure, kgce, kgco2e "
|
||||
" FROM tbl_energy_categories "
|
||||
" ORDER BY id ", )
|
||||
rows_energy_categories = cursor_system.fetchall()
|
||||
if rows_energy_categories is None or len(rows_energy_categories) == 0:
|
||||
if cursor_system:
|
||||
cursor_system.close()
|
||||
if cnx_system:
|
||||
cnx_system.disconnect()
|
||||
|
||||
if cursor_energy:
|
||||
cursor_energy.close()
|
||||
if cnx_energy:
|
||||
cnx_energy.disconnect()
|
||||
|
||||
if cnx_historical:
|
||||
cnx_historical.close()
|
||||
if cursor_historical:
|
||||
cursor_historical.disconnect()
|
||||
raise falcon.HTTPError(falcon.HTTP_404,
|
||||
title='API.NOT_FOUND',
|
||||
description='API.ENERGY_CATEGORY_NOT_FOUND')
|
||||
energy_category_dict = dict()
|
||||
for row_energy_category in rows_energy_categories:
|
||||
if row_energy_category[0] in energy_category_set_input or \
|
||||
row_energy_category[0] in energy_category_set_output:
|
||||
energy_category_dict[row_energy_category[0]] = {"name": row_energy_category[1],
|
||||
"unit_of_measure": row_energy_category[2],
|
||||
"kgce": row_energy_category[3],
|
||||
"kgco2e": row_energy_category[4]}
|
||||
|
||||
################################################################################################################
|
||||
# Step 5: query associated points
|
||||
# Step 3: query associated points
|
||||
################################################################################################################
|
||||
point_list = list()
|
||||
cursor_system.execute(" SELECT p.id, p.name, p.units, p.object_type "
|
||||
|
@ -266,84 +172,181 @@ class Reporting:
|
|||
for row in rows_points:
|
||||
point_list.append({"id": row[0], "name": row[1], "units": row[2], "object_type": row[3]})
|
||||
|
||||
print(point_list)
|
||||
################################################################################################################
|
||||
# Step 6: query base period energy input
|
||||
# Step 4: query associated fractions
|
||||
################################################################################################################
|
||||
base_input = dict()
|
||||
if energy_category_set_input is not None and len(energy_category_set_input) > 0:
|
||||
for energy_category_id in energy_category_set_input:
|
||||
base_input[energy_category_id] = dict()
|
||||
base_input[energy_category_id]['timestamps'] = list()
|
||||
base_input[energy_category_id]['values'] = list()
|
||||
base_input[energy_category_id]['subtotal'] = Decimal(0.0)
|
||||
fraction_list = list()
|
||||
cursor_system.execute(" SELECT id, name, numerator_meter_uuid, denominator_meter_uuid "
|
||||
" FROM tbl_combined_equipments_parameters "
|
||||
" WHERE combined_equipment_id = %s AND parameter_type = 'fraction' ",
|
||||
(combined_equipment['id'],))
|
||||
rows_fractions = cursor_system.fetchall()
|
||||
if rows_fractions is not None and len(rows_fractions) > 0:
|
||||
for row in rows_fractions:
|
||||
fraction_list.append({"id": row[0],
|
||||
"name": row[1],
|
||||
"numerator_meter_uuid": row[2],
|
||||
"denominator_meter_uuid": row[3],
|
||||
})
|
||||
|
||||
cursor_energy.execute(" SELECT start_datetime_utc, actual_value "
|
||||
" FROM tbl_combined_equipment_input_category_hourly "
|
||||
" WHERE combined_equipment_id = %s "
|
||||
" AND energy_category_id = %s "
|
||||
" AND start_datetime_utc >= %s "
|
||||
" AND start_datetime_utc < %s "
|
||||
" ORDER BY start_datetime_utc ",
|
||||
(combined_equipment['id'],
|
||||
energy_category_id,
|
||||
base_start_datetime_utc,
|
||||
base_end_datetime_utc))
|
||||
rows_combined_equipment_hourly = cursor_energy.fetchall()
|
||||
print(fraction_list)
|
||||
|
||||
rows_combined_equipment_periodically = \
|
||||
utilities.aggregate_hourly_data_by_period(rows_combined_equipment_hourly,
|
||||
################################################################################################################
|
||||
# Step 5: query fractions' numerator and denominator
|
||||
################################################################################################################
|
||||
# get all meters
|
||||
meter_dict = dict()
|
||||
query = (" SELECT m.id, m.uuid, ec.unit_of_measure "
|
||||
" FROM tbl_meters m, tbl_energy_categories ec "
|
||||
" WHERE m.energy_category_id = ec.id ")
|
||||
cursor_system.execute(query)
|
||||
rows_meters = cursor_system.fetchall()
|
||||
|
||||
if rows_meters is not None and len(rows_meters) > 0:
|
||||
for row in rows_meters:
|
||||
meter_dict[row[1]] = {'id': row[0], 'unit': row[2]}
|
||||
# get all offline meters
|
||||
offline_meter_dict = dict()
|
||||
query = (" SELECT m.id, m.uuid, ec.unit_of_measure "
|
||||
" FROM tbl_offline_meters m, tbl_energy_categories ec "
|
||||
" WHERE m.energy_category_id = ec.id ")
|
||||
cursor_system.execute(query)
|
||||
rows_offline_meters = cursor_system.fetchall()
|
||||
|
||||
if rows_offline_meters is not None and len(rows_offline_meters) > 0:
|
||||
for row in rows_offline_meters:
|
||||
offline_meter_dict[row[1]] = {'id': row[0], 'unit': row[2]}
|
||||
# get all virtual meters
|
||||
virtual_meter_dict = dict()
|
||||
query = (" SELECT m.id, m.uuid, ec.unit_of_measure "
|
||||
" FROM tbl_virtual_meters m, tbl_energy_categories ec "
|
||||
" WHERE m.energy_category_id = ec.id ")
|
||||
cursor_system.execute(query)
|
||||
rows_virtual_meters = cursor_system.fetchall()
|
||||
|
||||
if rows_virtual_meters is not None and len(rows_virtual_meters) > 0:
|
||||
for row in rows_virtual_meters:
|
||||
virtual_meter_dict[row[1]] = {'id': row[0], 'unit': row[2]}
|
||||
|
||||
if fraction_list is not None and len(fraction_list) > 0:
|
||||
for fraction in fraction_list:
|
||||
if fraction['numerator_meter_uuid'] in offline_meter_dict:
|
||||
fraction['numerator_meter_id'] = offline_meter_dict[fraction['numerator_meter_uuid']]['id']
|
||||
fraction['numerator_meter_unit'] = offline_meter_dict[fraction['numerator_meter_uuid']]['unit']
|
||||
fraction['numerator_meter_type'] = 'offline_meter'
|
||||
elif fraction['numerator_meter_uuid'] in virtual_meter_dict:
|
||||
fraction['numerator_meter_id'] = virtual_meter_dict[fraction['numerator_meter_uuid']]['id']
|
||||
fraction['numerator_meter_unit'] = virtual_meter_dict[fraction['numerator_meter_uuid']]['unit']
|
||||
fraction['numerator_meter_type'] = 'virtual_meter'
|
||||
elif fraction['numerator_meter_uuid'] in meter_dict:
|
||||
fraction['numerator_meter_id'] = meter_dict[fraction['numerator_meter_uuid']]['id']
|
||||
fraction['numerator_meter_unit'] = meter_dict[fraction['numerator_meter_uuid']]['unit']
|
||||
fraction['numerator_meter_type'] = 'meter'
|
||||
|
||||
if fraction['denominator_meter_uuid'] in offline_meter_dict:
|
||||
fraction['denominator_meter_id'] = offline_meter_dict[fraction['denominator_meter_uuid']]['id']
|
||||
fraction['denominator_meter_unit'] = offline_meter_dict[fraction['denominator_meter_uuid']]['unit']
|
||||
fraction['denominator_meter_type'] = 'offline_meter'
|
||||
elif fraction['denominator_meter_uuid'] in virtual_meter_dict:
|
||||
fraction['denominator_meter_id'] = virtual_meter_dict[fraction['denominator_meter_uuid']]['id']
|
||||
fraction['denominator_meter_unit'] = virtual_meter_dict[fraction['denominator_meter_uuid']]['unit']
|
||||
fraction['denominator_meter_type'] = 'virtual_meter'
|
||||
elif fraction['denominator_meter_uuid'] in meter_dict:
|
||||
fraction['denominator_meter_id'] = meter_dict[fraction['denominator_meter_uuid']]['id']
|
||||
fraction['denominator_meter_unit'] = meter_dict[fraction['denominator_meter_uuid']]['unit']
|
||||
fraction['denominator_meter_type'] = 'meter'
|
||||
|
||||
print(fraction_list)
|
||||
|
||||
################################################################################################################
|
||||
# Step 5: calculate base period fractions
|
||||
################################################################################################################
|
||||
base = dict()
|
||||
if fraction_list is not None and len(fraction_list) > 0:
|
||||
for fraction in fraction_list:
|
||||
base[fraction['id']] = dict()
|
||||
base[fraction['id']]['name'] = fraction['name']
|
||||
base[fraction['id']]['unit'] = fraction['numerator_meter_unit'] + '/' + \
|
||||
fraction['denominator_meter_unit']
|
||||
base[fraction['id']]['numerator_timestamps'] = list()
|
||||
base[fraction['id']]['numerator_values'] = list()
|
||||
base[fraction['id']]['numerator_cumulation'] = Decimal(0.0)
|
||||
base[fraction['id']]['denominator_timestamps'] = list()
|
||||
base[fraction['id']]['denominator_values'] = list()
|
||||
base[fraction['id']]['denominator_cumulation'] = Decimal(0.0)
|
||||
base[fraction['id']]['timestamps'] = list()
|
||||
base[fraction['id']]['values'] = list()
|
||||
base[fraction['id']]['cumulation'] = Decimal(0.0)
|
||||
# query numerator meter output
|
||||
if fraction['numerator_meter_type'] == 'meter':
|
||||
query = (" SELECT start_datetime_utc, actual_value "
|
||||
" FROM tbl_meter_hourly "
|
||||
" WHERE meter_id = %s "
|
||||
" AND start_datetime_utc >= %s "
|
||||
" AND start_datetime_utc < %s "
|
||||
" ORDER BY start_datetime_utc ")
|
||||
elif fraction['numerator_meter_type'] == 'offline_meter':
|
||||
query = (" SELECT start_datetime_utc, actual_value "
|
||||
" FROM tbl_offline_meter_hourly "
|
||||
" WHERE offline_meter_id = %s "
|
||||
" AND start_datetime_utc >= %s "
|
||||
" AND start_datetime_utc < %s "
|
||||
" ORDER BY start_datetime_utc ")
|
||||
elif fraction['numerator_meter_type'] == 'virtual_meter':
|
||||
query = (" SELECT start_datetime_utc, actual_value "
|
||||
" FROM tbl_virtual_meter_hourly "
|
||||
" WHERE virtual_meter_id = %s "
|
||||
" AND start_datetime_utc >= %s "
|
||||
" AND start_datetime_utc < %s "
|
||||
" ORDER BY start_datetime_utc ")
|
||||
|
||||
cursor_energy.execute(query, (fraction['numerator_meter_id'],
|
||||
base_start_datetime_utc,
|
||||
base_end_datetime_utc))
|
||||
rows_numerator_meter_hourly = cursor_energy.fetchall()
|
||||
|
||||
rows_numerator_meter_periodically = \
|
||||
utilities.aggregate_hourly_data_by_period(rows_numerator_meter_hourly,
|
||||
base_start_datetime_utc,
|
||||
base_end_datetime_utc,
|
||||
period_type)
|
||||
for row_combined_equipment_periodically in rows_combined_equipment_periodically:
|
||||
current_datetime_local = row_combined_equipment_periodically[0].replace(tzinfo=timezone.utc) + \
|
||||
timedelta(minutes=timezone_offset)
|
||||
if period_type == 'hourly':
|
||||
current_datetime = current_datetime_local.strftime('%Y-%m-%dT%H:%M:%S')
|
||||
elif period_type == 'daily':
|
||||
current_datetime = current_datetime_local.strftime('%Y-%m-%d')
|
||||
elif period_type == 'monthly':
|
||||
current_datetime = current_datetime_local.strftime('%Y-%m')
|
||||
elif period_type == 'yearly':
|
||||
current_datetime = current_datetime_local.strftime('%Y')
|
||||
# query denominator meter input
|
||||
if fraction['denominator_meter_type'] == 'meter':
|
||||
query = (" SELECT start_datetime_utc, actual_value "
|
||||
" FROM tbl_meter_hourly "
|
||||
" WHERE meter_id = %s "
|
||||
" AND start_datetime_utc >= %s "
|
||||
" AND start_datetime_utc < %s "
|
||||
" ORDER BY start_datetime_utc ")
|
||||
elif fraction['denominator_meter_type'] == 'offline_meter':
|
||||
query = (" SELECT start_datetime_utc, actual_value "
|
||||
" FROM tbl_offline_meter_hourly "
|
||||
" WHERE offline_meter_id = %s "
|
||||
" AND start_datetime_utc >= %s "
|
||||
" AND start_datetime_utc < %s "
|
||||
" ORDER BY start_datetime_utc ")
|
||||
elif fraction['denominator_meter_type'] == 'virtual_meter':
|
||||
query = (" SELECT start_datetime_utc, actual_value "
|
||||
" FROM tbl_virtual_meter_hourly "
|
||||
" WHERE virtual_meter_id = %s "
|
||||
" AND start_datetime_utc >= %s "
|
||||
" AND start_datetime_utc < %s "
|
||||
" ORDER BY start_datetime_utc ")
|
||||
|
||||
actual_value = Decimal(0.0) if row_combined_equipment_periodically[1] is None \
|
||||
else row_combined_equipment_periodically[1]
|
||||
base_input[energy_category_id]['timestamps'].append(current_datetime)
|
||||
base_input[energy_category_id]['values'].append(actual_value)
|
||||
base_input[energy_category_id]['subtotal'] += actual_value
|
||||
cursor_energy.execute(query, (fraction['denominator_meter_id'],
|
||||
base_start_datetime_utc,
|
||||
base_end_datetime_utc))
|
||||
rows_denominator_meter_hourly = cursor_energy.fetchall()
|
||||
|
||||
################################################################################################################
|
||||
# Step 7: query base period energy output
|
||||
################################################################################################################
|
||||
base_output = dict()
|
||||
if energy_category_set_output is not None and len(energy_category_set_output) > 0:
|
||||
for energy_category_id in energy_category_set_output:
|
||||
base_output[energy_category_id] = dict()
|
||||
base_output[energy_category_id]['timestamps'] = list()
|
||||
base_output[energy_category_id]['values'] = list()
|
||||
base_output[energy_category_id]['subtotal'] = Decimal(0.0)
|
||||
|
||||
cursor_energy.execute(" SELECT start_datetime_utc, actual_value "
|
||||
" FROM tbl_combined_equipment_output_category_hourly "
|
||||
" WHERE combined_equipment_id = %s "
|
||||
" AND energy_category_id = %s "
|
||||
" AND start_datetime_utc >= %s "
|
||||
" AND start_datetime_utc < %s "
|
||||
" ORDER BY start_datetime_utc ",
|
||||
(combined_equipment['id'],
|
||||
energy_category_id,
|
||||
base_start_datetime_utc,
|
||||
base_end_datetime_utc))
|
||||
rows_combined_equipment_hourly = cursor_energy.fetchall()
|
||||
|
||||
rows_combined_equipment_periodically = \
|
||||
utilities.aggregate_hourly_data_by_period(rows_combined_equipment_hourly,
|
||||
rows_denominator_meter_periodically = \
|
||||
utilities.aggregate_hourly_data_by_period(rows_denominator_meter_hourly,
|
||||
base_start_datetime_utc,
|
||||
base_end_datetime_utc,
|
||||
period_type)
|
||||
for row_combined_equipment_periodically in rows_combined_equipment_periodically:
|
||||
current_datetime_local = row_combined_equipment_periodically[0].replace(tzinfo=timezone.utc) + \
|
||||
|
||||
for row_numerator_meter_periodically in rows_numerator_meter_periodically:
|
||||
current_datetime_local = row_numerator_meter_periodically[0].replace(tzinfo=timezone.utc) + \
|
||||
timedelta(minutes=timezone_offset)
|
||||
if period_type == 'hourly':
|
||||
current_datetime = current_datetime_local.strftime('%Y-%m-%dT%H:%M:%S')
|
||||
|
@ -354,91 +357,133 @@ class Reporting:
|
|||
elif period_type == 'yearly':
|
||||
current_datetime = current_datetime_local.strftime('%Y')
|
||||
|
||||
actual_value = Decimal(0.0) if row_combined_equipment_periodically[1] is None \
|
||||
else row_combined_equipment_periodically[1]
|
||||
base_output[energy_category_id]['timestamps'].append(current_datetime)
|
||||
base_output[energy_category_id]['values'].append(actual_value)
|
||||
base_output[energy_category_id]['subtotal'] += actual_value
|
||||
actual_value = Decimal(0.0) if row_numerator_meter_periodically[1] is None \
|
||||
else row_numerator_meter_periodically[1]
|
||||
|
||||
base[fraction['id']]['numerator_timestamps'].append(current_datetime)
|
||||
base[fraction['id']]['numerator_values'].append(actual_value)
|
||||
base[fraction['id']]['numerator_cumulation'] += actual_value
|
||||
|
||||
for row_denominator_meter_periodically in rows_denominator_meter_periodically:
|
||||
current_datetime_local = row_denominator_meter_periodically[0].replace(tzinfo=timezone.utc) + \
|
||||
timedelta(minutes=timezone_offset)
|
||||
if period_type == 'hourly':
|
||||
current_datetime = current_datetime_local.strftime('%Y-%m-%dT%H:%M:%S')
|
||||
elif period_type == 'daily':
|
||||
current_datetime = current_datetime_local.strftime('%Y-%m-%d')
|
||||
elif period_type == 'monthly':
|
||||
current_datetime = current_datetime_local.strftime('%Y-%m')
|
||||
elif period_type == 'yearly':
|
||||
current_datetime = current_datetime_local.strftime('%Y')
|
||||
|
||||
actual_value = Decimal(0.0) if row_denominator_meter_periodically[1] is None \
|
||||
else row_denominator_meter_periodically[1]
|
||||
|
||||
base[fraction['id']]['denominator_timestamps'].append(current_datetime)
|
||||
base[fraction['id']]['denominator_values'].append(actual_value)
|
||||
base[fraction['id']]['denominator_cumulation'] += actual_value
|
||||
|
||||
for i in range(len(base[fraction['id']]['denominator_timestamps'])):
|
||||
timestamp = base[fraction['id']]['denominator_timestamps'][i]
|
||||
base[fraction['id']]['timestamps'].append(timestamp)
|
||||
value = (base[fraction['id']]['numerator_values'][i] /
|
||||
base[fraction['id']]['denominator_values'][i]) \
|
||||
if base[fraction['id']]['denominator_values'][i] > Decimal(0.0) else Decimal(0.0)
|
||||
base[fraction['id']]['values'].append(value)
|
||||
|
||||
cumulation = (base[fraction['id']]['numerator_cumulation'] /
|
||||
base[fraction['id']]['denominator_cumulation']) \
|
||||
if base[fraction['id']]['denominator_cumulation'] > Decimal(0.0) else Decimal(0.0)
|
||||
base[fraction['id']]['cumulation'] = cumulation
|
||||
|
||||
################################################################################################################
|
||||
# Step 8: query reporting period energy input
|
||||
# Step 6: calculate reporting period fractions
|
||||
################################################################################################################
|
||||
reporting_input = dict()
|
||||
if energy_category_set_input is not None and len(energy_category_set_input) > 0:
|
||||
for energy_category_id in energy_category_set_input:
|
||||
reporting = dict()
|
||||
if fraction_list is not None and len(fraction_list) > 0:
|
||||
for fraction in fraction_list:
|
||||
reporting[fraction['id']] = dict()
|
||||
reporting[fraction['id']]['name'] = fraction['name']
|
||||
reporting[fraction['id']]['unit'] = fraction['numerator_meter_unit'] + '/' + \
|
||||
fraction['denominator_meter_unit']
|
||||
reporting[fraction['id']]['numerator_timestamps'] = list()
|
||||
reporting[fraction['id']]['numerator_values'] = list()
|
||||
reporting[fraction['id']]['numerator_cumulation'] = Decimal(0.0)
|
||||
reporting[fraction['id']]['denominator_timestamps'] = list()
|
||||
reporting[fraction['id']]['denominator_values'] = list()
|
||||
reporting[fraction['id']]['denominator_cumulation'] = Decimal(0.0)
|
||||
reporting[fraction['id']]['timestamps'] = list()
|
||||
reporting[fraction['id']]['values'] = list()
|
||||
reporting[fraction['id']]['cumulation'] = Decimal(0.0)
|
||||
# query numerator meter output
|
||||
if fraction['numerator_meter_type'] == 'meter':
|
||||
query = (" SELECT start_datetime_utc, actual_value "
|
||||
" FROM tbl_meter_hourly "
|
||||
" WHERE meter_id = %s "
|
||||
" AND start_datetime_utc >= %s "
|
||||
" AND start_datetime_utc < %s "
|
||||
" ORDER BY start_datetime_utc ")
|
||||
elif fraction['numerator_meter_type'] == 'offline_meter':
|
||||
query = (" SELECT start_datetime_utc, actual_value "
|
||||
" FROM tbl_offline_meter_hourly "
|
||||
" WHERE offline_meter_id = %s "
|
||||
" AND start_datetime_utc >= %s "
|
||||
" AND start_datetime_utc < %s "
|
||||
" ORDER BY start_datetime_utc ")
|
||||
elif fraction['numerator_meter_type'] == 'virtual_meter':
|
||||
query = (" SELECT start_datetime_utc, actual_value "
|
||||
" FROM tbl_virtual_meter_hourly "
|
||||
" WHERE virtual_meter_id = %s "
|
||||
" AND start_datetime_utc >= %s "
|
||||
" AND start_datetime_utc < %s "
|
||||
" ORDER BY start_datetime_utc ")
|
||||
|
||||
reporting_input[energy_category_id] = dict()
|
||||
reporting_input[energy_category_id]['timestamps'] = list()
|
||||
reporting_input[energy_category_id]['values'] = list()
|
||||
reporting_input[energy_category_id]['subtotal'] = Decimal(0.0)
|
||||
cursor_energy.execute(query, (fraction['numerator_meter_id'],
|
||||
reporting_start_datetime_utc,
|
||||
reporting_end_datetime_utc))
|
||||
rows_numerator_meter_hourly = cursor_energy.fetchall()
|
||||
|
||||
cursor_energy.execute(" SELECT start_datetime_utc, actual_value "
|
||||
" FROM tbl_combined_equipment_input_category_hourly "
|
||||
" WHERE combined_equipment_id = %s "
|
||||
" AND energy_category_id = %s "
|
||||
" AND start_datetime_utc >= %s "
|
||||
" AND start_datetime_utc < %s "
|
||||
" ORDER BY start_datetime_utc ",
|
||||
(combined_equipment['id'],
|
||||
energy_category_id,
|
||||
reporting_start_datetime_utc,
|
||||
reporting_end_datetime_utc))
|
||||
rows_combined_equipment_hourly = cursor_energy.fetchall()
|
||||
|
||||
rows_combined_equipment_periodically = \
|
||||
utilities.aggregate_hourly_data_by_period(rows_combined_equipment_hourly,
|
||||
rows_numerator_meter_periodically = \
|
||||
utilities.aggregate_hourly_data_by_period(rows_numerator_meter_hourly,
|
||||
reporting_start_datetime_utc,
|
||||
reporting_end_datetime_utc,
|
||||
period_type)
|
||||
for row_combined_equipment_periodically in rows_combined_equipment_periodically:
|
||||
current_datetime_local = row_combined_equipment_periodically[0].replace(tzinfo=timezone.utc) + \
|
||||
timedelta(minutes=timezone_offset)
|
||||
if period_type == 'hourly':
|
||||
current_datetime = current_datetime_local.strftime('%Y-%m-%dT%H:%M:%S')
|
||||
elif period_type == 'daily':
|
||||
current_datetime = current_datetime_local.strftime('%Y-%m-%d')
|
||||
elif period_type == 'monthly':
|
||||
current_datetime = current_datetime_local.strftime('%Y-%m')
|
||||
elif period_type == 'yearly':
|
||||
current_datetime = current_datetime_local.strftime('%Y')
|
||||
# query denominator meter input
|
||||
if fraction['denominator_meter_type'] == 'meter':
|
||||
query = (" SELECT start_datetime_utc, actual_value "
|
||||
" FROM tbl_meter_hourly "
|
||||
" WHERE meter_id = %s "
|
||||
" AND start_datetime_utc >= %s "
|
||||
" AND start_datetime_utc < %s "
|
||||
" ORDER BY start_datetime_utc ")
|
||||
elif fraction['denominator_meter_type'] == 'offline_meter':
|
||||
query = (" SELECT start_datetime_utc, actual_value "
|
||||
" FROM tbl_offline_meter_hourly "
|
||||
" WHERE offline_meter_id = %s "
|
||||
" AND start_datetime_utc >= %s "
|
||||
" AND start_datetime_utc < %s "
|
||||
" ORDER BY start_datetime_utc ")
|
||||
elif fraction['denominator_meter_type'] == 'virtual_meter':
|
||||
query = (" SELECT start_datetime_utc, actual_value "
|
||||
" FROM tbl_virtual_meter_hourly "
|
||||
" WHERE virtual_meter_id = %s "
|
||||
" AND start_datetime_utc >= %s "
|
||||
" AND start_datetime_utc < %s "
|
||||
" ORDER BY start_datetime_utc ")
|
||||
|
||||
actual_value = Decimal(0.0) if row_combined_equipment_periodically[1] is None \
|
||||
else row_combined_equipment_periodically[1]
|
||||
reporting_input[energy_category_id]['timestamps'].append(current_datetime)
|
||||
reporting_input[energy_category_id]['values'].append(actual_value)
|
||||
reporting_input[energy_category_id]['subtotal'] += actual_value
|
||||
cursor_energy.execute(query, (fraction['denominator_meter_id'],
|
||||
reporting_start_datetime_utc,
|
||||
reporting_end_datetime_utc))
|
||||
rows_denominator_meter_hourly = cursor_energy.fetchall()
|
||||
|
||||
################################################################################################################
|
||||
# Step 9: query reporting period energy output
|
||||
################################################################################################################
|
||||
reporting_output = dict()
|
||||
if energy_category_set_output is not None and len(energy_category_set_output) > 0:
|
||||
for energy_category_id in energy_category_set_output:
|
||||
|
||||
reporting_output[energy_category_id] = dict()
|
||||
reporting_output[energy_category_id]['timestamps'] = list()
|
||||
reporting_output[energy_category_id]['values'] = list()
|
||||
reporting_output[energy_category_id]['subtotal'] = Decimal(0.0)
|
||||
|
||||
cursor_energy.execute(" SELECT start_datetime_utc, actual_value "
|
||||
" FROM tbl_combined_equipment_output_category_hourly "
|
||||
" WHERE combined_equipment_id = %s "
|
||||
" AND energy_category_id = %s "
|
||||
" AND start_datetime_utc >= %s "
|
||||
" AND start_datetime_utc < %s "
|
||||
" ORDER BY start_datetime_utc ",
|
||||
(combined_equipment['id'],
|
||||
energy_category_id,
|
||||
reporting_start_datetime_utc,
|
||||
reporting_end_datetime_utc))
|
||||
rows_combined_equipment_hourly = cursor_energy.fetchall()
|
||||
|
||||
rows_combined_equipment_periodically = \
|
||||
utilities.aggregate_hourly_data_by_period(rows_combined_equipment_hourly,
|
||||
rows_denominator_meter_periodically = \
|
||||
utilities.aggregate_hourly_data_by_period(rows_denominator_meter_hourly,
|
||||
reporting_start_datetime_utc,
|
||||
reporting_end_datetime_utc,
|
||||
period_type)
|
||||
for row_combined_equipment_periodically in rows_combined_equipment_periodically:
|
||||
current_datetime_local = row_combined_equipment_periodically[0].replace(tzinfo=timezone.utc) + \
|
||||
|
||||
for row_numerator_meter_periodically in rows_numerator_meter_periodically:
|
||||
current_datetime_local = row_numerator_meter_periodically[0].replace(tzinfo=timezone.utc) + \
|
||||
timedelta(minutes=timezone_offset)
|
||||
if period_type == 'hourly':
|
||||
current_datetime = current_datetime_local.strftime('%Y-%m-%dT%H:%M:%S')
|
||||
|
@ -449,42 +494,53 @@ class Reporting:
|
|||
elif period_type == 'yearly':
|
||||
current_datetime = current_datetime_local.strftime('%Y')
|
||||
|
||||
actual_value = Decimal(0.0) if row_combined_equipment_periodically[1] is None \
|
||||
else row_combined_equipment_periodically[1]
|
||||
reporting_output[energy_category_id]['timestamps'].append(current_datetime)
|
||||
reporting_output[energy_category_id]['values'].append(actual_value)
|
||||
reporting_output[energy_category_id]['subtotal'] += actual_value
|
||||
actual_value = Decimal(0.0) if row_numerator_meter_periodically[1] is None \
|
||||
else row_numerator_meter_periodically[1]
|
||||
|
||||
reporting[fraction['id']]['numerator_timestamps'].append(current_datetime)
|
||||
reporting[fraction['id']]['numerator_values'].append(actual_value)
|
||||
reporting[fraction['id']]['numerator_cumulation'] += actual_value
|
||||
|
||||
for row_denominator_meter_periodically in rows_denominator_meter_periodically:
|
||||
current_datetime_local = row_denominator_meter_periodically[0].replace(tzinfo=timezone.utc) + \
|
||||
timedelta(minutes=timezone_offset)
|
||||
if period_type == 'hourly':
|
||||
current_datetime = current_datetime_local.strftime('%Y-%m-%dT%H:%M:%S')
|
||||
elif period_type == 'daily':
|
||||
current_datetime = current_datetime_local.strftime('%Y-%m-%d')
|
||||
elif period_type == 'monthly':
|
||||
current_datetime = current_datetime_local.strftime('%Y-%m')
|
||||
elif period_type == 'yearly':
|
||||
current_datetime = current_datetime_local.strftime('%Y')
|
||||
|
||||
actual_value = Decimal(0.0) if row_denominator_meter_periodically[1] is None \
|
||||
else row_denominator_meter_periodically[1]
|
||||
|
||||
reporting[fraction['id']]['denominator_timestamps'].append(current_datetime)
|
||||
reporting[fraction['id']]['denominator_values'].append(actual_value)
|
||||
reporting[fraction['id']]['denominator_cumulation'] += actual_value
|
||||
|
||||
for i in range(len(reporting[fraction['id']]['denominator_timestamps'])):
|
||||
timestamp = reporting[fraction['id']]['denominator_timestamps'][i]
|
||||
reporting[fraction['id']]['timestamps'].append(timestamp)
|
||||
value = reporting[fraction['id']]['numerator_values'][i] / \
|
||||
reporting[fraction['id']]['denominator_values'][i] \
|
||||
if reporting[fraction['id']]['denominator_values'][i] > Decimal(0.0) else Decimal(0.0)
|
||||
reporting[fraction['id']]['values'].append(value)
|
||||
|
||||
cumulation = (reporting[fraction['id']]['numerator_cumulation'] /
|
||||
reporting[fraction['id']]['denominator_cumulation']) \
|
||||
if reporting[fraction['id']]['denominator_cumulation'] > Decimal(0.0) else Decimal(0.0)
|
||||
reporting[fraction['id']]['cumulation'] = cumulation
|
||||
|
||||
################################################################################################################
|
||||
# Step 10: query tariff data
|
||||
# Step 7: query associated points data
|
||||
################################################################################################################
|
||||
parameters_data = dict()
|
||||
parameters_data['names'] = list()
|
||||
parameters_data['timestamps'] = list()
|
||||
parameters_data['values'] = list()
|
||||
if energy_category_set_input is not None and len(energy_category_set_input) > 0:
|
||||
for energy_category_id in energy_category_set_input:
|
||||
energy_category_tariff_dict = utilities.get_energy_category_tariffs(
|
||||
combined_equipment['cost_center_id'],
|
||||
energy_category_id,
|
||||
reporting_start_datetime_utc,
|
||||
reporting_end_datetime_utc)
|
||||
|
||||
tariff_timestamp_list = list()
|
||||
tariff_value_list = list()
|
||||
for k, v in energy_category_tariff_dict.items():
|
||||
# convert k from utc to local
|
||||
k = k + timedelta(minutes=timezone_offset)
|
||||
tariff_timestamp_list.append(k.isoformat()[0:19][0:19])
|
||||
tariff_value_list.append(v)
|
||||
|
||||
parameters_data['names'].append('TARIFF-' + energy_category_dict[energy_category_id]['name'])
|
||||
parameters_data['timestamps'].append(tariff_timestamp_list)
|
||||
parameters_data['values'].append(tariff_value_list)
|
||||
|
||||
################################################################################################################
|
||||
# Step 11: query associated points data
|
||||
################################################################################################################
|
||||
for point in point_list:
|
||||
point_values = []
|
||||
point_timestamps = []
|
||||
|
@ -548,7 +604,7 @@ class Reporting:
|
|||
parameters_data['values'].append(point_values)
|
||||
|
||||
################################################################################################################
|
||||
# Step 12: construct the report
|
||||
# Step 8: construct the report
|
||||
################################################################################################################
|
||||
if cursor_system:
|
||||
cursor_system.close()
|
||||
|
@ -565,119 +621,11 @@ class Reporting:
|
|||
result['combined_equipment'] = dict()
|
||||
result['combined_equipment']['name'] = combined_equipment['name']
|
||||
|
||||
result['base_period_input'] = dict()
|
||||
result['base_period_input']['names'] = list()
|
||||
result['base_period_input']['units'] = list()
|
||||
result['base_period_input']['timestamps'] = list()
|
||||
result['base_period_input']['values'] = list()
|
||||
result['base_period_input']['subtotals'] = list()
|
||||
if energy_category_set_input is not None and len(energy_category_set_input) > 0:
|
||||
for energy_category_id in energy_category_set_input:
|
||||
result['base_period_input']['names'].append(energy_category_dict[energy_category_id]['name'])
|
||||
result['base_period_input']['units'].append(energy_category_dict[energy_category_id]['unit_of_measure'])
|
||||
result['base_period_input']['timestamps'].append(base_input[energy_category_id]['timestamps'])
|
||||
result['base_period_input']['values'].append(base_input[energy_category_id]['values'])
|
||||
result['base_period_input']['subtotals'].append(base_input[energy_category_id]['subtotal'])
|
||||
|
||||
result['base_period_output'] = dict()
|
||||
result['base_period_output']['names'] = list()
|
||||
result['base_period_output']['units'] = list()
|
||||
result['base_period_output']['timestamps'] = list()
|
||||
result['base_period_output']['values'] = list()
|
||||
result['base_period_output']['subtotals'] = list()
|
||||
|
||||
if energy_category_set_output is not None and len(energy_category_set_output) > 0:
|
||||
for energy_category_id in energy_category_set_output:
|
||||
result['base_period_output']['names'].append(energy_category_dict[energy_category_id]['name'])
|
||||
result['base_period_output']['units'].append(
|
||||
energy_category_dict[energy_category_id]['unit_of_measure'])
|
||||
result['base_period_output']['timestamps'].append(base_output[energy_category_id]['timestamps'])
|
||||
result['base_period_output']['values'].append(base_output[energy_category_id]['values'])
|
||||
result['base_period_output']['subtotals'].append(base_output[energy_category_id]['subtotal'])
|
||||
|
||||
result['base_period_efficiency'] = dict()
|
||||
result['base_period_efficiency']['names'] = list()
|
||||
result['base_period_efficiency']['units'] = list()
|
||||
result['base_period_efficiency']['timestamps'] = list()
|
||||
result['base_period_efficiency']['values'] = list()
|
||||
result['base_period_efficiency']['cumulations'] = list()
|
||||
|
||||
if energy_category_set_output is not None and len(energy_category_set_output) > 0:
|
||||
for energy_category_id_output in energy_category_set_output:
|
||||
for energy_category_id_input in energy_category_set_input:
|
||||
result['base_period_efficiency']['names'].append(
|
||||
energy_category_dict[energy_category_id_output]['name'] + '/' +
|
||||
energy_category_dict[energy_category_id_input]['name'])
|
||||
result['base_period_efficiency']['units'].append(
|
||||
energy_category_dict[energy_category_id_output]['unit_of_measure'] + '/' +
|
||||
energy_category_dict[energy_category_id_input]['unit_of_measure'])
|
||||
result['base_period_efficiency']['timestamps'].append(
|
||||
base_output[energy_category_id_output]['timestamps'])
|
||||
efficiency_values = list()
|
||||
for i in range(len(base_output[energy_category_id_output]['timestamps'])):
|
||||
efficiency_values.append((base_output[energy_category_id_output]['values'][i] /
|
||||
base_input[energy_category_id_input]['values'][i])
|
||||
if base_input[energy_category_id_input]['values'][i] > Decimal(0.0)
|
||||
else None)
|
||||
result['base_period_efficiency']['values'].append(efficiency_values)
|
||||
|
||||
base_cumulation = (base_output[energy_category_id_output]['subtotal'] /
|
||||
base_input[energy_category_id_input]['subtotal']) if \
|
||||
base_input[energy_category_id_input]['subtotal'] > Decimal(0.0) else None
|
||||
result['base_period_efficiency']['cumulations'].append(base_cumulation)
|
||||
|
||||
result['reporting_period_input'] = dict()
|
||||
result['reporting_period_input']['names'] = list()
|
||||
result['reporting_period_input']['energy_category_ids'] = list()
|
||||
result['reporting_period_input']['units'] = list()
|
||||
result['reporting_period_input']['timestamps'] = list()
|
||||
result['reporting_period_input']['values'] = list()
|
||||
result['reporting_period_input']['subtotals'] = list()
|
||||
result['reporting_period_input']['increment_rates'] = list()
|
||||
|
||||
if energy_category_set_input is not None and len(energy_category_set_input) > 0:
|
||||
for energy_category_id in energy_category_set_input:
|
||||
result['reporting_period_input']['names'].append(energy_category_dict[energy_category_id]['name'])
|
||||
result['reporting_period_input']['energy_category_ids'].append(energy_category_id)
|
||||
result['reporting_period_input']['units'].append(
|
||||
energy_category_dict[energy_category_id]['unit_of_measure'])
|
||||
result['reporting_period_input']['timestamps'].append(
|
||||
reporting_input[energy_category_id]['timestamps'])
|
||||
result['reporting_period_input']['values'].append(
|
||||
reporting_input[energy_category_id]['values'])
|
||||
result['reporting_period_input']['subtotals'].append(
|
||||
reporting_input[energy_category_id]['subtotal'])
|
||||
result['reporting_period_input']['increment_rates'].append(
|
||||
(reporting_input[energy_category_id]['subtotal'] -
|
||||
base_input[energy_category_id]['subtotal']) /
|
||||
base_input[energy_category_id]['subtotal']
|
||||
if base_input[energy_category_id]['subtotal'] > 0.0 else None)
|
||||
|
||||
result['reporting_period_output'] = dict()
|
||||
result['reporting_period_output']['names'] = list()
|
||||
result['reporting_period_output']['energy_category_ids'] = list()
|
||||
result['reporting_period_output']['units'] = list()
|
||||
result['reporting_period_output']['timestamps'] = list()
|
||||
result['reporting_period_output']['values'] = list()
|
||||
result['reporting_period_output']['subtotals'] = list()
|
||||
result['reporting_period_output']['increment_rates'] = list()
|
||||
|
||||
if energy_category_set_output is not None and len(energy_category_set_output) > 0:
|
||||
for energy_category_id in energy_category_set_output:
|
||||
result['reporting_period_output']['names'].append(energy_category_dict[energy_category_id]['name'])
|
||||
result['reporting_period_output']['energy_category_ids'].append(energy_category_id)
|
||||
result['reporting_period_output']['units'].append(
|
||||
energy_category_dict[energy_category_id]['unit_of_measure'])
|
||||
result['reporting_period_output']['timestamps'].append(
|
||||
reporting_output[energy_category_id]['timestamps'])
|
||||
result['reporting_period_output']['values'].append(reporting_output[energy_category_id]['values'])
|
||||
result['reporting_period_output']['subtotals'].append(reporting_output[energy_category_id]['subtotal'])
|
||||
result['reporting_period_output']['increment_rates'].append(
|
||||
(reporting_output[energy_category_id]['subtotal'] -
|
||||
base_output[energy_category_id]['subtotal']) /
|
||||
base_output[energy_category_id]['subtotal']
|
||||
if base_output[energy_category_id]['subtotal'] > 0.0 else None)
|
||||
|
||||
result['reporting_period_efficiency'] = dict()
|
||||
result['reporting_period_efficiency']['names'] = list()
|
||||
result['reporting_period_efficiency']['units'] = list()
|
||||
|
@ -685,39 +633,19 @@ class Reporting:
|
|||
result['reporting_period_efficiency']['values'] = list()
|
||||
result['reporting_period_efficiency']['cumulations'] = list()
|
||||
result['reporting_period_efficiency']['increment_rates'] = list()
|
||||
|
||||
if energy_category_set_output is not None and len(energy_category_set_output) > 0:
|
||||
for energy_category_id_output in energy_category_set_output:
|
||||
for energy_category_id_input in energy_category_set_input:
|
||||
result['reporting_period_efficiency']['names'].append(
|
||||
energy_category_dict[energy_category_id_output]['name'] + '/' +
|
||||
energy_category_dict[energy_category_id_input]['name'])
|
||||
result['reporting_period_efficiency']['units'].append(
|
||||
energy_category_dict[energy_category_id_output]['unit_of_measure'] + '/' +
|
||||
energy_category_dict[energy_category_id_input]['unit_of_measure'])
|
||||
result['reporting_period_efficiency']['timestamps'].append(
|
||||
reporting_output[energy_category_id_output]['timestamps'])
|
||||
efficiency_values = list()
|
||||
for i in range(len(reporting_output[energy_category_id_output]['timestamps'])):
|
||||
efficiency_values.append((reporting_output[energy_category_id_output]['values'][i] /
|
||||
reporting_input[energy_category_id_input]['values'][i])
|
||||
if reporting_input[energy_category_id_input]['values'][i] >
|
||||
Decimal(0.0) else None)
|
||||
result['reporting_period_efficiency']['values'].append(efficiency_values)
|
||||
|
||||
base_cumulation = (base_output[energy_category_id_output]['subtotal'] /
|
||||
base_input[energy_category_id_input]['subtotal']) if \
|
||||
base_input[energy_category_id_input]['subtotal'] > Decimal(0.0) else None
|
||||
|
||||
reporting_cumulation = (reporting_output[energy_category_id_output]['subtotal'] /
|
||||
reporting_input[energy_category_id_input]['subtotal']) if \
|
||||
reporting_input[energy_category_id_input]['subtotal'] > Decimal(0.0) else None
|
||||
|
||||
result['reporting_period_efficiency']['cumulations'].append(reporting_cumulation)
|
||||
result['reporting_period_efficiency']['increment_rates'].append(
|
||||
((reporting_cumulation - base_cumulation) / base_cumulation if (base_cumulation > Decimal(0.0))
|
||||
else None)
|
||||
)
|
||||
if fraction_list is not None and len(fraction_list) > 0:
|
||||
for fraction in fraction_list:
|
||||
result['base_period_efficiency']['timestamps'].append(base[fraction['id']]['timestamps'])
|
||||
result['base_period_efficiency']['values'].append(base[fraction['id']]['values'])
|
||||
result['base_period_efficiency']['cumulations'].append(base[fraction['id']]['cumulation'])
|
||||
result['reporting_period_efficiency']['names'].append(reporting[fraction['id']]['name'])
|
||||
result['reporting_period_efficiency']['units'].append(reporting[fraction['id']]['unit'])
|
||||
result['reporting_period_efficiency']['timestamps'].append(reporting[fraction['id']]['timestamps'])
|
||||
result['reporting_period_efficiency']['values'].append(reporting[fraction['id']]['values'])
|
||||
result['reporting_period_efficiency']['cumulations'].append(reporting[fraction['id']]['cumulation'])
|
||||
result['reporting_period_efficiency']['increment_rates'].append(
|
||||
(reporting[fraction['id']]['cumulation'] - base[fraction['id']]['cumulation']) /
|
||||
base[fraction['id']]['cumulation'] if base[fraction['id']]['cumulation'] > Decimal(0.0) else None)
|
||||
|
||||
result['parameters'] = {
|
||||
"names": parameters_data['names'],
|
||||
|
@ -725,4 +653,11 @@ class Reporting:
|
|||
"values": parameters_data['values']
|
||||
}
|
||||
|
||||
# export result to Excel file and then encode the file to base64 string
|
||||
result['excel_bytes_base64'] = excelexporters.combinedequipmentefficiency.export(result,
|
||||
combined_equipment['name'],
|
||||
reporting_start_datetime_local,
|
||||
reporting_end_datetime_local,
|
||||
period_type)
|
||||
|
||||
resp.body = json.dumps(result)
|
||||
|
|
|
@ -148,10 +148,10 @@ class Reporting:
|
|||
if cnx_energy:
|
||||
cnx_energy.disconnect()
|
||||
|
||||
if cnx_historical:
|
||||
cnx_historical.close()
|
||||
if cursor_historical:
|
||||
cursor_historical.disconnect()
|
||||
cursor_historical.close()
|
||||
if cnx_historical:
|
||||
cnx_historical.disconnect()
|
||||
raise falcon.HTTPError(falcon.HTTP_404,
|
||||
title='API.NOT_FOUND',
|
||||
description='API.COMBINED_EQUIPMENT_NOT_FOUND')
|
||||
|
@ -205,10 +205,10 @@ class Reporting:
|
|||
if cnx_energy:
|
||||
cnx_energy.disconnect()
|
||||
|
||||
if cnx_historical:
|
||||
cnx_historical.close()
|
||||
if cursor_historical:
|
||||
cursor_historical.disconnect()
|
||||
cursor_historical.close()
|
||||
if cnx_historical:
|
||||
cnx_historical.disconnect()
|
||||
raise falcon.HTTPError(falcon.HTTP_404,
|
||||
title='API.NOT_FOUND',
|
||||
description='API.ENERGY_CATEGORY_NOT_FOUND')
|
||||
|
@ -466,6 +466,11 @@ class Reporting:
|
|||
if cnx_energy:
|
||||
cnx_energy.disconnect()
|
||||
|
||||
if cursor_historical:
|
||||
cursor_historical.close()
|
||||
if cnx_historical:
|
||||
cnx_historical.disconnect()
|
||||
|
||||
result = dict()
|
||||
|
||||
result['combined_equipment'] = dict()
|
||||
|
|
|
@ -148,10 +148,10 @@ class Reporting:
|
|||
if cnx_energy:
|
||||
cnx_energy.disconnect()
|
||||
|
||||
if cnx_historical:
|
||||
cnx_historical.close()
|
||||
if cursor_historical:
|
||||
cursor_historical.disconnect()
|
||||
cursor_historical.close()
|
||||
if cnx_historical:
|
||||
cnx_historical.disconnect()
|
||||
raise falcon.HTTPError(falcon.HTTP_404,
|
||||
title='API.NOT_FOUND',
|
||||
description='API.COMBINED_EQUIPMENT_NOT_FOUND')
|
||||
|
@ -207,10 +207,10 @@ class Reporting:
|
|||
if cnx_energy:
|
||||
cnx_energy.disconnect()
|
||||
|
||||
if cnx_historical:
|
||||
cnx_historical.close()
|
||||
if cursor_historical:
|
||||
cursor_historical.disconnect()
|
||||
cursor_historical.close()
|
||||
if cnx_historical:
|
||||
cnx_historical.disconnect()
|
||||
raise falcon.HTTPError(falcon.HTTP_404,
|
||||
title='API.NOT_FOUND',
|
||||
description='API.ENERGY_ITEM_NOT_FOUND')
|
||||
|
@ -456,6 +456,11 @@ class Reporting:
|
|||
if cnx_energy:
|
||||
cnx_energy.disconnect()
|
||||
|
||||
if cursor_historical:
|
||||
cursor_historical.close()
|
||||
if cnx_historical:
|
||||
cnx_historical.disconnect()
|
||||
|
||||
result = dict()
|
||||
|
||||
result['combined_equipment'] = dict()
|
||||
|
|
|
@ -5,6 +5,7 @@ import config
|
|||
from datetime import datetime, timedelta, timezone
|
||||
from core import utilities
|
||||
from decimal import Decimal
|
||||
import excelexporters.combinedequipmentincome
|
||||
|
||||
|
||||
class Reporting:
|
||||
|
@ -147,10 +148,10 @@ class Reporting:
|
|||
if cnx_billing:
|
||||
cnx_billing.disconnect()
|
||||
|
||||
if cnx_historical:
|
||||
cnx_historical.close()
|
||||
if cursor_historical:
|
||||
cursor_historical.disconnect()
|
||||
cursor_historical.close()
|
||||
if cnx_historical:
|
||||
cnx_historical.disconnect()
|
||||
raise falcon.HTTPError(falcon.HTTP_404,
|
||||
title='API.NOT_FOUND',
|
||||
description='API.COMBINED_EQUIPMENT_NOT_FOUND')
|
||||
|
@ -204,10 +205,10 @@ class Reporting:
|
|||
if cnx_billing:
|
||||
cnx_billing.disconnect()
|
||||
|
||||
if cnx_historical:
|
||||
cnx_historical.close()
|
||||
if cursor_historical:
|
||||
cursor_historical.disconnect()
|
||||
cursor_historical.close()
|
||||
if cnx_historical:
|
||||
cnx_historical.disconnect()
|
||||
raise falcon.HTTPError(falcon.HTTP_404,
|
||||
title='API.NOT_FOUND',
|
||||
description='API.ENERGY_CATEGORY_NOT_FOUND')
|
||||
|
@ -431,6 +432,11 @@ class Reporting:
|
|||
if cnx_billing:
|
||||
cnx_billing.disconnect()
|
||||
|
||||
if cursor_historical:
|
||||
cursor_historical.close()
|
||||
if cnx_historical:
|
||||
cnx_historical.disconnect()
|
||||
|
||||
result = dict()
|
||||
|
||||
result['combined_equipment'] = dict()
|
||||
|
@ -491,4 +497,10 @@ class Reporting:
|
|||
"values": parameters_data['values']
|
||||
}
|
||||
|
||||
# export result to Excel file and then encode the file to base64 string
|
||||
result['excel_bytes_base64'] = excelexporters.combinedequipmentincome.export(result,
|
||||
combined_equipment['name'],
|
||||
reporting_start_datetime_local,
|
||||
reporting_end_datetime_local,
|
||||
period_type)
|
||||
resp.body = json.dumps(result)
|
||||
|
|
|
@ -148,10 +148,10 @@ class Reporting:
|
|||
if cnx_energy:
|
||||
cnx_energy.disconnect()
|
||||
|
||||
if cnx_historical:
|
||||
cnx_historical.close()
|
||||
if cursor_historical:
|
||||
cursor_historical.disconnect()
|
||||
cursor_historical.close()
|
||||
if cnx_historical:
|
||||
cnx_historical.disconnect()
|
||||
raise falcon.HTTPError(falcon.HTTP_404,
|
||||
title='API.NOT_FOUND',
|
||||
description='API.COMBINED_EQUIPMENT_NOT_FOUND')
|
||||
|
@ -205,10 +205,10 @@ class Reporting:
|
|||
if cnx_energy:
|
||||
cnx_energy.disconnect()
|
||||
|
||||
if cnx_historical:
|
||||
cnx_historical.close()
|
||||
if cursor_historical:
|
||||
cursor_historical.disconnect()
|
||||
cursor_historical.close()
|
||||
if cnx_historical:
|
||||
cnx_historical.disconnect()
|
||||
raise falcon.HTTPError(falcon.HTTP_404,
|
||||
title='API.NOT_FOUND',
|
||||
description='API.ENERGY_CATEGORY_NOT_FOUND')
|
||||
|
@ -452,6 +452,11 @@ class Reporting:
|
|||
if cnx_energy:
|
||||
cnx_energy.disconnect()
|
||||
|
||||
if cursor_historical:
|
||||
cursor_historical.close()
|
||||
if cnx_historical:
|
||||
cnx_historical.disconnect()
|
||||
|
||||
result = dict()
|
||||
|
||||
result['combined_equipment'] = dict()
|
||||
|
@ -502,19 +507,22 @@ class Reporting:
|
|||
result['reporting_period']['averages'].append(reporting[energy_category_id]['average'])
|
||||
result['reporting_period']['averages_increment_rate'].append(
|
||||
(reporting[energy_category_id]['average'] - base[energy_category_id]['average']) /
|
||||
base[energy_category_id]['average'] if (base[energy_category_id]['average'] is not None and
|
||||
base[energy_category_id]['average'] if (reporting[energy_category_id]['average'] is not None and
|
||||
base[energy_category_id]['average'] is not None and
|
||||
base[energy_category_id]['average'] > Decimal(0.0))
|
||||
else None)
|
||||
result['reporting_period']['maximums'].append(reporting[energy_category_id]['maximum'])
|
||||
result['reporting_period']['maximums_increment_rate'].append(
|
||||
(reporting[energy_category_id]['maximum'] - base[energy_category_id]['maximum']) /
|
||||
base[energy_category_id]['maximum'] if (base[energy_category_id]['maximum'] is not None and
|
||||
base[energy_category_id]['maximum'] if (reporting[energy_category_id]['maximum'] is not None and
|
||||
base[energy_category_id]['maximum'] is not None and
|
||||
base[energy_category_id]['maximum'] > Decimal(0.0))
|
||||
else None)
|
||||
result['reporting_period']['factors'].append(reporting[energy_category_id]['factor'])
|
||||
result['reporting_period']['factors_increment_rate'].append(
|
||||
(reporting[energy_category_id]['factor'] - base[energy_category_id]['factor']) /
|
||||
base[energy_category_id]['factor'] if (base[energy_category_id]['factor'] is not None and
|
||||
base[energy_category_id]['factor'] if (reporting[energy_category_id]['factor'] is not None and
|
||||
base[energy_category_id]['factor'] is not None and
|
||||
base[energy_category_id]['factor'] > Decimal(0.0))
|
||||
else None)
|
||||
|
||||
|
|
|
@ -148,10 +148,10 @@ class Reporting:
|
|||
if cnx_energy:
|
||||
cnx_energy.disconnect()
|
||||
|
||||
if cnx_historical:
|
||||
cnx_historical.close()
|
||||
if cursor_historical:
|
||||
cursor_historical.disconnect()
|
||||
cursor_historical.close()
|
||||
if cnx_historical:
|
||||
cnx_historical.disconnect()
|
||||
raise falcon.HTTPError(falcon.HTTP_404,
|
||||
title='API.NOT_FOUND',
|
||||
description='API.COMBINED_EQUIPMENT_NOT_FOUND')
|
||||
|
@ -205,10 +205,10 @@ class Reporting:
|
|||
if cnx_energy:
|
||||
cnx_energy.disconnect()
|
||||
|
||||
if cnx_historical:
|
||||
cnx_historical.close()
|
||||
if cursor_historical:
|
||||
cursor_historical.disconnect()
|
||||
cursor_historical.close()
|
||||
if cnx_historical:
|
||||
cnx_historical.disconnect()
|
||||
raise falcon.HTTPError(falcon.HTTP_404,
|
||||
title='API.NOT_FOUND',
|
||||
description='API.ENERGY_CATEGORY_NOT_FOUND')
|
||||
|
@ -432,6 +432,11 @@ class Reporting:
|
|||
if cnx_energy:
|
||||
cnx_energy.disconnect()
|
||||
|
||||
if cursor_historical:
|
||||
cursor_historical.close()
|
||||
if cnx_historical:
|
||||
cnx_historical.disconnect()
|
||||
|
||||
result = dict()
|
||||
|
||||
result['combined_equipment'] = dict()
|
||||
|
|
|
@ -156,10 +156,10 @@ class Reporting:
|
|||
if cnx_energy_baseline:
|
||||
cnx_energy_baseline.disconnect()
|
||||
|
||||
if cnx_historical:
|
||||
cnx_historical.close()
|
||||
if cursor_historical:
|
||||
cursor_historical.disconnect()
|
||||
cursor_historical.close()
|
||||
if cnx_historical:
|
||||
cnx_historical.disconnect()
|
||||
raise falcon.HTTPError(falcon.HTTP_404,
|
||||
title='API.NOT_FOUND',
|
||||
description='API.COMBINED_EQUIPMENT_NOT_FOUND')
|
||||
|
@ -218,10 +218,10 @@ class Reporting:
|
|||
if cnx_energy_baseline:
|
||||
cnx_energy_baseline.disconnect()
|
||||
|
||||
if cnx_historical:
|
||||
cnx_historical.close()
|
||||
if cursor_historical:
|
||||
cursor_historical.disconnect()
|
||||
cursor_historical.close()
|
||||
if cnx_historical:
|
||||
cnx_historical.disconnect()
|
||||
raise falcon.HTTPError(falcon.HTTP_404,
|
||||
title='API.NOT_FOUND',
|
||||
description='API.ENERGY_CATEGORY_NOT_FOUND')
|
||||
|
@ -586,6 +586,11 @@ class Reporting:
|
|||
if cnx_energy_baseline:
|
||||
cnx_energy_baseline.disconnect()
|
||||
|
||||
if cursor_historical:
|
||||
cursor_historical.close()
|
||||
if cnx_historical:
|
||||
cnx_historical.disconnect()
|
||||
|
||||
result = dict()
|
||||
|
||||
result['combined_equipment'] = dict()
|
||||
|
|
|
@ -5,6 +5,7 @@ import config
|
|||
from datetime import datetime, timedelta, timezone
|
||||
from core import utilities
|
||||
from decimal import Decimal
|
||||
import excelexporters.combinedequipmentstatistics
|
||||
|
||||
|
||||
class Reporting:
|
||||
|
@ -147,10 +148,10 @@ class Reporting:
|
|||
if cnx_energy:
|
||||
cnx_energy.disconnect()
|
||||
|
||||
if cnx_historical:
|
||||
cnx_historical.close()
|
||||
if cursor_historical:
|
||||
cursor_historical.disconnect()
|
||||
cursor_historical.close()
|
||||
if cnx_historical:
|
||||
cnx_historical.disconnect()
|
||||
raise falcon.HTTPError(falcon.HTTP_404,
|
||||
title='API.NOT_FOUND',
|
||||
description='API.COMBINED_EQUIPMENT_NOT_FOUND')
|
||||
|
@ -204,10 +205,10 @@ class Reporting:
|
|||
if cnx_energy:
|
||||
cnx_energy.disconnect()
|
||||
|
||||
if cnx_historical:
|
||||
cnx_historical.close()
|
||||
if cursor_historical:
|
||||
cursor_historical.disconnect()
|
||||
cursor_historical.close()
|
||||
if cnx_historical:
|
||||
cnx_historical.disconnect()
|
||||
raise falcon.HTTPError(falcon.HTTP_404,
|
||||
title='API.NOT_FOUND',
|
||||
description='API.ENERGY_CATEGORY_NOT_FOUND')
|
||||
|
@ -457,6 +458,11 @@ class Reporting:
|
|||
if cnx_energy:
|
||||
cnx_energy.disconnect()
|
||||
|
||||
if cursor_historical:
|
||||
cursor_historical.close()
|
||||
if cnx_historical:
|
||||
cnx_historical.disconnect()
|
||||
|
||||
result = dict()
|
||||
|
||||
result['combined_equipment'] = dict()
|
||||
|
@ -560,4 +566,11 @@ class Reporting:
|
|||
"values": parameters_data['values']
|
||||
}
|
||||
|
||||
# export result to Excel file and then encode the file to base64 string
|
||||
result['excel_bytes_base64'] = excelexporters.combinedequipmentstatistics.export(result,
|
||||
combined_equipment['name'],
|
||||
reporting_start_datetime_local,
|
||||
reporting_end_datetime_local,
|
||||
period_type)
|
||||
|
||||
resp.body = json.dumps(result)
|
||||
|
|
|
@ -143,10 +143,10 @@ class Reporting:
|
|||
if cnx_billing:
|
||||
cnx_billing.disconnect()
|
||||
|
||||
if cnx_historical:
|
||||
cnx_historical.close()
|
||||
if cursor_historical:
|
||||
cursor_historical.disconnect()
|
||||
cursor_historical.close()
|
||||
if cnx_historical:
|
||||
cnx_historical.disconnect()
|
||||
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.EQUIPMENT_NOT_FOUND')
|
||||
|
||||
equipment = dict()
|
||||
|
@ -198,10 +198,10 @@ class Reporting:
|
|||
if cnx_billing:
|
||||
cnx_billing.disconnect()
|
||||
|
||||
if cnx_historical:
|
||||
cnx_historical.close()
|
||||
if cursor_historical:
|
||||
cursor_historical.disconnect()
|
||||
cursor_historical.close()
|
||||
if cnx_historical:
|
||||
cnx_historical.disconnect()
|
||||
raise falcon.HTTPError(falcon.HTTP_404,
|
||||
title='API.NOT_FOUND',
|
||||
description='API.ENERGY_CATEGORY_NOT_FOUND')
|
||||
|
@ -441,6 +441,11 @@ class Reporting:
|
|||
if cnx_billing:
|
||||
cnx_billing.disconnect()
|
||||
|
||||
if cursor_historical:
|
||||
cursor_historical.close()
|
||||
if cnx_historical:
|
||||
cnx_historical.disconnect()
|
||||
|
||||
result = dict()
|
||||
|
||||
result['equipment'] = dict()
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue