Skip to content

Commit

Permalink
Renamed CWA History page to CWA Stats, added Server Stats to Stats pa…
Browse files Browse the repository at this point in the history
…ge, fixed stat page css, starting to migrate CWA css to caliBlur_cwa.css as caliBlur.css is just way too big, repaired progress bar for EPUB Fixer
crocodilestick committed Jan 6, 2025

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
1 parent 9ab6661 commit 86bd29c
Showing 11 changed files with 276 additions and 230 deletions.
43 changes: 27 additions & 16 deletions root/app/calibre-web/cps/cwa_functions.py
Original file line number Diff line number Diff line change
@@ -19,6 +19,8 @@
from datetime import datetime
import re

from .web import cwa_get_num_books_in_library

import sys
sys.path.insert(1, '/app/calibre-web-automated/scripts/')
from cwa_db import CWA_DB
@@ -27,7 +29,7 @@
library_refresh = Blueprint('library_refresh', __name__)
convert_library = Blueprint('convert_library', __name__)
epub_fixer = Blueprint('epub_fixer', __name__)
cwa_history = Blueprint('cwa_history', __name__)
cwa_stats = Blueprint('cwa_stats', __name__)
cwa_check_status = Blueprint('cwa_check_status', __name__)
cwa_settings = Blueprint('cwa_settings', __name__)

@@ -193,6 +195,14 @@ def set_cwa_settings():
## ##
##————————————————————————————————————————————————————————————————————————————##

def get_cwa_stats() -> dict[str,int]:
"""Returns CWA stat totals as a dict (keys are table names except for total_books)"""
cwa_db = CWA_DB()
totals = cwa_db.get_stat_totals()
totals["total_books"] = cwa_get_num_books_in_library() # from web.py

return totals

### TABLE HEADERS
headers = {
"enforcement":{
@@ -213,10 +223,10 @@ def set_cwa_settings():
"Timestamp", "Filename", "Original Format", "End Format", "Original Backed Up?"],
}

@cwa_history.route("/cwa-history-show", methods=["GET", "POST"])
@cwa_stats.route("/cwa-history-show", methods=["GET", "POST"])
@login_required_if_no_ano
@admin_required
def cwa_history_show():
def cwa_stats_show():
cwa_db = CWA_DB()
data_enforcement = cwa_db.enforce_show(paths=False, verbose=False, web_ui=True)
data_enforcement_with_paths = cwa_db.enforce_show(paths=True, verbose=False, web_ui=True)
@@ -225,66 +235,67 @@ def cwa_history_show():
data_epub_fixer = cwa_db.get_epub_fixer_history(fixes=False, verbose=False)
data_epub_fixer_with_fixes = cwa_db.get_epub_fixer_history(fixes=True, verbose=False)

return render_title_template("cwa_history.html", title=_("Calibre-Web Automated Stats"), page="cwa-history",
return render_title_template("cwa_stats.html", title=_("Calibre-Web Automated Stats"), page="cwa-history",
cwa_stats=get_cwa_stats(),
data_enforcement=data_enforcement, headers_enforcement=headers["enforcement"]["no_paths"],
data_enforcement_with_paths=data_enforcement_with_paths,headers_enforcement_with_paths=headers["enforcement"]["with_paths"],
data_imports=data_imports, headers_import=headers["imports"],
data_conversions=data_conversions, headers_conversion=headers["conversions"],
data_epub_fixer=data_epub_fixer, headers_epub_fixer=headers["epub_fixer"]["no_fixes"],
data_epub_fixer_with_fixes=data_epub_fixer_with_fixes, headers_epub_fixer_with_fixes=headers["epub_fixer"]["with_fixes"])

@cwa_history.route("/cwa-history-show/full-enforcement", methods=["GET", "POST"])
@cwa_stats.route("/cwa-history-show/full-enforcement", methods=["GET", "POST"])
@login_required_if_no_ano
@admin_required
def show_full_enforcement():
cwa_db = CWA_DB()
data = cwa_db.enforce_show(paths=False, verbose=True, web_ui=True)
return render_title_template("cwa_history_full.html", title=_("Calibre-Web Automated - Full Enforcement History"), page="cwa-history-full",
return render_title_template("cwa_stats_full.html", title=_("Calibre-Web Automated - Full Enforcement History"), page="cwa-history-full",
table_headers=headers["enforcement"]["no_paths"], data=data)

@cwa_history.route("/cwa-history-show/full-enforcement-with-paths", methods=["GET", "POST"])
@cwa_stats.route("/cwa-history-show/full-enforcement-with-paths", methods=["GET", "POST"])
@login_required_if_no_ano
@admin_required
def show_full_enforcement_path():
cwa_db = CWA_DB()
data = cwa_db.enforce_show(paths=True, verbose=True, web_ui=True)
return render_title_template("cwa_history_full.html", title=_("Calibre-Web Automated - Full Enforcement History (w/ Paths)"), page="cwa-history-full",
return render_title_template("cwa_stats_full.html", title=_("Calibre-Web Automated - Full Enforcement History (w/ Paths)"), page="cwa-history-full",
table_headers=headers["enforcement"]["with_paths"], data=data)

@cwa_history.route("/cwa-history-show/full-imports", methods=["GET", "POST"])
@cwa_stats.route("/cwa-history-show/full-imports", methods=["GET", "POST"])
@login_required_if_no_ano
@admin_required
def show_full_imports():
cwa_db = CWA_DB()
data = cwa_db.get_import_history(verbose=True)
return render_title_template("cwa_history_full.html", title=_("Calibre-Web Automated - Full Import History"), page="cwa-history-full",
return render_title_template("cwa_stats_full.html", title=_("Calibre-Web Automated - Full Import History"), page="cwa-history-full",
table_headers=headers["imports"], data=data)

@cwa_history.route("/cwa-history-show/full-conversions", methods=["GET", "POST"])
@cwa_stats.route("/cwa-history-show/full-conversions", methods=["GET", "POST"])
@login_required_if_no_ano
@admin_required
def show_full_conversions():
cwa_db = CWA_DB()
data = cwa_db.get_conversion_history(verbose=True)
return render_title_template("cwa_history_full.html", title=_("Calibre-Web Automated - Full Conversion History"), page="cwa-history-full",
return render_title_template("cwa_stats_full.html", title=_("Calibre-Web Automated - Full Conversion History"), page="cwa-history-full",
table_headers=headers["conversions"], data=data)

@cwa_history.route("/cwa-history-show/full-epub-fixer", methods=["GET", "POST"])
@cwa_stats.route("/cwa-history-show/full-epub-fixer", methods=["GET", "POST"])
@login_required_if_no_ano
@admin_required
def show_full_epub_fixer():
cwa_db = CWA_DB()
data = cwa_db.get_epub_fixer_history(fixes=False, verbose=True)
return render_title_template("cwa_history_full.html", title=_("Calibre-Web Automated - Full EPUB Fixer History (w/out Paths & Fixes)"), page="cwa-history-full",
return render_title_template("cwa_stats_full.html", title=_("Calibre-Web Automated - Full EPUB Fixer History (w/out Paths & Fixes)"), page="cwa-history-full",
table_headers=headers["epub_fixer"]["no_fixes"], data=data)

@cwa_history.route("/cwa-history-show/full-epub-fixer-with-paths-fixes", methods=["GET", "POST"])
@cwa_stats.route("/cwa-history-show/full-epub-fixer-with-paths-fixes", methods=["GET", "POST"])
@login_required_if_no_ano
@admin_required
def show_full_epub_fixer_with_paths_fixes():
cwa_db = CWA_DB()
data = cwa_db.get_epub_fixer_history(fixes=True, verbose=True)
return render_title_template("cwa_history_full.html", title=_("Calibre-Web Automated - Full EPUB Fixer History (w/ Paths & Fixes)"), page="cwa-history-full",
return render_title_template("cwa_stats_full.html", title=_("Calibre-Web Automated - Full EPUB Fixer History (w/ Paths & Fixes)"), page="cwa-history-full",
table_headers=headers["epub_fixer"]["with_fixes"], data=data)

##————————————————————————————————————————————————————————————————————————————##
4 changes: 2 additions & 2 deletions root/app/calibre-web/cps/main.py
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ def request_username():
def main():
app = create_app()

from .cwa_functions import switch_theme, library_refresh, convert_library, epub_fixer, cwa_history, cwa_check_status, cwa_settings
from .cwa_functions import switch_theme, library_refresh, convert_library, epub_fixer, cwa_stats, cwa_check_status, cwa_settings
from .web import web
from .opds import opds
from .admin import admi
@@ -67,7 +67,7 @@ def main():
app.register_blueprint(library_refresh)
app.register_blueprint(convert_library)
app.register_blueprint(epub_fixer)
app.register_blueprint(cwa_history)
app.register_blueprint(cwa_stats)
app.register_blueprint(cwa_check_status)
app.register_blueprint(cwa_settings)

68 changes: 1 addition & 67 deletions root/app/calibre-web/cps/static/css/caliBlur.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
2 changes: 1 addition & 1 deletion root/app/calibre-web/cps/templates/admin.html
Original file line number Diff line number Diff line change
@@ -203,7 +203,7 @@ <h2>{{_('Scheduled Tasks ⌛')}}</h2>
<div class="row form-group">
<h2>{{_('CWA Admin Functions⚡')}}</h2>
<a class="btn btn-default" id="cwa-settings" href="{{url_for('cwa_settings.set_cwa_settings')}}">{{_('CWA Settings')}}</a>
<a class="btn btn-default" id="cwa_history" href="{{url_for('cwa_history.cwa_history_show')}}">{{_('Show CWA Stats')}}</a>
<a class="btn btn-default" id="cwa_stats" href="{{url_for('cwa_stats.cwa_stats_show')}}">{{_('Show CWA Stats')}}</a>
<a class="btn btn-default" id="check_mon_srvs" href="{{url_for('cwa_check_status.cwa_flash_status')}}">{{_('Check CWA Status')}}</a>
</div>
<div class="row form-group">
4 changes: 3 additions & 1 deletion root/app/calibre-web/cps/templates/cwa_epub_fixer.html
Original file line number Diff line number Diff line change
@@ -18,7 +18,9 @@ <h3 style="color: whitesmoke;">CWA Send-to-Kindle EPUB Fixer</h3><br>
<a class="btn btn-default" href="{{ url_for('epub_fixer.start_epub_fixer') }}" style="vertical-align: top; float: right; width: 100px;">{{_('Start')}}</a>
</div>
</div>

<div class="progress-container" style="margin: 20px 0;">
<div id="progress-bar" style="width: 0%; height: 25px; background-color: green; text-align: center; color: white;"></div>
</div>
<div class="row">
<div class="logging_window" style="padding-left: 15px;
padding-right: 15px;
139 changes: 0 additions & 139 deletions root/app/calibre-web/cps/templates/cwa_history.html

This file was deleted.

229 changes: 229 additions & 0 deletions root/app/calibre-web/cps/templates/cwa_stats.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
{% extends "layout.html" %}
{% block body %}

{% block header %}
<style>
body {
margin: 0;
font-family: Arial, sans-serif;
}

.cwa_stats_container {
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr; /* Default: 4 equal columns */
gap: 10px; /* Space between sections */
padding: 20px;
width: 100%; /* Ensure it spans the full width */
height: auto; /* Allow height to adjust based on content */
}

.cwa_stats_section {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
border: none;
border-radius: 8px;
padding: 20px;
text-align: center;
background-color: #1520268a;
}

.cwa_stats_header {
font-size: 1.5em;
font-weight: bold;
margin-bottom: 10px;
color: whitesmoke;
}

.cwa_stats_value {
font-size: 2.5em;
font-weight: bold;
color: #cc7b19;
}

/* Styling for background colors */
/* .cwa_stats_section:nth-child(1) { background-color: #e0f7fa; } */
/* .cwa_stats_section:nth-child(2) { background-color: #c8e6c9; } */
/* .cwa_stats_section:nth-child(3) { background-color: #ffcdd2; } */
/* .cwa_stats_section:nth-child(4) { background-color: #fff9c4; } */

/* Media Query for Medium Screens */
@media (max-width: 1024px) {
.cwa_stats_container {
grid-template-columns: repeat(2, 1fr); /* 2 equal columns on medium screens */
}
}

/* Media Query for Mobile Screens or Thin Windows */
@media (max-width: 480px) {
.cwa_stats_container {
grid-template-columns: 1fr; /* 1 column, 4 sections stacked vertically */
}
}

.stats_see_more_btn {
border-radius: 6px;
margin-bottom: 0px;
}

</style>
{% endblock %}

<div class="discover">
<h2>{{title}}</h2>

<div>
<h3>Calibre-Web Automated - Server Stats</h3>
<div class="cwa_stats_container">
<div class="cwa_stats_section">
<div class="cwa_stats_header">Total Books</div>
<div class="cwa_stats_value">{{cwa_stats["total_books"]}}</div>
</div>
<div class="cwa_stats_section">
<div class="cwa_stats_header">Books Enforced</div>
<div class="cwa_stats_value">{{cwa_stats["cwa_enforcement"]}}</div>
</div>
<div class="cwa_stats_section">
<div class="cwa_stats_header">Books Converted</div>
<div class="cwa_stats_value">{{cwa_stats["total_conversions"]}}</div>
</div>
<div class="cwa_stats_section">
<div class="cwa_stats_header">Books Fixed</div>
<div class="cwa_stats_value">{{cwa_stats["epub_fixes"]}}</div>
</div>
</div>
</div>

<hr style="width: 85%;text-align: center;margin-bottom: 36px;border-width: medium;border-color: #96a2a9;border-radius: 8px;">

<div>
<div style="display: flex; justify-content: space-between; align-items: center;">
<h3 style="margin: 0;">Calibre-Web Automated Conversion History</h3>
<a class="btn btn-default stats_see_more_btn" href="{{ url_for('cwa_stats.show_full_conversions') }}">{{_('Click to See More')}}</a>
</div>
<br>
<table class="table table-striped">
<tr>
{% for header in headers_conversion %}
<th>{{ header }}</th>
{% endfor %}
</tr>
{% for row in data_conversions|reverse %}
<tr>
{% for cell in row %}
<td>{{ cell }}</td>
{% endfor %}
</tr>
{% endfor %}
</table>
</div>

<div>
<div style="display: flex; justify-content: space-between; align-items: center;">
<h3 style="margin: 0;">Calibre-Web Automated Import History</h3>
<a class="btn btn-default stats_see_more_btn" href="{{ url_for('cwa_stats.show_full_imports') }}">{{_('Click to See More')}}</a>
</div>
<br>
<table class="table table-striped">
<tr>
{% for header in headers_import %}
<th>{{ header }}</th>
{% endfor %}
</tr>
{% for row in data_imports|reverse %}
<tr>
{% for cell in row %}
<td>{{ cell }}</td>
{% endfor %}
</tr>
{% endfor %}
</table>
</div>

<div>
<div style="display: flex; justify-content: space-between; align-items: center;">
<h3 style="margin: 0;">Calibre-Web Automated EPUB Fixer History</h3>
<a class="btn btn-default stats_see_more_btn" href="{{ url_for('cwa_stats.show_full_epub_fixer') }}">{{_('Click to See More')}}</a>
</div>
<br>
<table class="table table-striped">
<tr>
{% for header in headers_epub_fixer %}
<th>{{ header }}</th>
{% endfor %}
</tr>
{% for row in data_epub_fixer|reverse %}
<tr>
{% for cell in row %}
<td>{{ cell }}</td>
{% endfor %}
</tr>
{% endfor %}
</table>
<div style="display: flex; justify-content: space-between; align-items: center;">
<h4 style="margin: 0;"><i>EPUB Fixer History with Paths & Fixes</i></h4>
<a class="btn btn-default stats_see_more_btn" href="{{ url_for('cwa_stats.show_full_epub_fixer_with_paths_fixes') }}">{{_('Click to See More')}}</a>
</div>
<br>
<table class="table table-striped">
<tr>
{% for header in headers_epub_fixer_with_fixes %}
<th>{{ header }}</th>
{% endfor %}
</tr>
{% for row in data_epub_fixer_with_fixes|reverse %}
<tr>
{% for cell in row %}
<td>
<div style="max-height: 20rem; overflow-y: auto;">{{ cell | replace("\n", "<br>") | safe }}</div>
</td>
{% endfor %}
</tr>
{% endfor %}
</table>
</div>

<div>
<div style="display: flex; justify-content: space-between; align-items: center;">
<h3 style="margin: 0;">Calibre-Web Automated Enforcement History</h3>
<a class="btn btn-default stats_see_more_btn" href="{{url_for('cwa_stats.show_full_enforcement')}}">{{_('Click to See More')}}</a>
</div>
<br>
<table class="table table-striped">
<tr>
{% for header in headers_enforcement %}
<th>{{ header }}</th>
{% endfor %}
</tr>
{% for row in data_enforcement|reverse %}
<tr>
{% for cell in row %}
<td>{{ cell }}</td>
{% endfor %}
</tr>
{% endfor %}
</table>
<div style="display: flex; justify-content: space-between; align-items: center;">
<h4 style="margin: 0;"><i>Enforcement History with Paths</i></h4>
<a class="btn btn-default stats_see_more_btn" href="{{ url_for('cwa_stats.show_full_enforcement_path') }}">{{_('Click to See More')}}</a>
</div>
<br>
<table class="table table-striped">
<tr>
{% for header in headers_enforcement_with_paths %}
<th>{{ header }}</th>
{% endfor %}
</tr>
{% for row in data_enforcement_with_paths|reverse %}
<tr>
{% for cell in row %}
<td>{{ cell }}</td>
{% endfor %}
</tr>
{% endfor %}
</table>
</div>

</div>
{% endblock %}
1 change: 1 addition & 0 deletions root/app/calibre-web/cps/templates/layout.html
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@
{% if g.current_theme == 1 %}
<link href="{{ url_for('static', filename='css/caliBlur.css') }}" rel="stylesheet" media="screen">
<link href="{{ url_for('static', filename='css/caliBlur_override.css') }}" rel="stylesheet" media="screen">
<link href="{{ url_for('static', filename='css/caliBlur_cwa.css') }}" rel="stylesheet" media="screen">
{% endif %}
<script>
const flash_success = document.getElementById("flash_success");
16 changes: 12 additions & 4 deletions scripts/cwa_db.py
Original file line number Diff line number Diff line change
@@ -16,18 +16,14 @@ def __init__(self, verbose=False):
self.con, self.cur = self.connect_to_db() # type: ignore

self.schema_path = "/app/calibre-web-automated/scripts/cwa_schema.sql"

self.stats_tables = ["cwa_enforcement", "cwa_import", "cwa_conversions", "epub_fixes"]

self.tables, self.schema = self.make_tables()

self.cwa_default_settings = self.get_cwa_default_settings()
self.ensure_settings_schema_match()
self.match_stat_table_columns_with_schema()
self.set_default_settings()

self.temp_disable_split_library()

self.cwa_settings = self.get_cwa_settings()


@@ -383,6 +379,18 @@ def epub_fixer_add_entry(self, filename, manually_triggered, num_of_fixes_applie
self.cur.execute("INSERT INTO epub_fixes(timestamp, filename, manually_triggered, num_of_fixes_applied, original_backed_up, file_path, fixes_applied) VALUES (?, ?, ?, ?, ?, ?, ?);", (timestamp, filename, manually_triggered, num_of_fixes_applied, original_backed_up, file_path, fixes_applied))
self.con.commit()

def get_stat_totals(self) -> dict[str,int]:
totals = {"cwa_enforcement":0,
"cwa_conversions":0,
"epub_fixes":0}

for table in totals:
try:
totals[table] = self.cur.execute(f"SELECT count(*) FROM cwa_enforcement").fetchone()[0]
except Exception as e:
print(f"[cwa-db] ERROR - The following error occurred when fetching stat totals:\n{e}")

return totals

def main():
db = CWA_DB()

0 comments on commit 86bd29c

Please sign in to comment.