/// <summary> /// Initializes a new instance of the <see cref="ProgressViewModel"/> class. /// </summary> public ProgressViewModel( GameData gameData, TelemetryClient telemetryClient, IDatabaseCommandFactory databaseCommandFactory, IUserSettingsProvider userSettingsProvider, ClaimsPrincipal user, UserManager <ApplicationUser> userManager, string progressUserName, string range) { this.ProgressUserName = progressUserName; var userId = userManager.GetUserId(user); string progressUserId = null; if (string.IsNullOrEmpty(progressUserName)) { progressUserId = userId; } else { var progressUser = AsyncHelper.RunSynchronously(async() => await userManager.FindByNameAsync(progressUserName)); if (progressUser != null) { progressUserId = AsyncHelper.RunSynchronously(async() => await userManager.GetUserIdAsync(progressUser)); } } if (string.IsNullOrEmpty(progressUserId)) { // If we didn't get data, it's a user that doesn't exist return; } var progressUserSettings = userSettingsProvider.Get(progressUserId); if (!progressUserId.Equals(userId, StringComparison.OrdinalIgnoreCase) && !progressUserSettings.AreUploadsPublic && !user.IsInRole("Admin")) { // Not permitted return; } var userSettings = userSettingsProvider.Get(userId); this.RangeSelector = new GraphRangeSelectorViewModel(range); var data = new ProgressData( gameData, telemetryClient, databaseCommandFactory, progressUserId, this.RangeSelector.Start, this.RangeSelector.End); if (!data.IsValid) { return; } var prominentGraphs = new List <GraphViewModel>(); this.TryAddGraph(prominentGraphs, "Souls Spent", data.SoulsSpentData, userSettings); this.TryAddGraph(prominentGraphs, "Titan Damage", data.TitanDamageData, userSettings); this.TryAddGraph(prominentGraphs, "Hero Souls Sacrificed", data.HeroSoulsSacrificedData, userSettings); this.TryAddGraph(prominentGraphs, "Total Ancient Souls", data.TotalAncientSoulsData, userSettings); this.TryAddGraph(prominentGraphs, "Transcendent Power", data.TranscendentPowerData, userSettings, 2); this.TryAddGraph(prominentGraphs, "Rubies", data.RubiesData, userSettings); this.TryAddGraph(prominentGraphs, "Highest Zone This Transcension", data.HighestZoneThisTranscensionData, userSettings); this.TryAddGraph(prominentGraphs, "Highest Zone Lifetime", data.HighestZoneLifetimeData, userSettings); this.TryAddGraph(prominentGraphs, "Ascensions This Transcension", data.AscensionsThisTranscensionData, userSettings); this.TryAddGraph(prominentGraphs, "Ascensions Lifetime", data.AscensionsLifetimeData, userSettings); var secondaryGraphs = new List <GraphViewModel>(); foreach (var pair in data.OutsiderLevelData) { this.TryAddGraph(secondaryGraphs, pair.Key, pair.Value, userSettings); } foreach (var pair in data.AncientLevelData) { this.TryAddGraph(secondaryGraphs, pair.Key, pair.Value, userSettings); } this.ProminentGraphs = prominentGraphs; this.SecondaryGraphs = secondaryGraphs; this.IsValid = true; }
/// <summary> /// Initializes a new instance of the <see cref="DashboardViewModel"/> class. /// </summary> public DashboardViewModel( GameData gameData, TelemetryClient telemetryClient, IDatabaseCommandFactory databaseCommandFactory, IUserSettingsProvider userSettingsProvider, ClaimsPrincipal user, UserManager <ApplicationUser> userManager) { var userId = userManager.GetUserId(user); var userSettings = userSettingsProvider.Get(userId); var startTime = DateTime.UtcNow.AddDays(-7); var data = new ProgressData( gameData, telemetryClient, databaseCommandFactory, userId, startTime, null); if (!data.IsValid) { return; } var dataSeries = data.SoulsSpentData; if (dataSeries.Count > 0) { this.ProgressSummaryGraph = new GraphData { Chart = new Chart { Type = ChartType.Line, }, Title = new Title { Text = "Souls Spent", }, XAxis = new Axis { TickInterval = 24 * 3600 * 1000, // one day Type = AxisType.Datetime, TickWidth = 0, GridLineWidth = 1, Labels = new Labels { Align = Align.Left, X = 3, Y = -3, Format = "{value:%m/%d}", }, }, YAxis = new Axis { Labels = new Labels { Align = Align.Left, X = 3, Y = 16, Format = "{value:.,0f}", }, ShowFirstLabel = false, Type = GetYAxisType(dataSeries, userSettings), }, Legend = new Legend { Enabled = false, }, Series = new Series[] { new Series { Color = Colors.PrimarySeriesColor, Data = dataSeries .Select(datum => new Point { X = datum.Key.ToJavascriptTime(), Y = datum.Value.ToString("F0"), }) .Concat(new[] { new Point { X = DateTime.UtcNow.ToJavascriptTime(), Y = dataSeries.Last().Value.ToString("F0"), }, }) .ToList(), }, }, }; } this.Follows = new List <string>(); var parameters = new Dictionary <string, object> { { "@UserId", userId }, }; const string GetUserFollowsCommandText = @" SELECT UserName FROM UserFollows INNER JOIN AspNetUsers ON UserFollows.FollowUserId = AspNetUsers.Id WHERE UserId = @UserId ORDER BY UserName ASC" ; using (var command = databaseCommandFactory.Create( GetUserFollowsCommandText, parameters)) using (var reader = command.ExecuteReader()) { while (reader.Read()) { this.Follows.Add(reader["UserName"].ToString()); } } this.IsValid = true; }
/// <summary> /// Initializes a new instance of the <see cref="CompareViewModel"/> class. /// </summary> public CompareViewModel( GameData gameData, TelemetryClient telemetryClient, IDatabaseCommandFactory databaseCommandFactory, IUserSettings userSettings, string userId1, string userName1, string userId2, string userName2, string range) { this.UserName1 = userName1; this.UserName2 = userName2; this.RangeSelector = new GraphRangeSelectorViewModel(range); var userData1 = new ProgressData( gameData, telemetryClient, databaseCommandFactory, userId1, this.RangeSelector.Start, this.RangeSelector.End); var userData2 = new ProgressData( gameData, telemetryClient, databaseCommandFactory, userId2, this.RangeSelector.Start, this.RangeSelector.End); if (!userData1.IsValid || !userData2.IsValid) { return; } var prominentGraphs = new List <GraphViewModel>(); this.TryAddGraph(prominentGraphs, "Souls Spent", this.UserName1, userData1.SoulsSpentData, this.UserName2, userData2.SoulsSpentData, userSettings); this.TryAddGraph(prominentGraphs, "Titan Damage", this.UserName1, userData1.TitanDamageData, this.UserName2, userData2.TitanDamageData, userSettings); this.TryAddGraph(prominentGraphs, "Hero Souls Sacrificed", this.UserName1, userData1.HeroSoulsSacrificedData, this.UserName2, userData2.HeroSoulsSacrificedData, userSettings); this.TryAddGraph(prominentGraphs, "Total Ancient Souls", this.UserName1, userData1.TotalAncientSoulsData, this.UserName2, userData2.TotalAncientSoulsData, userSettings); this.TryAddGraph(prominentGraphs, "Transcendent Power", this.UserName1, userData1.TranscendentPowerData, this.UserName2, userData2.TranscendentPowerData, userSettings, 2); this.TryAddGraph(prominentGraphs, "Rubies", this.UserName1, userData1.RubiesData, this.UserName2, userData2.RubiesData, userSettings); this.TryAddGraph(prominentGraphs, "Highest Zone This Transcension", this.UserName1, userData1.HighestZoneThisTranscensionData, this.UserName2, userData2.HighestZoneThisTranscensionData, userSettings); this.TryAddGraph(prominentGraphs, "Highest Zone Lifetime", this.UserName1, userData1.HighestZoneLifetimeData, this.UserName2, userData2.HighestZoneLifetimeData, userSettings); this.TryAddGraph(prominentGraphs, "Ascensions This Transcension", this.UserName1, userData1.AscensionsThisTranscensionData, this.UserName2, userData2.AscensionsThisTranscensionData, userSettings); this.TryAddGraph(prominentGraphs, "Ascensions Lifetime", this.UserName1, userData1.AscensionsLifetimeData, this.UserName2, userData2.AscensionsLifetimeData, userSettings); var secondaryGraphs = new List <GraphViewModel>(); foreach (var pair in userData1.OutsiderLevelData) { this.TryAddGraph(secondaryGraphs, pair.Key, this.UserName1, pair.Value, this.UserName2, userData2.OutsiderLevelData.SafeGet(pair.Key), userSettings); } foreach (var pair in userData1.AncientLevelData) { this.TryAddGraph(secondaryGraphs, pair.Key, this.UserName1, pair.Value, this.UserName2, userData2.AncientLevelData.SafeGet(pair.Key), userSettings); } this.ProminentGraphs = prominentGraphs; this.SecondaryGraphs = secondaryGraphs; this.IsValid = true; }