-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
71 lines (54 loc) · 2 KB
/
test.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# 김민주 - 실행 성공
# 유지예 - 실행 성공
import os
import datetime
from azure.ai.metricsadvisor import (
MetricsAdvisorKeyCredential,
MetricsAdvisorAdministrationClient,
)
from azure.ai.metricsadvisor.models import (
SqlServerDataFeedSource,
DataFeedSchema,
DataFeedMetric,
DataFeedDimension,
DataFeedGranularity,
DataFeedGranularityType,
)
endpoint = os.getenv("ENDPOINT")
subscriptionKey = os.getenv("SUBSCRIPTION_KEY")
apiKey = os.getenv("API_KEY")
credential = MetricsAdvisorKeyCredential(subscriptionKey, apiKey)
adminClient = MetricsAdvisorAdministrationClient(endpoint, credential)
sqlServerConnectionString = os.getenv("SQL_SERVER_CONNECTION_STRING")
sqlServerQuery = "SELECT @IntervalStart as timestamp, region, category, revenue, cost FROM MASampleRevenueCost WHERE timestamp >= @IntervalStart and timestamp < @IntervalEnd"
# set Datafeed
name = "<change name>"
source = SqlServerDataFeedSource(
connection_string=sqlServerConnectionString, query=sqlServerQuery)
granularity = DataFeedGranularity(DataFeedGranularityType.Daily)
schema = DataFeedSchema(
metrics=[
DataFeedMetric(name="cost", display_name="Cost"),
DataFeedMetric(name="revenue", display_name="Revenue")
],
dimensions=[
DataFeedDimension(name="category", display_name="Category"),
DataFeedDimension(name="city", display_name="City")
],
)
ingestionSettings = datetime.datetime(2019, 10, 1)
dataFeed = adminClient.create_data_feed(
name, source, granularity, schema, ingestionSettings)
# print data inside of the dataFeed
print(f"Data feed ID: {dataFeed.id}")
print(f"Data feed status: {dataFeed.status}")
print(f"Data feed created time: {dataFeed.created_time}")
print(f"Data feed administrators:")
for admin in dataFeed.admins:
print(f" - {admin}")
print(f"Metric IDs:")
for metric in dataFeed.schema.metrics:
print(f" - {metric.name}: {metric.id}")
print(f"Dimensions:")
for dimension in dataFeed.schema.dimensions:
print(f"- {dimension.name}")