Erster Checkin: Tool arbeitet

This commit is contained in:
2026-02-02 12:40:51 +01:00
parent 69fcca1fd0
commit 12926c7e83
12 changed files with 616 additions and 0 deletions

28
app/aggregator.py Normal file
View File

@@ -0,0 +1,28 @@
from __future__ import annotations
from collections import Counter
from dataclasses import dataclass
from typing import List
from .models import WorkingWithRelation
@dataclass
class DepartmentLink:
source_department: str
destination_department: str
weight: int
def aggregate_department_links(relations: List[WorkingWithRelation]) -> List[DepartmentLink]:
counter: Counter[tuple[str, str]] = Counter()
for rel in relations:
src = (rel.source.department or "").strip()
dst = (rel.destination.department or "").strip()
if not src or not dst:
continue
counter[(src, dst)] += 1
links: List[DepartmentLink] = [
DepartmentLink(source_department=s, destination_department=d, weight=w)
for (s, d), w in counter.items()
]
return sorted(links, key=lambda l: l.weight, reverse=True)