private void TelemetryStateUpdater(TelemetryState obj) { MethodInvoker dele = delegate() { pfd1.YawAngle = obj.Yaw; pfd1.RollAngle = obj.Roll; pfd1.PitchAngle = obj.Pitch; pfd1.Altitude = obj.Height; pfd1.AirSpeed = 100.0f * (float)Math.Sqrt(obj.SpeedY * obj.SpeedY + obj.SpeedX * obj.SpeedX + obj.SpeedZ * obj.SpeedZ); pfd1.VerticalSpeed = obj.SpeedZ * 100.0f; pfd1.Invalidate(); lbBar.Text = obj.Barometer.ToString(); gBattery.Value = obj.Battery; gTemp.Value = obj.Temperature; gSpeedX.Value = 100.0f * obj.SpeedX; gSpeedY.Value = 100.0f * obj.SpeedY; gSpeedZ.Value = 100.0f * obj.SpeedZ; gAccelX.Value = obj.AccelX; gAccelY.Value = obj.AccelY; gAccelZ.Value = obj.AccelZ; lblTime.Text = obj.FlyTime.ToString(); lblTof.Text = obj.TOF.ToString(); lblBatLow.Visible = obj.Battery <= 20; }; Invoke(dele); }
/// <summary> /// Post-Request processing /// </summary> /// <param name="context">type: IOwinContext</param> private void EndRequest(IOwinContext context) { if (HttpContext.Current == null) { return; } var startTime = ItemDecorator.GetInspectorInstance()[ItemDecorator.RequestStartTime]; if (startTime != null //// ignore non-user pings && TelemetryState.IsTelemetryEnabledUserAgent() //// ignore requests to specific paths && TelemetryState.IsTelemetryEnabledRequestPath() //// ignore requests to specific extensions && TelemetryState.IsTelemetryEnabledRequestExtension() //// make sure the portal is configured && this.IsPortalConfigured()) { var requestStartTime = (DateTime)startTime; var elapsedTime = DateTime.UtcNow - requestStartTime; MdmMetrics.RequestExecutionTimeMetric.LogValue((long)elapsedTime.TotalMilliseconds); var ag = PerformanceAggregateLogger.GetPerformanceAggregate(); if (ag != null) { PerformanceEventSource.Log.PerformanceAggregate(ag, elapsedTime); } } }
/// <inheritdoc /> public void InitializeTargetFrameworkRules(ImmutableArray <ITargetFramework> targetFrameworks, IReadOnlyCollection <string> rules) { if (_stateByFramework == null) { return; } lock (_stateUpdateLock) { if (_stateByFramework == null) { return; } foreach (ITargetFramework targetFramework in targetFrameworks) { if (!_stateByFramework.TryGetValue(targetFramework, out TelemetryState telemetryState)) { telemetryState = _stateByFramework[targetFramework] = new TelemetryState(); } foreach (string rule in rules) { telemetryState.InitializeRule(rule); } } } }
public static TelemetryState ToTelemetryState(this Sim instance, DGConfig config, TelemetryState oldState) { var tState = new TelemetryState() { IsConnected = instance.Sdk.IsConnected, IsRunning = instance.Sdk.IsRunning, DriverMarker = instance.Sdk.GetTelemetryValue <bool>("DriverMarker").Value, OnPitRoad = instance.Sdk.GetTelemetryValue <bool>("OnPitRoad").Value, PlayerCarTowTime = instance.Sdk.GetTelemetryValue <float>("PlayerCarTowTime").Value, PlayerCarInPitStall = instance.Sdk.GetTelemetryValue <bool>("PlayerCarInPitStall").Value, LapsCompleted = instance.Sdk.GetTelemetryValue <int>("LapCompleted").Value, CurrentDriver = instance.Driver?.Name, TeamName = instance.Driver?.TeamName, CurrentSessionNumber = instance.CurrentSessionNumber, SubsessionId = instance.SessionData.SubsessionId }; tState.UpdateEvent = GetUpdateType(tState, oldState); foreach (KeyValuePair <string, ConfFormField> field in config.FormMapping) { object value; switch (field.Key) { case "UpdateEvent": value = tState.UpdateEvent; break; case "CurrentDriver": value = instance.Driver?.Name; break; case "TeamName": value = instance.Driver?.TeamName; break; case "CurrentSessionNumber": value = instance.CurrentSessionNumber; break; case "SubsessionId": value = instance.SessionData.SubsessionId; break; default: value = instance.Sdk.GetTelemetryValue <object>(field.Key)?.Value; break; } tState.Fields.Add(field.Key, new TelemetryFormField() { Name = field.Key, FormId = field.Value.FormId, SendOn = field.Value.SendOn, Value = value }); } return(tState); }
public IRacingMonitor(DGConfig config) { this.config = config; Sim.Instance.TelemetryUpdated += TelemetryUpdate; this.httpClient = new HttpClient(); this.state = new TelemetryState(); }
private async Task <SearchResult <IPackageSearchMetadata> > AggregateSearchResultsAsync( string searchText, IEnumerable <SearchResult <IPackageSearchMetadata> > results, TelemetryState telemetryState) { SearchResult <IPackageSearchMetadata> result; var nonEmptyResults = results.Where(r => r.Any()).ToArray(); if (nonEmptyResults.Length == 0) { result = SearchResult.Empty <IPackageSearchMetadata>(); } else if (nonEmptyResults.Length == 1) { result = SearchResult.FromItems(nonEmptyResults[0].Items); } else { var items = nonEmptyResults.Select(r => r.Items).ToArray(); var indexer = new RelevanceSearchResultsIndexer(); var aggregator = new SearchResultsAggregator(indexer, new PackageSearchMetadataSplicer()); var aggregatedItems = await aggregator.AggregateAsync( searchText, items); result = SearchResult.FromItems(aggregatedItems.ToArray()); // set correct count of unmerged items result.RawItemsCount = items.Aggregate(0, (r, next) => r + next.Count); } result.SourceSearchStatus = results .SelectMany(r => r.SourceSearchStatus) .ToDictionary(kv => kv.Key, kv => kv.Value); var cursors = results .Where(r => r.NextToken != null) .ToDictionary(r => r.SourceSearchStatus.Single().Key, r => r.NextToken); if (cursors.Keys.Any()) { result.NextToken = new AggregatedContinuationToken { TelemetryState = telemetryState, SearchString = searchText, SourceSearchCursors = cursors }; } return(result); }
protected void Session_Start(object sender, EventArgs e) { Session["init"] = 0; if (FeatureCheckHelper.IsFeatureEnabled(FeatureNames.TelemetryFeatureUsage) // ignore non-user pings && TelemetryState.IsTelemetryEnabledUserAgent() // ignore requests to and referred requests from specific paths && TelemetryState.IsTelemetryEnabledRequestPage() // only report this telemetry when the portal is configured && SetupConfig.IsPortalConfigured()) { PortalFeatureTrace.TraceInstance.LogSessionInfo(FeatureTraceCategory.SessionStart); } }
public override bool Equals(object obj) { bool result = false; if (obj is ConsoleState) { ConsoleState other = (ConsoleState)obj; result = Id.Equals(other.Id) && Connected.Equals(other.Connected) && TelemetryState.Equals(other.TelemetryState) && TelemetryInterval.Equals(other.TelemetryInterval) && ConsoleColor.Equals(other.ConsoleColor); } return(result); }
/// <summary> /// Initialize telemetry state with the set of rules we expect to observe for target framework /// </summary> public void InitializeTargetFrameworkRules(ITargetFramework targetFramework, IEnumerable <string> rules) { lock (_stateUpdateLock) { if (_stopTelemetry) { return; } TelemetryState telemetryState = _telemetryStates.GetOrAdd(targetFramework, (key) => new TelemetryState()); foreach (string rule in rules) { telemetryState.InitializeRule(rule); } } }
private static UpdateEvents GetUpdateType(TelemetryState newState, TelemetryState oldState) { // Tow start if (oldState.PlayerCarTowTime == 0 && newState.PlayerCarTowTime > 0) { return(UpdateEvents.TowStart); } // New Lap if (oldState.LapsCompleted < newState.LapsCompleted) { return(UpdateEvents.LapStart); } // Pit road entry if (!oldState.OnPitRoad && newState.OnPitRoad) { return(UpdateEvents.PitRdEntry); } // Pit Stop Start if (!oldState.PlayerCarInPitStall && newState.PlayerCarInPitStall) { return(UpdateEvents.PitStart); } // Pit stop end if (oldState.PlayerCarInPitStall && !newState.PlayerCarInPitStall) { return(UpdateEvents.PitFinish); } // Pit road exit if (oldState.OnPitRoad && !newState.OnPitRoad) { return(UpdateEvents.PitRdExit); } return(UpdateEvents.None); }
private async void TelemetryUpdate(object sender, SdkWrapper.TelemetryUpdatedEventArgs e) { List <long> myTimes = new List <long>(); var newState = Sim.Instance.ToTelemetryState(this.config, this.state); if (!String.IsNullOrWhiteSpace(this.config.FormUrl)) { if (newState.UpdateEvent != UpdateEvents.None) { var req = new HttpRequestMessage(HttpMethod.Post, this.config.FormUrl); req.Content = newState.GetForm(); await this.httpClient.SendAsync(req); Console.WriteLine("Posted to sheet @ {0}", DateTime.Now); } } this.state = newState; if (this.config.PostTelemetryToConsole) { this.Print(e.TelemetryInfo, string.Join(" | ", myTimes)); } }
private async Task <SearchResult <IPackageSearchMetadata> > WaitForCompletionOrBailOutAsync( string searchText, IDictionary <string, Task <SearchResult <IPackageSearchMetadata> > > searchTasks, TelemetryState telemetryState, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); if (searchTasks.Count == 0) { return(SearchResult.Empty <IPackageSearchMetadata>()); } var aggregatedTask = Task.WhenAll(searchTasks.Values); RefreshToken refreshToken = null; if (aggregatedTask != await Task.WhenAny(aggregatedTask, Task.Delay(DefaultTimeout))) { refreshToken = new AggregatedRefreshToken { TelemetryState = telemetryState, SearchString = searchText, SearchTasks = searchTasks, RetryAfter = DefaultTimeout }; } var partitionedTasks = searchTasks .ToLookup(t => t.Value.Status == TaskStatus.RanToCompletion); var completedOnly = partitionedTasks[true]; SearchResult <IPackageSearchMetadata> aggregated; IEnumerable <TimeSpan> timings = null; var timeAggregation = new Stopwatch(); if (completedOnly.Any()) { var results = await Task.WhenAll(completedOnly.Select(kv => kv.Value)); timings = results.Select(e => e.Duration); timeAggregation.Start(); aggregated = await AggregateSearchResultsAsync(searchText, results, telemetryState); timeAggregation.Stop(); } else { timings = Enumerable.Empty <TimeSpan>(); aggregated = SearchResult.Empty <IPackageSearchMetadata>(); } aggregated.OperationId = telemetryState?.OperationId; aggregated.RefreshToken = refreshToken; var notCompleted = partitionedTasks[false]; if (notCompleted.Any()) { var statuses = notCompleted.ToDictionary( kv => kv.Key, kv => GetLoadingStatus(kv.Value.Status)); foreach (var item in statuses) { aggregated.SourceSearchStatus.Add(item); } var exceptions = notCompleted .Where(kv => kv.Value.Exception != null) .ToDictionary( kv => kv.Key, kv => (Exception)kv.Value.Exception); foreach (var item in exceptions) { aggregated.SourceSearchException.Add(item); } } if (_telemetryService != null && aggregated.SourceSearchStatus != null && aggregated.SourceSearchStatus.Values != null && telemetryState != null) { var loadingStatus = aggregated.SourceSearchStatus.Values.Aggregate(); if (loadingStatus != LoadingStatus.Loading && telemetryState.ShouldEmit) { telemetryState.Duration.Stop(); _telemetryService.EmitTelemetryEvent(new SearchPageTelemetryEvent( telemetryState.OperationId, telemetryState.PageIndex, aggregated.Items?.Count ?? 0, telemetryState.Duration.Elapsed, timings, timeAggregation.Elapsed, loadingStatus)); } } return(aggregated); }
private TelemetryState ParseState(string[] pairs) { var state = new TelemetryState(); // pitch:-1;roll:0;yaw:-92;vgx:0;vgy:0;vgz:0;templ:47;temph:49;tof:10;h:0;bat:9;baro:93.10;time:0;agx:-23.00;agy:-8.00;agz:-995.00; float?temp = null; int some; foreach (var pair in pairs) { var tokens = pair.Split(':'); switch (tokens[0]) { case "pitch": state.Pitch = DegreeToValue(int.Parse(tokens[1])); break; case "roll": state.Roll = DegreeToValue(int.Parse(tokens[1])); break; case "yaw": state.Yaw = DegreeToValue(int.Parse(tokens[1])); break; case "vgx": state.SpeedX = int.Parse(tokens[1]) / 100.0f; break; case "vgy": state.SpeedY = int.Parse(tokens[1]) / 100.0f; break; case "vgz": state.SpeedZ = int.Parse(tokens[1]) / 100.0f; break; case "templ": some = int.Parse(tokens[1]); if (temp == null) { temp = some; } else { temp = (temp.Value + some) / 2.0f; } break; case "temph": some = int.Parse(tokens[1]); if (temp == null) { temp = some; } else { temp = (temp.Value + some) / 2.0f; } break; case "tof": state.TOF = int.Parse(tokens[1]) / 100.0f; break; case "h": state.Height = int.Parse(tokens[1]) / 100.0f; break; case "bat": state.Battery = int.Parse(tokens[1]); break; case "baro": state.Barometer = float.Parse(tokens[1]); break; case "time": state.FlyTime = int.Parse(tokens[1]); break; case "agx": state.AccelX = float.Parse(tokens[1]) / 100.0f; break; case "agy": state.AccelY = float.Parse(tokens[1]) / 100.0f; break; case "agz": state.AccelZ = float.Parse(tokens[1]) / 100.0f; break; default: break; } } state.Temperature = temp.GetValueOrDefault(); return(state); }
public override int GetHashCode() { return(Id.GetHashCode() + Connected.GetHashCode() + TelemetryState.GetHashCode() + TelemetryInterval.GetHashCode() + ConsoleColor.GetHashCode()); }