2022-09-30 11:40:22 +03:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2022-04-08 03:10:44 +03:00
|
|
|
from dataclasses import dataclass, field
|
|
|
|
from typing import Dict, List, Union
|
|
|
|
|
|
|
|
from chia.protocols.harvester_protocol import Plot
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class DeltaType:
|
|
|
|
additions: Union[Dict[str, Plot], List[str]]
|
|
|
|
removals: List[str]
|
|
|
|
|
|
|
|
def __str__(self) -> str:
|
|
|
|
return f"+{len(self.additions)}/-{len(self.removals)}"
|
|
|
|
|
|
|
|
def clear(self) -> None:
|
|
|
|
self.additions.clear()
|
|
|
|
self.removals.clear()
|
|
|
|
|
|
|
|
def empty(self) -> bool:
|
|
|
|
return len(self.additions) == 0 and len(self.removals) == 0
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class PlotListDelta(DeltaType):
|
|
|
|
additions: Dict[str, Plot] = field(default_factory=dict)
|
|
|
|
removals: List[str] = field(default_factory=list)
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class PathListDelta(DeltaType):
|
|
|
|
additions: List[str] = field(default_factory=list)
|
|
|
|
removals: List[str] = field(default_factory=list)
|
|
|
|
|
|
|
|
@staticmethod
|
2023-10-24 20:01:23 +03:00
|
|
|
def from_lists(old: List[str], new: List[str]) -> PathListDelta:
|
2022-04-08 03:10:44 +03:00
|
|
|
return PathListDelta([x for x in new if x not in old], [x for x in old if x not in new])
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class Delta:
|
|
|
|
valid: PlotListDelta = field(default_factory=PlotListDelta)
|
|
|
|
invalid: PathListDelta = field(default_factory=PathListDelta)
|
|
|
|
keys_missing: PathListDelta = field(default_factory=PathListDelta)
|
|
|
|
duplicates: PathListDelta = field(default_factory=PathListDelta)
|
|
|
|
|
|
|
|
def empty(self) -> bool:
|
|
|
|
return self.valid.empty() and self.invalid.empty() and self.keys_missing.empty() and self.duplicates.empty()
|
|
|
|
|
|
|
|
def __str__(self) -> str:
|
|
|
|
return (
|
2022-05-25 02:21:56 +03:00
|
|
|
f"[valid {self.valid}, invalid {self.invalid}, keys missing: {self.keys_missing}, "
|
|
|
|
f"duplicates: {self.duplicates}]"
|
2022-04-08 03:10:44 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
def clear(self) -> None:
|
|
|
|
self.valid.clear()
|
|
|
|
self.invalid.clear()
|
|
|
|
self.keys_missing.clear()
|
|
|
|
self.duplicates.clear()
|