|
15 | 15 | FREE_SPACE_TEXT_COLOR = "#FF7f33" |
16 | 16 |
|
17 | 17 | # --- New: Color constants and font --- |
18 | | -TILE_CLICKED_BG_COLOR = "#3b82f6" # Blue background for clicked tiles |
19 | | -TILE_CLICKED_TEXT_COLOR = "white" |
20 | | -TILE_UNCLICKED_BG_COLOR = "#facc15" # Yellow background for unclicked tiles |
21 | | -TILE_UNCLICKED_TEXT_COLOR = "black" |
| 18 | +TILE_CLICKED_BG_COLOR = "#100079" |
| 19 | +TILE_CLICKED_TEXT_COLOR = "#1BEFF5" |
| 20 | +TILE_UNCLICKED_BG_COLOR = "#1BEFF5" |
| 21 | +TILE_UNCLICKED_TEXT_COLOR = "#100079" |
22 | 22 |
|
23 | 23 |
|
24 | 24 | HOME_BG_COLOR = "#100079" # Background for home page |
@@ -63,7 +63,34 @@ def get_line_style_for_lines(line_count: int, default_text_color: str) -> str: |
63 | 63 |
|
64 | 64 | # Read phrases from a text file and convert them to uppercase. |
65 | 65 | with open("phrases.txt", "r") as f: |
66 | | - phrases = [line.strip().upper() for line in f if line.strip()] |
| 66 | + raw_phrases = [line.strip().upper() for line in f if line.strip()] |
| 67 | + |
| 68 | +# Remove duplicates while preserving order. |
| 69 | +unique_phrases = [] |
| 70 | +seen = set() |
| 71 | +for p in raw_phrases: |
| 72 | + if p not in seen: |
| 73 | + seen.add(p) |
| 74 | + unique_phrases.append(p) |
| 75 | + |
| 76 | +# Optional: filter out phrases with too many repeated words. |
| 77 | +def has_too_many_repeats(phrase, threshold=0.5): |
| 78 | + """ |
| 79 | + Returns True if too many of the words in the phrase repeat. |
| 80 | + For example, if the ratio of unique words to total words is less than the threshold. |
| 81 | + Logs a debug message if the phrase is discarded. |
| 82 | + """ |
| 83 | + words = phrase.split() |
| 84 | + if not words: |
| 85 | + return False |
| 86 | + unique_count = len(set(words)) |
| 87 | + ratio = unique_count / len(words) |
| 88 | + if ratio < threshold: |
| 89 | + logging.debug(f"Discarding phrase '{phrase}' due to repeats: {unique_count}/{len(words)} = {ratio:.2f} < {threshold}") |
| 90 | + return True |
| 91 | + return False |
| 92 | + |
| 93 | +phrases = [p for p in unique_phrases if not has_too_many_repeats(p)] |
67 | 94 |
|
68 | 95 | # Use today's date as the seed for deterministic shuffling |
69 | 96 | today_seed = datetime.date.today().strftime("%Y%m%d") |
@@ -256,7 +283,7 @@ def create_board_view(background_color: str, is_global: bool): |
256 | 283 | ui.timer(0.1, lambda: update_tile_styles(local_tile_buttons)) |
257 | 284 | # Display the seed beneath the board. |
258 | 285 | with ui.element("div").classes("w-full mt-4"): |
259 | | - ui.label(f"Seed: {today_seed}").classes("text-md text-gray-300 text-center") |
| 286 | + ui.label(f"Seed: {today_seed}").classes("text-md text-center").style(f"color: {TILE_UNCLICKED_BG_COLOR};") |
260 | 287 |
|
261 | 288 | @ui.page("/") |
262 | 289 | def home_page(): |
@@ -441,7 +468,34 @@ def check_phrases_file_change(): |
441 | 468 | last_phrases_mtime = mtime |
442 | 469 | # Re-read phrases.txt |
443 | 470 | with open("phrases.txt", "r") as f: |
444 | | - phrases = [line.strip().upper() for line in f if line.strip()] |
| 471 | + raw_phrases = [line.strip().upper() for line in f if line.strip()] |
| 472 | + |
| 473 | + # Remove duplicates while preserving order. |
| 474 | + unique_phrases = [] |
| 475 | + seen = set() |
| 476 | + for p in raw_phrases: |
| 477 | + if p not in seen: |
| 478 | + seen.add(p) |
| 479 | + unique_phrases.append(p) |
| 480 | + |
| 481 | + # Optional: filter out phrases with too many repeated words. |
| 482 | + def has_too_many_repeats(phrase, threshold=0.5): |
| 483 | + """ |
| 484 | + Returns True if too many of the words in the phrase repeat. |
| 485 | + For example, if the ratio of unique words to total words is less than the threshold. |
| 486 | + Logs a debug message if the phrase is discarded. |
| 487 | + """ |
| 488 | + words = phrase.split() |
| 489 | + if not words: |
| 490 | + return False |
| 491 | + unique_count = len(set(words)) |
| 492 | + ratio = unique_count / len(words) |
| 493 | + if ratio < threshold: |
| 494 | + logging.debug(f"Discarding phrase '{phrase}' due to repeats: {unique_count}/{len(words)} = {ratio:.2f} < {threshold}") |
| 495 | + return True |
| 496 | + return False |
| 497 | + |
| 498 | + phrases = [p for p in unique_phrases if not has_too_many_repeats(p)] |
445 | 499 | # Rebuild board data: re-shuffle and re-create board structure. |
446 | 500 | shuffled_phrases = random.sample(phrases, 24) |
447 | 501 | shuffled_phrases.insert(12, FREE_SPACE_TEXT) |
|
0 commit comments