Skip to content

Commit

Permalink
Script for recomputing FK scores for languages with new constants (#250)
Browse files Browse the repository at this point in the history
* Script for recomputing FK scores for languages with new constants

* Added Verbose Flag and Checkpoint commits

- When testing locally the script would be killed about 1/3 into the process.

---------

Co-authored-by: Tiago Ribeiro <[email protected]>
  • Loading branch information
gustavkrist and tfnribeiro authored Oct 10, 2024
1 parent a71c82d commit 88810d4
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tools/recompute_fk_difficulties.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import zeeguu.core
from zeeguu.api.app import create_app
from zeeguu.core.model import Article, Language
from zeeguu.core.language.difficulty_estimator_factory import DifficultyEstimatorFactory

VERBOSE = False
CHECKPOINT_STEP = 10000

app = create_app()
app.app_context().push()

print("starting...")

session = zeeguu.core.model.db.session
articles_to_update = Article.query.filter(
Article.language.has(Language.code.in_(["es", "fr", "it", "nl", "ru"]))
).all()
for i, article in enumerate(articles_to_update):
if VERBOSE:
print(f"Article language: {article.language}")
print(f"Difficulty before: {article.fk_difficulty} for {article.title}")
fk_estimator = DifficultyEstimatorFactory.get_difficulty_estimator("fk")
fk_difficulty = fk_estimator.estimate_difficulty(
article.content, article.language, None
)["grade"]

article.fk_difficulty = fk_difficulty
if VERBOSE:
print(f"Difficulty after: {article.fk_difficulty} for {article.title}\n")

session.add(article)
if (i + 1) % CHECKPOINT_STEP == 0:
print("Checkpointing changes, commiting...")
session.commit()
print(f"Checkpoint done, completed ({i+1}/{len(articles_to_update)}).")
session.commit()

0 comments on commit 88810d4

Please sign in to comment.