Skip to content

Commit

Permalink
Merge pull request #195 from InTaVia/ms/190-create-an-enityType-stati…
Browse files Browse the repository at this point in the history
…stics-endpoint

Ms/190 create an enity type statistics endpoint
  • Loading branch information
sennierer authored Aug 23, 2023
2 parents d1dd176 + a6f3660 commit 67504f8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
35 changes: 35 additions & 0 deletions intavia_backend/main_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
StatisticsOccupationPrelim,
StatisticsOccupationPrelimList,
StatisticsOccupationReturn,
StatsEntityType,
VocabularyEntry,
)
from intavia_backend.query_parameters_v2 import (
Expand Down Expand Up @@ -614,3 +615,37 @@ async def statistics_birth_bulk(ids: RequestID, search: StatisticsBinsQuery = De
b["count"] += date["count"]
bins[idx] = b
return {"bins": bins}


@router.get(
"/api/statistics/entity_types/search",
response_model=StatsEntityType,
response_model_exclude_none=True,
tags=["Statistics"],
description="Endpoint that returns counts of entity types",
)
@cache()
async def statistics_entity_type(search: Search = Depends()):
res = get_query_from_triplestore_v2(search, "statistics_entity_types_v2_1.sparql")
res = flatten_rdf_data(res)
res_fin = {}
for ent in res:
res_fin[ent["entityTypeLabel"]] = ent["count"]
return res_fin


@router.post(
"/api/statistics/entity_types/bulk",
response_model=StatsEntityType,
response_model_exclude_none=True,
tags=["Statistics"],
description="Endpoint that returns counts of entity types",
)
@cache()
async def statistics_entity_type_bulk(ids: RequestID):
res = get_query_from_triplestore_v2({"ids": ids.id}, "statistics_entity_types_v2_1.sparql")
res = flatten_rdf_data(res)
res_fin = {}
for ent in res:
res_fin[ent["entityTypeLabel"]] = ent["count"]
return res_fin
13 changes: 13 additions & 0 deletions intavia_backend/models_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,19 @@ class StatisticsBins(BaseModel):
bins: list[Bin]


class StatsEntityType(BaseModel):
person: PositiveInt = Field(default=0, rdfconfig=FieldConfigurationRDF(path="personCount"))
place: PositiveInt = Field(default=0, rdfconfig=FieldConfigurationRDF(path="placeCount"))
group: PositiveInt = Field(default=0, rdfconfig=FieldConfigurationRDF(path="groupCount"))
culturalHeritageObject: PositiveInt = Field(default=0, alias="cultural-heritage-object", rdfconfig=FieldConfigurationRDF(path="culturalHeritageObjectCount"))

class Config:
RDF_utils_catch_errors = True
RDF_utils_error_field_name = "errors"
RDF_utils_move_errors_to_top = True
allow_population_by_field_name = True


EntityEventRelation.update_forward_refs()
Event.update_forward_refs()
Entity.update_forward_refs()
Expand Down

0 comments on commit 67504f8

Please sign in to comment.