def test_parse_breaks(self): # Tokyo [Nhawak's Beginner]. path = os.path.join(TEST_BEATMAPS_DIR, "valid_breaks.osu") beatmap = Beatmap.from_osu_file(path) self.assertEqual("tokyo.mp3", beatmap.audio_path) self.assertEqual(801333, beatmap.id) self.assertAlmostEqual(1, beatmap.hp) self.assertAlmostEqual(2.5, beatmap.cs) self.assertAlmostEqual(1, beatmap.od) self.assertAlmostEqual(2, beatmap.ar) training_labels = beatmap.get_training_labels() self.assertEqual(2, len(training_labels)) labels = training_labels[0] self.assert_expected_labels([(HitObjectType.SLIDER, 32), (HitObjectType.SILENCE, 16)], labels) self.assert_expected_labels([(HitObjectType.SPINNER, 32), (HitObjectType.SILENCE, 7), (HitObjectType.HIT_CIRCLE, 1)], labels, from_ending=True) labels = training_labels[1] self.assert_expected_labels([(HitObjectType.SLIDER, 32), (HitObjectType.SILENCE, 16)], labels) self.assert_expected_labels([(HitObjectType.SPINNER, 32), (HitObjectType.SILENCE, 7), (HitObjectType.HIT_CIRCLE, 1)], labels, from_ending=True) self.assertTrue(len(training_labels[0]) > len(training_labels[1]))
def test_parse_no_breaks(self): # Take a Hint [Nelliel's Easy]. path = os.path.join(TEST_BEATMAPS_DIR, "valid_no_breaks.osu") beatmap = Beatmap.from_osu_file(path) self.assertEqual("audio.mp3", beatmap.audio_path) self.assertEqual(2060307, beatmap.id) self.assertAlmostEqual(2, beatmap.hp) self.assertAlmostEqual(3, beatmap.cs) self.assertAlmostEqual(2, beatmap.od) self.assertAlmostEqual(3, beatmap.ar) training_labels = beatmap.get_training_labels() self.assertEqual(1, len(training_labels)) labels = training_labels[0] self.assert_expected_labels([(HitObjectType.SLIDER, 8), (HitObjectType.SILENCE, 4), (HitObjectType.HIT_CIRCLE, 1), (HitObjectType.SILENCE, 3), (HitObjectType.SLIDER, 8), (HitObjectType.SILENCE, 4), (HitObjectType.HIT_CIRCLE, 1), (HitObjectType.SILENCE, 3), (HitObjectType.SLIDER, 8), (HitObjectType.SILENCE, 4), (HitObjectType.HIT_CIRCLE, 1), (HitObjectType.SILENCE, 3), (HitObjectType.SLIDER, 8), (HitObjectType.SILENCE, 8), (HitObjectType.SLIDER, 4), (HitObjectType.SILENCE, 4)], labels) self.assert_expected_labels([(HitObjectType.HIT_CIRCLE, 1), (HitObjectType.SILENCE, 4)], labels, from_ending=True) self.assertEqual(573, len(labels))
def process_osu_files(osu_dir, logger): beatmap_infos = [] for file in os.listdir(osu_dir): if is_osu_file(file): full_path = os.path.join(osu_dir, file) try: beatmap = Beatmap.from_osu_file(full_path) beatmap_infos.append((beatmap, full_path)) logger.debug(f"Processed beatmap [{file}] successfully.") except Exception as e: # Beatmap doesn't meet training data criteria. logger.debug(f"Skipping beatmap [{file}]: {e}") return beatmap_infos
import os from osu.audio.audio_preprocessor import AudioPreprocessor from osu.beatmap.beatmap import Beatmap from osu.difficulty.difficulty_properties import DifficultyProperties from osu.training.utils import is_osu_file, training_path training_folder = training_path() for beatmapset in os.listdir(training_folder): beatmapset_path = os.path.join(training_folder, beatmapset) files = os.listdir(beatmapset_path) # Check that this is not just a marker for a failed beatmapset during collection. if len(files) > 0: onsets = AudioPreprocessor.read_training_audio(beatmapset_path) difficulty_json = DifficultyProperties.read_training_star_difficulties( beatmapset_path) for file in files: if is_osu_file(file): osu_file = os.path.join(beatmapset_path, file) beatmap = Beatmap.from_osu_file(osu_file) labels = beatmap.get_training_labels()
def test_late_starting_timing_point(self): path = os.path.join(TEST_BEATMAPS_DIR, "late_starting_timing_point.osu") Beatmap.from_osu_file(path)
def test_parse_wrong_divisor(self): # Missing beatmpa id. path = os.path.join(TEST_BEATMAPS_DIR, "old_format.osu") with self.assertRaises(Exception): Beatmap.from_osu_file(path)
def test_parse_wrong_mode(self): path = os.path.join(TEST_BEATMAPS_DIR, "taiko.osu") with self.assertRaises(Exception): Beatmap.from_osu_file(path)
def test_rounding_error(self): path = os.path.join(TEST_BEATMAPS_DIR, "rounding_error.osu") Beatmap.from_osu_file(path) path = os.path.join(TEST_BEATMAPS_DIR, "rounding_error2.osu") Beatmap.from_osu_file(path)
def test_not_on_divisor(self): path = os.path.join(TEST_BEATMAPS_DIR, "not_on_divisor.osu") with self.assertRaises(Exception): Beatmap.from_osu_file(path)