Added the value card sort to the BeyondFacts Lab (#1206)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2026-11-15 13:06:06 +01:00
1 parent 1361b984eb
commit 3ca4b3878b
42 files changed
+2111 -114

No files matched your search

@@ -94,7 +94,9 @@ public static class BflStaleness
/// Computes the fingerprint of a form, which tells whether the person changed it.
/// </summary>
/// <remarks>
/// Line endings and spaces around a value do not count, since they change nothing the model reads.
/// Line endings and spaces around a value do not count, since they change nothing the model reads. The card sort
/// counts as a detail of its step; without one, or with an empty one, the fingerprint is the same as before the lab
/// had a card sort, so that no confirmation of an older preparation turns into "Details changed".
/// </remarks>
/// <param name="form">The form.</param>
/// <returns>The fingerprint, in hexadecimal digits.</returns>
@@ -110,6 +112,33 @@ public static class BflStaleness
text.Append(fieldId).Append(SEPARATOR).Append(normalized).Append(SEPARATOR);
}
if (form.CardSort is { IsEmpty: false } cardSort)
AppendCardSort(text, cardSort);
return Convert.ToHexStringLower(SHA256.HashData(Encoding.UTF8.GetBytes(text.ToString())));
}
/// <summary>
/// Appends a card sort to the text a fingerprint is computed from.
/// </summary>
/// <remarks>
/// Each part starts with a separator and its name, which no ID of a field begins with. The values to look at more
/// closely count as a set: the order the person chose them in is no ranking.
/// </remarks>
/// <param name="text">The text so far.</param>
/// <param name="cardSort">The card sort.</param>
private static void AppendCardSort(StringBuilder text, BflCardSort cardSort)
{
text.Append(SEPARATOR).Append("categories").Append(SEPARATOR);
foreach (var (valueId, category) in cardSort.Categories.Where(entry => entry.Value is not BflValueCategory.NONE).OrderBy(entry => entry.Key, StringComparer.Ordinal))
text.Append(valueId).Append(SEPARATOR).Append(category.ToString()).Append(SEPARATOR);
text.Append(SEPARATOR).Append("own values").Append(SEPARATOR);
foreach (var value in cardSort.OwnValues)
text.Append(value.Id).Append(SEPARATOR).Append(value.Name.Trim()).Append(SEPARATOR).Append(value.Definition.Trim()).Append(SEPARATOR);
text.Append(SEPARATOR).Append("focus").Append(SEPARATOR);
foreach (var valueId in cardSort.Focus.Distinct(StringComparer.Ordinal).Order(StringComparer.Ordinal))
text.Append(valueId).Append(SEPARATOR);
}
}