-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
39 lines (27 loc) · 1.32 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
import json
import asyncio
from azure.identity import DefaultAzureCredential
from azure.digitaltwins.core import DigitalTwinsClient
from downloader import download_dataset
from preprocessor import preprocess_all
from dt_manager import create_twin_istanbul
from traffic_manager import traffic_flow_tiles
if __name__ == "__main__":
# DefaultAzureCredential supports different authentication mechanisms and determines the appropriate credential type based of the environment it is executing in.
# It attempts to use multiple credential types in an order until it finds a working credential.
env = json.loads(open("variables.env").read())
for k, v in env.items():
os.environ[k] = v
# - AZURE_URL: The URL to the ADT in Azure
url = os.getenv("AZURE_URL")
credential = DefaultAzureCredential()
service_client = DigitalTwinsClient("https://twin-istanbul.api.weu.digitaltwins.azure.net", credential)
# download data if needed!
path, file_paths = download_dataset()
# load data to pandas dataframe, preprocess if needed
data_frames = preprocess_all(path, file_paths)
# create digital twin instance in Azure
create_twin_istanbul(data_frames, service_client)
# will continue to extract traffic tiles per 5 minutes
asyncio.run(traffic_flow_tiles(data_frames))