public override void Execute() { var currentRuleset = LegacyHelper.GetRulesetFromLegacyID(0); var allowedUsers = new List <string>(); var songsFolderPath = OsuPathUtils.GetSongsFolderPath(); if (ExtraUsernames != null) { allowedUsers.AddRange(ExtraUsernames); } OsuDb osuDb = OsuDb.Read(OsuPathUtils.GetOsuDbPath()); ScoresDb scoresDb = ScoresDb.Read(OsuPathUtils.GetOsuScoresDbPath()); Dictionary <string, string> checkSumToOsuFile = new Dictionary <string, string>(); foreach (var beatmap in osuDb.Beatmaps.Where(beatmap => beatmap.BeatmapChecksum != null && beatmap.RankedStatus == SubmissionStatus.Ranked)) { if (!checkSumToOsuFile.TryAdd(beatmap.BeatmapChecksum, songsFolderPath + "/" + beatmap.FolderName + "/" + beatmap.BeatmapFileName)) { Console.WriteLine("WARNING: beatmap " + beatmap.BeatmapFileName + " found multiple times in osu db"); } } string[] keys = scoresDb.Beatmaps.Keys.ToArray(); var allScoresBag = new ConcurrentBag <LocalReplayInfo>(); string[] keysToProcess = TestRun ? keys[..20] : keys;
static osuElements() { StoryboardFileRepository = Storyboard.FileReader(); SkinFileRepository = SkinFileReader.SkinReader(); BeatmapFileRepository = BeatmapFileReader.BeatmapReader(); ReplayFileRepository = Replay.FileReader(); CollectionDbRepository = CollectionDb.FileReader(); OsuDbRepository = OsuDb.FileReader(); ScoresDbRepository = ScoresDb.FileReader(); ApiReplayRepository = new ApiReplayRepository(); ApiBeatmapRepository = new ApiBeatmapRepository(); ApiReplayRepository = new ApiReplayRepository(); ApiUserRepository = new ApiUserRepository(); using (var osureg = Registry.ClassesRoot.OpenSubKey("osu\\DefaultIcon")) { if (osureg == null) { return; } var osukey = osureg.GetValue(null).ToString(); var osupath = osukey.Remove(0, 1); OsuDirectory = osupath.Remove(osupath.Length - 11); } }
private void LoadCollections() { if (loading) return; loading = true; System.Windows.Application.Current.Dispatcher.Invoke(() => { collections.Clear(); collections.Add(new Collection("loading...", new TimeSpan())); } ); //string path = @"D:\Program Files\osu"; CollectionDb collectionsdb = CollectionDb.Read(Path.Combine(osuPath, "collection.db")); ScoresDb scores = ScoresDb.Read(Path.Combine(osuPath, "scores.db")); OsuDb maps = OsuDb.Read(Path.Combine(osuPath, "osu!.db")); System.Windows.Application.Current.Dispatcher.Invoke(() => collections.Clear()); foreach (var coll in collectionsdb.Collections) { ObservableCollection<Map> loadedMaps = new ObservableCollection<Map>(); int totalPlayTime = 0; foreach (string hash in coll.BeatmapHashes) { int playCount; if (scores.Beatmaps.ContainsKey(hash)) playCount = scores.Beatmaps[hash].Count; else playCount = 0; var map = maps.Beatmaps.Where((a) => a.BeatmapChecksum == hash).FirstOrDefault(); if (map == null) continue; int length = map.DrainTimeSeconds; double stars = -1; if (map.DiffStarRatingStandard.Count > 0) stars = map.DiffStarRatingStandard[osu.Shared.Mods.None]; else if (map.DiffStarRatingCtB.Count > 0) stars = map.DiffStarRatingCtB[osu.Shared.Mods.None]; else if (map.DiffStarRatingMania.Count > 0) stars = map.DiffStarRatingMania[osu.Shared.Mods.None]; else if (map.DiffStarRatingTaiko.Count > 0) stars = map.DiffStarRatingTaiko[osu.Shared.Mods.None]; var loadedMap = new Map(map.Title + ' ' + '[' + map.Version + ']', stars, TimeSpan.FromSeconds(length * playCount)); loadedMaps.Add(loadedMap); totalPlayTime += length * playCount; } Collection loaded = new Collection(coll.Name, TimeSpan.FromSeconds(totalPlayTime)); loaded.Maps = loadedMaps; System.Windows.Application.Current.Dispatcher.Invoke(() => collections.Add(loaded)); } loading = false; }
public void ScoresTest() { var scoreDb = new ScoresDb(); var logger = new BasicLogger(); scoreDb.ReadFile(logger); var scores = scoreDb.ScoreLists.Sum(s => s.Replays.Count); }
public void Scores() { var scoresDb = new ScoresDb(); scoresDb.ReadFile(); //pathing works the same way as collectionDb var scorelists = scoresDb.ScoreLists; //these are the local replays, grouped by beatmaphash var hash = scorelists[0].MapHash; var shitmisses = scorelists[0].Replays.Where(s => s.CountMiss == 1); }
public void TestScoresDb(string file) { ScoresDb db = null; Assert.DoesNotThrow(() => db = new ScoresDb(file)); foreach (string name in db.scores.Values.SelectMany(s => s).Select(s => s.playerName).ToHashSet()) { Console.WriteLine(name); } }
private void AddOption(string key, string value) { if (value.Length > 0) { Settings.Add(key, value); } if (key == "osudir" && File.Exists(Path.Combine(value, "osu!.db"))) { Database = new OsuDbFile(Path.Combine(value, "osu!.db"), byHash: true); ScoresDb = new ScoresDb(Path.Combine(value, "scores.db")); HasDatabase = true; } }
private void AddOption(string key, string value) { if (value.Length > 0) { Settings.Add(key, value); if (key == "osudir" && File.Exists(Path.Combine(value, "osu!.db")) && File.Exists(Path.Combine(value, "scores.db")) && Directory.Exists(Path.Combine(value, "Data", "r"))) { Database = new OsuDbFile(Path.Combine(value, "osu!.db"), byHash: true); ScoresDb = new ScoresDb(Path.Combine(value, "scores.db")); OsuDirAccessible = true; } } }
public void ReadWriteScoresDb() { ScoresDb db; using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("UnitTestProject.Data.Scores.20210316.db")) db = ScoresDb.Read(stream); using var ms = new MemoryStream(); using var sw = new SerializationWriter(ms); db.WriteToStream(sw); ms.Position = 0; var read = ScoresDb.Read(ms); db.Should().BeEquivalentTo(read); }
/// <summary> /// Use scoresDb to generate collections based on accuracy. /// </summary> /// <param name="scoresDb"></param> /// <param name="seperators"></param> /// <param name="name"></param> /// <param name="collectionDb">Merge collections into existing collectionDb. Overwrites existing collections.</param> /// <returns></returns> public static CollectionDb GenerateCollectionDbByAccuracy(ScoresDb scoresDb, List <int> seperators, string name = null, string prefix = "", CollectionDb collectionDb = null) { List <Score> scores = new List <Score>(); foreach (BeatmapScores beatmapScores in scoresDb.GetBeatmapScores()) { Score topScore = null; if (string.IsNullOrWhiteSpace(name)) { topScore = beatmapScores.GetHighestScore(); } else { topScore = beatmapScores.GetHighestScore(name); } if (topScore != null) { scores.Add(topScore); } } List <Collection> collections = GenerateCollectionsByAccuracy(scores, seperators, prefix); CollectionDb colDb; if (collectionDb != null) { colDb = collectionDb; } else { colDb = new CollectionDb(20190620); } foreach (Collection collection in collections) { colDb.AddCollection(collection, AddMode.Overwrite); } return(colDb); }
public void ReadScoresDb() { ScoresDb db = ScoresDb.Read(OsuPath + "scores.db"); Debug.WriteLine("Version: " + db.OsuVersion); Debug.WriteLine("Amount of beatmaps: " + db.AmountOfBeatmaps); Debug.WriteLine("Amount of scores: " + db.AmountOfScores); string[] keys = db.Beatmaps.Keys.ToArray(); for (int i = 0; i < Math.Min(25, db.AmountOfBeatmaps); i++) //print 25 at most { string md5 = keys[i]; List <Replay> replays = db.Beatmaps[md5]; Debug.WriteLine($"Beatmap with md5 {md5} has replays:"); for (int j = 0; j < Math.Min(5, replays.Count); j++) //again, 5 at most { var r = replays[j]; Debug.WriteLine($"\tReplay by {r.PlayerName}, for {r.Score} score with {r.Combo}x combo. Played at {r.TimePlayed}"); } } }
public void ReadScoresDb() { using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("UnitTestProject.Data.Scores.20210316.db"); var db = ScoresDb.Read(stream); db.OsuVersion.Should().Be(20210316); db.Beatmaps.Should().HaveCount(8); db.Beatmaps.ContainsKey("f281f4cb1a1cf13f4456443a7725bff2").Should().BeTrue(); db.Beatmaps.ContainsKey("a0f3d86d32caaf0f3ed7474365ef830d").Should().BeTrue(); db.Beatmaps["f281f4cb1a1cf13f4456443a7725bff2"].Should().HaveCount(1); db.Beatmaps["a0f3d86d32caaf0f3ed7474365ef830d"].Should().HaveCount(2); var replay = db.Beatmaps["f281f4cb1a1cf13f4456443a7725bff2"][0]; // Equivalent to replay header replay.GameMode.Should().Be(GameMode.Standard); replay.OsuVersion.Should().Be(20210316); replay.BeatmapHash.Should().Be("f281f4cb1a1cf13f4456443a7725bff2"); replay.PlayerName.Should().Be("Ilex"); replay.ReplayHash.Should().Be("cc94fbdcd78ad26ff14bf906bf62336c"); replay.Count300.Should().Be(246); replay.Count100.Should().Be(66); replay.Count50.Should().Be(1); replay.CountGeki.Should().Be(49); replay.CountKatu.Should().Be(28); replay.CountMiss.Should().Be(22); replay.Combo.Should().Be(119); replay.Score.Should().Be(322376); replay.FullCombo.Should().BeFalse(); replay.Mods.Should().Be(Mods.NoFail); replay.TimePlayed.Should().BeAfter(new DateTime(2021, 4, 10, 18, 15, 05, DateTimeKind.Utc)) .And.BeBefore(new DateTime(2021, 4, 10, 18, 15, 06, DateTimeKind.Utc)); replay.ScoreId.Should().Be(0); replay.ReplayData.Should().BeNull(); }
// generate collections by accuracy private static object RunGenColByAccAndReturnExitCode(GenColByAccOptions opts) { // if online: // check if osu!.db present // check if key and name present // if offline: // check if scores.db present // if online: // collect list of all maps with scores that are ranked, loved or approved // collect list of all maps in osu!.db where // Grade achieved in standard // Grade achieved in taiko // Grade achieved in CTB // Grade achieved in mania // are not unplayed // use api to get scores // can use ranked_score to see if all maps // if local: get scores from scores.db // if name specified: can use ranked_score to see if all maps CollectionDb colDb = null; if (opts.Online) { if (string.IsNullOrWhiteSpace(opts.Key)) { throw new ArgumentException("Key is empty."); } if (string.IsNullOrWhiteSpace(opts.Name)) { throw new ArgumentException("Name is empty."); } if (!File.Exists(Path.Combine(opts.OsuPath, "osu!.db"))) { throw new FileNotFoundException("Missing osu!.db in selected folder."); } throw new NotImplementedException(); } else { string scoresDbPath = Path.Combine(opts.OsuPath, "scores.db"); if (!File.Exists(scoresDbPath)) { throw new FileNotFoundException("Missing scores.db in selected folder."); } ScoresDb scoresDb = new ScoresDb(scoresDbPath); List <int> seperators = new List <int>(opts.Seperators); colDb = CollectionTools.GenerateCollectionDbByAccuracy(scoresDb, seperators, opts.Name, opts.Prefix); } if (opts.MergeWithExisting) { string existingPath = Path.Combine(opts.OsuPath, "collection.db"); if (!File.Exists(existingPath)) { Console.WriteLine("Missing collection.db in selected folder. Skipping merge operation"); } else { CollectionDb existing = new CollectionDb(existingPath); existing.Merge(colDb, AddMode.Overwrite); colDb = existing; } } colDb.WriteToFile(opts.OutputFile); return(0); }