livia-test/Astroke/ViewModels/AspectsScoreRoiSummaryControlViewModel.cs
2025-03-28 14:31:53 +08:00

39 lines
1.7 KiB
C#

using Livia.Models;
using Livia.ViewModels;
using Microsoft.Extensions.Logging;
namespace Astroke.ViewModels;
public class AspectsScoreRoiSummaryControlViewModel(ILogger logger, IRoiLegendManager roiLegendManager)
: RoiSummaryControlViewModel(logger, roiLegendManager)
{
public int CbfIscScore { get => _cbfIscScore; private set => SetProperty(ref _cbfIscScore, value); }
public int AdcIscScore { get => _adcIscScore; private set => SetProperty(ref _adcIscScore, value); }
private int _cbfIscScore;
private int _adcIscScore;
private const int MaxScore = 10;
private const float Threshold = 100.0f / 3;
protected override void UpdateDiagnosis()
{
CbfIscScore = CalculateScores(GetSelectedRoiExpanderGroupControlViewModel("CBF-IC")?.RoiViewModelCollection.Items);
AdcIscScore = CalculateScores(GetSelectedRoiExpanderGroupControlViewModel("ADC-IC")?.RoiViewModelCollection.Items);
}
private static int CalculateScores(IEnumerable<RoiExpanderControlViewModel>? roiCollection)
{
if (roiCollection == null) return MaxScore;
int score = MaxScore - roiCollection.Where(roiExpanderControlViewModel => roiExpanderControlViewModel.IsChecked)
.SelectMany(roiExpanderControlViewModel => roiExpanderControlViewModel.Locations)
.GroupBy(roiLocationDataViewModel => roiLocationDataViewModel.Name, roiLocationDataViewModel => roiLocationDataViewModel)
.Where(group => !group.Key.StartsWith("M") || group.Select(x => x.RegionPercentage).Sum() > Threshold)
.Sum(group => group.First().Weight);
//Just in case
return Math.Clamp(score, 0, MaxScore);
}
}