Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script for recomputing FK scores for languages with new constants #250

Merged
merged 2 commits into from
Oct 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Loading