[chore:] implemented symmetric difference (combiner) and its usage
This commit is contained in:
@@ -186,6 +186,7 @@
|
|||||||
</Button>
|
</Button>
|
||||||
<Button HorizontalAlignment="Stretch" MinWidth="240"
|
<Button HorizontalAlignment="Stretch" MinWidth="240"
|
||||||
HorizontalContentAlignment="Center" x:Name="BtnCombineSymmetric"
|
HorizontalContentAlignment="Center" x:Name="BtnCombineSymmetric"
|
||||||
|
Click="BtnCombineSymmetricDifference_OnClick"
|
||||||
Margin="0,0,0,10">
|
Margin="0,0,0,10">
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
<LucideIcon Kind="SquaresExclude" Width="36" Height="36" />
|
<LucideIcon Kind="SquaresExclude" Width="36" Height="36" />
|
||||||
|
|||||||
@@ -522,4 +522,14 @@ public partial class MainWindow : Window
|
|||||||
|
|
||||||
StartCombine(list, Convert.ToInt32(LstCustomers.SelectedItem.ToString().Split(" - ")[0]), "intersection");
|
StartCombine(list, Convert.ToInt32(LstCustomers.SelectedItem.ToString().Split(" - ")[0]), "intersection");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void BtnCombineSymmetricDifference_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]), "symdiff");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -23,6 +23,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);
|
if (type == "intersection") return Intersection(address_lists);
|
||||||
|
if (type == "symdiff") return SymmetricDifference(address_lists);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
@@ -205,9 +206,56 @@ public class CombineAddresses
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task<KasAddressList> SymmetricDifference()
|
public async Task<KasAddressList> SymmetricDifference(List<KasAddressList> address_lists, Progress progress = null)
|
||||||
{
|
{
|
||||||
return null;
|
var result = new KasAddressList("symmetric_difference");
|
||||||
|
|
||||||
|
if (address_lists == null || address_lists.Count == 0)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
var total = address_lists.Sum(l => l.KasPersons.Count);
|
||||||
|
var processed = 0;
|
||||||
|
|
||||||
|
// Wir sammeln alle Personen + zählen, wie oft sie vorkommen
|
||||||
|
var allPersons = new List<(KasPerson person, int count)>();
|
||||||
|
|
||||||
|
foreach (var list in address_lists)
|
||||||
|
foreach (var person in list.KasPersons)
|
||||||
|
{
|
||||||
|
// Prüfen, ob schon vorhanden
|
||||||
|
var existing = allPersons.FirstOrDefault(p => CompareAddresses(p.person, person));
|
||||||
|
if (existing.person != null)
|
||||||
|
{
|
||||||
|
// Falls schon drin → Vorkommen erhöhen
|
||||||
|
var index = allPersons.IndexOf(existing);
|
||||||
|
allPersons[index] = (existing.person, existing.count + 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Neu hinzufügen
|
||||||
|
allPersons.Add((person, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
processed++;
|
||||||
|
var percent = processed / (double)total * 100;
|
||||||
|
var logMessage =
|
||||||
|
$"{percent:F1}%: Person mit {person.refsid} verarbeitet (Zwischengröße {allPersons.Count})";
|
||||||
|
|
||||||
|
if (progress != null)
|
||||||
|
{
|
||||||
|
if (Dispatcher.UIThread.CheckAccess())
|
||||||
|
progress.LogAction?.Invoke(logMessage);
|
||||||
|
else
|
||||||
|
Dispatcher.UIThread.Post(() => progress.LogAction?.Invoke(logMessage));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Nur diejenigen übernehmen, die *genau einmal* vorkamen
|
||||||
|
foreach (var (person, count) in allPersons)
|
||||||
|
if (count == 1)
|
||||||
|
result.KasPersons.Add(person);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user