init the service
This commit is contained in:
parent
d6fd5c5e13
commit
48279ca657
4 changed files with 93 additions and 0 deletions
|
|
@ -27,6 +27,7 @@
|
||||||
|
|
||||||
services.wanikani-bypass-lessons.enable = true;
|
services.wanikani-bypass-lessons.enable = true;
|
||||||
services.wanikani-fetch-data.enable = true;
|
services.wanikani-fetch-data.enable = true;
|
||||||
|
services.wanikani-stats.enable = true;
|
||||||
|
|
||||||
# paperless is giving an error
|
# paperless is giving an error
|
||||||
# services.paperless = {
|
# services.paperless = {
|
||||||
|
|
|
||||||
|
|
@ -17,5 +17,6 @@
|
||||||
./vscode-server.nix
|
./vscode-server.nix
|
||||||
./wanikani-bypass-lessons.nix
|
./wanikani-bypass-lessons.nix
|
||||||
./wanikani-fetch-data
|
./wanikani-fetch-data
|
||||||
|
./wanikani-stats
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
30
modules/services/wanikani-stats/app.py
Normal file
30
modules/services/wanikani-stats/app.py
Normal file
|
|
@ -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"))
|
||||||
61
modules/services/wanikani-stats/default.nix
Normal file
61
modules/services/wanikani-stats/default.nix
Normal file
|
|
@ -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";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue