Skip to content

Commit

Permalink
✨ (util) Move utils from ftmstore-fastapi
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwoerpel committed Jul 24, 2024
1 parent 9fd5dd9 commit 81c6ee9
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions ftmq/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,34 @@ def prop_is_numeric(schema: Schema, prop: str) -> bool:
if prop is not None:
return prop.type == registry.number
return False


def get_proxy_caption_property(proxy: CE) -> dict[str, str]:
for prop in proxy.schema.caption:
for value in proxy.get(prop):
return {prop: value}
return {}


def get_dehydrated_proxy(proxy: CE) -> CE:
"""
reduce proxy payload to only include caption property
"""
return make_proxy(
{
"id": proxy.id,
"schema": proxy.schema.name,
"properties": get_proxy_caption_property(proxy),
"datasets": proxy.datasets,
}
)


def get_featured_proxy(proxy: CE) -> CE:
"""
reduce proxy payload to only include featured properties
"""
featured = get_dehydrated_proxy(proxy)
for prop in proxy.schema.featured:
featured.add(prop, proxy.get(prop))
return featured

0 comments on commit 81c6ee9

Please sign in to comment.