[chore:] implemented intersection (combiner) and its usage
This commit is contained in:
@@ -164,6 +164,7 @@
|
||||
</Button>
|
||||
<Button HorizontalAlignment="Stretch" MinWidth="240"
|
||||
HorizontalContentAlignment="Center" x:Name="BtnCombineIntersect"
|
||||
Click="BtnCombineIntersection_OnClick"
|
||||
Margin="0,0,0,10">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<LucideIcon Kind="SquaresIntersect" Width="36" Height="36" />
|
||||
|
||||
@@ -512,4 +512,14 @@ public partial class MainWindow : Window
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ public class CombineAddresses
|
||||
{
|
||||
if (type == "difference") return Difference(address_lists);
|
||||
if (type == "union") return Union(address_lists);
|
||||
if (type == "intersection") return Intersection(address_lists);
|
||||
|
||||
return null;
|
||||
});
|
||||
@@ -115,13 +116,11 @@ public class CombineAddresses
|
||||
result.KasPersons.Add(person);
|
||||
|
||||
progress.Increment();
|
||||
if (progress.LogAction != null)
|
||||
{
|
||||
if (progress.LogAction == null) continue;
|
||||
var logMessage =
|
||||
$"Person mit refsid {person.refsid} verglichen mit {restUnion.Count} Personen des Restes.";
|
||||
await Dispatcher.UIThread.InvokeAsync(() => progress.LogAction?.Invoke(logMessage));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -148,7 +147,51 @@ public class CombineAddresses
|
||||
var logMessage =
|
||||
$"{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 (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()
|
||||
{
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user