private static void CalculateTanksReferences(DateTime?lastReferencesXbox, DateTime?lastReferencesPs, DbProvider provider, DbRecorder recorder, MailSender mailSender, string resultDirectoryXbox, string resultDirectoryPs, FtpPutter ftpPutterXbox, FtpPutter ftpPutterPs, int utcShiftToCalculate) { var csw = Stopwatch.StartNew(); recorder.CalculateReference(utcShiftToCalculate); csw.Stop(); Log.Debug($"Cálculo das Referências de Tanques feito em {csw.Elapsed.TotalSeconds:N0}."); if (csw.Elapsed.TotalMinutes > 1) { mailSender.Send("Cálculo das Referências de Tanques", $"Cálculo das Referências de Tanques feito em {csw.Elapsed.TotalSeconds:N0}."); } if (lastReferencesXbox.HasValue) { PutTanksReferencesOnPlataform(Platform.XBOX, lastReferencesXbox, provider, mailSender, resultDirectoryXbox, ftpPutterXbox, utcShiftToCalculate); } if (lastReferencesPs.HasValue) { PutTanksReferencesOnPlataform(Platform.PS, lastReferencesPs, provider, mailSender, resultDirectoryPs, ftpPutterPs, utcShiftToCalculate); } }
public ValueTask ExecuteAsync(IConsole console) { Log.Info($"Starting {nameof(CalculateStats)}..."); var csw = Stopwatch.StartNew(); _recorder.CalculateReference(UtcShiftToCalculate, MaxDates); csw.Stop(); Log.Debug($"Statistics for tanks calculated in {csw.Elapsed.TotalSeconds:N0}s."); // Get the last one to see of there's the need to upload to the remote site var siteDiagnostic = _fetcher.GetSiteDiagnostic(); var lastLeaderboard = siteDiagnostic.TankLeadersLastDate; Log.Info($"Last leaderboard on site: {lastLeaderboard:yyyy-MM-dd}"); var cd = DateTime.UtcNow.AddHours(UtcShiftToCalculate); var previousMonday = cd.PreviousDayOfWeek(DayOfWeek.Monday); Log.Info($"Previous Monday: {previousMonday:yyyy-MM-dd}"); if (previousMonday <= lastLeaderboard) { Log.Info("No need to upload."); return(default);
private static void CalculateAndPutReferences() { var connectionString = ConfigurationManager.ConnectionStrings["Main"].ConnectionString; var provider = new DbProvider(connectionString); var recorder = new DbRecorder(connectionString); var cacheDirectory = ConfigurationManager.AppSettings["CacheDirectory"]; var wargamingApplicationId = ConfigurationManager.AppSettings["WgAppId"]; var wotClansAdminApiKey = ConfigurationManager.AppSettings["ApiAdminKey"]; var webCacheAge = TimeSpan.FromMinutes(1); var fetcher = new Fetcher(cacheDirectory) { WebCacheAge = webCacheAge, WebFetchInterval = TimeSpan.FromSeconds(1), WargamingApplicationId = wargamingApplicationId, WotClansAdminApiKey = wotClansAdminApiKey, WotClansBaseUrl = "http://localhost/ClanStatsWeb" }; var putter = new Putter(wotClansAdminApiKey) { BaseUrl = "http://localhost/ClanStatsWeb" }; const int utcShiftToCalculate = -7; const int topLeaders = 50; const int maxParallel = 1; recorder.CalculateReference(utcShiftToCalculate); var siteDiagnostic = fetcher.GetSiteDiagnostic(); var lastLeaderboard = siteDiagnostic.TankLeadersLastDate; Log.Info($"Last leaderboard on site: {lastLeaderboard:yyyy-MM-dd}"); var cd = DateTime.UtcNow.AddHours(utcShiftToCalculate); var previousMonday = cd.PreviousDayOfWeek(DayOfWeek.Monday); Log.Info($"Previous Monday: {previousMonday:yyyy-MM-dd}"); if (previousMonday <= lastLeaderboard) { Log.Info("No need to upload."); return; } Log.Info($"Getting tanks stats for {previousMonday:yyyy-MM-dd}..."); var references = provider.GetTanksReferences(previousMonday, null, true, false, true, topLeaders).ToArray(); Log.Debug($"Data for {references.Length} tanks retrieved."); var leaders = new ConcurrentBag <Leader>(); Parallel.For(0, references.Length, new ParallelOptions { MaxDegreeOfParallelism = maxParallel }, i => { var r = references[i]; Log.Debug($"Putting references for tank {r.Name}..."); if (!putter.Put(r)) { Log.Error($"Error putting tank reference files for tank {r.Name}."); } foreach (var leader in r.Leaders) { leaders.Add(leader); } }); var orderedLeaders = leaders.OrderByDescending(l => l.Tier).ThenBy(l => l.Type).ThenBy(l => l.Nation).ThenBy(l => l.Name).ThenBy(l => l.Order) .ToArray(); Log.Info($"Uploading leaderboard with {orderedLeaders.Length} players..."); if (!putter.Put(previousMonday, orderedLeaders)) { Log.Error("Error putting leaders to the server."); } }