private void processBeatmap(int beatmapId, List <Ruleset> rulesets) { try { var localBeatmap = BeatmapLoader.GetBeatmap(beatmapId, Verbose, ForceDownload); if (localBeatmap == null) { reporter.Warn($"Beatmap {beatmapId} skipped (beatmap file not found)."); return; } using (var conn = MasterDatabase.GetConnection()) { if (Converts && localBeatmap.BeatmapInfo.RulesetID == 0) { foreach (var ruleset in rulesets) { computeDifficulty(beatmapId, localBeatmap, ruleset, conn); } } else if (rulesets.Any(r => r.RulesetInfo.ID == localBeatmap.BeatmapInfo.RulesetID)) { computeDifficulty(beatmapId, localBeatmap, localBeatmap.BeatmapInfo.Ruleset.CreateInstance(), conn); } } reporter.Verbose($"Difficulty updated for beatmap {beatmapId}."); } catch (Exception e) { reporter.Error($"{beatmapId} failed with: {e}"); } Interlocked.Increment(ref processedBeatmaps); }
private void processBeatmap(int beatmapId, List <Ruleset> rulesets) { try { reporter.Verbose($"Processing difficulty for beatmap {beatmapId}."); var localBeatmap = BeatmapLoader.GetBeatmap(beatmapId, Verbose, ForceDownload, reporter); if (localBeatmap == null) { reporter.Error($"Beatmap {beatmapId} skipped (beatmap file not found)."); return; } if (localBeatmap.Beatmap.HitObjects.Count == 0) { using (var conn = Database.GetSlaveConnection()) { if (conn?.QuerySingleOrDefault <int>("SELECT `approved` FROM `osu_beatmaps` WHERE `beatmap_id` = @BeatmapId", new { BeatmapId = beatmapId }) > 0) { reporter.Error($"Ranked beatmap {beatmapId} has 0 hitobjects!"); } } } using (var conn = Database.GetConnection()) { if (Converts && localBeatmap.BeatmapInfo.RulesetID == 0) { foreach (var ruleset in rulesets) { computeDifficulty(beatmapId, localBeatmap, ruleset, conn); } } else if (rulesets.Any(r => r.RulesetInfo.ID == localBeatmap.BeatmapInfo.RulesetID)) { computeDifficulty(beatmapId, localBeatmap, localBeatmap.BeatmapInfo.Ruleset.CreateInstance(), conn); } } reporter.Verbose($"Difficulty updated for beatmap {beatmapId}."); } catch (Exception e) { reporter.Error($"{beatmapId} failed with: {e.Message}"); } Interlocked.Increment(ref processedBeatmaps); }
protected override void ProcessResult(BeatmapItem item) { using (var db = GetDatabaseConnection()) { var beatmaps = db.Query <long>("SELECT beatmap_id FROM osu_beatmaps WHERE beatmapset_id = @beatmapset_id AND deleted_at IS NULL", item); foreach (long beatmapId in beatmaps) { var working = BeatmapLoader.GetBeatmap((int)beatmapId); if (working == null) { throw new Exception($"Couldn't download beatmap for {beatmapId}"); } // ensure the correct online id is set working.BeatmapInfo.OnlineBeatmapID = (int)beatmapId; calculator.ProcessBeatmap(working); } } }
public void OnExecute(CommandLineApplication app, IConsole console) { reporter = new Reporter(console, LogFile) { IsQuiet = Quiet, IsVerbose = Verbose }; if (Concurrency < 1) { reporter.Error("Concurrency level must be above 1."); return; } threadBeatmapIds = new int[Concurrency]; if (AppSettings.RUN_AS_SANDBOX_DOCKER) { reporter.Output("Waiting for database..."); while (true) { try { bool initialised = false; using (var conn = Database.GetConnection()) { if (conn.QuerySingle <int>("SELECT `count` FROM `osu_counts` WHERE `name` = 'docker_db_step'") >= 1) { initialised = true; } } if (initialised) { break; } } catch { } Thread.Sleep(1000); } } var beatmaps = new ConcurrentQueue <int>(GetBeatmaps() ?? Enumerable.Empty <int>()); totalBeatmaps = beatmaps.Count; var tasks = new Task[Concurrency]; for (int i = 0; i < Concurrency; i++) { int tmp = i; tasks[i] = Task.Factory.StartNew(() => { var calc = new ServerDifficultyCalculator(Rulesets, Converts, DryRun); while (beatmaps.TryDequeue(out int beatmapId)) { threadBeatmapIds[tmp] = beatmapId; reporter.Verbose($"Processing difficulty for beatmap {beatmapId}."); try { var beatmap = BeatmapLoader.GetBeatmap(beatmapId, Verbose, ForceDownload, reporter); // ensure the correct online id is set beatmap.BeatmapInfo.OnlineID = beatmapId; calc.ProcessBeatmap(beatmap); reporter.Verbose($"Difficulty updated for beatmap {beatmapId}."); } catch (Exception e) { reporter.Error($"{beatmapId} failed with {e}"); } Interlocked.Increment(ref processedBeatmaps); } }); } reporter.Output($"Processing {totalBeatmaps} beatmaps."); using (new Timer(_ => outputProgress(), null, 1000, 1000)) using (new Timer(_ => outputHealth(), null, 5000, 5000)) Task.WaitAll(tasks); if (AppSettings.RUN_AS_SANDBOX_DOCKER) { using (var conn = Database.GetConnection()) { conn.Execute("INSERT INTO `osu_counts` (`name`, `count`) VALUES (@Name, @Count) ON DUPLICATE KEY UPDATE `count` = @Count", new { Name = "docker_db_step", Count = 2 }); } } outputProgress(); reporter.Output("Done."); }