diff --git a/hosts/pochita/configuration.nix b/hosts/pochita/configuration.nix index 688920a..30149a6 100644 --- a/hosts/pochita/configuration.nix +++ b/hosts/pochita/configuration.nix @@ -27,6 +27,7 @@ services.wanikani-bypass-lessons.enable = true; services.wanikani-fetch-data.enable = true; + services.wanikani-stats.enable = true; # paperless is giving an error # services.paperless = { diff --git a/modules/services/default.nix b/modules/services/default.nix index bc459ac..440cfbd 100644 --- a/modules/services/default.nix +++ b/modules/services/default.nix @@ -17,5 +17,6 @@ ./vscode-server.nix ./wanikani-bypass-lessons.nix ./wanikani-fetch-data + ./wanikani-stats ]; } diff --git a/modules/services/wanikani-stats/app.py b/modules/services/wanikani-stats/app.py new file mode 100644 index 0000000..e03e9cc --- /dev/null +++ b/modules/services/wanikani-stats/app.py @@ -0,0 +1,30 @@ +import zipfile +import json +from pathlib import Path +import streamlit as st +import pandas as pd +import matplotlib.pyplot as plt + +DATA_DIR = Path("/var/lib/wanikani-logs") + +def load_data(): + records = [] + for zip_path in sorted(DATA_DIR.glob("wanikani_data_*.zip")): + st.write(f"Processing {zip_path.name}...") + # with zipfile.ZipFile(zip_path) as z: + # for name in z.namelist(): + # with z.open(name) as f: + # data = json.load(f) + # date = zip_path.stem.split("_")[-1] + # # Adapt below to match your JSON structure + # record = { + # "date": date, + # "available_lessons": data.get("lessons", {}).get("available", 0), + # "level": data.get("level", 0), + # } + # records.append(record) + # return pd.DataFrame(records) + +st.title("📈 WaniKani Progress Tracker") +# df = load_data() +# st.line_chart(df.set_index("date")) \ No newline at end of file diff --git a/modules/services/wanikani-stats/default.nix b/modules/services/wanikani-stats/default.nix new file mode 100644 index 0000000..a64549c --- /dev/null +++ b/modules/services/wanikani-stats/default.nix @@ -0,0 +1,61 @@ +{ + pkgs, + config, + lib, + ... +}: +let + wanikani-stats-streamlit = pkgs.writeShellApplication { + name = "wanikani-stats-streamlit"; + runtimeInputs = [ + pkgs.python312.withPackages ( + ppkgs: + with pkgs.python312Packages; [ + pip + streamlit + ] + ) + ]; + text = '' + #!/usr/bin/env bash + exec streamlit run /path/to/your/wanikani_stats_app.py + ''; + }; +in +{ + options.services.wanikani-stats = { + enable = lib.mkEnableOption { + description = "Enable WaniKani Stats Service"; + default = false; + }; + + logDirectory = lib.mkOption { + type = lib.types.path; + default = "/var/lib/wanikani-logs"; + description = "Directory to get the log archives"; + }; + }; + + config = lib.mkIf config.services.wanikani-stats.enable { + # systemd.timers.wanikani-stats = { + # description = "WaniKani Stats Timer"; + # wantedBy = [ "timers.target" ]; + # timerConfig = { + # OnCalendar = "daily"; + # Persistent = true; + # }; + # }; + + systemd.services.wanikani-stats = { + description = "WaniKani Stats Service"; + serviceConfig = { + Type = "simple"; + ExecStart = "${lib.getExe wanikani-stats-streamlit}"; + Restart = "always"; + RestartSec = 60; + User = "root"; + Group = "root"; + }; + }; + }; +}