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

Cleanup and planning for refactoring
  • Loading branch information
Robert Meissner committed Jul 22, 2022
1 parent c69d17d commit 1b1718f
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 45 deletions.
8 changes: 3 additions & 5 deletions src/app/api/analytics/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,13 @@ class Config(ElasticConfig):
pass


COUNT_STATISTICS_TYPE = dict[str, int]
CountStatistics = dict[str, int]


class StatsResponse(ResponseModel):
derived_at: datetime
stats: dict[str, dict[str, COUNT_STATISTICS_TYPE]]
oer_ratio: int = Field(
default=0, ge=0, le=100, description="Overall ratio of OER content"
)
stats: dict[str, dict[str, CountStatistics]]
oer_ratio: int = Field(ge=0, le=100, description="Overall ratio of OER content")


ValidationStatsT = TypeVar("ValidationStatsT")
Expand Down
3 changes: 2 additions & 1 deletion src/app/api/analytics/background_task.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import os
import uuid
from datetime import datetime

from fastapi import APIRouter
Expand Down Expand Up @@ -117,7 +118,7 @@ def run():
)

all_collections = [
Row(id=value["value"], title=key)
Row(id=uuid.UUID(value["value"]), title=key)
for key, value in COLLECTION_NAME_TO_ID.items()
]
print("Tree ready to iterate. Length: ", len(all_collections))
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/analytics/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

# TODO: Rename, as used for materials in background_task, as well
class Collection(BaseModel):
id: str
id: str # TODO: Refactored to UUID
doc: dict
derived_at: datetime
8 changes: 4 additions & 4 deletions src/app/api/analytics/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from glom import merge

from app.api.analytics.analytics import (
COUNT_STATISTICS_TYPE,
CollectionValidationStats,
CountStatistics,
MaterialValidationStats,
StatsNotFoundException,
StatsResponse,
Expand Down Expand Up @@ -142,7 +142,7 @@ def nodes(data: list[CollectionNode]) -> list:

def query_material_types(
node_id: uuid.UUID, oer_only: bool
) -> dict[str, COUNT_STATISTICS_TYPE]:
) -> dict[str, CountStatistics]:
"""
get collections with parent id equal to node_id
Expand All @@ -162,7 +162,7 @@ def query_material_types(
# TODO: Refactor with filter and dict comprehension
for collection in collections:
for count in counts:
if str(collection.id) == str(count.noderef_id):
if collection.id == str(count.noderef_id):
stats.update(
{str(collection.id): {"total": count.total, **count.counts}}
)
Expand All @@ -179,7 +179,7 @@ def filtered_collections(collections: list[Collection], node_id: uuid.UUID):

async def query_search_statistics(
node_id: uuid.UUID,
) -> dict[str, COUNT_STATISTICS_TYPE]:
) -> dict[str, CountStatistics]:
for stats in global_store.search:
if str(node_id) == str(stats.node_id):
return {
Expand Down
10 changes: 6 additions & 4 deletions src/app/api/analytics/storage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import uuid
from dataclasses import dataclass

from app.api.analytics.analytics import CountStatistics

_COLLECTIONS = "collections"
_MATERIALS = "materials"
_COLLECTION_COUNT = "counts"
Expand All @@ -17,20 +19,20 @@
} # TODO: Refactor me ASAP


@dataclass
@dataclass(frozen=True)
class SearchStoreCollection:
node_id: uuid.UUID
missing_materials: dict[str, int]
missing_materials: CountStatistics


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


@dataclass
@dataclass(frozen=True)
class Store:
__slots__ = "search"
search: list[SearchStore]
Expand Down
14 changes: 7 additions & 7 deletions src/app/api/collections/missing_materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,14 @@ def missing_attributes_search(
qmatch(**{"collections.path": node_id}),
qmatch(**{"collections.nodeRef.id": node_id}),
],
"filter": type_filter[
ResourceType.MATERIAL
].copy(), # copy otherwise appending the query causes mutation
"filter": [
*type_filter[
ResourceType.MATERIAL
].copy(), # copy otherwise appending the query causes mutation
Q("bool", **{"must_not": [{"term": {"aspects": "ccm:io_childobject"}}]}),
Q({"term": {"content.mimetype.keyword": "text/plain"}}),
],
}
query["filter"].append(
Q("bool", **{"must_not": [{"term": {"aspects": "ccm:io_childobject"}}]})
)
query["filter"].append(Q({"term": {"content.mimetype.keyword": "text/plain"}}))
if missing_attribute == LearningMaterialAttribute.LICENSES.path:
query["filter"].append(query_missing_material_license().to_dict())
else:
Expand Down
37 changes: 16 additions & 21 deletions src/app/api/score/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,75 +4,70 @@


class MissingCollectionProperties(BaseModel):
total: int = Field(default=0, ge=0, description="Number of entries")
total: int = Field(ge=0, description="Number of entries")
short_description: float = Field(
default=0.0,
ge=0.0,
le=1.0,
description="Ratio of entries without short description",
)
short_title: float = Field(
default=0.0, ge=0.0, le=1.0, description="Ratio of entries without short title"
ge=0.0, le=1.0, description="Ratio of entries without short title"
)
missing_edu_context: float = Field(
default=0.0, ge=0.0, le=1.0, description="Ratio of entries without edu context"
ge=0.0, le=1.0, description="Ratio of entries without edu context"
)
missing_description: float = Field(
default=0.0, ge=0.0, le=1.0, description="Ratio of entries without description"
ge=0.0, le=1.0, description="Ratio of entries without description"
)
few_keywords: float = Field(
default=0.0, ge=0.0, le=1.0, description="Ratio of entries with few keywords"
ge=0.0, le=1.0, description="Ratio of entries with few keywords"
)
missing_keywords: float = Field(
default=0.0, ge=0.0, le=1.0, description="Ratio of entries without keywords"
ge=0.0, le=1.0, description="Ratio of entries without keywords"
)
missing_title: float = Field(
default=0.0, ge=0.0, le=1.0, description="Ratio of entries without title"
ge=0.0, le=1.0, description="Ratio of entries without title"
)


class MissingMaterialProperties(BaseModel):
total: int = Field(default=0, ge=0, description="Number of entries")
missing_title: float = Field(
default=0.0, ge=0.0, le=1.0, description="Ratio of entries without title"
ge=0.0, le=1.0, description="Ratio of entries without title"
)
missing_material_type: float = Field(
default=0.0,
ge=0.0,
le=1.0,
description="Ratio of entries missing material type",
)
missing_subjects: float = Field(
default=0.0, ge=0.0, le=1.0, description="Ratio of entries missing subjects"
ge=0.0, le=1.0, description="Ratio of entries missing subjects"
)
missing_url: float = Field(
default=0.0, ge=0.0, le=1.0, description="Ratio of entries without url"
ge=0.0, le=1.0, description="Ratio of entries without url"
)
missing_license: float = Field(
default=0.0, ge=0.0, le=1.0, description="Ratio of entries with missing license"
ge=0.0, le=1.0, description="Ratio of entries with missing license"
)
missing_publisher: float = Field(
default=0.0, ge=0.0, le=1.0, description="Ratio of entries without publisher"
ge=0.0, le=1.0, description="Ratio of entries without publisher"
)
missing_description: float = Field(
default=0.0, ge=0.0, le=1.0, description="Ratio of entries without description"
ge=0.0, le=1.0, description="Ratio of entries without description"
)
missing_intended_end_user_role: float = Field(
default=0.0,
ge=0.0,
le=1.0,
description="Ratio of entries without intended end user role",
)
missing_edu_context: float = Field(
default=0.0, ge=0.0, le=1.0, description="Ratio of entries without edu context"
ge=0.0, le=1.0, description="Ratio of entries without edu context"
)


class ScoreOutput(BaseModel):
score: int = Field(default=0, ge=0, le=100, description="Overall score")
oer_ratio: int = Field(
default=0, ge=0, le=100, description="Overall ratio of OER content"
)
score: int = Field(ge=0, le=100, description="Overall score")
oer_ratio: int = Field(ge=0, le=100, description="Overall ratio of OER content")
collections: MissingCollectionProperties = Field(
description="Score for specific collection properties"
)
Expand Down
4 changes: 2 additions & 2 deletions src/app/core/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
COLLECTION_NAME_TO_ID = {
COLLECTION_NAME_TO_ID: dict[str, dict[str, str]] = {
"Physik": {"value": "94f22c9b-0d3a-4c1c-8987-4c8e83f3a92e"},
"Mathematik": {"value": "bd8be6d5-0fbe-4534-a4b3-773154ba6abc"},
"Biologie": {"value": "15fce411-54d9-467f-8f35-61ea374a298d"},
Expand All @@ -25,6 +25,6 @@
"Franzoesisch": {"value": "86b990ef-0955-45ad-bdae-ec2623cf0e1a"},
"Musik": {"value": "2eda0065-f69b-46c8-ae09-d258c8226a5e"},
"Philosophie": {"value": "9d364fd0-4374-40b4-a153-3c722b9cda35"},
}
} # TODO: Refactor by removing value and refactoring the API constructor respectively
OPEN_API_VERSION = "2.1.0"
COLLECTION_ROOT_ID = "5e40e372-735c-4b17-bbf7-e827a5702b57"

0 comments on commit 1b1718f

Please sign in to comment.