Glass server db updater & more!
This commit is contained in:
parent
e78fc06a89
commit
df292832b8
|
@ -61,11 +61,11 @@
|
||||||
"shimmeringvoid": {
|
"shimmeringvoid": {
|
||||||
"flake": false,
|
"flake": false,
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1744143898,
|
"lastModified": 1744146722,
|
||||||
"narHash": "sha256-JwcjV/uofAjyJs3xLJ57Uv7N7vkXDgovLjvwzKU5Qwo=",
|
"narHash": "sha256-qvh6UxyLbbaSrrpAJwW3fzA1YqrwnTUT8qj17poi0aY=",
|
||||||
"ref": "refs/heads/main",
|
"ref": "refs/heads/main",
|
||||||
"rev": "97fe5eded99a08f96e2d3f061199b0730331b60b",
|
"rev": "b6ab7c08daac587a1da5649cfdbc082ef2a01a20",
|
||||||
"revCount": 11,
|
"revCount": 13,
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "ssh://forgejo@ssh.git.moonythm.dev/prescientmoon/shimmeringvoid.git"
|
"url": "ssh://forgejo@ssh.git.moonythm.dev/prescientmoon/shimmeringvoid.git"
|
||||||
},
|
},
|
||||||
|
|
|
@ -25,7 +25,12 @@
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
packages = {
|
packages = {
|
||||||
inherit (pkgs) shimmeringmoon glass-bundler private-config;
|
inherit (pkgs)
|
||||||
|
shimmeringmoon
|
||||||
|
glass-bundler
|
||||||
|
private-config
|
||||||
|
glass-server-db-updater
|
||||||
|
;
|
||||||
default = pkgs.shimmeringmoon;
|
default = pkgs.shimmeringmoon;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -55,7 +60,7 @@
|
||||||
SHIMMERING_FONT_DIR = pkgs.shimmering-fonts;
|
SHIMMERING_FONT_DIR = pkgs.shimmering-fonts;
|
||||||
SHIMMERING_CC_DIR = pkgs.arcaea-ptt-data;
|
SHIMMERING_CC_DIR = pkgs.arcaea-ptt-data;
|
||||||
SHIMMERING_PRIVATE_CONFIG_DIR = pkgs.private-config;
|
SHIMMERING_PRIVATE_CONFIG_DIR = pkgs.private-config;
|
||||||
SHIMMERING_PRIVATE_COMPTIME_CONFIG_DIR = inputs.shimmeringdarkness;
|
SHIMMERING_COMPTIME_PRIVATE_CONFIG_DIR = inputs.shimmeringdarkness;
|
||||||
};
|
};
|
||||||
# }}}
|
# }}}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,6 @@
|
||||||
pkgs.fetchFromGitHub {
|
pkgs.fetchFromGitHub {
|
||||||
owner = "OllyDoge";
|
owner = "OllyDoge";
|
||||||
repo = "ASCPSongConstant";
|
repo = "ASCPSongConstant";
|
||||||
rev = "19e727711938239a42371d231d6fcd0d40a5f6b1";
|
rev = "f99de5d1b9b1e82f24a284d97e986d7bb4d0fd69";
|
||||||
sha256 = "12jxfbbkra5x7vqar615qq9l55vr7rd1bnzc2csp6l7rzz8x4930";
|
sha256 = "0vvl0852la65xkfxh4amrnh81m08v9aknlp73ifh7llxd1k6qb9q";
|
||||||
}
|
}
|
||||||
|
|
42
nix/glass-server-db-updater.nix
Normal file
42
nix/glass-server-db-updater.nix
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
{
|
||||||
|
arcaea-ptt-data,
|
||||||
|
lib,
|
||||||
|
makeWrapper,
|
||||||
|
python3,
|
||||||
|
stdenvNoCC,
|
||||||
|
symlinkJoin,
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
unpatched = stdenvNoCC.mkDerivation {
|
||||||
|
name = "glass-server-db-updater";
|
||||||
|
src = lib.fileset.toSource {
|
||||||
|
root = ../scripts;
|
||||||
|
fileset = lib.fileset.unions [ ../scripts/update-db-songs.py ];
|
||||||
|
};
|
||||||
|
|
||||||
|
nativeBuildInputs = [ makeWrapper ];
|
||||||
|
|
||||||
|
buildPhase = ''
|
||||||
|
runHook preBuild
|
||||||
|
echo "#!${python3}/bin/python" > glass-server-db-updater
|
||||||
|
cat $src/update-db-songs.py >> glass-server-db-updater
|
||||||
|
chmod +x glass-server-db-updater
|
||||||
|
runHook postBuild
|
||||||
|
'';
|
||||||
|
|
||||||
|
installPhase = ''
|
||||||
|
runHook preInstall
|
||||||
|
install -Dm755 glass-server-db-updater -t $out/bin/
|
||||||
|
runHook postInstall
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
in
|
||||||
|
symlinkJoin {
|
||||||
|
inherit (unpatched) name meta;
|
||||||
|
paths = [ unpatched ];
|
||||||
|
nativeBuildInputs = [ makeWrapper ];
|
||||||
|
postBuild = ''
|
||||||
|
wrapProgram $out/bin/glass-server-db-updater \
|
||||||
|
--set SHIMMERING_CC_DIR "${arcaea-ptt-data}"
|
||||||
|
'';
|
||||||
|
}
|
|
@ -14,4 +14,5 @@ final: prev: {
|
||||||
|
|
||||||
arcaea-ptt-data = final.callPackage ./cc-data.nix { };
|
arcaea-ptt-data = final.callPackage ./cc-data.nix { };
|
||||||
shimmeringmoon = final.callPackage ./shimmeringmoon.nix { };
|
shimmeringmoon = final.callPackage ./shimmeringmoon.nix { };
|
||||||
|
glass-server-db-updater = final.callPackage ./glass-server-db-updater.nix { };
|
||||||
}
|
}
|
||||||
|
|
75
scripts/update-db-songs.py
Normal file
75
scripts/update-db-songs.py
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
import sqlite3
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
|
# Check if the correct number of arguments are provided
|
||||||
|
if len(sys.argv) != 2:
|
||||||
|
print("Usage: update-db-songs <db_file>")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# {{{ Collect data
|
||||||
|
json_file_path = f"{os.environ.get('SHIMMERING_CC_DIR')}/ptt.json"
|
||||||
|
db_file_path = sys.argv[1]
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open(json_file_path, "r") as json_file:
|
||||||
|
json_data = json.load(json_file)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error reading JSON file: {e}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
try:
|
||||||
|
conn = sqlite3.connect(db_file_path)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
except sqlite3.Error as e:
|
||||||
|
print(f"Error connecting to SQLite database: {e}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
cursor.execute("SELECT song_id FROM chart")
|
||||||
|
current_entries = {row[0] for row in cursor.fetchall()}
|
||||||
|
# }}}
|
||||||
|
# {{{ Print diff & delete entries
|
||||||
|
json_entries = set(json_data.keys())
|
||||||
|
removed_entries = current_entries - json_entries
|
||||||
|
if removed_entries:
|
||||||
|
print(f"Removed entries: {removed_entries}")
|
||||||
|
else:
|
||||||
|
print("No entries were removed.")
|
||||||
|
|
||||||
|
added_entries = json_entries - current_entries
|
||||||
|
if added_entries:
|
||||||
|
print(f"Added entries: {added_entries}")
|
||||||
|
else:
|
||||||
|
print("No new entries were added.")
|
||||||
|
|
||||||
|
cursor.execute("DELETE FROM chart")
|
||||||
|
# }}}
|
||||||
|
# {{{ Add new entries
|
||||||
|
for song_id, ratings in json_data.items():
|
||||||
|
cursor.execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO chart(song_id)
|
||||||
|
VALUES (?)
|
||||||
|
""",
|
||||||
|
[song_id],
|
||||||
|
)
|
||||||
|
|
||||||
|
for rating_type, rating_value in ratings.items():
|
||||||
|
rating_column = ["prs", "pst", "ftr", "byn", "etr"][int(rating_type)]
|
||||||
|
rating_column = f"rating_{rating_column}"
|
||||||
|
cursor.execute(
|
||||||
|
f"""
|
||||||
|
UPDATE chart
|
||||||
|
SET {rating_column}=?
|
||||||
|
WHERE song_id=?
|
||||||
|
""",
|
||||||
|
(rating_value, song_id),
|
||||||
|
)
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
# }}}
|
||||||
|
|
||||||
|
# Print final status
|
||||||
|
print("Database updated successfully.")
|
|
@ -188,20 +188,27 @@ pub fn import_songlist(
|
||||||
};
|
};
|
||||||
|
|
||||||
song_count += 1;
|
song_count += 1;
|
||||||
transaction.execute(
|
transaction
|
||||||
"
|
.execute(
|
||||||
|
"
|
||||||
INSERT INTO songs(id,title,shorthand,artist,side,bpm)
|
INSERT INTO songs(id,title,shorthand,artist,side,bpm)
|
||||||
VALUES (?,?,?,?,?,?)
|
VALUES (?,?,?,?,?,?)
|
||||||
",
|
",
|
||||||
(
|
(
|
||||||
song.id,
|
song.id,
|
||||||
song.title.get(),
|
song.title.get(),
|
||||||
&song.shorthand,
|
&song.shorthand,
|
||||||
&song.artist,
|
&song.artist,
|
||||||
Side::SIDES[song.side as usize],
|
Side::SIDES[song.side as usize],
|
||||||
song.bpm,
|
song.bpm,
|
||||||
),
|
),
|
||||||
)?;
|
)
|
||||||
|
.with_context(|| {
|
||||||
|
anyhow!(
|
||||||
|
"Failed to create song \"{}\" from songlist file",
|
||||||
|
song.title.get(),
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
|
||||||
for chart in song.difficulties {
|
for chart in song.difficulties {
|
||||||
if chart.rating == 0 {
|
if chart.rating == 0 {
|
||||||
|
@ -251,24 +258,36 @@ pub fn import_songlist(
|
||||||
anyhow!("Cannot find PTT data for song '{}' [{}]", name, difficulty)
|
anyhow!("Cannot find PTT data for song '{}' [{}]", name, difficulty)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
transaction.execute(
|
transaction
|
||||||
"
|
.execute(
|
||||||
|
"
|
||||||
INSERT INTO charts(
|
INSERT INTO charts(
|
||||||
song_id, title, difficulty,
|
song_id, title, difficulty,
|
||||||
level, note_count, chart_constant,
|
level, note_count, chart_constant,
|
||||||
note_design
|
note_design
|
||||||
) VALUES(?,?,?,?,?,?,?)
|
) VALUES(?,?,?,?,?,?,?)
|
||||||
",
|
",
|
||||||
(
|
(
|
||||||
song.id,
|
song.id,
|
||||||
chart.title.as_ref().map(|t| t.get()),
|
chart.title.as_ref().map(|t| t.get()),
|
||||||
difficulty,
|
difficulty,
|
||||||
level,
|
level,
|
||||||
notecount,
|
notecount,
|
||||||
rating_as_fixed(cc),
|
rating_as_fixed(cc),
|
||||||
chart.chart_designer,
|
chart.chart_designer,
|
||||||
),
|
),
|
||||||
)?;
|
)
|
||||||
|
.with_context(|| {
|
||||||
|
anyhow!(
|
||||||
|
"Failed to create chart \"{}\" [{}] from songlist file",
|
||||||
|
chart
|
||||||
|
.title
|
||||||
|
.as_ref()
|
||||||
|
.map(|t| t.get())
|
||||||
|
.unwrap_or(song.title.get()),
|
||||||
|
difficulty,
|
||||||
|
)
|
||||||
|
})?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ use crate::context::Error;
|
||||||
pub const SPLIT_FACTOR: u32 = 8;
|
pub const SPLIT_FACTOR: u32 = 8;
|
||||||
pub const IMAGE_VEC_DIM: usize = (SPLIT_FACTOR * SPLIT_FACTOR * 3) as usize;
|
pub const IMAGE_VEC_DIM: usize = (SPLIT_FACTOR * SPLIT_FACTOR * 3) as usize;
|
||||||
pub const BITMAP_IMAGE_SIZE: u32 = 174;
|
pub const BITMAP_IMAGE_SIZE: u32 = 174;
|
||||||
pub const JACKET_RECOGNITITION_DIMENSIONS: usize = 20;
|
pub const JACKET_RECOGNITITION_DIMENSIONS: usize = 64;
|
||||||
|
|
||||||
// {{{ (Image => vector) encoding
|
// {{{ (Image => vector) encoding
|
||||||
#[allow(clippy::identity_op)]
|
#[allow(clippy::identity_op)]
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue