Skip to content

Commit

Permalink
Issue 405: add UserSetting for stats sample size.
Browse files Browse the repository at this point in the history
  • Loading branch information
jzohrab committed Sep 26, 2024
1 parent 87350a9 commit d4a376a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lute/book/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from lute.read.render.service import get_paragraphs
from lute.db import db
from lute.models.book import Book
from lute.models.setting import UserSetting

# from lute.utils.debug_helpers import DebugTimer

Expand Down Expand Up @@ -36,7 +37,7 @@ def get_status_distribution(book):
txindex += 1

# Use a sample of pages to speed up stats count.
sample_size = 5
sample_size = int(UserSetting.get_value("stats_calc_sample_size") or 5)
texts = _last_n_pages(book, txindex, sample_size)

# Getting the individual paragraphs per page, and then combining,
Expand Down
1 change: 1 addition & 0 deletions lute/models/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def load():
# Behaviour:
"open_popup_in_new_tab": False,
"stop_audio_on_term_form_open": True,
"stats_calc_sample_size": 5,
}
for k, v in keys_and_defaults.items():
if not UserSetting.key_exists(k):
Expand Down
7 changes: 7 additions & 0 deletions lute/settings/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ class UserSettingsForm(FlaskForm):

open_popup_in_new_tab = BooleanField("Open popup in new tab")
stop_audio_on_term_form_open = BooleanField("Stop audio on term form open")
stats_calc_sample_size = IntegerField(
"Book stats page sample size",
validators=[InputRequired(), NumberRange(min=1, max=200)],
render_kw={
"title": "Number of pages to use for book stats calculation. Max 200 for performance."
},
)

mecab_path = StringField("MECAB_PATH environment variable")
reading_choices = [
Expand Down
3 changes: 2 additions & 1 deletion lute/static/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -1774,7 +1774,8 @@ input[type="checkbox"][disabled] + label {

#current_theme,
#japanese_reading,
#backup_count,
#backup_count,
#stats_calc_sample_size,
#test_mecab_btn,
#parser_type,
#language_id,
Expand Down
1 change: 1 addition & 0 deletions lute/templates/settings/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ <h2>Behaviour</h2>
{% for f in [
form.open_popup_in_new_tab,
form.stop_audio_on_term_form_open,
form.stats_calc_sample_size,
]%}
<tr>
<td>{{ f.label }}</td>
Expand Down

0 comments on commit d4a376a

Please sign in to comment.