init the service

This commit is contained in:
Osman Faruk Bayram 2025-07-31 17:22:11 +03:00
parent d6fd5c5e13
commit 48279ca657
4 changed files with 93 additions and 0 deletions

View file

@ -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 = {

View file

@ -17,5 +17,6 @@
./vscode-server.nix
./wanikani-bypass-lessons.nix
./wanikani-fetch-data
./wanikani-stats
];
}

View 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"))

View 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";
};
};
};
}