An application in which multiple Meters generates power values in Watts and sends it to a single simulated PV cell (photovoltaic) which also generates power values in Watts and finally stores the power value generated from the Meters and self to a CSV file. The Meters publishes the power values to a Broker queue after every time interval and the PV simulator subscribes to this Broker queue and receives the power value for further processing.
┌──────────────────────────────┐
│ │
│ │
│ ┌─────────────┐ │ publish
│ │ Meter ├────────┼───────────┐
│ │ HOUSE A │ │ │
│ └─────────────┘ │ ▼
│ │ ┌──────────────┐ ┌──────────────┐
│ ┌─────────────┐ │ │ │ subscribe │ │
│ │ Meter │ publish │ BROKER │◄─────────────┤ PV SIMULATOR│
│ │ HOUSE B ├────────┬─────►│ (RABBITMQ) │ │ │
│ └─────────────┘ │ │ │ └──────┬───────┘
│ │ └──────────────┘ │
│ ┌─────────────┐ │ ▲ ▼
│ │ Meter ├────────┼───────────┘ ┌─────────────┐
│ │ HOUSE C │ │ │ │
│ └─────────────┘ │ publish │ CSV FILE │
│ │ │ STORAGE │
│ Neighbourhood │ └─────────────┘
└──────────────────────────────┘
Meter produces power in Watts (W) from 0 to 9000W. This mocks a regular home power consumption.
More than one house can send its meter power value if they are in a neighbourhood and hence i have used 3 houses ie HOUSE A, HOUSE B and HOUSE C which sends power values from its meter at the interval of 10 seconds to the Broker.
PV simulator generates power in Watts (W) over a period of time. The result to be saved in a file with at least a timestamp, meter power value, PV power value and the sum of the powers (meter + PV).
- PV simulator assumes to generate a power value between 0 to 4000W which is considered an avarage for a given solar panel. PV simulator is assumed to be located in a different location wrt Meter and hence will be receiving power values from multiple meters via broker and saves these values in a CSV file.
- For each Meter(house) a separate CSV file will be generated per day and the file will be rolled depending on the date for that Meter. This approach is used for the sake of documenting and analysing the power values generated by each Meter and thus can be retrieved based on the date. This approach can support more number of Meters/houses.
Broker used here is RabbitMQ
docker run -d --name some-rabbit -p 4369:4369 -p 5671:5671 -p 5672:5672 -p 15672:15672 rabbitmq:3-alpine
docker container exec -it some-rabbit rabbitmq-plugins enable rabbitmq_management
pip install aio-pika
BROKER_ADDRESS = "amqp://guest:guest@127.0.0.1/"
EXCHANGE_NAME = "pv_simulator_exchange"
QUEUE_NAME = "pv_simulator_queue"
PV_MIN = 0
PV_MAX = 9000(Meter) and 4000(PV Simulator)
PRODUCER_TIME_INTERVAL = 10
CONSUMER_TIME_INTERVAL = 10
python pypvsimulator/meter/__main__.py
python pypvsimulator/pvsimulator/__main__.py
The output can be viewed in the CSV file generated in csv_storage/ directory. The sample CSV file name will be HOUSE_A_20210527.csv and the content will look like below. Fields meter_power_value, PV_power_value and sum_of_powers are all in Watts.
timestamp,meter_power_value,PV_power_value,sum_of_powers
1622119421.561638,3434,2396,5830
1622123496.272077,3966,2820,6786
1622123770.39747,2349,91,2440
1622124063.509059,7595,606,8201
1622124126.941191,7488,905,8393
http://localhost:15672/ or http://127.0.0.1:15672/
username: guest
password: guest
The logs are saved in the log/ directory. A rotate file handler log is used for both Meter and PV Simulator. Meter logs are named meter.log and PV Simulator logs are pv_simulator.log and this is due to the fact that Meter and PV simulator will be deployed at different location. Both Meter and PV Simulator module can create log/ directory automatically. The default log level is INFO.
Both Meter and PV Simulator module has a Dockerfile and requirements file. A docker compose file can be created for Meter, PV simulator and RabbitMQ for the purpose of QA and Prod parallel performance testing.
cd pypvsimulator/meter/
docker build -t meter:v1.0 .
docker run meter:v1.0
cd pypvsimulator/pvsimulator/
docker build -t pvsimulator:v1.0 .
docker run pvsimulator:v1.0
cd pypvsimulator/meter/
python -m unittest discover test
cd pypvsimulator/pvsimulator/
python -m unittest discover test