forked from amkovkov/GranuSightSoftware2
1) GSS2.Core: - strip prefixes in GSS2.Core.Analysis.AmineContent namespace class names - add IEnumerable<double>.Variance extension - remake analysis + update database so not needed to store all every file, calibration data also stored in database, also currently capturing images stored in system temporary directory and rewriting every time 2) GSS.UI.Core: AsyncImageRecordViewModel make zoom and pans public 3) GSS: - remove image-storage-clear command - remove ResultsView and ResultsViewModel, results presented in analysis - rework calibration views - add analysis views - add text and number fields editors view - add confirmation view on danger buttons
50 lines
2.0 KiB
C#
50 lines
2.0 KiB
C#
using System.Collections;
|
|
|
|
namespace GSS2.Core.Extensions;
|
|
|
|
public static class EnumerableExtensions
|
|
{
|
|
public static IEnumerable<(int i, T value)> Enumerate<T>(this IEnumerable<T> values) => values.Select((value, i) => (i, value));
|
|
|
|
public static string ToString<TKey, TValue>(this IDictionary<TKey, TValue> values, string separator, int indent) => string.Join(separator, values.Select(v => $"{new string(' ', indent)} {v.Key}: {v.Value}"));
|
|
public static string ToString(this IDictionary values, string separator, int indent)
|
|
{
|
|
var strs = new List<string?>();
|
|
var enumerator = values.GetEnumerator();
|
|
while (enumerator.MoveNext())
|
|
strs.Add($"{enumerator.Key}: {enumerator.Value}");
|
|
return string.Join(separator, strs.Select(s => $"{new string(' ', indent)}{s}"));
|
|
}
|
|
|
|
public static string ToString<TValue>(this IEnumerable<TValue> values, string separator, int indent) => (values as IEnumerable).ToString(separator, indent);
|
|
public static string ToString(this IEnumerable values, string separator, int indent)
|
|
{
|
|
var strs = new List<string?>();
|
|
var enumerator = values.GetEnumerator();
|
|
while (enumerator.MoveNext())
|
|
strs.Add(enumerator.Current.ToString());
|
|
return string.Join(separator, strs.Select(s => $"{new string(' ', indent)}{s}"));
|
|
}
|
|
|
|
public static bool All(this IEnumerable<bool> values) => values.All(v => v);
|
|
public static bool Any(this IEnumerable<bool> values) => values.Any(v => v);
|
|
|
|
public static void AddRange<TValue, TKey>(this IDictionary<TValue, TKey> values, IEnumerable<KeyValuePair<TValue, TKey>> collection)
|
|
{
|
|
foreach (var kv in collection)
|
|
values.Add(kv);
|
|
}
|
|
|
|
public static double Variance(this IEnumerable<double> values)
|
|
{
|
|
if (values.Count() == 1)
|
|
return 0;
|
|
|
|
double mean = values.Average();
|
|
double variance = 0.0;
|
|
foreach (int value in values)
|
|
variance += Math.Pow(value - mean, 2.0);
|
|
return variance / values.Count();
|
|
}
|
|
}
|