updated postman collection and README of myems-api

pull/82/MERGE
13621160019@163.com 2021-11-26 19:17:09 +08:00
parent 013ee28003
commit 27f9bb8629
2 changed files with 227 additions and 118 deletions

View File

@ -1,6 +1,6 @@
{ {
"info": { "info": {
"_postman_id": "188bbc28-1018-45ae-bdc8-c0b465102f5f", "_postman_id": "edda43bf-7618-4cef-a9dc-b5eb90fde85a",
"name": "MyEMS", "name": "MyEMS",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
}, },
@ -1844,7 +1844,20 @@
"name": "POST Create an Energy Category", "name": "POST Create an Energy Category",
"request": { "request": {
"method": "POST", "method": "POST",
"header": [], "header": [
{
"key": "User-UUID",
"value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4 ",
"type": "text",
"description": "Any admin users' UUID"
},
{
"key": "Token",
"value": "073b43c05dadd89b833c0595b81c49cb9c1a54ca52b024b301a001720e52c5bf3b95951d5c54766de1028d20301cbd2bb6ec3fb62f9e14d9658cbf3811fe6c93",
"type": "text",
"description": "Login to get a valid token"
}
],
"body": { "body": {
"mode": "raw", "mode": "raw",
"raw": "{\"data\":{\"name\":\"柴油\",\"unit_of_measure\":\"L\", \"kgce\":0.1229 , \"kgco2e\":0.8825}}" "raw": "{\"data\":{\"name\":\"柴油\",\"unit_of_measure\":\"L\", \"kgce\":0.1229 , \"kgco2e\":0.8825}}"
@ -1865,19 +1878,32 @@
"name": "PUT Update an Energy Category", "name": "PUT Update an Energy Category",
"request": { "request": {
"method": "PUT", "method": "PUT",
"header": [], "header": [
{
"key": "User-UUID",
"value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4 ",
"type": "text",
"description": "Any admin users' UUID"
},
{
"key": "Token",
"value": "073b43c05dadd89b833c0595b81c49cb9c1a54ca52b024b301a001720e52c5bf3b95951d5c54766de1028d20301cbd2bb6ec3fb62f9e14d9658cbf3811fe6c93",
"type": "text",
"description": "Login to get a valid token"
}
],
"body": { "body": {
"mode": "raw", "mode": "raw",
"raw": "{\"data\":{\"name\":\"汽油\",\"unit_of_measure\":\"L\", \"kgce\":0.1229 , \"kgco2e\":0.8825}}" "raw": "{\"data\":{\"name\":\"汽油\",\"unit_of_measure\":\"L\", \"kgce\":0.1229 , \"kgco2e\":0.8825}}"
}, },
"url": { "url": {
"raw": "{{base_url}}/energycategories/9", "raw": "{{base_url}}/energycategories/12",
"host": [ "host": [
"{{base_url}}" "{{base_url}}"
], ],
"path": [ "path": [
"energycategories", "energycategories",
"9" "12"
] ]
} }
}, },
@ -1887,15 +1913,28 @@
"name": "DELETE an Energy Category", "name": "DELETE an Energy Category",
"request": { "request": {
"method": "DELETE", "method": "DELETE",
"header": [], "header": [
{
"key": "User-UUID",
"value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4 ",
"type": "text",
"description": "Any admin users' UUID"
},
{
"key": "Token",
"value": "073b43c05dadd89b833c0595b81c49cb9c1a54ca52b024b301a001720e52c5bf3b95951d5c54766de1028d20301cbd2bb6ec3fb62f9e14d9658cbf3811fe6c93",
"type": "text",
"description": "Login to get a valid token"
}
],
"url": { "url": {
"raw": "{{base_url}}/energycategories/9", "raw": "{{base_url}}/energycategories/12",
"host": [ "host": [
"{{base_url}}" "{{base_url}}"
], ],
"path": [ "path": [
"energycategories", "energycategories",
"9" "12"
] ]
} }
}, },
@ -3274,7 +3313,20 @@
"name": "POST Create New Meter", "name": "POST Create New Meter",
"request": { "request": {
"method": "POST", "method": "POST",
"header": [], "header": [
{
"key": "User-UUID",
"value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4 ",
"type": "text",
"description": "Any admin users' UUID"
},
{
"key": "Token",
"value": "073b43c05dadd89b833c0595b81c49cb9c1a54ca52b024b301a001720e52c5bf3b95951d5c54766de1028d20301cbd2bb6ec3fb62f9e14d9658cbf3811fe6c93",
"type": "text",
"description": "Login to get a valid token"
}
],
"body": { "body": {
"mode": "raw", "mode": "raw",
"raw": "{\"data\":{\"name\":\"PM20\", \"energy_category_id\":1, \"hourly_low_limit\":0.000, \"hourly_high_limit\":999.99, \"is_counted\":true, \"cost_center_id\":1, \"energy_item_id\":1, \"master_meter_id\":1, \"description\":\"空调用电\"}}" "raw": "{\"data\":{\"name\":\"PM20\", \"energy_category_id\":1, \"hourly_low_limit\":0.000, \"hourly_high_limit\":999.99, \"is_counted\":true, \"cost_center_id\":1, \"energy_item_id\":1, \"master_meter_id\":1, \"description\":\"空调用电\"}}"
@ -3295,19 +3347,32 @@
"name": "PUT Update a Meter", "name": "PUT Update a Meter",
"request": { "request": {
"method": "PUT", "method": "PUT",
"header": [], "header": [
{
"key": "User-UUID",
"value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4 ",
"type": "text",
"description": "Any admin users' UUID"
},
{
"key": "Token",
"value": "073b43c05dadd89b833c0595b81c49cb9c1a54ca52b024b301a001720e52c5bf3b95951d5c54766de1028d20301cbd2bb6ec3fb62f9e14d9658cbf3811fe6c93",
"type": "text",
"description": "Login to get a valid token"
}
],
"body": { "body": {
"mode": "raw", "mode": "raw",
"raw": "{\"data\":{\"name\":\"PM201\", \"energy_category_id\":1, \"hourly_low_limit\":0.000, \"hourly_high_limit\":999.99, \"is_counted\":true, \"cost_center_id\":1, \"energy_item_id\":1, \"master_meter_id\":7, \"description\":\"空调用电\"}}" "raw": "{\"data\":{\"name\":\"PM201\", \"energy_category_id\":1, \"hourly_low_limit\":0.000, \"hourly_high_limit\":999.99, \"is_counted\":true, \"cost_center_id\":1, \"energy_item_id\":1, \"master_meter_id\":1, \"description\":\"空调用电\"}}"
}, },
"url": { "url": {
"raw": "{{base_url}}/meters/28", "raw": "{{base_url}}/meters/4",
"host": [ "host": [
"{{base_url}}" "{{base_url}}"
], ],
"path": [ "path": [
"meters", "meters",
"28" "4"
] ]
} }
}, },
@ -3317,15 +3382,28 @@
"name": "DELETE Meter by ID", "name": "DELETE Meter by ID",
"request": { "request": {
"method": "DELETE", "method": "DELETE",
"header": [], "header": [
{
"key": "User-UUID",
"value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4 ",
"type": "text",
"description": "Any admin users' UUID"
},
{
"key": "Token",
"value": "073b43c05dadd89b833c0595b81c49cb9c1a54ca52b024b301a001720e52c5bf3b95951d5c54766de1028d20301cbd2bb6ec3fb62f9e14d9658cbf3811fe6c93",
"type": "text",
"description": "Login to get a valid token"
}
],
"url": { "url": {
"raw": "{{base_url}}/meters/2", "raw": "{{base_url}}/meters/4",
"host": [ "host": [
"{{base_url}}" "{{base_url}}"
], ],
"path": [ "path": [
"meters", "meters",
"2" "4"
] ]
} }
}, },
@ -3357,7 +3435,7 @@
"header": [], "header": [],
"body": { "body": {
"mode": "raw", "mode": "raw",
"raw": "{\"data\":{\"point_id\":\"1\"}}" "raw": "{\"data\":{\"point_id\":\"3\"}}"
}, },
"url": { "url": {
"raw": "{{base_url}}/meters/1/points", "raw": "{{base_url}}/meters/1/points",

View File

@ -33,7 +33,7 @@ python-decouple
```bash ```bash
cd myems/myems-api cd myems/myems-api
pip install -r requirements.txt pip install -r requirements.txt -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
cp example.env .env cp example.env .env
chmod +x run.sh chmod +x run.sh
./run.sh ./run.sh
@ -41,7 +41,7 @@ chmod +x run.sh
## Installation ## Installation
### Option 1: Install myems-api on Docker ### Installation Option 1: Install myems-api on Docker
In this section, you will install myems-api on Docker. In this section, you will install myems-api on Docker.
@ -69,107 +69,18 @@ docker run -d -p 8000:8000 --restart always --name myems-api myems/myems-api
--name Assign a name to the container --name Assign a name to the container
### Option 2: Install myems-api on Ubuntu Server (bare-metal or virtual machine) ### Option 2: Online install myems-api on Ubuntu Server with internet access
In this section, you will install myems-api on Ubuntu Server. In this section, you will online install myems-api on Ubuntu Server with internet access.
* Copy source code to a production Ubuntu Server and then install tools
* Install anytree
```bash ```bash
cd ~/tools cd ~/myems/myems-api
git clone https://github.com/c0fec0de/anytree.git pip install -r requirements.txt -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
cd anytree
python3 setup.py install
``` ```
* Install simplejson * Install myems-api service:
```bash ```bash
cd ~/tools cp -r ~/myems/myems-api /myems-api
git clone https://github.com/simplejson/simplejson.git
cd simplejson
python3 setup.py install
```
* Install MySQL Connector
```bash
cd ~/tools
wget https://cdn.mysql.com/archives/mysql-connector-python-8.0/mysql-connector-python-8.0.23.tar.gz
tar xzf mysql-connector-python-8.0.23.tar.gz
cd ~/tools/mysql-connector-python-8.0.23
python3 setup.py install
```
* Install Falcon,
if you are behind proxy, use --proxy parameter
Refer to
https://falconframework.org/
https://github.com/lwcolton/falcon-cors
https://github.com/yohanboniface/falcon-multipart
```bash
mkdir ~/tools/falcon && cd ~/tools/falcon
pip3 download cython falcon falcon-cors falcon-multipart
export LC_ALL="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
dpkg-reconfigure locales
pip3 install --upgrade --no-index --find-links ~/tools/falcon cython falcon falcon-cors falcon-multipart
```
* Install gunicorn, refer to http://gunicorn.org
```bash
mkdir ~/tools/gunicorn && cd ~/tools/gunicorn
pip3 download gunicorn
pip3 install --no-index --find-links ~/tools/gunicorn gunicorn
```
* Install openpyxl, refer to https://foss.heptapod.net/openpyxl/openpyxl
Get the latest version of et_xmlfile from https://foss.heptapod.net/openpyxl/et_xmlfile/
```bash
cd ~/tools
wget https://foss.heptapod.net/openpyxl/et_xmlfile/-/archive/1.1/et_xmlfile-1.1.tar.gz
tar xzf et_xmlfile-1.1.tar.gz
```
Get jdcal
```bash
cd ~/tools
git clone https://github.com/phn/jdcal.git
```
Get Pillow
```
mkdir ~/tools/pillow && cd ~/tools/pillow
pip3 download Pillow
```
Get the latest version of openpyxl from https://foss.heptapod.net/openpyxl/openpyxl
```bash
cd ~/tools
wget https://foss.heptapod.net/openpyxl/openpyxl/-/archive/3.0.7/openpyxl-3.0.7.tar.gz
tar xzf openpyxl-3.0.7.tar.gz
```
```bash
cd ~/tools/et_xmlfile-1.1
python3 setup.py install
cd ~/tools/jdcal
python3 setup.py install
pip3 install --no-index --find-links ~/tools/pillow Pillow
cd ~/tools/openpyxl-3.0.7
python3 setup.py install
```
Download and install Python Decouple
```bash
cd ~/tools
git clone https://github.com/henriquebastos/python-decouple.git
cd ~/tools/python-decouple
python3 setup.py install
```
* Install gunicorn service for myems-api:
```bash
cp -R myems/myems-api /myems-api
``` ```
Create .env file based on example.env and edit the .env file if needed: Create .env file based on example.env and edit the .env file if needed:
```bash ```bash
@ -180,7 +91,7 @@ Check or change the listening port (default is 8000) in myems-api.service and my
```bash ```bash
nano /myems-api/myems-api.service nano /myems-api/myems-api.service
``` ```
``` ```bash
ExecStart=/usr/local/bin/gunicorn -b 0.0.0.0:8000 --pid /run/myems-api/pid --timeout 600 --workers=4 app:api ExecStart=/usr/local/bin/gunicorn -b 0.0.0.0:8000 --pid /run/myems-api/pid --timeout 600 --workers=4 app:api
``` ```
```bash ```bash
@ -210,7 +121,105 @@ systemctl start myems-api.socket
systemctl start myems-api.service systemctl start myems-api.service
``` ```
### Option 3: Install myems-api on macOS ### Option 3: Offline install myems-api on Ubuntu Server without internet access
In this section, you will offline install myems-api on Ubuntu Server without internet access.
* Download tools
```bash
mkdir ~tools && cd ~/tools
git clone https://github.com/c0fec0de/anytree.git
git clone https://github.com/simplejson/simplejson.git
wget https://cdn.mysql.com/archives/mysql-connector-python-8.0/mysql-connector-python-8.0.23.tar.gz
mkdir ~/tools/falcon && cd ~/tools/falcon
pip download cython falcon falcon-cors falcon-multipart
cd ~/tools
mkdir ~/tools/gunicorn && cd ~/tools/gunicorn
pip download gunicorn
cd ~/tools
wget https://foss.heptapod.net/openpyxl/et_xmlfile/-/archive/1.1/et_xmlfile-1.1.tar.gz
cd ~/tools
git clone https://github.com/phn/jdcal.git
mkdir ~/tools/pillow && cd ~/tools/pillow
pip download Pillow
cd ~/tools
wget https://foss.heptapod.net/openpyxl/openpyxl/-/archive/3.0.7/openpyxl-3.0.7.tar.gz
cd ~/tools
git clone https://github.com/henriquebastos/python-decouple.git
```
* Copy source code and tools to the production Ubuntu Server and then run:
```bash
cd ~/tools/anytree
python setup.py install
cd ~/tools/simplejson
python setup.py install
cd ~/tools
tar xzf mysql-connector-python-8.0.23.tar.gz
cd ~/tools/mysql-connector-python-8.0.23
python setup.py install
export LC_ALL="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
dpkg-reconfigure locales
pip install --upgrade --no-index --find-links ~/tools/falcon cython falcon falcon-cors falcon-multipart
pip install --no-index --find-links ~/tools/gunicorn gunicorn
cd ~/tools
tar xzf et_xmlfile-1.1.tar.gz
cd ~/tools/et_xmlfile-1.1
python setup.py install
cd ~/tools/jdcal
python setup.py install
cd ~/tools
pip install --no-index --find-links ~/tools/pillow Pillow
tar xzf openpyxl-3.0.7.tar.gz
cd ~/tools/openpyxl-3.0.7
python setup.py install
cd ~/tools/python-decouple
python setup.py install
```
* Install myems-api service:
```bash
cp -r ~/myems/myems-api /myems-api
```
Create .env file based on example.env and edit the .env file if needed:
```bash
cp /myems-api/example.env /myems-api/.env
nano /myems-api/.env
```
Check or change the listening port (default is 8000) in myems-api.service and myems-api.socket:
```bash
nano /myems-api/myems-api.service
```
```bash
ExecStart=/usr/local/bin/gunicorn -b 0.0.0.0:8000 --pid /run/myems-api/pid --timeout 600 --workers=4 app:api
```
```bash
nano /myems-api/myems-api.socket
```
```bash
ListenStream=0.0.0.0:8000
```
Add port to firewall:
```bash
ufw allow 8000
```
Setup systemd configure files:
```bash
cp /myems-api/myems-api.service /lib/systemd/system/
cp /myems-api/myems-api.socket /lib/systemd/system/
cp /myems-api/myems-api.conf /usr/lib/tmpfiles.d/
```
Next enable the services so that they autostart at boot:
```bash
systemctl enable myems-api.socket
systemctl enable myems-api.service
```
Start the services :
```bash
systemctl start myems-api.socket
systemctl start myems-api.service
```
### Installation Option 4: Install myems-api on macOS
Please refer to [Installation on macOS (Chinese)](./installation_macos_zh.md) Please refer to [Installation on macOS (Chinese)](./installation_macos_zh.md)
@ -219,7 +228,6 @@ Please refer to [Installation on macOS (Chinese)](./installation_macos_zh.md)
View in Postman: import the file MyEMS.postman_collection.json with Postman View in Postman: import the file MyEMS.postman_collection.json with Postman
[Energy Category](#Energy-Category) | [Energy Item](#Energy-Item) [Energy Category](#Energy-Category) | [Energy Item](#Energy-Item)
[Data Source](#Data-Source) | [Point](#Point) [Data Source](#Data-Source) | [Point](#Point)
@ -2390,3 +2398,26 @@ curl -i -X GET {{base_url}}/reports/virtualmeterenergy?virtualmeterid=1&periodty
```bash ```bash
curl -i -X GET {{base_url}}/reports/virtualmetercost?virtualmeterid=1&periodtype=daily&baseperiodstartdatetime=2020-08-01T00:00:00&baseperiodenddatetime=2020-09-01T00:00:00&reportingperiodstartdatetime=2020-09-01T00:00:00&reportingperiodenddatetime=2020-10-01T00:00:00 curl -i -X GET {{base_url}}/reports/virtualmetercost?virtualmeterid=1&periodtype=daily&baseperiodstartdatetime=2020-08-01T00:00:00&baseperiodenddatetime=2020-09-01T00:00:00&reportingperiodstartdatetime=2020-09-01T00:00:00&reportingperiodenddatetime=2020-10-01T00:00:00
``` ```
## References
[1]. http://myems.io
[2]. https://falconframework.org/
[3]. https://github.com/lwcolton/falcon-cors
[4]. https://github.com/yohanboniface/falcon-multipart
[5]. http://gunicorn.org
[6]. https://github.com/henriquebastos/python-decouple/
[7]. https://foss.heptapod.net/openpyxl/openpyxl
[8]. https://foss.heptapod.net/openpyxl/et_xmlfile/