Skip to content

Commit ee0f270

Browse files
authored
Merge pull request #364 from microsoft/retail-sampleData
feat - retail sample data
2 parents da29a66 + 5727e0e commit ee0f270

20 files changed

+189
-0
lines changed

src/Data/.env.sample

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SEARCH_ENDPOINT=
2+
SEARCH_API_KEY=
3+
BLOB_CONNECTION_STRING=
4+
BLOB_CONTAINER_NAME=
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import os
2+
from dotenv import load_dotenv
3+
from azure.core.credentials import AzureKeyCredential
4+
from azure.search.documents.indexes import SearchIndexClient, SearchIndexerClient
5+
from azure.search.documents.indexes.models import (
6+
SearchIndexerDataSourceConnection,
7+
SearchIndexer,
8+
SearchIndex,
9+
SimpleField,
10+
SearchableField,
11+
SearchFieldDataType
12+
)
13+
14+
# Load environment variables from .env file
15+
load_dotenv()
16+
17+
# Retrieve environment variables
18+
SEARCH_ENDPOINT = os.getenv("SEARCH_ENDPOINT")
19+
SEARCH_API_KEY = os.getenv("SEARCH_API_KEY")
20+
BLOB_CONNECTION_STRING = os.getenv("BLOB_CONNECTION_STRING")
21+
BLOB_CONTAINER_NAME = os.getenv("BLOB_CONTAINER_NAME")
22+
23+
# Validate required environment variables
24+
required_vars = [SEARCH_ENDPOINT, SEARCH_API_KEY, BLOB_CONNECTION_STRING, BLOB_CONTAINER_NAME]
25+
if any(var is None for var in required_vars):
26+
raise ValueError("One or more required environment variables are missing.")
27+
28+
def create_search_resources():
29+
"""Create Azure AI Search resources: data source, index, and indexer."""
30+
try:
31+
# Initialize SearchIndexClient for index operations
32+
index_client = SearchIndexClient(
33+
endpoint=SEARCH_ENDPOINT,
34+
credential=AzureKeyCredential(SEARCH_API_KEY)
35+
)
36+
37+
# Initialize SearchIndexerClient for data source and indexer operations
38+
indexer_client = SearchIndexerClient(
39+
endpoint=SEARCH_ENDPOINT,
40+
credential=AzureKeyCredential(SEARCH_API_KEY)
41+
)
42+
43+
# Define data source connection
44+
data_source = SearchIndexerDataSourceConnection(
45+
name="macae-blob-datasets",
46+
type="azureblob",
47+
connection_string=BLOB_CONNECTION_STRING,
48+
container={"name": BLOB_CONTAINER_NAME}
49+
)
50+
indexer_client.create_or_update_data_source_connection(data_source)
51+
print("Data source 'macae-blob-datasets' created successfully.")
52+
53+
# Define index schema
54+
index = SearchIndex(
55+
name="macae-index",
56+
fields=[
57+
SimpleField(name="id", type=SearchFieldDataType.String, key=True),
58+
SearchableField(name="content", type=SearchFieldDataType.String),
59+
SearchableField(name="metadata", type=SearchFieldDataType.String)
60+
]
61+
)
62+
index_client.create_or_update_index(index)
63+
print("Index 'macae-index' created successfully.")
64+
65+
# Define indexer
66+
indexer = SearchIndexer(
67+
name="macae-indexer",
68+
data_source_name="macae-blob-datasets",
69+
target_index_name="macae-index"
70+
)
71+
indexer_client.create_or_update_indexer(indexer)
72+
print("Indexer 'macae-indexer' created successfully.")
73+
74+
except Exception as e:
75+
print(f"An error occurred while creating search resources: {e}")
76+
77+
if __name__ == "__main__":
78+
create_search_resources()

src/Data/data_upload.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from azure.storage.blob import BlobServiceClient
2+
import os
3+
from dotenv import load_dotenv
4+
5+
load_dotenv()
6+
7+
# Retrieve environment variables
8+
BLOB_CONNECTION_STRING = os.getenv("BLOB_CONNECTION_STRING")
9+
BLOB_CONTAINER_NAME = os.getenv("BLOB_CONTAINER_NAME")
10+
local_folder = "./datasets"
11+
12+
blob_service_client = BlobServiceClient.from_connection_string(BLOB_CONNECTION_STRING)
13+
container_client = blob_service_client.get_container_client(BLOB_CONTAINER_NAME)
14+
15+
for filename in os.listdir(local_folder):
16+
file_path = os.path.join(local_folder, filename)
17+
if os.path.isfile(file_path):
18+
print(f"Uploading {filename}...")
19+
with open(file_path, "rb") as data:
20+
container_client.upload_blob(name=filename, data=data, overwrite=True)
21+
print("Upload complete!")
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ProductCategory,ContosoAveragePrice,CompetitorAveragePrice
2+
Dresses,120,100
3+
Shoes,100,105
4+
Accessories,60,55
5+
Sportswear,80,85
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ReasonForCancellation,Percentage
2+
Service Dissatisfaction,40
3+
Financial Reasons,3
4+
Competitor Offer,15
5+
Moving to a Non-Service Area,5
6+
Other,37
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Campaign,Opened,Clicked,Unsubscribed
2+
Summer Sale,Yes,Yes,No
3+
New Arrivals,Yes,No,No
4+
Exclusive Member Offers,No,No,No
5+
Personal Styling Invite,No,No,No
6+
Autumn Collection Preview,Yes,Yes,No
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
TotalPointsEarned,PointsRedeemed,CurrentPointBalance,PointsExpiringNextMonth
2+
4800,3600,1200,1200
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Benefit,UsageFrequency
2+
Free Shipping,7
3+
Early Access to Collections,2
4+
Exclusive Discounts,1
5+
Personalized Styling Sessions,0
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Date,IPAddress,Location,SuccessfulLogin
2+
2023-06-20,192.168.1.1,Home Network,Yes
3+
2023-07-22,203.0.113.45,Unknown,No
4+
2023-08-15,198.51.100.23,Office Network,Yes
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Date,IncidentDescription,AffectedOrders
2+
2023-06-15,Inventory system outage,100
3+
2023-07-18,Logistics partner strike,250
4+
2023-08-25,Warehouse flooding due to heavy rain,150

0 commit comments

Comments
 (0)