Skip to content

Commit

Permalink
KBMBF-452: #37 Show ratio of oer-content
Browse files Browse the repository at this point in the history
KBMBF-502: Improving frontend
SD_WLO-238: Showing OER

Removing SearchStoreCollection due to duplication
  • Loading branch information
Robert Meissner committed Jul 25, 2022
1 parent 1b1718f commit 9a24322
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 27 deletions.
13 changes: 5 additions & 8 deletions src/app/api/analytics/background_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
_COLLECTIONS,
_MATERIALS,
SearchStore,
SearchStoreCollection,
global_store,
)
from app.api.collections.counts import AggregationMappings, collection_counts
Expand Down Expand Up @@ -128,15 +127,13 @@ def run():
for row in all_collections:
sub_collections: list[Row] = asyncio.run(get_ids_to_iterate(node_id=row.id))
print("Working on: ", row.title, len(sub_collections))
collections = {
sub.id: SearchStoreCollection(
node_id=sub.id,
missing_materials=search_hits_by_material_type(sub.title),
)
for sub in sub_collections
missing_materials = {
sub.id: search_hits_by_material_type(sub.title) for sub in sub_collections
}

search_store.append(SearchStore(node_id=row.id, collections=collections))
search_store.append(
SearchStore(node_id=row.id, missing_materials=missing_materials)
)

global_store.search = search_store

Expand Down
7 changes: 2 additions & 5 deletions src/app/api/analytics/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def search_hits_by_material_type(collection_title: str) -> dict:
response: Response = s[:0].execute()

if response.success():
# TODO: Clear and cleanu p: what does this do?
# TODO: Clear and cleanup: what does this do?
stats = merge_agg_response(response.aggregations.material_types)
stats["total"] = sum(stats.values())
return stats
Expand Down Expand Up @@ -182,10 +182,7 @@ async def query_search_statistics(
) -> dict[str, CountStatistics]:
for stats in global_store.search:
if str(node_id) == str(stats.node_id):
return {
str(key): value.missing_materials
for key, value in stats.collections.items()
}
return {str(key): value for key, value in stats.missing_materials.items()}
return {}


Expand Down
12 changes: 3 additions & 9 deletions src/app/api/analytics/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,14 @@
} # TODO: Refactor me ASAP


@dataclass(frozen=True)
class SearchStoreCollection:
node_id: uuid.UUID
missing_materials: CountStatistics


@dataclass(frozen=True)
class SearchStore:
__slots__ = "node_id", "collections"
__slots__ = "node_id", "missing_materials"
node_id: uuid.UUID
collections: dict[uuid.UUID, SearchStoreCollection]
missing_materials: dict[uuid.UUID, CountStatistics]


@dataclass(frozen=True)
@dataclass(frozen=False)
class Store:
__slots__ = "search"
search: list[SearchStore]
Expand Down
8 changes: 3 additions & 5 deletions tests/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
overall_stats,
query_material_types,
)
from app.api.analytics.storage import SearchStore, SearchStoreCollection
from app.api.analytics.storage import SearchStore
from app.api.collections.counts import CollectionTreeCount


Expand Down Expand Up @@ -52,10 +52,8 @@ def _get_item(_, key):
return [
SearchStore(
node_id=uuid.UUID(test_node),
collections={
key: SearchStoreCollection(
node_id=key, missing_materials=item["missing_materials"]
)
missing_materials={
key: item["missing_materials"]
for key, item in entry["collections"].items()
},
)
Expand Down

0 comments on commit 9a24322

Please sign in to comment.