Skip to content

Commit

Permalink
Restore quotes for stats distribution keys.
Browse files Browse the repository at this point in the history
  • Loading branch information
jzohrab committed Jan 4, 2024
1 parent cd4ac04 commit 0a7d3b5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
1 change: 0 additions & 1 deletion lute/book/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ def _get_stats(book):
percent = round(100.0 * unknowns / allunique)

sd = json.dumps(status_distribution)
sd = sd.replace('"', "")

# Any change in the below fields requires a change to
# update_stats as well, query insert doesn't check field order.
Expand Down
29 changes: 23 additions & 6 deletions tests/unit/book/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def add_terms(lang, terms):
def assert_stats(expected, msg=""):
"helper."
sql = """select wordcount, distinctterms, distinctunknowns,
unknownpercent, status_distribution from bookstats"""
unknownpercent, replace(status_distribution, '"', "'") from bookstats"""
assert_sql_result(sql, expected, msg)


Expand All @@ -124,31 +124,48 @@ def test_stats_smoke_test(_test_book, spanish):
"Terms are rendered to count stats."
add_terms(spanish, ["gato", "TENGO"])
refresh_stats()
assert_stats(["4; 4; 2; 50; {0: 2, 1: 2, 2: 0, 3: 0, 4: 0, 5: 0, 98: 0, 99: 0}"])
assert_stats(
[
"4; 4; 2; 50; {'0': 2, '1': 2, '2': 0, '3': 0, '4': 0, '5': 0, '98': 0, '99': 0}"
]
)


def test_stats_calculates_rendered_text(_test_book, spanish):
"Multiword term counted as one term."
add_terms(spanish, ["tengo un"])
refresh_stats()
assert_stats(["4; 3; 2; 67; {0: 2, 1: 1, 2: 0, 3: 0, 4: 0, 5: 0, 98: 0, 99: 0}"])
assert_stats(
[
"4; 3; 2; 67; {'0': 2, '1': 1, '2': 0, '3': 0, '4': 0, '5': 0, '98': 0, '99': 0}"
]
)


def test_stats_only_update_books_marked_stale(_test_book, spanish):
"Have to mark book as stale, too expensive otherwise."
add_terms(spanish, ["gato", "TENGO"])
refresh_stats()
assert_stats(["4; 4; 2; 50; {0: 2, 1: 2, 2: 0, 3: 0, 4: 0, 5: 0, 98: 0, 99: 0}"])
assert_stats(
[
"4; 4; 2; 50; {'0': 2, '1': 2, '2': 0, '3': 0, '4': 0, '5': 0, '98': 0, '99': 0}"
]
)

add_terms(spanish, ["hola"])
refresh_stats()
assert_stats(
["4; 4; 2; 50; {0: 2, 1: 2, 2: 0, 3: 0, 4: 0, 5: 0, 98: 0, 99: 0}"],
[
"4; 4; 2; 50; {'0': 2, '1': 2, '2': 0, '3': 0, '4': 0, '5': 0, '98': 0, '99': 0}"
],
"not updated",
)

mark_stale(_test_book)
refresh_stats()
assert_stats(
["4; 4; 1; 25; {0: 1, 1: 3, 2: 0, 3: 0, 4: 0, 5: 0, 98: 0, 99: 0}"], "updated"
[
"4; 4; 1; 25; {'0': 1, '1': 3, '2': 0, '3': 0, '4': 0, '5': 0, '98': 0, '99': 0}"
],
"updated",
)

0 comments on commit 0a7d3b5

Please sign in to comment.