This module helps to connect to our data warehouse
Project description
This project helps to connect to our data warehouse.
Requirements
- Python
3.8.x
or later.
Quick start
Synchronize tags
Synchronize tags from PI server to Data warehouse on period [01/01/2022 05:00:00 - 31/01/2022 05:00:00]
can be easily achieved by the code below:
from datetime import datetime
from edv_dwh_connector.pg_dwh import PgDwh
from edv_dwh_connector.pi_web_api_client import PiWebAPIClient
from edv_dwh_connector.pi.rest.rest_sync_pi_tags import RestSyncPITags
from edv_dwh_connector.utils.periods import DayIntervals
from edv_dwh_connector.pi.sync_pi_data import SyncPIDataRestToDwh
from edv_dwh_connector.pi.db.pg_pi_tag import PgPITags
# We should firstly declare the Data warehouse pool connection.
dwh = PgDwh.from_connection(
name="dwh_db_name", host="dwh_server_name_or_ip",
user="dwh_user", password="dwh_password", port=5432
)
# Next, we should declare the PI server REST API client.
client = PiWebAPIClient(
base_url="base/url/of/pi/server", username="admin_user",
password="admin_password", session_timeout=2.5
)
# Finally, we can synchronize tags measures.
# The code below will automatically synchronize tags (create new tags),
# split period provided into day intervals and synchronize PI measures
# on these intervals.
SyncPIDataRestToDwh(
tags=RestSyncPITags(
server_id="F1DSmN2338899MpX8PREOtdbEZ56sypOOOKRZLVNSVi1QSS1ISTGt", # Fake server ID
client=client,
codes=['AI162003_SCLD', 'AI162007_SCLD', 'AI162014_SCLD'],
target=PgPITags(dwh)
),
periods=DayIntervals(
datetime(2022, 1, 1, 5, 0, 0), datetime(2022, 1, 31, 5, 0, 0)
),
client=client, dwh=dwh
).synchronize()
Read tags and measures from DWH
Read tags
To get all tags, just do this:
tags = PgCachedPITags(dwh).items()
Read measures
To read measures of a tag on a period, just do this:
tag = ... # get PI tag here
measures = PgCachedPIMeasures(tag, dwh).items(
datetime(2022, 1, 1, 5, 0, 0), datetime(2022, 1, 31, 5, 0, 0)
)
# or use only tag code
measures = PgCachedPIMeasures.of_tag_code("AI162014_SCLD", dwh).items(
datetime(2022, 1, 1, 5, 0, 0), datetime(2022, 1, 31, 5, 0, 0)
)
Synchronize blend proposals
We easily synchronize by this code below:
SyncBlendProposals(
src=ExcelBlendProposals(
file="path/of/excel/file/name",
start_date=date.fromisoformat("2022-10-18"),
end_date=date.fromisoformat("2022-10-20")
),
target=PgBlendProposals(dwh)
).synchronize()
Read blend proposals from DWH
blends = PgBlendProposals(dwh).items(
date(2022, 10, 18), datetime(2022, 10, 20)
)
Development environment
It is recommended to start by creating a virtual environment. You could do it by following commands:
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
N.B. We activate an environment on Windows by executing:
.venv\Scripts\activate.bat
How to contribute
Please read contributing rules.
Fork repository, make changes, send us a pull request. We will review
your changes and apply them to the master
branch shortly, provided
they don't violate our quality standards. To avoid frustration, before
sending us your pull request please run these commands:
sh pyqulice.sh # Linux
pyqulice.bat # Windows
pytest tests/unit/
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for edv_dwh_connector-0.6.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e0446f24a80b1c3fceca62b22b1e437856e605d89b2d92d6a76b638e9375d36 |
|
MD5 | 143fa67197621b95f6042686bbbd277e |
|
BLAKE2b-256 | 01e07eb83d7c98d83490f6a31e567e49fe8722e933dc664700f268e8779d2e9a |