[chore:] implemented intersection (combiner) and its usage

This commit is contained in:
Elias Fierke
2025-10-23 16:43:23 +02:00
parent d0ecfda404
commit bed0ebaf16
3 changed files with 61 additions and 17 deletions

View File

@@ -164,6 +164,7 @@
</Button> </Button>
<Button HorizontalAlignment="Stretch" MinWidth="240" <Button HorizontalAlignment="Stretch" MinWidth="240"
HorizontalContentAlignment="Center" x:Name="BtnCombineIntersect" HorizontalContentAlignment="Center" x:Name="BtnCombineIntersect"
Click="BtnCombineIntersection_OnClick"
Margin="0,0,0,10"> Margin="0,0,0,10">
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<LucideIcon Kind="SquaresIntersect" Width="36" Height="36" /> <LucideIcon Kind="SquaresIntersect" Width="36" Height="36" />

View File

@@ -512,4 +512,14 @@ public partial class MainWindow : Window
StartCombine(list, Convert.ToInt32(LstCustomers.SelectedItem.ToString().Split(" - ")[0]), "union"); StartCombine(list, Convert.ToInt32(LstCustomers.SelectedItem.ToString().Split(" - ")[0]), "union");
} }
private void BtnCombineIntersection_OnClick(object? sender, RoutedEventArgs e)
{
var list = new List<KasAddressList>();
foreach (var item in LstCustomerAdressSets.SelectedItems)
list.Add(Settings._instance.addressSets.GetAddressSetByID(
Convert.ToInt32(item.ToString().Split(" - ")[0])));
StartCombine(list, Convert.ToInt32(LstCustomers.SelectedItem.ToString().Split(" - ")[0]), "intersection");
}
} }

View File

@@ -22,6 +22,7 @@ public class CombineAddresses
{ {
if (type == "difference") return Difference(address_lists); if (type == "difference") return Difference(address_lists);
if (type == "union") return Union(address_lists); if (type == "union") return Union(address_lists);
if (type == "intersection") return Intersection(address_lists);
return null; return null;
}); });
@@ -115,12 +116,10 @@ public class CombineAddresses
result.KasPersons.Add(person); result.KasPersons.Add(person);
progress.Increment(); progress.Increment();
if (progress.LogAction != null) if (progress.LogAction == null) continue;
{ var logMessage =
var logMessage = $"Person mit refsid {person.refsid} verglichen mit {restUnion.Count} Personen des Restes.";
$"Person mit refsid {person.refsid} verglichen mit {restUnion.Count} Personen des Restes."; await Dispatcher.UIThread.InvokeAsync(() => progress.LogAction?.Invoke(logMessage));
await Dispatcher.UIThread.InvokeAsync(() => progress.LogAction?.Invoke(logMessage));
}
} }
return result; return result;
@@ -148,7 +147,51 @@ public class CombineAddresses
var logMessage = var logMessage =
$"{percent:F1}%: Person mit {person.refsid} hinzugefügt (aktuell {result.KasPersons.Count} Einträge)"; $"{percent:F1}%: Person mit {person.refsid} hinzugefügt (aktuell {result.KasPersons.Count} Einträge)";
// Sicher, nicht blockierend: if (progress == null) continue;
if (Dispatcher.UIThread.CheckAccess())
progress.LogAction?.Invoke(logMessage);
else
Dispatcher.UIThread.Post(() => progress.LogAction?.Invoke(logMessage));
}
return result;
}
public async Task<KasAddressList> MoveDuplicatesToNew()
{
return null;
}
public async Task<KasAddressList> Intersection(List<KasAddressList> address_lists, Progress progress = null)
{
var result = new KasAddressList("intersection");
if (address_lists == null || address_lists.Count == 0)
return result;
// Nur die erste Liste als Ausgangspunkt verwenden
var baseList = address_lists[0];
var otherLists = address_lists.Skip(1).ToList();
var total = baseList.KasPersons.Count;
var processed = 0;
foreach (var person in baseList.KasPersons)
{
// Prüfen, ob Person in *allen* anderen Listen vorkommt
var isInAll = otherLists.All(list =>
list.KasPersons.Any(existing => CompareAddresses(existing, person)));
if (isInAll)
result.KasPersons.Add(person);
processed++;
var percent = processed / (double)total * 100;
var logMessage =
$"{percent:F1}%: Person mit {person.refsid} geprüft {(isInAll ? "in allen enthalten" : "nicht überall vorhanden")}";
// Sicher und nicht blockierend loggen
if (progress != null) if (progress != null)
{ {
if (Dispatcher.UIThread.CheckAccess()) if (Dispatcher.UIThread.CheckAccess())
@@ -162,16 +205,6 @@ public class CombineAddresses
} }
public async Task<KasAddressList> MoveDuplicatesToNew()
{
return null;
}
public async Task<KasAddressList> Intersection()
{
return null;
}
public async Task<KasAddressList> SymmetricDifference() public async Task<KasAddressList> SymmetricDifference()
{ {
return null; return null;