|
@ -1,23 +1,24 @@ |
|
|
|
|
|
from typing import List |
|
|
|
|
|
|
|
|
from django.shortcuts import get_object_or_404 |
|
|
from django.shortcuts import get_object_or_404 |
|
|
|
|
|
|
|
|
from examples.assignment.strategies import StrategyName, create_assignment_strategy |
|
|
from examples.assignment.strategies import StrategyName, create_assignment_strategy |
|
|
from examples.assignment.workload import WorkloadAllocation |
|
|
|
|
|
from examples.models import Assignment, Example |
|
|
from examples.models import Assignment, Example |
|
|
from projects.models import Member, Project |
|
|
from projects.models import Member, Project |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def bulk_assign(project_id: int, workload_allocation: WorkloadAllocation, strategy_name: StrategyName) -> None: |
|
|
|
|
|
|
|
|
def bulk_assign(project_id: int, strategy_name: StrategyName, member_ids: List[int], weights: List[int]) -> None: |
|
|
project = get_object_or_404(Project, pk=project_id) |
|
|
project = get_object_or_404(Project, pk=project_id) |
|
|
members = Member.objects.filter(project=project, pk__in=workload_allocation.member_ids) |
|
|
|
|
|
if len(members) != len(workload_allocation.member_ids): |
|
|
|
|
|
|
|
|
members = Member.objects.filter(project=project, pk__in=member_ids) |
|
|
|
|
|
if len(members) != len(member_ids): |
|
|
raise ValueError("Invalid member ids") |
|
|
raise ValueError("Invalid member ids") |
|
|
# Sort members by workload_allocation.member_ids |
|
|
|
|
|
members = sorted(members, key=lambda m: workload_allocation.member_ids.index(m.id)) |
|
|
|
|
|
|
|
|
# Sort members by member_ids |
|
|
|
|
|
members = sorted(members, key=lambda m: member_ids.index(m.id)) |
|
|
|
|
|
|
|
|
unassigned_examples = Example.objects.filter(project=project, assignments__isnull=True) |
|
|
unassigned_examples = Example.objects.filter(project=project, assignments__isnull=True) |
|
|
dataset_size = unassigned_examples.count() |
|
|
dataset_size = unassigned_examples.count() |
|
|
|
|
|
|
|
|
strategy = create_assignment_strategy(strategy_name, dataset_size, workload_allocation.weights) |
|
|
|
|
|
|
|
|
strategy = create_assignment_strategy(strategy_name, dataset_size, weights) |
|
|
assignments = strategy.assign() |
|
|
assignments = strategy.assign() |
|
|
assignments = [ |
|
|
assignments = [ |
|
|
Assignment( |
|
|
Assignment( |
|
|