/// <summary> Show an estimated countdown to a region's next update </summary> public async Task Run(string userAgent, Dictionary <string, string> userTags, bool interactiveLog = false) { dump = RepoRegionDump.Dump(userAgent, userTags); api = RepoApi.Api(userAgent); var regions = await dump.Regions(interactiveLog); var targetIndex = -1; // Get index of target region in list from dump targetIndex = regions.FindIndex(r => string.Equals(r.Name, targetRegion, StringComparison.InvariantCultureIgnoreCase)); if (targetIndex < 0) { throw new Exception("Target region not found"); } target = regions[targetIndex]; // A boolean indicating if the next update is major (true) or minor (false) nextUpdateIsMajor = TimeUtil.UnixLastMajorStart() < TimeUtil.UnixLastMinorStart(); // Length of the last update in seconds var lastUpdateTook = nextUpdateIsMajor ? await dump.MajorTook() : await dump.MinorTook(); // Select the most appropriate triggers for the target, given the length of the last update await Triggers(targetIndex, regions, lastUpdateTook); // For each trigger, an average "seconds-per-nation" value is calculated and appended to this list. As the // update goes faster or slower, these averages will change in between triggers. This can then be used // to determine variance (unpredictability of the update), which the user can use to better determine how // much risk they can take. secondsPerNation = new List <double> { // The first seconds-per-nation value is taken from the previous update nextUpdateIsMajor?await dump.MajorTick() : await dump.MinorTick() }; // Watch the triggers and target to adjust seconds-per-nation and exit when target updates await WatchTriggers(); }
/// <summary> Generate a report of likely military operations during the last (major or minor) update </summary> public async Task Run(string userAgent, Dictionary <string, string> userTags, bool interactiveLog = false) { Console.Write("Compiling operations report... \n"); api = RepoApi.Api(userAgent); regions = await RepoRegionDump.Dump(userAgent, userTags).Regions(); // Start and end of last (major or minor) update var updateStart = StartOfLastUpdate(); var updateEnd = await api.LastUpdateFor(regions.Last().Name); // Get happenings var delegateChangeHappenings = await api.DelegateChangesFrom(updateStart, updateEnd); // Parse each happening to the DelegacyChange DTO var delegacyChanges = DelegacyChanges(delegateChangeHappenings); // Filter out the suspicious changes from among the (supposedly) legitimate changes var ops = await FilterOps(delegacyChanges, updateEnd - 43200, userTags, interactiveLog); if (interactiveLog) { Console.Write("Saving to report... "); } // Generate report ops = ops.OrderBy(o => o.ChangeTimeStamp).ToList(); var report = Report(ops); // Save var date = TimeUtil.DateForPath(); Directory.CreateDirectory(date); await File.WriteAllTextAsync($"{date}/Kronos-Ops_{date}.md", report); if (interactiveLog) { Console.Write("[done].\n"); } }