Skip to content

Commit

Permalink
#25 oprava opakovanych pismen
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyno committed Jan 27, 2022
1 parent ede7ffe commit 8ac6a2a
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 7 deletions.
2 changes: 1 addition & 1 deletion data_calculate/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __repr__(self):
result = ContingencyField()
exceptions = 0

DAY = 11
DAY = 12

loosers = []

Expand Down
23 changes: 20 additions & 3 deletions data_prepare/upload_data_to_fb.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,20 @@ def get_data() -> List[str]:

# https://stackoverflow.com/questions/67654272/using-document-id-name-to-query-with-where-operators
def get_previous_words(db, lastDate):
doc_ref = db.collection(u'word2').where(
doc_ref = db.collection(u'word').where(
u'exactTimeStamp', u'<=', lastDate).stream()
return [item.to_dict()['solution'] for item in doc_ref]


def delete_last_words(db, lastDate):
print("Deleting data after {}".format(lastDate))
doc_ref = db.collection(u'word').where(
u'exactTimeStamp', u'>=', lastDate).stream()
for doc in doc_ref:
# https://firebase.google.com/docs/firestore/manage-data/delete-data#python_5
doc.reference.delete()


if __name__ == '__main__':

# Use a service account
Expand All @@ -56,20 +65,27 @@ def get_previous_words(db, lastDate):
print("Original words: ", words_original)
words = list(
filter(lambda x: x not in already_existing_words, words_original))
print("Words after removal existing: ", words)
print("Words after removal existing: ", len(words))
print("Updating words since ", min_date)

random.shuffle(words)
random.shuffle(words)
random.shuffle(words)
random.shuffle(words)

# in order if any removal happens not need to remove from db
words = words[0:530]

# need to run this if we reduce the count of words compared to previous run
#delete_last_words(db, datetime.datetime(2023, 5, 1))

id = 0
for id, word in enumerate(words):
actual_date = actual_date + datetime.timedelta(days=1)
if (actual_date < min_date):
continue

print(actual_date, word)
#print(actual_date, word)
word = words[id]
actual_date_str = actual_date.strftime('%Y-%m-%d')
doc_ref = db.collection(u'word').document(actual_date_str)
Expand All @@ -80,3 +96,4 @@ def get_previous_words(db, lastDate):
'solutionMd5': hashlib.md5(word.encode('utf-8')).hexdigest(),
'locked': True
})
print("Uploaded, final index: ", id)
7 changes: 7 additions & 0 deletions src/lib/dataAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { PlayContext } from "./playContext";
import { firestore } from "./settingsFirebase";
import { PlayState } from "./statuses";
import { dateToStr } from "./timeFunctions";
import { DEBUG_WORD } from "./words";

export const saveGameResultFirebase = async (
playContext: PlayContext,
Expand Down Expand Up @@ -120,6 +121,12 @@ export const useGetWordOfDay = (date: Date): any => {
solution: data?.solution,
solutionIndex: data?.solutionIndex,
};
if (DEBUG_WORD) {
context = {
solution: DEBUG_WORD,
solutionIndex: 99,
};
}
} else {
context = { solution: "", solutionIndex: -1 };
}
Expand Down
31 changes: 29 additions & 2 deletions src/lib/statuses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export type CharValue =
| "É"
| "Ů";

function find_occurences(str: string, char_to_count: string): number {
return str.split(char_to_count).length - 1;
}

export const getStatuses = (
playContext: PlayContext,
guesses: string[]
Expand All @@ -56,8 +60,31 @@ export const getStatuses = (
}

if (letter === solution[i]) {
//make status correct
return (charObj[letter] = "correct");
// make status correct
// if the letter appears more times, then we need to make sure we have all of them. If not mark it orange on keyboard.
// see https://github.com/tonyno/wordle-czech/issues/25
let status: CharStatus = "correct";
if (
find_occurences(solution, letter) >= 2 &&
charObj[letter] !== "correct"
) {
// to be save run this logic only for reocuring letters
// and also if the user already caught the correct position earlier, don't change it to orange
for (let i2 = 0; i2 < solution.length; ++i2) {
if (i !== i2) {
// other letters
if (solution[i2] === letter || word[i2] === letter) {
// another occurence in the solution for same letter
//console.log(i, i2, solution[i], letter);
if (word[i2] !== solution[i2]) {
//console.log("kuk");
status = "present";
}
}
}
}
}
return (charObj[letter] = status);
}

if (charObj[letter] !== "correct") {
Expand Down
6 changes: 5 additions & 1 deletion src/lib/words.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { msInDay, startDate } from "../constants/otherConstants";
import { VALIDGUESSES } from "../constants/validGuesses";

export const isWordInWordList = (solution: string, word: string) => {
// if set, then no validation of incoming words
export const DEBUG_WORD: string | null | undefined = null;

export const isWordInWordList = (solution: string, word: string): boolean => {
if (DEBUG_WORD) return true;
return solution === word || VALIDGUESSES.includes(word.toLowerCase());
};

Expand Down

0 comments on commit 8ac6a2a

Please sign in to comment.