-
-
Save zilto/e99624e329c4f7ab1ed518643ab65775 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import feast | |
import datetime | |
# an entity has no upstream dependencies; it is our join index | |
def driver_entity() -> feast.Entity: | |
"""Feast definition: driver entity""" | |
return feast.Entity(name="driver", join_keys=["driver_id"], value_type=feast.ValueType.INT64) | |
# the filesource only needs a file path | |
# it could have been hardcoded, but here we pass it as argument because we want to ensure | |
# that is it the same value passed as the storage for our feature_transformations.py code | |
def driver_hourly_stats_source(driver_source_path: str) -> feast.FileSource: | |
"""Feast definition: source with hourly stats of driver""" | |
return feast.FileSource( | |
name="driver_hourly_stats", | |
path=driver_source_path, | |
timestamp_field="event_timestamp", | |
created_timestamp_column="created", | |
) | |
# the FeatureView is a 1-to-1 with the DataSource, but adds metadata and time-to-live (TTL) | |
def driver_hourly_stats_fv( | |
driver_entity: feast.Entity, | |
driver_hourly_stats_source: feast.FileSource | |
) -> feast.FeatureView: | |
"""Feast definition: feature view with hourly stats of driver""" | |
return feast.FeatureView( | |
name="driver_hourly_stats", | |
entities=[driver_entity], | |
ttl=timedelta(days=1), | |
schema=[ | |
feast.Field(name="conv_rate", dtype=feast.types.Float32), | |
feast.Field(name="acc_rate", dtype=feast.types.Float32), | |
feast.Field( | |
name="avg_daily_trips", dtype=feast.types.Int64, description="Average daily trips" | |
), | |
], | |
online=True, | |
source=driver_hourly_stats_source, | |
tags={"team": "driver_performance"}, | |
) | |
# the FeatureService defines how the data is stored in the online store | |
# and how it's retrieved | |
def driver_activity_v1_fs( | |
driver_hourly_stats_fv: feast.FeatureView, | |
) -> feast.FeatureService: | |
"""Feast definition: grouping of features relative to driver activity""" | |
return feast.FeatureService( | |
name="driver_activity_v1", | |
features=[ | |
driver_hourly_stats_fv, | |
], | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment