Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨(api) implement video new downloads endpoint #44

Merged
merged 7 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ and this project adheres to
- Add the LTI django application
- Rename the API directory to a more descriptive name.
- Add a select and date range picker to the web dashboard.
- Implement video downloads endpoint

[unreleased]: https://github.com/openfun/warren
2 changes: 1 addition & 1 deletion src/api/core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ dependencies = [
"rfc3987==1.3.8",
"sentry-sdk[fastapi]==1.15.0",
"uvicorn[standard]==0.20.0",
"ralph-malph[backend-lrs]==3.7.0"
"ralph-malph[backend-lrs]==3.8.0"
lebaudantoine marked this conversation as resolved.
Show resolved Hide resolved
]
dynamic = ["version"]

Expand Down
14 changes: 7 additions & 7 deletions src/api/core/warren/base_indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ def parse_raw_statements(raw_statements) -> pd.DataFrame:
return flattened


def add_actor_unique_id(statements: pd.DataFrame) -> pd.DataFrame:
"""Add a `actor.uuid` column that uniquely identifies the agent.
def add_actor_uid(statements: pd.DataFrame) -> pd.DataFrame:
"""Add a `actor.uid` column that uniquely identifies the agent.

Depending on the xAPI statements, the actor can be identified in 4 different ways :
https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Data.md#details-4. This
function handles the 4 cases and creates a `unique_actor_id` column that
can be used later without worrying about the 4 IFIs.
function handles the 4 cases and creates a `uid` column that can be used later
without worrying about the 4 IFIs.
"""
xapi_actor_identifier_columns = settings.XAPI_ACTOR_IDENTIFIER_PATHS.intersection(
set(statements.columns)
Expand All @@ -35,7 +35,7 @@ def add_actor_unique_id(statements: pd.DataFrame) -> pd.DataFrame:
raise ValueError(
"There is no way of identifying the agent in submitted statements."
)
statements["actor.uuid"] = statements.apply(
statements["actor.uid"] = statements.apply(
lambda row: hashlib.sha256(
"-".join(str(row[col]) for col in xapi_actor_identifier_columns).encode()
).hexdigest(),
Expand All @@ -48,8 +48,8 @@ def add_actor_unique_id(statements: pd.DataFrame) -> pd.DataFrame:
def pre_process_statements(statements: List) -> pd.DataFrame:
"""Denormalize raw statements, and add utility columns."""
parsed = parse_raw_statements(statements)
with_unique_id = add_actor_unique_id(parsed)
return with_unique_id
with_actor_uid = add_actor_uid(parsed)
return with_actor_uid


class BaseIndicator(ABC):
Expand Down
18 changes: 17 additions & 1 deletion src/api/core/warren/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""Warren's core models."""
from enum import Enum
from typing import Any, Dict, Generic, TypeVar
from typing import Any, Dict, Generic, List, TypeVar

from pydantic.main import BaseModel

from warren.fields import Date


class StatusEnum(str, Enum):
"""Enum for status types."""
Expand All @@ -29,3 +31,17 @@ class Response(BaseModel, Generic[T]):


XAPI_STATEMENT = Dict[str, Any]


class DailyCount(BaseModel):
"""Base model to represent a count for a date."""

date: Date
count: int = 0


class DailyCounts(BaseModel):
"""Base model to represent daily counts summary."""

total_count: int = 0
count_by_date: List[DailyCount] = []
23 changes: 12 additions & 11 deletions src/api/core/warren/tests/test_base_indicator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Test the functions from the BaseIndicator class."""
import pandas as pd

from warren.base_indicator import add_actor_unique_id, parse_raw_statements
from warren.base_indicator import add_actor_uid, parse_raw_statements
from warren.factories.base import BaseXapiStatementFactory


Expand All @@ -24,13 +24,13 @@ def test_parse_raw_statements():
assert len(statements) == len(parsed)


def test_add_actor_unique_id():
"""Test the generation of a `actor.uuid` column.
def test_add_actor_uid():
"""Test the generation of a `actor.uid` column.

Builds a list of xAPI statements with various identification methods (See the 4
IFIs of the spec
https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Data.md#details-4), and ensure
the UUID is created properly, and is the same for two equal actors.
the UID is created properly, and is the same for two equal actors.
"""
statements = [
BaseXapiStatementFactory.build(
Expand Down Expand Up @@ -86,10 +86,11 @@ def test_add_actor_unique_id():
]

statements = parse_raw_statements(statements)
statements = add_actor_unique_id(statements)
assert "actor.uuid" in statements.columns
assert statements["actor.uuid"].notna
# Check that 2 identical actors have the same UUID
uuids_john = statements[statements["actor.account.name"] == "John"]["actor.uuid"]
assert len(uuids_john) == 2
assert len(uuids_john.unique()) == 1
statements = add_actor_uid(statements)
assert "actor.uid" in statements.columns
assert statements["actor.uid"].notna
# Check that 2 identical actors have the same UID
ids_john = statements[statements["actor.account.name"] == "John"]["actor.uid"]
assert len(ids_john) == 2
# Make sure these ids are UID.
assert len(ids_john.unique()) == 1
Loading