主要功能為綠能交易平台的 API,詳細資訊:API Document
- python 3.6.8
- docker 19.03.5
Installing Packages & Running
pipenv install
pipenv run python pt/app.py
- update the .env file
- run docker
docker build -t et_platform . --no-cache
docker-compose up -d
Database using UTC timezone to store timestamps.
Through the setting at base_models, ORM will convert UTC time to local time when reading and searching data, and also convert local time to UTC time when saving data.
Some tables like AMI
and History
are saving and using in UTC timezone, because their timestamp data type is Date
.
Most query can just use local time, we have known that few query way need to change to UTC time by your self, like extract
.
-
Running database at background
docker-compose up -d
This project is already migration initialized. No need for flask db init
.
To make migration change:
python pt/manage.py db migrate
To apply migration changes to database:
python pt/manage.py db upgrade
To stamp existing database to certain revision version
python pt/manage.py db stamp {revision ID / head}
command reference: flask-migrate
Some scripts need to be triggered based on time. We use crontab to run the script inside container and log in to docker log.
*Crontab doesn't know PATH at runtime, use full path or set PATH in crontab.
- Get Datas from IOTA and decrypt, based on address from database and tags from configs.
- Run IOTA Tracker every 5 minutes and save logs
-
提供 AMI Data Uploader 詢問上傳的 IOTA Address
-
Authorization: Bearer Token
-
Address 規則:
- 每個上傳 AMI 對應到一個 Address
- 每天更新一次 Address
- 模擬資料傳送至平台
- 模擬 BEMS 的 用電資料傳送至平台
sh /energy-trading-platform-simulate/pt/simulate/trigger/data.sh <bems_name> <simulate_data_path>
Name | Description |
---|---|
bems_name | BEMS account name |
simulate_data_path | .csv file path. The .csv file must in specific format |
*/15 * * * * sh $HOME/energy-trading-platform/pt/simulate/trigger/data.sh ABC_BEMS $HOME/ABC_BEMS.csv
ABRI_BEMS
AMI_1,AMI_2,AMI_3,total_load(kW),PV_generate(kW),net_load(kW),TIME
8,12.16,1.8,21.96,0,21.96,2020/5/2 00:00
8.5,10.88,2.2,21.58,0,21.58,2020/5/2 00:15
8.5,11.52,1.6,21.62,0,21.62,2020/5/2 00:30
Carlab_BEMS
id,field,grid_power,inserted_at
4451,carlab,12.228,2020/4/25 00:00
4452,carlab,11.817,2020/4/25 00:15
4453,carlab,12.13,2020/4/25 00:30
4454,carlab,12.264,2020/4/25 00:45
4455,carlab,12.069,2020/4/25 01:00
NCKU_BEMS
id,field,grid_power,inserted_at
33147,NCKU,1.075,2020/3/14 00:00
33148,NCKU,1.087,2020/3/14 00:15
33149,NCKU,1.072,2020/3/14 00:30
33150,NCKU,1.067,2020/3/14 00:45
33151,NCKU,1.073,2020/3/14 01:00
- 模擬 BEMS 的投標資料(買 or 賣)傳送至平台
sh /energy-trading-platform-simulate/pt/simulate/trigger/bidsubmit.sh <bems_account> <password> <bid_amount> <bid_value> <bid_type>
10 16 * * * sh $HOME/energy-trading-platform/pt/simulate/trigger/bidsubmit.sh ABC_BEMS password 10 20 buy
-
set Time Zone at
.env
file -
.travis.yml
中的secure
key 已經過加密 -
config/config
中的API_URI
未來會用於完善 IOTA Tracker,提供動態選擇 URI 的清單。 -
config/__init__.py
中的app
參數是用於 IOTA Tracker 直接寫入資料庫用,和主程式的app
無關。