// read all lines containing measurements from the log file, // save info in a list of structs // and change all measurements below threshold to ZERO private static List <MeasurementInfo> ReadAndNormalizeMeasurements(string logFilePath, double zeroThreshold) { var normalizedMeasurements = new List <MeasurementInfo>(); using (var logFile = new StreamReader(logFilePath)) { string line; while ((line = logFile.ReadLine()) != null) { if (!line.Contains(" - W: ")) { continue; } var splitLine = line.Split(' '); var measurementInfo = new MeasurementInfo(); measurementInfo.Time = splitLine[0]; measurementInfo.IsStable = (splitLine[4] == "T"); int.TryParse(splitLine[7], out var measurement); if (measurement < zeroThreshold) { measurement = 0; } measurementInfo.Measurement = measurement; normalizedMeasurements.Add(measurementInfo); } } return(normalizedMeasurements); }
public InspectionInfo Inspect(ImageInfo imageInfo) { var defectInfos = new DefectInfo[1024]; var measurementInfos = new MeasurementInfo[1024]; var inspectInfo = SimInspectorInteropApi.Inspect(imageInfo, defectInfos, measurementInfos); var iiEntity = new InspectionInfo { Index = inspectInfo.Index, SurfaceTypeIndex = inspectInfo.SurfaceTypeIndex, HasError = (inspectInfo.HasError != 0), }; for (int i = 0; i < inspectInfo.DefectsCount; i++) { var di = defectInfos[i]; // di.X = di.X - di.Width/2; // di.Y = di.Y - di.Height/2; iiEntity.DefectInfos.Add(di); } for (int i = 0; i < inspectInfo.MeasurementsCount; i++) { var di = measurementInfos[i]; iiEntity.MeasurementInfos.Add(di); } return(iiEntity); }
private static bool IsBetterFit(MeasurementInfo currentMeasurement, MeasurementInfo bestFit, double netWeight) { if (Math.Abs(currentMeasurement.Measurement - netWeight) < Math.Abs(bestFit.Measurement - netWeight)) { return(true); } return(false); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { JObject obj = JObject.Load(reader); MeasurementInfo info = new MeasurementInfo(); info.Instrument = obj["Instrument"].ToObject <Instrument>(serializer); info.MinReading = ReadPhysical(obj, "Min Reading", info.Instrument); info.MaxReading = ReadPhysical(obj, "Max Reading", info.Instrument); info.AmbientTemperature = ReadPhysical(obj, "Ambient Temperature", Instrument.Thermometer); return(info); }
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { MeasurementInfo info = (MeasurementInfo)value; JObject obj = new JObject(); obj.Add("Instrument", JToken.FromObject(info.Instrument, serializer)); WritePhysical(obj, "Min Reading", info.MinReading); WritePhysical(obj, "Max Reading", info.MaxReading); WritePhysical(obj, "Ambient Temperature", info.AmbientTemperature); obj.WriteTo(writer); }
private static void Main(string[] args) { SimInspectorInteropApi.Init(); SimInspectorInteropApi.LoadParameters(); var dis = new DefectInfo[1024]; var mis = new MeasurementInfo[1024]; var ii = SimInspectorInteropApi.Inspect(new ImageInfo(), dis, mis); Console.WriteLine("Press any key to exit!"); Console.ReadKey(); SimInspectorInteropApi.FreeObject(); }
private bool CreateField(MeasurementInfo info) { if (info.Type == UpdateMeasurementType.NewField) { info.FieldIndex = Model.Table.Fields.Add(info.Name, AttributeType.Double, info.Precision, info.Width); if (info.FieldIndex == -1) { MessageService.Current.Info("Failed to create field."); return(false); } } return(true); }
private static IList <MeasurementInfo> GetMeasurements(string url) { XmlDocument xmlDoc = XmlWebRequest(url); XmlElement root = xmlDoc.DocumentElement; XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable); nsmgr.AddNamespace("ns", Plugin.ApplicationNamespace); XmlElement errorNode = (XmlElement)root.SelectSingleNode("ns:error", nsmgr); if (errorNode != null) { throw new Exception(errorNode.InnerText); } IList <MeasurementInfo> measurements = new List <MeasurementInfo>(); XmlNodeList nodes = root.SelectNodes("ns:measure", nsmgr); if (nodes != null) { foreach (XmlNode node in nodes) { DateTime entryTime = DateTime.MinValue; XmlNode dateNode = node.SelectSingleNode("ns:date", nsmgr); if (dateNode != null) { try { entryTime = XmlConvert.ToDateTime(dateNode.InnerText, XmlDateTimeSerializationMode.Utc); } catch { } } if (entryTime == DateTime.MinValue) { continue; } MeasurementInfo info = new MeasurementInfo(entryTime); info.Source = MeasurementInfo.Parse(XmlNodeInnerText(node.SelectSingleNode("ns:source", nsmgr))); info.WeightKilograms = XmlNodeInnerTextFloatVal(node.SelectSingleNode("ns:weight", nsmgr)); info.HeightMeters = XmlNodeInnerTextFloatVal(node.SelectSingleNode("ns:height", nsmgr)); info.PercentFat = XmlNodeInnerTextFloatVal(node.SelectSingleNode("ns:percent-fat", nsmgr)); measurements.Add(info); } } return(measurements); }
public void Execute() { ITangraAstrometricSolution solution = m_Host.GetAstrometryProvider().GetCurrentFrameAstrometricSolution(); List <ITangraMatchedStar> matchedStars = solution.GetAllMatchedStars(); foreach (ITangraMatchedStar star in matchedStars) { if (star.CatalogStar != null) { List <MeasurementInfo> currentMeasurements; if (!m_MeasurementsPerStar.TryGetValue(star.CatalogStar.StarNo, out currentMeasurements)) { currentMeasurements = new List <MeasurementInfo>(); m_MeasurementsPerStar.Add(star.CatalogStar.StarNo, currentMeasurements); m_CatalogStars.Add(star.CatalogStar); } var mea = new MeasurementInfo() { Intensity = star.Intensity, PsfAmplitude = star.PSFAmplitude, ExcludedForHighResiduals = star.ExcludedForHighResidual, IsSaturated = star.IsSaturated }; var meaInfo = star as ITangraStarMeasurementInfo; if (meaInfo != null) { mea.MeaSignalMethod = meaInfo.MeaSignalMethod; mea.MeaBackgroundMethod = meaInfo.MeaBackgroundMethod; mea.MeaSingleApertureSize = meaInfo.MeaSingleApertureSize; mea.MeaBackgroundPixelCount = meaInfo.MeaBackgroundPixelCount; mea.MeaSaturationLevel = meaInfo.MeaSaturationLevel; } else { mea.MeaSignalMethod = PhotometryReductionMethod.Unknown; mea.MeaBackgroundMethod = BackgroundMethod.Unknown; mea.MeaSingleApertureSize = null; mea.MeaBackgroundPixelCount = 0; mea.MeaSaturationLevel = 0; } currentMeasurements.Add(mea); } } }
public Transport(uint max_speed, uint weight, uint power, double timeTo100) { _numberOfObjects++; if (timeTo100 <= 0 || (power * timeTo100 <= 5 * weight / 3.6 / 3.6)) { _maxSpeed = 0; _weight = 0; _power = 0; _timeTo100 = 0; } else { _maxSpeed = max_speed; _weight = weight; _power = power; _timeTo100 = timeTo100; } _measurement = new MeasurementInfo(); }
private bool TryOverwriteField(MeasurementInfo item) { var fields = Model.Table.Fields; if (Model.Table.Fields.Any(f => f.Name.ContainsIgnoreCase(item.Name))) { if ( !MessageService.Current.Ask( "Field name already exist: " + item.Name + Environment.NewLine + "Do you want to override it?")) { return(false); } int index = fields.IndexByName(item.Name); if (!fields.Remove(index)) { MessageService.Current.Info("Failed to remove field: " + item.Name); } } return(true); }
public override bool ViewOkClicked() { _areaInfo = View.AreaInfo; _lengthInfo = View.LengthInfo; if (!Validate()) { return(false); } if (!CreateField(_lengthInfo)) { return(false); } if (!CreateField(_areaInfo)) { return(false); } Calculate(); return(true); }
public static MeasurementInfoViewModel ToViewModel(this MeasurementInfo source) { var vm = source.Map <MeasurementInfo, MeasurementInfoViewModel>(); return(vm); }
/// <summary> /// This method goes through normalized measurements from back to front and /// detects / decides what were the measurements for each interval between consecutive zeroes. /// Zero measurements are usually triggers for reseting variables (if beginning) or /// adding a measurement to the final list (if ending a series of measurements). /// There are 3 things detected: /// Stable measurements within tolerance. Once this is detected we add it to list and noting more is done on that interval. /// Stable measurements not within tolerance. First potential candidate: a stable measurement close to scale unloading, but does not fit within tolerance. /// Best Guesses: Continously, independent if Stable or not we compare each measurement to the desired net weght. This is used when nothing stable is found. /// </summary> private static List <MeasurementInfo> ExtractFinalMeasurements(List <MeasurementInfo> normalizedMeasurements, double netWeight) { var measurementsDetected = false; var stableMeasurementFound = false; var finalMeasurements = new List <MeasurementInfo>(); var potentialMeasurementIndex = 0; var firstNonZeroIndex = 0; MeasurementInfo bestFit = new MeasurementInfo(); var tolerance = Settings.Default.ConfidenceLevel; for (var i = normalizedMeasurements.Count - 1; i >= 0; i--) { var currentMeasurement = normalizedMeasurements[i]; if (currentMeasurement.Measurement == 0) { if (measurementsDetected && !stableMeasurementFound) { if (potentialMeasurementIndex > 0) { finalMeasurements.Add(normalizedMeasurements[potentialMeasurementIndex]); potentialMeasurementIndex = 0; } else { // mark measurement as not stable by chainging milliseconds time to 42 bestFit.Time = bestFit.Time.Split(',')[0] + ",42"; finalMeasurements.Add(bestFit); } bestFit = new MeasurementInfo(); } measurementsDetected = false; stableMeasurementFound = false; } else { if (stableMeasurementFound) { continue; } if (IsBetterFit(currentMeasurement, bestFit, netWeight)) { bestFit = currentMeasurement; } if (!measurementsDetected) { measurementsDetected = true; firstNonZeroIndex = i; } // find the "first" aka last 4 stable measurements if (!currentMeasurement.IsStable || i <= 4) { continue; } // find if stable more than 3 if (normalizedMeasurements[i - 1].IsStable && normalizedMeasurements[i - 2].IsStable) { if (potentialMeasurementIndex == 0) { if (normalizedMeasurements[i - 3].IsStable && normalizedMeasurements[i - 4].IsStable) { if (firstNonZeroIndex - i < 10) { potentialMeasurementIndex = i - 2; } else if (firstNonZeroIndex - i < 15) { potentialMeasurementIndex = i - 2; } else if (firstNonZeroIndex - i < 20) { potentialMeasurementIndex = i - 2; } } } if (IsWithinSkewedTolerance(currentMeasurement.Measurement, netWeight, tolerance)) { stableMeasurementFound = true; finalMeasurements.Add(normalizedMeasurements[i - 1]); potentialMeasurementIndex = 0; bestFit = new MeasurementInfo(); } } } } finalMeasurements.Reverse(); return(finalMeasurements); }
public void Execute() { ITangraAstrometricSolution solution = m_Host.GetAstrometryProvider().GetCurrentFrameAstrometricSolution(); List<ITangraMatchedStar> matchedStars = solution.GetAllMatchedStars(); foreach (ITangraMatchedStar star in matchedStars) { if (star.CatalogStar != null) { List<MeasurementInfo> currentMeasurements; if (!m_MeasurementsPerStar.TryGetValue(star.CatalogStar.StarNo, out currentMeasurements)) { currentMeasurements = new List<MeasurementInfo>(); m_MeasurementsPerStar.Add(star.CatalogStar.StarNo, currentMeasurements); m_CatalogStars.Add(star.CatalogStar); } var mea = new MeasurementInfo() { Intensity = star.Intensity, PsfAmplitude = star.PSFAmplitude, ExcludedForHighResiduals = star.ExcludedForHighResidual, IsSaturated = star.IsSaturated }; var meaInfo = star as ITangraStarMeasurementInfo; if (meaInfo != null) { mea.MeaSignalMethod = meaInfo.MeaSignalMethod; mea.MeaBackgroundMethod = meaInfo.MeaBackgroundMethod; mea.MeaSingleApertureSize = meaInfo.MeaSingleApertureSize; mea.MeaBackgroundPixelCount = meaInfo.MeaBackgroundPixelCount; mea.MeaSaturationLevel = meaInfo.MeaSaturationLevel; } else { mea.MeaSignalMethod = PhotometryReductionMethod.Unknown; mea.MeaBackgroundMethod = BackgroundMethod.Unknown; mea.MeaSingleApertureSize = null; mea.MeaBackgroundPixelCount = 0; mea.MeaSaturationLevel = 0; } currentMeasurements.Add(mea); } } }
private static IList<MeasurementInfo> GetMeasurements(string url) { XmlDocument xmlDoc = XmlWebRequest(url); XmlElement root = xmlDoc.DocumentElement; XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable); nsmgr.AddNamespace("ns", Plugin.ApplicationNamespace); XmlElement errorNode = (XmlElement)root.SelectSingleNode("ns:error", nsmgr); if (errorNode != null) { throw new Exception(errorNode.InnerText); } IList<MeasurementInfo> measurements = new List<MeasurementInfo>(); XmlNodeList nodes = root.SelectNodes("ns:measure", nsmgr); if (nodes != null) { foreach (XmlNode node in nodes) { DateTime entryTime = DateTime.MinValue; XmlNode dateNode = node.SelectSingleNode("ns:date", nsmgr); if (dateNode != null) { try { entryTime = XmlConvert.ToDateTime(dateNode.InnerText, XmlDateTimeSerializationMode.Utc); } catch { } } if (entryTime == DateTime.MinValue) continue; MeasurementInfo info = new MeasurementInfo(entryTime); info.Source = MeasurementInfo.Parse(XmlNodeInnerText(node.SelectSingleNode("ns:source", nsmgr))); info.WeightKilograms = XmlNodeInnerTextFloatVal(node.SelectSingleNode("ns:weight", nsmgr)); info.HeightMeters = XmlNodeInnerTextFloatVal(node.SelectSingleNode("ns:height", nsmgr)); info.PercentFat = XmlNodeInnerTextFloatVal(node.SelectSingleNode("ns:percent-fat", nsmgr)); measurements.Add(info); } } return measurements; }