(position, load)
点作为image
存储在SQL Server中。每次机器敲击时,创建一个记录以存储该位置/负载图以及其他数据。
我需要将'图像'转换为数字进行分析。我计划在Spotfire中进行分析,因此可以在解决方案中使用任何Spotfire功能。
我有一个C#程序,它从SQL查询数据并将其转换为CSV;但是,我希望有一种方法可以跳过此步骤,直接在Spotfire中查询要查看/分析的点。
这个C#可以工作并完成我想要的工作。如何使用此(或某些变体)处理来自SQL的查询数据,以便用户在打开Spotfire文件之前不运行单独的“转换器”控制台应用程序?
// Return a list of points from an array of bytes:
public static IList<PositionLoadPoint> GetPositionLoadPoints(byte[] bytes)
{
IList<PositionLoadPoint> result = new List<PositionLoadPoint>();
int midIndex = bytes.Length / 2;
for (int i = 0; i < midIndex; i += 4)
{
byte[] load = new byte[4];
byte[] position = new byte[4];
Array.Copy(bytes, i, load, 0, 4);
Array.Copy(bytes, midIndex + i, position, 0, 4);
var point = new PositionLoadPoint(BitConverter.ToSingle(load, 0),
BitConverter.ToSingle(position, 0));
result.Add(point);
}
return result;
}
您可以使用CLR Table-Valued Function运行该C#代码并将二进制数据转换为结果集。
CLR TVF有一个返回集合的“init”方法,然后SQL将为返回集合的每个成员运行“FillRow”方法。 FillRow方法将对象转换为输出参数的“行”。例如:
using System;
using System.Data.Sql;
using Microsoft.SqlServer.Server;
using System.Collections;
using System.Data.SqlTypes;
using System.Diagnostics;
public class TabularEventLog
{
[SqlFunction(FillRowMethodName = "FillRow")]
public static IEnumerable InitMethod(String logname)
{
return new EventLog(logname).Entries;
}
public static void FillRow(Object obj, out SqlDateTime timeWritten, out SqlChars message, out SqlChars category, out long instanceId)
{
EventLogEntry eventLogEntry = (EventLogEntry)obj;
timeWritten = new SqlDateTime(eventLogEntry.TimeWritten);
message = new SqlChars(eventLogEntry.Message);
category = new SqlChars(eventLogEntry.Category);
instanceId = eventLogEntry.InstanceId;
}
}