Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 51 additions & 5 deletions Views/Stats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ private static bool IsAlreadyRunning() {
private int GoldMedals, SilverMedals, BronzeMedals, PinkMedals, EliminatedMedals;
private int CustomAndCasualGoldMedals, CustomAndCasualSilverMedals, CustomAndCasualBronzeMedals, CustomAndCasualPinkMedals, CustomAndCasualEliminatedMedals;
private int nextShowID;
private bool isUpcomingShowUpdated;
private bool loadingExisting;
private bool updateFilterType, updateFilterRange;
private DateTime customfilterRangeStart = DateTime.MinValue;
Expand Down Expand Up @@ -300,7 +301,7 @@ private static bool IsAlreadyRunning() {
private readonly object dbTaskLock = new object();
public List<Task> dbTasks = new List<Task>();

private readonly int currentDbVersion = 132;
private readonly int currentDbVersion = 133;

public readonly string[] PublicShowIdList = {
"main_show",
Expand Down Expand Up @@ -781,13 +782,22 @@ private void UpdateUpcomingShow(bool updateViaGitHub) {

if (isCacheUpdated) {
lock (this.StatsDB) {
List<RoundInfo> roundInfoList = (from ri in this.RoundDetails.FindAll()
where this.UpcomingShowCache.Exists(u => string.Equals(u.LevelId, ri.Name)) &&
string.IsNullOrEmpty(ri.CreativeShareCode)
select ri).ToList();
foreach (RoundInfo ri in roundInfoList) {
ri.CreativeShareCode = this.UpcomingShowCache.Find(u => string.Equals(u.LevelId, ri.Name)).ShareCode;
}
Task updateUpcomingShowTask = new Task(() => {
this.StatsDB.BeginTrans();
this.RoundDetails.Update(roundInfoList);
this.UpcomingShow.DeleteAll();
this.UpcomingShow.InsertBulk(this.UpcomingShowCache);
this.StatsDB.Commit();
});
this.RunDatabaseTask(updateUpcomingShowTask, false);
this.isUpcomingShowUpdated = true;
}
}
} else {
Expand Down Expand Up @@ -851,13 +861,22 @@ private void UpdateUpcomingShow(bool updateViaGitHub) {

if (isCacheUpdated) {
lock (this.StatsDB) {
List<RoundInfo> roundInfoList = (from ri in this.RoundDetails.FindAll()
where this.UpcomingShowCache.Exists(u => string.Equals(u.LevelId, ri.Name)) &&
string.IsNullOrEmpty(ri.CreativeShareCode)
select ri).ToList();
foreach (RoundInfo ri in roundInfoList) {
ri.CreativeShareCode = this.UpcomingShowCache.Find(u => string.Equals(u.LevelId, ri.Name)).ShareCode;
}
Task updateUpcomingShowTask = new Task(() => {
this.StatsDB.BeginTrans();
this.RoundDetails.Update(roundInfoList);
this.UpcomingShow.DeleteAll();
this.UpcomingShow.InsertBulk(this.UpcomingShowCache);
this.StatsDB.Commit();
});
this.RunDatabaseTask(updateUpcomingShowTask, false);
this.isUpcomingShowUpdated = true;
}
}
} else {
Expand Down Expand Up @@ -905,13 +924,22 @@ private void UpdateUpcomingShow(bool updateViaGitHub) {

if (isCacheUpdated) {
lock (this.StatsDB) {
List<RoundInfo> roundInfoList = (from ri in this.RoundDetails.FindAll()
where this.UpcomingShowCache.Exists(u => string.Equals(u.LevelId, ri.Name)) &&
string.IsNullOrEmpty(ri.CreativeShareCode)
select ri).ToList();
foreach (RoundInfo ri in roundInfoList) {
ri.CreativeShareCode = this.UpcomingShowCache.Find(u => string.Equals(u.LevelId, ri.Name)).ShareCode;
}
Task updateUpcomingShowTask = new Task(() => {
this.StatsDB.BeginTrans();
this.RoundDetails.Update(roundInfoList);
this.UpcomingShow.DeleteAll();
this.UpcomingShow.InsertBulk(this.UpcomingShowCache);
this.StatsDB.Commit();
});
this.RunDatabaseTask(updateUpcomingShowTask, false);
this.isUpcomingShowUpdated = true;
}
}
this.CurrentSettings.UpcomingShowVersion = upcomingShow.version;
Expand All @@ -926,7 +954,7 @@ private void UpdateUpcomingShow(bool updateViaGitHub) {
}

private void GenerateLevelStats() {
lock (this.UpcomingShowCache) {
if (this.UpcomingShowCache.Any()) {
var sortedUpcomingShows = this.UpcomingShowCache.OrderByDescending(u => u.AddDate).ToList();
foreach (var level in sortedUpcomingShows) {
if (!LevelStats.ALL.ContainsKey(level.LevelId)) {
Expand Down Expand Up @@ -965,9 +993,10 @@ private void UpdateDatabaseOnline(bool initJob) {

this.CheckDatabaseUpdateViaGitHub();
this.UpdateUpcomingShow(false);
this.GenerateLevelStats();
lock (this.UpcomingShowCache) {
if (this.UpcomingShowCache.Any()) {
if (this.isUpcomingShowUpdated) {
this.isUpcomingShowUpdated = false;
this.GenerateLevelStats();
lock (this.StatLookup) {
this.StatLookup = LevelStats.ALL.ToDictionary(entry => entry.Key, entry => entry.Value);
}
Expand All @@ -984,9 +1013,10 @@ private void UpdateDatabaseOnline(bool initJob) {
this.SortGridDetails(true);
});
}
this.ResetStats();
IsOverlayRoundInfoNeedRefresh = true;
}
}
IsOverlayRoundInfoNeedRefresh = true;
this.UpdateDatabaseOnlineJob(initJob);
}

Expand Down Expand Up @@ -2010,6 +2040,22 @@ private void UpdateDatabaseDateFormat() {
private void UpdateDatabaseVersion() {
for (int version = this.CurrentSettings.Version; version < currentDbVersion; version++) {
switch (version) {
case 132: {
if (this.UpcomingShowCache.Any()) {
List<RoundInfo> roundInfoList = (from ri in this.RoundDetails.FindAll()
where this.UpcomingShowCache.Exists(u => string.Equals(u.LevelId, ri.Name)) &&
string.IsNullOrEmpty(ri.CreativeShareCode)
select ri).ToList();

foreach (RoundInfo ri in roundInfoList) {
ri.CreativeShareCode = this.UpcomingShowCache.Find(u => string.Equals(u.LevelId, ri.Name)).ShareCode;
}
this.StatsDB.BeginTrans();
this.RoundDetails.Update(roundInfoList);
this.StatsDB.Commit();
}
break;
}
case 131: {
this.CurrentSettings.WinPerDayGraphStyle = 2;
break;
Expand Down