anonymize bpms

This commit is contained in:
Ash Garcia 2024-09-22 21:51:10 -07:00
parent 33376ab44b
commit 275f27155d

View file

@ -3,6 +3,7 @@ import csv
import _csv import _csv
from dataclasses import dataclass from dataclasses import dataclass
from datetime import datetime from datetime import datetime
from decimal import Decimal
import enum import enum
import os import os
from random import Random from random import Random
@ -22,6 +23,7 @@ import simfile
from simfile.dir import SimfilePack, SimfileDirectory from simfile.dir import SimfilePack, SimfileDirectory
from simfile.sm import SMChart, SMSimfile from simfile.sm import SMChart, SMSimfile
from simfile.ssc import SSCChart, SSCSimfile from simfile.ssc import SSCChart, SSCSimfile
from simfile.timing import BeatValues, BeatValue
from simfile.types import Simfile from simfile.types import Simfile
@ -456,6 +458,17 @@ def maybe_anonymize_entries(
os.remove(absolute_path) os.remove(absolute_path)
print(f"Deleted {os.path.relpath(absolute_path, temp_fs.root_path)}") print(f"Deleted {os.path.relpath(absolute_path, temp_fs.root_path)}")
def anonymize_bpms(bpm_str: str | None) -> str:
bpm_values = BeatValues.from_str(bpm_str)
bpm_values.append(
BeatValue(
beat=bpm_values[-1].beat + 10000,
value=bpm_values[-1].value + Decimal("0.001"),
)
)
print(f"Anonymized BPMs from {repr(bpm_str)} to {repr(str(bpm_values))}")
return str(bpm_values)
for row in csv_contents: for row in csv_contents:
if row[KnownColumns.IgnoreFile]: if row[KnownColumns.IgnoreFile]:
continue continue
@ -484,6 +497,7 @@ def maybe_anonymize_entries(
sm.cdtitle = "" sm.cdtitle = ""
sm.genre = "" sm.genre = ""
sm.music = f"{canonical_filename}.ogg" sm.music = f"{canonical_filename}.ogg"
sm.bpms = anonymize_bpms(sm.bpms)
for _chart in sm.charts: for _chart in sm.charts:
sm_chart: SMChart = _chart # typing workaround sm_chart: SMChart = _chart # typing workaround
sm_chart.description = row[KnownColumns.GeneratedAlias] sm_chart.description = row[KnownColumns.GeneratedAlias]
@ -505,12 +519,15 @@ def maybe_anonymize_entries(
ssc.cdimage = "" ssc.cdimage = ""
ssc.discimage = "" ssc.discimage = ""
ssc.labels = "" ssc.labels = ""
ssc.bpms = anonymize_bpms(ssc.bpms)
for _chart in ssc.charts: for _chart in ssc.charts:
ssc_chart: SSCChart = _chart # typing workaround ssc_chart: SSCChart = _chart # typing workaround
ssc_chart.description = "" ssc_chart.description = ""
ssc_chart.chartname = "" ssc_chart.chartname = ""
ssc_chart.chartstyle = "" ssc_chart.chartstyle = ""
ssc_chart.credit = row[KnownColumns.GeneratedAlias] ssc_chart.credit = row[KnownColumns.GeneratedAlias]
if ssc_chart.bpms:
ssc_chart.bpms = anonymize_bpms(ssc_chart.bpms)
maybe_rename_file(simfile_dir.ssc_path, f"{canonical_filename}.ssc") maybe_rename_file(simfile_dir.ssc_path, f"{canonical_filename}.ssc")
print( print(
f"Scrubbed {os.path.relpath(absolute_simfile_dir_path, temp_fs.root_path)}/{canonical_filename}.ssc" f"Scrubbed {os.path.relpath(absolute_simfile_dir_path, temp_fs.root_path)}/{canonical_filename}.ssc"