-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathtest_python_fetch.py
More file actions
54 lines (46 loc) · 1.32 KB
/
test_python_fetch.py
File metadata and controls
54 lines (46 loc) · 1.32 KB
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
from feast import FeatureStore
import requests
import json
import pandas as pd
def run_demo_http():
print("\n--- Online features with HTTP endpoint ---")
online_request = {
"features": [
"driver_hourly_stats:conv_rate",
],
"entities": {"driver_id": [1001, 1002]},
}
r = requests.post(
"http://localhost:6566/get-online-features", data=json.dumps(online_request)
)
resp_data = json.loads(r.text)
records = pd.DataFrame.from_records(
columns=resp_data["metadata"]["feature_names"],
data=[
[r["values"][i] for r in resp_data["results"]]
for i in range(len(resp_data["results"]))
],
)
for col in sorted(records.columns):
print(col, " : ", records[col].values)
def run_demo_sdk():
store = FeatureStore(repo_path=".")
print("\n--- Online features with SDK ---")
features = store.get_online_features(
features=[
"driver_hourly_stats:conv_rate",
],
entity_rows=[
{
"driver_id": 1001,
},
{
"driver_id": 1002,
},
],
).to_dict()
for key, value in sorted(features.items()):
print(key, " : ", value)
if __name__ == "__main__":
run_demo_sdk()
run_demo_http()