82 lines
2.2 KiB
C#
82 lines
2.2 KiB
C#
using System.Collections.ObjectModel;
|
|
using System.IO;
|
|
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
using JetBrains.Annotations;
|
|
using Livia.Models.Data;
|
|
using Livia.ViewModels;
|
|
|
|
namespace iBrain.ViewModels;
|
|
|
|
public readonly record struct FeatureDataDisplay
|
|
{
|
|
public string Name { get; init; }
|
|
public double Value { get; init; }
|
|
public string Reference { get; init; }
|
|
public string Note { get; init; }
|
|
public int ColorCode { get; init; }
|
|
}
|
|
|
|
public record struct FeatureData
|
|
{
|
|
[UsedImplicitly, JsonPropertyName("featureChineseName")]
|
|
public string FeatureChineseName { get; init; }
|
|
|
|
[UsedImplicitly, JsonPropertyName("featureValue")]
|
|
public double FeatureValue { get; init; }
|
|
|
|
[UsedImplicitly, JsonPropertyName("remark")]
|
|
public int Trend { get; init; }
|
|
|
|
[UsedImplicitly, JsonPropertyName("range")]
|
|
public string Range { get; init; }
|
|
}
|
|
|
|
|
|
public class FeatureDataGridControlViewModel : ILiviaModuleViewModel
|
|
{
|
|
public ObservableCollection<FeatureDataDisplay> RegionsCollection { get; } = [];
|
|
public string LoadPath { get; set; } = string.Empty;
|
|
|
|
public async Task LoadData(DataBlock dataBlock)
|
|
{
|
|
if (string.IsNullOrEmpty(LoadPath))
|
|
return;
|
|
|
|
RegionsCollection.Clear();
|
|
|
|
string file = Path.Combine(dataBlock.ResultPath, LoadPath);
|
|
await using FileStream openStream = File.OpenRead(file);
|
|
List<FeatureData>? featureList = await JsonSerializer.DeserializeAsync<List<FeatureData>>(openStream);
|
|
|
|
if (featureList == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
foreach (FeatureData data in featureList)
|
|
{
|
|
|
|
FeatureDataDisplay featureDataDisplay = new()
|
|
{
|
|
Name = data.FeatureChineseName,
|
|
Value = data.FeatureValue,
|
|
Reference = data.Range,
|
|
Note = data.Trend switch
|
|
{
|
|
-1 => "↓",
|
|
1 => "↑",
|
|
_ => "-"
|
|
},
|
|
ColorCode = data.Trend
|
|
};
|
|
|
|
RegionsCollection.Add(featureDataDisplay);
|
|
}
|
|
|
|
}
|
|
|
|
public void Init()
|
|
{
|
|
}
|
|
} |