cskmeans/SWITRS.cs

36 lines
1.3 KiB
C#
Raw Normal View History

2024-02-12 17:22:50 +00:00
using System.Collections.Generic;
2024-02-16 04:50:22 +00:00
using System.Data;
2024-02-12 17:22:50 +00:00
using System.IO;
using System.Linq;
using Microsoft.Data.Sqlite;
public class SWITRS
{
2024-02-16 04:50:22 +00:00
public static (string[], string?[], double[][]) LoadDataSet()
2024-02-12 17:22:50 +00:00
{
var qry = File.ReadAllText("query.sql");
2024-02-16 04:50:22 +00:00
List<string> identities = [];
List<string?> labels = [];
2024-02-12 17:22:50 +00:00
List<double>[] values = [];
using (var connection = new SqliteConnection("Data Source=switrs.sqlite"))
{
connection.Open();
var command = connection.CreateCommand();
command.CommandText = qry;
using (var reader = command.ExecuteReader())
{
2024-02-16 04:50:22 +00:00
values = new List<double>[reader.FieldCount - 2];
foreach (var cellId in Enumerable.Range(0, reader.FieldCount - 2))
2024-02-12 17:22:50 +00:00
values[cellId] = new List<double>();
while (reader.Read())
{
2024-02-16 04:50:22 +00:00
identities.Add(reader.GetString(0));
labels.Add(reader.IsDBNull(1) ? null : reader.GetString(1));
foreach (var cellId in Enumerable.Range(0, reader.FieldCount - 2))
values[cellId].Add(reader.GetDouble(cellId + 2));
2024-02-12 17:22:50 +00:00
}
}
}
2024-02-16 04:50:22 +00:00
return (identities.ToArray(), labels.ToArray(), values.Select(x => x.ToArray()).ToArray());
2024-02-12 17:22:50 +00:00
}
}