fixed some issues, but the pass button will eventually be removed
This commit is contained in:
parent
9d82c861e7
commit
b22b7bd37f
3 changed files with 44 additions and 29 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
FROM python:3.10-slim
|
FROM python:3.10-slim
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
RUN apt-get clean
|
||||||
RUN apt-get update && apt-get install -y build-essential && rm -rf /var/lib/apt/lists/*
|
RUN apt-get update && apt-get install -y build-essential && rm -rf /var/lib/apt/lists/*
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN pip install --no-cache-dir flask gensim gunicorn numpy
|
RUN pip install --no-cache-dir flask gensim gunicorn numpy
|
||||||
|
|
|
||||||
|
|
@ -117,17 +117,23 @@ def submit_score():
|
||||||
history.append({'word': guess_word, 'score': score, 'remaining': len(new_word_indexes)})
|
history.append({'word': guess_word, 'score': score, 'remaining': len(new_word_indexes)})
|
||||||
session['history'] = history
|
session['history'] = history
|
||||||
if not new_word_indexes:
|
if not new_word_indexes:
|
||||||
return jsonify({'result': 'Plus aucun mot possible. Terminé.', 'history': history})
|
session['current_guess_idx'] = None
|
||||||
|
return jsonify({'result': 'Plus aucun mot possible. Terminé.', 'history': history, 'remaining': 0})
|
||||||
|
else:
|
||||||
|
session['current_guess_idx'] = new_word_indexes[0]
|
||||||
if len(new_word_indexes) == 1:
|
if len(new_word_indexes) == 1:
|
||||||
return jsonify({'result': f"Plus qu'un seul mot possible: {all_words[new_word_indexes[0]]}", 'history': history})
|
return jsonify({'result': f"Plus qu'un seul mot possible: {all_words[new_word_indexes[0]]}", 'history': history, 'remaining': 1})
|
||||||
return jsonify({'remaining': len(new_word_indexes), 'history': history})
|
return jsonify({'remaining': len(new_word_indexes), 'history': history})
|
||||||
|
|
||||||
@app.route('/skip', methods=['POST'])
|
@app.route('/skip', methods=['POST'])
|
||||||
def skip_word():
|
def skip_word():
|
||||||
word_indexes = session.get('word_indexes', [])
|
word_indexes = session.get('word_indexes', [])
|
||||||
current_guess_idx = session.get('current_guess_idx')
|
current_guess_idx = session.get('current_guess_idx')
|
||||||
if current_guess_idx is None or not word_indexes:
|
if not word_indexes:
|
||||||
return jsonify({'error': 'Aucun mot à passer'}), 400
|
return jsonify({'result': 'Plus aucun mot possible. Terminé.', 'history': session.get('history', [])})
|
||||||
|
if current_guess_idx is None or current_guess_idx >= len(word_indexes):
|
||||||
|
# Si aucun mot sélectionné, on prend le premier
|
||||||
|
current_guess_idx = word_indexes[0]
|
||||||
# Recalculer all_words à partir du modèle et du mot de départ
|
# Recalculer all_words à partir du modèle et du mot de départ
|
||||||
lang = session.get('lang', 'en')
|
lang = session.get('lang', 'en')
|
||||||
model_path = session.get('model_path')
|
model_path = session.get('model_path')
|
||||||
|
|
@ -143,6 +149,7 @@ def skip_word():
|
||||||
with open("english_words.txt") as f:
|
with open("english_words.txt") as f:
|
||||||
valid_words = set(w.strip() for w in f)
|
valid_words = set(w.strip() for w in f)
|
||||||
all_words = [w for w in model.index_to_key if w != first_word and is_valid_word(w, lang, valid_words)]
|
all_words = [w for w in model.index_to_key if w != first_word and is_valid_word(w, lang, valid_words)]
|
||||||
|
# On retire le mot courant de la liste
|
||||||
try:
|
try:
|
||||||
word_indexes.remove(current_guess_idx)
|
word_indexes.remove(current_guess_idx)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|
@ -151,9 +158,14 @@ def skip_word():
|
||||||
history = session.get('history', [])
|
history = session.get('history', [])
|
||||||
history.append({'word': all_words[current_guess_idx], 'score': 'pass', 'remaining': len(word_indexes)})
|
history.append({'word': all_words[current_guess_idx], 'score': 'pass', 'remaining': len(word_indexes)})
|
||||||
session['history'] = history
|
session['history'] = history
|
||||||
if not word_indexes:
|
# On avance l'index courant si possible
|
||||||
|
if word_indexes:
|
||||||
|
session['current_guess_idx'] = word_indexes[0]
|
||||||
|
guess = all_words[word_indexes[0]]
|
||||||
|
return jsonify({'guess': guess, 'remaining': len(word_indexes), 'history': history})
|
||||||
|
else:
|
||||||
|
session['current_guess_idx'] = None
|
||||||
return jsonify({'result': 'Plus aucun mot possible. Terminé.', 'history': history})
|
return jsonify({'result': 'Plus aucun mot possible. Terminé.', 'history': history})
|
||||||
return jsonify({'remaining': len(word_indexes), 'history': history})
|
|
||||||
|
|
||||||
|
|
||||||
# Servir index.html à la racine
|
# Servir index.html à la racine
|
||||||
|
|
@ -166,5 +178,4 @@ def root():
|
||||||
def static_files(filename):
|
def static_files(filename):
|
||||||
return send_from_directory('.', filename)
|
return send_from_directory('.', filename)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
## Le serveur est lancé par gunicorn dans Docker, ne rien lancer ici
|
||||||
app.run(debug=True)
|
|
||||||
|
|
|
||||||
41
index.html
41
index.html
|
|
@ -30,8 +30,7 @@
|
||||||
<button id="skipWordBtn" style="margin-left:1em;">Passer</button>
|
<button id="skipWordBtn" style="margin-left:1em;">Passer</button>
|
||||||
<div id="result"></div>
|
<div id="result"></div>
|
||||||
<div id="remaining"></div>
|
<div id="remaining"></div>
|
||||||
<h3>Historique</h3>
|
<!-- Historique supprimé -->
|
||||||
<ul id="history"></ul>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
|
|
@ -39,15 +38,7 @@
|
||||||
let history = [];
|
let history = [];
|
||||||
let remaining = 0;
|
let remaining = 0;
|
||||||
|
|
||||||
function updateHistory() {
|
// Historique supprimé
|
||||||
const histElem = document.getElementById('history');
|
|
||||||
histElem.innerHTML = '';
|
|
||||||
history.forEach(item => {
|
|
||||||
const li = document.createElement('li');
|
|
||||||
li.textContent = `${item.word} : ${item.score} (restants: ${item.remaining})`;
|
|
||||||
histElem.appendChild(li);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateRemaining() {
|
function updateRemaining() {
|
||||||
document.getElementById('remaining').textContent = `Mots restants : ${remaining}`;
|
document.getElementById('remaining').textContent = `Mots restants : ${remaining}`;
|
||||||
|
|
@ -89,11 +80,19 @@
|
||||||
const resp = await fetch('/next', { method: 'POST' });
|
const resp = await fetch('/next', { method: 'POST' });
|
||||||
const data = await resp.json();
|
const data = await resp.json();
|
||||||
if (data.error) {
|
if (data.error) {
|
||||||
document.getElementById('word').textContent = 'Fini !';
|
document.getElementById('word').textContent = '';
|
||||||
document.getElementById('submitScoreBtn').disabled = true;
|
document.getElementById('submitScoreBtn').disabled = true;
|
||||||
document.getElementById('skipWordBtn').disabled = true;
|
document.getElementById('skipWordBtn').disabled = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (data.result) {
|
||||||
|
document.getElementById('word').textContent = '';
|
||||||
|
document.getElementById('result').textContent = data.result;
|
||||||
|
document.getElementById('submitScoreBtn').disabled = true;
|
||||||
|
document.getElementById('skipWordBtn').disabled = true;
|
||||||
|
updateRemaining();
|
||||||
|
return;
|
||||||
|
}
|
||||||
currentWord = data.guess;
|
currentWord = data.guess;
|
||||||
remaining = data.remaining;
|
remaining = data.remaining;
|
||||||
history = data.history || [];
|
history = data.history || [];
|
||||||
|
|
@ -101,7 +100,6 @@
|
||||||
document.getElementById('scoreInput').value = '';
|
document.getElementById('scoreInput').value = '';
|
||||||
document.getElementById('result').textContent = '';
|
document.getElementById('result').textContent = '';
|
||||||
document.getElementById('scoreInput').focus();
|
document.getElementById('scoreInput').focus();
|
||||||
updateHistory();
|
|
||||||
updateRemaining();
|
updateRemaining();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -127,7 +125,7 @@
|
||||||
}
|
}
|
||||||
history = data.history || history;
|
history = data.history || history;
|
||||||
remaining = data.remaining || remaining;
|
remaining = data.remaining || remaining;
|
||||||
updateHistory();
|
// updateHistory supprimé
|
||||||
updateRemaining();
|
updateRemaining();
|
||||||
await nextWord();
|
await nextWord();
|
||||||
};
|
};
|
||||||
|
|
@ -141,12 +139,17 @@
|
||||||
}
|
}
|
||||||
if (data.result) {
|
if (data.result) {
|
||||||
document.getElementById('result').textContent = data.result;
|
document.getElementById('result').textContent = data.result;
|
||||||
}
|
|
||||||
history = data.history || history;
|
|
||||||
remaining = data.remaining || remaining;
|
|
||||||
updateHistory();
|
|
||||||
updateRemaining();
|
|
||||||
await nextWord();
|
await nextWord();
|
||||||
|
} else if (data.guess) {
|
||||||
|
currentWord = data.guess;
|
||||||
|
remaining = data.remaining;
|
||||||
|
history = data.history || history;
|
||||||
|
document.getElementById('word').textContent = currentWord;
|
||||||
|
document.getElementById('scoreInput').value = '';
|
||||||
|
document.getElementById('result').textContent = '';
|
||||||
|
document.getElementById('scoreInput').focus();
|
||||||
|
updateRemaining();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue