public async Task <SessionDetailDTO> Handle(GetSessionDetailByFileIdQuery request, CancellationToken cancellationToken) { var(fileName, fileBytes) = await _sessionService.DownloadAsset(request.FileId); if (fileName.EndsWith(".gz")) { fileBytes = fileBytes.Decompress(); } var session = JsonConvert.DeserializeObject <Session>(Encoding.UTF8.GetString(fileBytes)); var infos = session.Info.GetType().GetProperties().Where(p => p.GetCustomAttributes(false).Any(a => a is DescriptionAttribute)).ToDictionary(p => (p.GetCustomAttributes(false).First(a => a is DescriptionAttribute) as DescriptionAttribute)?.Description, p => Convert.ToString(p.GetValue(session.Info))); var sensorItems = SensorReport.GetReportFromSessionSensorData(session.Runs.Select(r => r.SensorData)).ToArray(); var frametimeStatisticsProviderOptions = new FrametimeStatisticProviderOptions() { MovingAverageWindowSize = 1000, FpsValuesRoundingDigits = 2 }; var plotSettings = new PlotSettings(); var frametimeStatisticProvider = new FrametimeStatisticProvider(frametimeStatisticsProviderOptions); var fpsGraphBuilder = new FpsGraphPlotBuilder(frametimeStatisticsProviderOptions, frametimeStatisticProvider); fpsGraphBuilder.BuildPlotmodel(session, plotSettings, 0, 1000, ERemoveOutlierMethod.None); var frametimeGraphBuilder = new FrametimePlotBuilder(frametimeStatisticsProviderOptions, frametimeStatisticProvider); frametimeGraphBuilder.BuildPlotmodel(session, plotSettings, 0, 1000, ERemoveOutlierMethod.None); var exporter = new SvgExporter { Width = 1000, Height = 400 }; using var frametimeGraphStream = new MemoryStream(); exporter.Export(frametimeGraphBuilder.PlotModel, frametimeGraphStream); using var fpsGraphStream = new MemoryStream(); exporter.Export(fpsGraphBuilder.PlotModel, fpsGraphStream); var frametimes = session.GetFrametimeTimeWindow(0, 1000, frametimeStatisticsProviderOptions, ERemoveOutlierMethod.None); var fpsTresholdsLabels = FrametimeStatisticProvider.FPSTHRESHOLDS.ToArray(); var fpsTresholdsCounts = frametimeStatisticProvider.GetFpsThresholdCounts(frametimes, false).Select(val => (double)val / frametimes.Count()).ToArray(); var fpsTresholdsCountsDictionary = Enumerable.Range(0, fpsTresholdsLabels.Count()).ToDictionary(idx => (int)fpsTresholdsLabels[idx], idx => fpsTresholdsCounts[idx]).Where(kvp => !double.IsNaN(kvp.Value)); var fpsTresholdsTimes = frametimeStatisticProvider.GetFpsThresholdTimes(frametimes, false).Select(val => val / frametimes.Sum()).ToArray(); var fpsTresholdsTimesDictionary = Enumerable.Range(0, fpsTresholdsLabels.Count()).ToDictionary(idx => (int)fpsTresholdsLabels[idx], idx => fpsTresholdsTimes[idx]).Where(kvp => !double.IsNaN(kvp.Value)); var fpsMetricDictionary = Enum.GetValues(typeof(EMetric)).Cast <EMetric>().ToDictionary(metric => metric.GetAttribute <DescriptionAttribute>().Description, metric => frametimeStatisticProvider.GetFpsMetricValue(frametimes, metric)).Where(kvp => !double.IsNaN(kvp.Value)); return(new SessionDetailDTO() { Infos = infos, SensorItems = sensorItems, FpsTresholdsCounts = fpsTresholdsCountsDictionary, FpsTresholdsTimes = fpsTresholdsTimesDictionary, FpsMetric = fpsMetricDictionary, FpsGraph = Encoding.UTF8.GetString(fpsGraphStream.ToArray()), FrametimeGraph = Encoding.UTF8.GetString(frametimeGraphStream.ToArray()) }); }
public void Construction() { SensorReport sr = new SensorReport(); LuminousIntensity li = new LuminousIntensity(sr); Assert.Equal <float>(0, li.Intensity); }
/// <summary> /// Creates a new instance of this class. /// </summary> /// <param name="report">The sensor report to evaluate.</param> public Acceleration3D( SensorReport report ) { this.acceleration[ (int)AccelerationAxis.X ] = (float)report.Values[ SensorPropertyKeys.SENSOR_DATA_TYPE_ACCELERATION_X_G.FormatId ][ 0 ]; this.acceleration[ (int)AccelerationAxis.Y ] = (float)report.Values[ SensorPropertyKeys.SENSOR_DATA_TYPE_ACCELERATION_Y_G.FormatId ][ 1 ]; this.acceleration[ (int)AccelerationAxis.Z ] = (float)report.Values[ SensorPropertyKeys.SENSOR_DATA_TYPE_ACCELERATION_Z_G.FormatId ][ 2 ]; }
/// <summary> /// Creates a new instance of this class. /// </summary> /// <param name="report">The sensor report to evaluate.</param> public Acceleration3D(SensorReport report) { this.acceleration[(int)AccelerationAxis.X] = (float)report.Values[SensorPropertyKeys.SENSOR_DATA_TYPE_ACCELERATION_X_G.FormatId][0]; this.acceleration[(int)AccelerationAxis.Y] = (float)report.Values[SensorPropertyKeys.SENSOR_DATA_TYPE_ACCELERATION_Y_G.FormatId][1]; this.acceleration[(int)AccelerationAxis.Z] = (float)report.Values[SensorPropertyKeys.SENSOR_DATA_TYPE_ACCELERATION_Z_G.FormatId][2]; }
private void MotionSensorOnMotionSensorTriggered(object sender, SensorReport e) { if (IsActive) { foreach (var powerPlug in _powerPlugs) { powerPlug.Switch(e.Value); } } }
private double GetHeading(SensorReport report) { if (report == null) { throw new ArgumentNullException("report"); } object val = report.Values[SensorDataKey][0]; return((double)val); }
/// <summary> /// Creates a new instance of this class. /// </summary> /// <param name="report">The sensor report to evaluate.</param> public Acceleration3D(SensorReport report) { if (report == null) { throw new ArgumentNullException("report"); } object val = report.Values[SensorPropertyKeys.SensorDataTypeAccelerationXG.FormatId][0]; this.acceleration[(int)AccelerationAxis.XAxis] = (double)report.Values[SensorPropertyKeys.SensorDataTypeAccelerationXG.FormatId][0]; this.acceleration[(int)AccelerationAxis.YAxis] = (double)report.Values[SensorPropertyKeys.SensorDataTypeAccelerationYG.FormatId][1]; this.acceleration[(int)AccelerationAxis.ZAxis] = (double)report.Values[SensorPropertyKeys.SensorDataTypeAccelerationZG.FormatId][2]; }
/// <summary> /// Creates a new instance of this class. /// </summary> /// <param name="report">The sensor report to evaluate.</param> internal OrientationSensorReading(SensorReport report) { if (report == null) { throw new ArgumentNullException("report"); } byte[] q = report.Values[SensorDataKey][0] as byte[]; byte[] m = report.Values[SensorDataKey][1] as byte[]; if (q != null && q.Length == 16) { Quaternion = new SensorQuaternion(q); } if (m != null && m.Length == 36) { RotationMatrix = new SensorRotationMatrix(m); } }
/// <summary> /// Initializes a new instance of the <see cref="WeTabSensorData"/> class. /// </summary> /// <param name="sensor">The sensor.</param> /// <param name="report">The report object.</param> public WeTabSensorData(Sensor sensor, SensorReport report) { // Get the message type int message = Convert.ToInt32(report.Values[GetMessage.FormatId][0]); switch (message) { case 0xea: Message = WeTabSensorMessage.RotationChanged; break; case 0x94: Message = WeTabSensorMessage.SensorButtonDown; break; case 0x95: Message = WeTabSensorMessage.SensorButtonUp; break; default: Message = WeTabSensorMessage.Unknown; break; } // To read the accelerometer rotation we need to update // the x,y,z properties DataFieldInfo[] info = { new DataFieldInfo(GetAcceleratorXRotation, "XLRX"), new DataFieldInfo(GetAcceleratorYRotation, "XLRY"), new DataFieldInfo(GetAcceleratorZRotation, "XLRZ") }; IDictionary <PropertyKey, object> result = sensor.SetProperties(info); XRotation = Convert.ToInt32(result[GetAcceleratorXRotation]); YRotation = Convert.ToInt32(result[GetAcceleratorYRotation]); ZRotation = Convert.ToInt32(result[GetAcceleratorZRotation]); Orientation = CalculateOrientation(XRotation, YRotation, ZRotation); }
private ReportInfo GetReportInfoFromRecordInfo(IFileRecordInfo recordInfo) { var session = _recordManager.LoadData(recordInfo.FullPath); double GeMetricValue(IList <double> sequence, EMetric metric) => _frametimeStatisticProvider.GetFpsMetricValue(sequence, metric); var frameTimes = session.Runs.SelectMany(r => r.CaptureData.MsBetweenPresents).ToList(); var recordTime = session.Runs.SelectMany(r => r.CaptureData.TimeInSeconds).Last(); var max = GeMetricValue(frameTimes, EMetric.Max); var p99_quantile = GeMetricValue(frameTimes, EMetric.P99); var p95_quantile = GeMetricValue(frameTimes, EMetric.P95); var average = GeMetricValue(frameTimes, EMetric.Average); var median = GeMetricValue(frameTimes, EMetric.Median); var p0dot1_quantile = GeMetricValue(frameTimes, EMetric.P0dot1); var p0dot2_quantile = GeMetricValue(frameTimes, EMetric.P0dot2); var p1_quantile = GeMetricValue(frameTimes, EMetric.P1); var p5_quantile = GeMetricValue(frameTimes, EMetric.P5); var p1_averageLow = GeMetricValue(frameTimes, EMetric.OnePercentLow); var p0dot1_averageLow = GeMetricValue(frameTimes, EMetric.ZerodotOnePercentLow); var min = GeMetricValue(frameTimes, EMetric.Min); var adaptiveStandardDeviation = GeMetricValue(frameTimes, EMetric.AdaptiveStd); var cpuFpsPerWatt = _frametimeStatisticProvider .GetPhysicalMetricValue(frameTimes, EMetric.CpuFpsPerWatt, SensorReport.GetAverageCpuPower(session.Runs.Select(run => run.SensorData), 0, double.PositiveInfinity)); //var gpuFpsPerWatt = _frametimeStatisticProvider // .GetPhysicalMetricValue(frameTimes, EMetric.GpuFpsPerWatt, // SensorReport.GetAverageGpuPower(session.Runs.Select(run => run.SensorData), // 0, double.PositiveInfinity)); var reportInfo = new ReportInfo() { Game = recordInfo.GameName, Resolution = recordInfo.Resolution, Date = recordInfo.CreationDate, Time = recordInfo.CreationTime, NumberOfSamples = frameTimes.Count, RecordTime = Math.Round(recordTime, 2).ToString(), Cpu = recordInfo.ProcessorName == null ? "" : recordInfo.ProcessorName.Trim(new Char[] { ' ', '"' }), GraphicCard = recordInfo.GraphicCardName == null ? "" : recordInfo.GraphicCardName.Trim(new Char[] { ' ', '"' }), Ram = recordInfo.SystemRamInfo == null ? "" : recordInfo.SystemRamInfo.Trim(new Char[] { ' ', '"' }), MaxFps = max, NinetyNinePercentQuantileFps = p99_quantile, NinetyFivePercentQuantileFps = p95_quantile, AverageFps = average, MedianFps = median, FivePercentQuantileFps = p5_quantile, OnePercentQuantileFps = p1_quantile, OnePercentLowAverageFps = p1_averageLow, ZeroDotTwoPercentQuantileFps = p0dot2_quantile, ZeroDotOnePercentQuantileFps = p0dot1_quantile, ZeroDotOnePercentLowAverageFps = p0dot1_averageLow, MinFps = min, AdaptiveSTDFps = adaptiveStandardDeviation, CpuFpsPerWatt = cpuFpsPerWatt, //GpuFpsPerWatt = gpuFpsPerWatt, CustomComment = recordInfo.Comment }; return(reportInfo); }
private void SetMetrics(ComparisonRecordInfoWrapper wrappedComparisonRecordInfo) { double startTime = FirstSeconds; double lastFrameStart = wrappedComparisonRecordInfo.WrappedRecordInfo.Session.Runs.SelectMany(r => r.CaptureData.TimeInSeconds).Last(); double endTime = LastSeconds > lastFrameStart ? lastFrameStart : lastFrameStart + LastSeconds; var frametimeTimeWindow = wrappedComparisonRecordInfo.WrappedRecordInfo.Session.GetFrametimeTimeWindow(startTime, endTime, _appConfiguration, ERemoveOutlierMethod.None); double GeMetricValue(IList <double> sequence, EMetric metric) => _frametimeStatisticProvider.GetFpsMetricValue(sequence, metric); if (SelectedFirstMetric == EMetric.CpuFpsPerWatt) { wrappedComparisonRecordInfo.WrappedRecordInfo.FirstMetric = _frametimeStatisticProvider.GetPhysicalMetricValue(frametimeTimeWindow, EMetric.CpuFpsPerWatt, SensorReport.GetAverageCpuPower(wrappedComparisonRecordInfo.WrappedRecordInfo.Session.Runs.Select(run => run.SensorData2), startTime, endTime)); } else if (SelectedFirstMetric == EMetric.GpuFpsPerWatt) { wrappedComparisonRecordInfo.WrappedRecordInfo.FirstMetric = _frametimeStatisticProvider.GetPhysicalMetricValue(frametimeTimeWindow, EMetric.GpuFpsPerWatt, SensorReport.GetAverageGpuPower(wrappedComparisonRecordInfo.WrappedRecordInfo.Session.Runs.Select(run => run.SensorData2), startTime, endTime)); } else { wrappedComparisonRecordInfo.WrappedRecordInfo.FirstMetric = GeMetricValue(frametimeTimeWindow, SelectedFirstMetric); } if (SelectedSecondMetric == EMetric.CpuFpsPerWatt) { wrappedComparisonRecordInfo.WrappedRecordInfo.SecondMetric = _frametimeStatisticProvider.GetPhysicalMetricValue(frametimeTimeWindow, EMetric.CpuFpsPerWatt, SensorReport.GetAverageCpuPower(wrappedComparisonRecordInfo.WrappedRecordInfo.Session.Runs.Select(run => run.SensorData2), startTime, endTime)); } else if (SelectedSecondMetric == EMetric.GpuFpsPerWatt) { wrappedComparisonRecordInfo.WrappedRecordInfo.SecondMetric = _frametimeStatisticProvider.GetPhysicalMetricValue(frametimeTimeWindow, EMetric.GpuFpsPerWatt, SensorReport.GetAverageGpuPower(wrappedComparisonRecordInfo.WrappedRecordInfo.Session.Runs.Select(run => run.SensorData2), startTime, endTime)); } else { wrappedComparisonRecordInfo.WrappedRecordInfo.SecondMetric = GeMetricValue(frametimeTimeWindow, SelectedSecondMetric); } if (SelectedThirdMetric == EMetric.CpuFpsPerWatt) { wrappedComparisonRecordInfo.WrappedRecordInfo.ThirdMetric = _frametimeStatisticProvider.GetPhysicalMetricValue(frametimeTimeWindow, EMetric.CpuFpsPerWatt, SensorReport.GetAverageCpuPower(wrappedComparisonRecordInfo.WrappedRecordInfo.Session.Runs.Select(run => run.SensorData2), startTime, endTime)); } else if (SelectedThirdMetric == EMetric.GpuFpsPerWatt) { wrappedComparisonRecordInfo.WrappedRecordInfo.ThirdMetric = _frametimeStatisticProvider.GetPhysicalMetricValue(frametimeTimeWindow, EMetric.GpuFpsPerWatt, SensorReport.GetAverageGpuPower(wrappedComparisonRecordInfo.WrappedRecordInfo.Session.Runs.Select(run => run.SensorData2), startTime, endTime)); } else { wrappedComparisonRecordInfo.WrappedRecordInfo.ThirdMetric = GeMetricValue(frametimeTimeWindow, SelectedThirdMetric); } }