Add trainings endpoints
This commit is contained in:
parent
74a3aae531
commit
3cadfb1d09
4 changed files with 34 additions and 14 deletions
|
|
@ -1,7 +1,8 @@
|
||||||
from fastapi import APIRouter
|
from fastapi import APIRouter
|
||||||
from app.api.v1.endpoints import parser, health
|
from app.api.v1.endpoints import parser, health, trainings
|
||||||
|
|
||||||
api_router = APIRouter()
|
api_router = APIRouter()
|
||||||
|
|
||||||
api_router.include_router(health.router, prefix="/health", tags=["health"])
|
api_router.include_router(health.router, prefix="/health", tags=["health"])
|
||||||
api_router.include_router(parser.router, prefix="/parser", tags=["parser"])
|
api_router.include_router(parser.router, prefix="/parser", tags=["parser"])
|
||||||
|
api_router.include_router(trainings.router, prefix="/trainings", tags=["trainings"])
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ router = APIRouter()
|
||||||
parser_service = ParserService()
|
parser_service = ParserService()
|
||||||
|
|
||||||
|
|
||||||
@router.post("/parse", response_model=List[ParseResponse])
|
@router.post("/parse/", response_model=List[ParseResponse])
|
||||||
async def parse_training_data(request: ParseRequest):
|
async def parse_training_data(request: ParseRequest):
|
||||||
try:
|
try:
|
||||||
result = await parser_service.parse_data(request)
|
result = await parser_service.parse_data(request)
|
||||||
|
|
@ -16,7 +16,7 @@ async def parse_training_data(request: ParseRequest):
|
||||||
raise HTTPException(status_code=500, detail=str(e))
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
|
|
||||||
|
|
||||||
@router.get("/supported-formats")
|
@router.get("/supported-formats/")
|
||||||
async def get_supported_formats():
|
async def get_supported_formats():
|
||||||
return {
|
return {
|
||||||
"formats": [
|
"formats": [
|
||||||
|
|
|
||||||
11
app/api/v1/endpoints/trainings.py
Normal file
11
app/api/v1/endpoints/trainings.py
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
from fastapi import APIRouter
|
||||||
|
|
||||||
|
from app.core.parsers.obsidian import parse_training_data
|
||||||
|
|
||||||
|
router = APIRouter()
|
||||||
|
|
||||||
|
@router.get("/obsidian/")
|
||||||
|
async def obsidian_trainings_list():
|
||||||
|
return {
|
||||||
|
"data": parse_training_data()
|
||||||
|
}
|
||||||
|
|
@ -10,16 +10,23 @@ class ObsidianNotesParser(BaseNotesParser):
|
||||||
"""Parser for Obsidian Notes format training data."""
|
"""Parser for Obsidian Notes format training data."""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__("obsidian.md", obsidian_unique_exercies_mapping)
|
super().__init__(
|
||||||
|
data_file_name="obsidian.md",
|
||||||
|
exercise_mapper=obsidian_unique_exercies_mapping,
|
||||||
|
)
|
||||||
|
|
||||||
def filter_training_data(self, training_data: str) -> str:
|
def filter_training_data(self, training_data: str) -> str:
|
||||||
"""Filter Obsidian-specific training data format."""
|
"""Filter Obsidian-specific training data format."""
|
||||||
cleaned_text = re.sub(r"^\s*?\n", "", training_data, flags=re.MULTILINE)
|
cleaned_text = re.sub(r"^\s*?\n", "", training_data, flags=re.MULTILINE)
|
||||||
return cleaned_text
|
return cleaned_text
|
||||||
|
|
||||||
def parse_training_header(self, training_data_line: str) -> Tuple[bool, str, str, str]:
|
def parse_training_header(
|
||||||
|
self, training_data_line: str
|
||||||
|
) -> Tuple[bool, str, str, str]:
|
||||||
"""Parse Obsidian Notes training header format."""
|
"""Parse Obsidian Notes training header format."""
|
||||||
pattern: str = r"#\s(?P<date>\d+.\d+.\d+)\s\((?P<trainer>.+)-(?P<year_counter>.+)\)"
|
pattern: str = (
|
||||||
|
r"#\s(?P<date>\d+.\d+.\d+)\s\((?P<trainer>.+)-(?P<year_counter>.+)\)"
|
||||||
|
)
|
||||||
match = re.search(pattern, training_data_line)
|
match = re.search(pattern, training_data_line)
|
||||||
if match:
|
if match:
|
||||||
date = match.group("date").strip()
|
date = match.group("date").strip()
|
||||||
|
|
@ -52,3 +59,4 @@ def remap_unique_exercises(obsidian_trainings: List[Training]) -> List[Training]
|
||||||
"""Remap exercise names using Obsidian-specific mapping (deprecated - use parser.parse_and_map_training_data())."""
|
"""Remap exercise names using Obsidian-specific mapping (deprecated - use parser.parse_and_map_training_data())."""
|
||||||
parser = ObsidianNotesParser()
|
parser = ObsidianNotesParser()
|
||||||
return parser.apply_exercise_mapping(obsidian_trainings)
|
return parser.apply_exercise_mapping(obsidian_trainings)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue