public virtual bool TryParse(string xiRawData, out object xoData) { Assert.NonEmptyString(xiRawData, "xiRawData"); xoData = null; bool result = false; if (xiRawData.IndexOf('%') < 0 && xiRawData.IndexOf('#') < 0) { string [] vals = xiRawData.Split(Text.kComma, StringSplitOptions.RemoveEmptyEntries); if (vals.Length > 7) // run_no, frame_no, sensor_no, measurement_id, origin_id, time, x_pos, y_pos, var_x, cov_xy, cov_yx, var_y|<EOL> { xoData = new Data.Measurement(); Data.Measurement measurement = xoData as Data.Measurement; measurement.timestamp = DateTime.Now; double timestamp; if (double.TryParse(vals[5], out timestamp)) { measurement.rawTimestamp = (long)timestamp; } double val; if (double.TryParse(vals[2], out val)) { measurement.transmitterNumber = (int)val; } if (double.TryParse(vals[6], out val)) { measurement.xPos = val; } if (double.TryParse(vals[7], out val)) { measurement.yPos = val; } result = true; } } return(result); }
public virtual bool TryParse(string xiRawData, out object xoData) { Assert.NonEmptyString(xiRawData, "xiRawData"); xoData = null; bool result = false; // 0 1 2 3 4 5 6 7 8 9 10 // % MCR Scan-Number Time Bearing Range var_Bearing var_Range Sensor-ID Transmitter-ID SNR PFA // 11 12 13 14 15 16 // X-Sensor/Receiver Y-Sensor/Receiver Z-Sensor/Receiver Xdot-Sensor/Receiver Ydot-Sensor/Receiver Zdot-Sensor/Receiver // 17 18 19 20 21 22 // X-Transmitter Y-Transmitter Z-Transmitter Xdot-Transmitter Ydot-Transmitter Zdot-Transmitter if (xiRawData.IndexOf('%') < 0 && xiRawData.IndexOf('#') < 0) { string [] vals = xiRawData.Split(Text.kWhiteSpace, StringSplitOptions.RemoveEmptyEntries); if (vals.Length > 12) { xoData = new Data.Measurement(); Data.Measurement measurement = xoData as Data.Measurement; measurement.timestamp = DateTime.Now; double run; if (double.TryParse(vals[0], out run)) { measurement.run = (int)run; } double frameNo; if (double.TryParse(vals[1], out frameNo)) { measurement.frameNo = (int)frameNo; } double time; if (double.TryParse(vals[2], out time)) { measurement.time = time; } double sensorId; if (double.TryParse(vals[7], out sensorId)) { measurement.sensorId = (int)sensorId; } int transmitterId; if (int.TryParse(vals[8], out transmitterId)) { measurement.transmitterNumber = transmitterId; } int receiverId; if (int.TryParse(vals[7], out receiverId)) { measurement.receiverNumber = receiverId; } double bearing; double range; double varBearing; double varRange; double sensorXPos; double sensorYPos; if (double.TryParse(vals[3], out bearing) && double.TryParse(vals[4], out range) && double.TryParse(vals[5], out varBearing) && double.TryParse(vals[6], out varRange) && double.TryParse(vals[11], out sensorXPos) && double.TryParse(vals[12], out sensorYPos)) { measurement.xPos = range * Math.Cos(bearing) + sensorXPos; measurement.yPos = range * Math.Sin(bearing) + sensorYPos; measurement.bearing = bearing; measurement.range = range; measurement.sensorXPos = sensorXPos; measurement.sensorYPos = sensorYPos; // var_x = (double) (r * r * vaz * s * s + vr * c * c); // var_y = (double) (r * r * vaz * c * c + vr * s * s); // cov_xy = (double) ((vr - r * r * vaz) * s * c); measurement.covarianceMatrix = new double [2, 2]; measurement.covarianceMatrix[0, 0] = range * range * varBearing * Math.Sin(bearing) * Math.Sin(bearing) + varRange * Math.Cos(bearing) * Math.Cos(bearing); measurement.covarianceMatrix[0, 1] = (varRange - range * range * varBearing) * Math.Sin(bearing) * Math.Cos(bearing); measurement.covarianceMatrix[1, 0] = (varRange - range * range * varBearing) * Math.Sin(bearing) * Math.Cos(bearing); measurement.covarianceMatrix[1, 1] = range * range * varBearing * Math.Cos(bearing) * Math.Cos(bearing) + varRange * Math.Sin(bearing) * Math.Sin(bearing); } result = true; } } return(result); }
public virtual bool TryParse(string xiRawData, out object xoData) { Assert.NonEmptyString(xiRawData, "xiRawData"); xoData = null; bool result = false; // 0 1 2 3 4 5 6 7 8 9 10 // % MCR Scan-Number Time X-Position Y-Position var_X-Position var_Y-Position Sensor-ID Transmitter-ID SNR PFA // 11 12 13 14 15 16 // X-Sensor/Receiver Y-Sensor/Receiver Z-Sensor/Receiver Xdot-Sensor/Receiver Ydot-Sensor/Receiver Zdot-Sensor/Receiver // 17 18 19 20 21 22 // X-Transmitter Y-Transmitter Z-Transmitter Xdot-Transmitter Ydot-Transmitter Zdot-Transmitter if (xiRawData.IndexOf('%') < 0 && xiRawData.IndexOf('#') < 0) { string [] vals = xiRawData.Split(Text.kWhiteSpace, StringSplitOptions.RemoveEmptyEntries); if (vals.Length > 8) { xoData = new Data.Measurement(); Data.Measurement measurement = xoData as Data.Measurement; measurement.timestamp = DateTime.Now; double run; if (double.TryParse(vals[0], out run)) { measurement.run = (int)run; } double frameNo; if (double.TryParse(vals[1], out frameNo)) { measurement.frameNo = (int)frameNo; } double time; if (double.TryParse(vals[2], out time)) { measurement.time = time; } double sensorId; if (double.TryParse(vals[7], out sensorId)) { measurement.sensorId = (int)sensorId; } double val; if (double.TryParse(vals[3], out val)) { measurement.xPos = val; } if (double.TryParse(vals[4], out val)) { measurement.yPos = val; } int transmitterId; if (int.TryParse(vals[8], out transmitterId)) { measurement.transmitterNumber = transmitterId; } int receiverId; if (int.TryParse(vals[7], out receiverId)) { measurement.receiverNumber = receiverId; } // In the measurement file, var_X-Position and var_Y-Position are the diagonal element of the covariance matrix, and off-diagonal elements are zero. measurement.covarianceMatrix = new double [2, 2]; measurement.covarianceMatrix[0, 0] = 0.0; measurement.covarianceMatrix[0, 1] = 0.0; measurement.covarianceMatrix[1, 0] = 0.0; measurement.covarianceMatrix[1, 1] = 0.0; double value; if (double.TryParse(vals[5], out value)) { measurement.covarianceMatrix[0, 0] = value; } if (double.TryParse(vals[6], out value)) { measurement.covarianceMatrix[1, 1] = value; } result = true; } } return(result); }
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 // plot, 2, run_no, frame_no, sensor_no, measurement_id, origin_id, time, x_pos, y_pos, var_x, cov_xy, cov_yx, var_y, <EOL> // plot, 2, 1, 1, 0, 1, 1, 1294754983.4030, -1825.9523, -6508.7564, 383.8955, -97.5964, -97.5964, 63.3847, <EOL> public virtual bool TryParse(string xiRawData, out object xoData) { Assert.NonEmptyString(xiRawData, "xiRawData"); xoData = null; bool result = false; string [] values = xiRawData.Split(new char [] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (values.Length > 0 && values[0].Trim().CompareTo("plot") == 0) { bool eol = false; bool eot = false; bool eos = false; bool hasFields = values.Length > 2 && values[2].Trim().CompareTo("fields") == 0; if (!hasFields) { eol = values[values.Length - 1].CompareTo(DataProvider.kEol) == 0; if (!eol) { eot = values[values.Length - 1].CompareTo(DataProvider.kEot) == 0; if (!eot) { eos = values[values.Length - 1].CompareTo(DataProvider.kEos) == 0; } } } if (eol || eot || eos || hasFields) { Data.Measurement measurement = new Data.Measurement(); measurement.timestamp = DateTime.Now; if (eol || eot) { if (values.Length > 9) { int transmitterNumber; if (int.TryParse(values[4], out transmitterNumber)) { measurement.transmitterNumber = transmitterNumber; } if (eol) { long timestamp; if (long.TryParse(values[4], out timestamp)) { measurement.rawTimestamp = timestamp; } double value; if (double.TryParse(values[8], out value)) { measurement.xPos = value; } if (double.TryParse(values[9], out value)) { measurement.yPos = value; } measurement.operation = EDataOperation.eUpdateData; } else { measurement.operation = EDataOperation.eRemoveData; } xoData = measurement; result = true; } } else if (hasFields) { measurement.operation = EDataOperation.eAddData; xoData = measurement; result = true; } else if (eos) { measurement.operation = EDataOperation.eClearData; xoData = measurement; result = true; } } } return(result); }