Skip to content

Commit c72166e

Browse files
Merge pull request #79 from OleSeifert/develop
Finish Sprint 3
2 parents dfa4286 + 59294bd commit c72166e

102 files changed

Lines changed: 12535 additions & 1467 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.DS_Store

-6 KB
Binary file not shown.

.github/workflows/docs.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Publish Sphinx Documentation
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
publish_sphinx_docs:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
steps:
14+
- uses: actions/checkout@v3
15+
- uses: ./.github/actions/setup
16+
- name: Install dependencies
17+
run: uv sync
18+
- name: Sphinx build
19+
run: uv run sphinx-build docs/source docs/build/html
20+
- name: Deploy
21+
uses: peaceiris/actions-gh-pages@v3
22+
with:
23+
publish_branch: gh-pages
24+
github_token: ${{ secrets.GITHUB_TOKEN }}
25+
publish_dir: docs/build/html
26+
force_orphan: true

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ celerybeat.pid
129129

130130
# Environments
131131
.env
132+
.env.env.lock
132133
.venv
133134
env/
134135
venv/
@@ -175,4 +176,4 @@ cython_debug/
175176

176177

177178
# Event logs as they are usually too big in size
178-
event_logs/*
179+
event_logs/*

.pre-commit-config.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ repos:
4242
- --no-incremental
4343
- --disable-error-code=override
4444

45-
- id: pytest
46-
name: run tests
47-
entry: pytest
48-
args: ["tests"]
49-
language: python
50-
always_run: true
51-
pass_filenames: false
45+
# - id: pytest
46+
# name: run tests
47+
# entry: pytest
48+
# args: ["tests"]
49+
# language: python
50+
# always_run: true
51+
# pass_filenames: false

backend.Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM python:3.12-slim
2+
3+
WORKDIR /app
4+
5+
# Install uv and dependencies
6+
RUN pip install --no-cache-dir uv
7+
8+
# Copy pyproject and lock file to install backend dependencies
9+
COPY pyproject.toml uv.lock ./
10+
# RUN uv pip install --system .
11+
RUN uv pip install --system ".[all]" jinja2
12+
13+
# Copy FastAPI backend source code
14+
COPY backend ./backend
15+
16+
# Expose FastAPI's port
17+
EXPOSE 8000
18+
19+
# Run the FastAPI application using uvicorn
20+
CMD ["uvicorn", "backend.main:app", "--host", "0.0.0.0", "--port", "8000"]

backend/.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Never send secrets into the docker image
2+
../.env
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""Contains the schemas for the output format of the API responses."""
2+
3+
from typing import List, Optional
4+
5+
from pydantic import BaseModel
6+
7+
8+
class TableModel(BaseModel):
9+
"""Represents a table with headers and rows."""
10+
11+
headers: List[str]
12+
rows: List[List[str]]
13+
14+
15+
class GraphNode(BaseModel):
16+
"""Represents a node in a graph."""
17+
18+
id: str
19+
20+
21+
class GraphEdge(BaseModel):
22+
"""Represents an edge with a label in a graph.
23+
24+
Connects two nodes.
25+
"""
26+
27+
from_: str # `from` is a reserved keyword
28+
to: str
29+
label: str
30+
31+
class Config:
32+
"""Represents a mapping for reserved keywords in Pydantic models."""
33+
34+
fields = {
35+
"from_": "from",
36+
}
37+
38+
39+
class GraphModel(BaseModel):
40+
"""Represents a complete graph with nodes and edges."""
41+
42+
nodes: List[GraphNode]
43+
edges: List[GraphEdge]
44+
45+
46+
class ResponseSchema(BaseModel):
47+
"""Represents the response schema for API endpoints."""
48+
49+
tables: Optional[List[TableModel]] = []
50+
graphs: Optional[List[GraphModel]] = []

backend/api/modules/declarative_router.py

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import uuid
44
from typing import Dict, List, TypeAlias, Union
55

6-
from fastapi import APIRouter, BackgroundTasks, Depends, Request
6+
from fastapi import APIRouter, BackgroundTasks, Depends, Request, Query
77

88
from backend.api.celonis import get_celonis_connection
99
from backend.api.jobs import verify_correct_job_module
@@ -14,23 +14,27 @@
1414
from backend.celonis_connection.celonis_connection_manager import (
1515
CelonisConnectionManager,
1616
)
17+
from backend.pql_queries import declarative_queries
1718

1819
# **************** Type Aliases ****************
1920

20-
ReturnGraphType: TypeAlias = Dict[
21-
str, List[Dict[str, List[Union[str, Dict[str, str]]]]]
22-
]
21+
TableType: TypeAlias = Dict[str, Union[List[str], List[List[str]]]]
22+
GraphType: TypeAlias = Dict[str, List[Dict[str, str]]]
23+
ReturnGraphType: TypeAlias = Dict[str, Union[List[TableType], List[GraphType]]]
2324

2425
router = APIRouter(
2526
prefix="/api/declarative-constraints", tags=["Declarative Constraints CC"]
2627
)
2728
MODULE_NAME = "declarative_constraints"
2829

2930

30-
@router.post("/compute-constraints", status_code=202)
31+
@router.get("/compute-constraints", status_code=202)
3132
async def compute_declarative_constraints(
3233
background_tasks: BackgroundTasks,
3334
request: Request,
35+
min_support: float = Query(0.3, description="Minimum support ratio"),
36+
min_confidence: float = Query(0.75, description="Minimum confidence ratio"),
37+
fitness_score: float = Query(1.0, description="Fitness score for the constraints"),
3438
celonis: CelonisConnectionManager = Depends(get_celonis_connection),
3539
) -> Dict[str, str]:
3640
"""Computes the declarative constraints and stores it.
@@ -44,6 +48,9 @@ async def compute_declarative_constraints(
4448
application state via `request.app.state`.
4549
celonis (optional): The CelonisManager dependency injection.
4650
Defaults to Depends(get_celonis_connection).
51+
min_support: The minimum support ratio for the constraints.
52+
min_confidence: The minimum confidence ratio for the constraints.
53+
fitness_score: The fitness score for the constraints.
4754
4855
Returns:
4956
A dictionary containing the job ID of the scheduled task.
@@ -55,13 +62,19 @@ async def compute_declarative_constraints(
5562

5663
# Schedule the worker
5764
background_tasks.add_task(
58-
compute_and_store_declarative_constraints, request.app, job_id, celonis
65+
compute_and_store_declarative_constraints,
66+
request.app,
67+
job_id,
68+
celonis,
69+
min_support,
70+
min_confidence,
71+
fitness_score,
5972
)
6073

6174
return {"job_id": job_id}
6275

6376

64-
# **************** Retrieving Declarative Model Attributes ****************
77+
# **************** Retrieving Declarative Model Attributes - PM4PY ****************
6578

6679

6780
@router.get("/get_existance_violations/{job_id}")
@@ -354,3 +367,42 @@ def get_nonchainsuccession_violations(job_id: str, request: Request) -> ReturnGr
354367
verify_correct_job_module(job_id, request, MODULE_NAME)
355368

356369
return request.app.state.jobs[job_id].result.get("nonchainsuccession", [])
370+
371+
372+
# **************** Retrieving Declarative Model Attributes - PQL Queries ****************
373+
374+
375+
@router.get("/get_always_after_pql/")
376+
def get_always_after_pql(
377+
request: Request,
378+
celonis: CelonisConnectionManager = Depends(get_celonis_connection),
379+
) -> Dict[str, Union[List[TableType], List[GraphType]]]:
380+
"""Retrieves the always-after relations via PQL.
381+
382+
Args:
383+
request: The FastAPI request object.
384+
celonis: The CelonisManager dependency injection.
385+
386+
Returns:
387+
A JSON object with "tables" and "graphs" keys.
388+
"""
389+
result_df = declarative_queries.get_always_after_relation(celonis)
390+
return result_df
391+
392+
393+
@router.get("/get_always_before_pql/")
394+
def get_always_before_pql(
395+
request: Request,
396+
celonis: CelonisConnectionManager = Depends(get_celonis_connection),
397+
) -> Dict[str, Union[List[TableType], List[GraphType]]]:
398+
"""Retrieves the always-before relations via PQL.
399+
400+
Args:
401+
request: The FastAPI request object.
402+
celonis: The CelonisManager dependency injection.
403+
404+
Returns:
405+
A JSON object with "tables" and "graphs" keys.
406+
"""
407+
result_df = declarative_queries.get_always_before_relation(celonis)
408+
return result_df

0 commit comments

Comments
 (0)