From 518eec7f2ae7cac5975f817760e668096dfbf0c2 Mon Sep 17 00:00:00 2001 From: Eyal Gruss Date: Mon, 8 Jan 2024 20:42:00 +0200 Subject: [PATCH] fix issue kw matching; update petri --- resen/pages.js | 10 +++++----- resen/petri/petri.json | 11 +++++------ resen/petri/script.js | 12 ++++++------ resen/petri/style.css | 4 ---- 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/resen/pages.js b/resen/pages.js index 8dbe736..a06a508 100644 --- a/resen/pages.js +++ b/resen/pages.js @@ -451,21 +451,21 @@ function make_header(reorder_contents=default_reorder_contents) { page_items.forEach(p => {const enabled = getComputedStyle(p).color == fg_rgb; p.querySelectorAll('a').forEach(a => {if (enabled) a.removeAttribute('aria-disabled'); else a.ariaDisabled = 'true'})}) if (reorder_contents) document.querySelector('.contents').append(...[...page_items].sort((a, b) => (getComputedStyle(b).color == fg_rgb) - (getComputedStyle(a).color == fg_rgb) || a.id.split('_')[1] - b.id.split('_')[1])) - if (on && this.id.match(/^kw_\d+$/)) - buttons_on.forEach(e => {if (e != this && e.id.match(/^kw_\d+$/)) e.click()}) + if (on && this.id.match(/kw_\d+$/)) + buttons_on.forEach(e => {if (e != this && e.id.match(/kw_\d+$/)) e.click()}) } keywords.forEach((kw, button_index) => { button = document.createElement(page == '/' ? 'button' : 'a') button.id = 'kw_' + sanitize(kw) let label = kw_labels[kw] || kw - if (kw.match(/\d+/)) + if (kw.match(/\d+$/)) label = ui[lang].issue + ' ' + kw let alt = '' if (trans) { alt = kw - if (kw.match(/\d+/)) + if (kw.match(/\d+$/)) alt = ui[alt_langs[0]].issue + ' ' + kw else if (lang) [label, alt] = [alt, label] @@ -577,7 +577,7 @@ function get_make_author(page, lang, make=false, author_pages_folder=default_aut prefix += '/' if (!prefix.includes(':')) prefix = 'https://' + prefix - if (author[net].match(/^(\.|@|$)/)) + if (author[net].match(/(\.|@|$)/)) author[net] = key + author[net] const a = span.appendChild(make_link(prefix + author[net] + (social[net].suffix || ''), social[net].label, net, net[0].toUpperCase() + net.slice(1), new_tab_for_social)) a.dataset.label = a.textContent diff --git a/resen/petri/petri.json b/resen/petri/petri.json index 99390c0..53b9ad5 100644 --- a/resen/petri/petri.json +++ b/resen/petri/petri.json @@ -28,12 +28,12 @@ ], "מבצע": [ - ["זעם ישראל", "עזה", "ארגון טרור", "צבא"], - ["צבא", "כלא", "בית עלמין עזה", "זעם עזה"] + ["זעם ישראל", "צבא", "ארגון טרור", "עזה", "עזה"], + ["צבא", "בית עלמין עזה", "בית עלמין עזה", "בית עלמין עזה", "זעם עזה"] ], "פיגוע": [ ["ישראל", "ארגון טרור"], - ["בית עלמין עזה", "בית עלמין ישראל", "זעם ישראל"] + ["כלא", "בית עלמין ישראל", "זעם ישראל", "זעם עזה"] ], "חטיפה": [ @@ -47,9 +47,8 @@ }, "marking": { - "ישראל": 10, - "עזה": 3, - "זעם ישראל": 1, + "ישראל": 20, + "עזה": 10, "זעם עזה": 1 }, diff --git a/resen/petri/script.js b/resen/petri/script.js index 34ab639..fbab22f 100644 --- a/resen/petri/script.js +++ b/resen/petri/script.js @@ -2,7 +2,7 @@ const json_file = 'petri.json' const grid_columns = 5 const halfstep_secs = .5 const restart_secs = 5 -const fast = false +const fast = location.hash.slice(1) == 'fast' const auto_vertical = true const fix_above = true @@ -10,9 +10,7 @@ const label_location = '' // Can be: 'half' (half above and half below, favorin const default_token_symbol = 'o' // Cannot be of 1-9 or capital A-N const arrow_width = 6 const arrow_height = 1 - -const comp_marking = 3 -const comp_overflow = 23 +const comp_marking = 5 const lang = get_lang() let global_reset_counter = 0; @@ -39,6 +37,7 @@ function sanitized_len(string, split=false) { const place_template = "\n .-'''-. \n \\ JD645CI / \n| NHB312AGM |\n / LF978EK \\ \n `-...-` \n" const place_lines = place_template.trim().split('\n') const place_width = Math.max(...place_lines.map(l => sanitized_len(l))) +const place_max_tokens = place_template.match(/[0-9A-Z]/g).length function center(label, width, align_start=false) { return label.padEnd((width+sanitized_len(label)+align_start) / 2).padStart(width) @@ -198,14 +197,15 @@ function step(grid, json, steps=0, max_tokens={}, result_counter={}, reset_count reset_counter = global_reset_counter max_tokens = Object.fromEntries(Object.entries(max_tokens).map(([p, counts]) => ([p, counts.slice(0, -1)]))) step(grid, json, 0, max_tokens, result_counter, reset_counter) - } else if (!enabled.length || comp && Object.values(tokens).some(n => n > comp_overflow) || !comp && !json.require?.every(require => require.some(t => tokens[t]))) { + } else if (!enabled.length || comp && Object.values(tokens).some(n => n > place_max_tokens) || !comp && !json.require?.every(require => require.some(t => tokens[t]))) { const result = json?.require.map(side => side.some(p => tokens[p]) | 0) result_counter[result] = (result_counter[result] || []).concat(steps).sort((a, b) => a - b) if (!comp) { const all_steps = Object.values(result_counter).flat() const sides = result.map((_, i) => Object.entries(result_counter).filter(x => x[0].split(',')[i] == 1).map(x => x[1]).flat().length) const avg_tokens = Object.fromEntries(Object.entries(max_tokens).map(([p, counts]) => [p, counts.reduce((a, b) => a + b, 0) / counts.length]).sort((a, b) => a[1] - b[1] || a[0].localeCompare(b[0]))) - console.log(all_steps.length, all_steps.reduce((a, b) => a + b, 0) / all_steps.length, sides[1] / sides.reduce((a, b) => a + b, 0), avg_tokens, Object.fromEntries(Object.entries(result_counter).sort((a, b) => compare_lists(a[1], b[1]) || compare_lists(a[0], b[0])))) + const sum = sides.reduce((a, b) => a + b, 0) + console.log(all_steps.length, all_steps.reduce((a, b) => a + b, 0) / all_steps.length, sum ? sides[1] / sum : .5, avg_tokens, Object.fromEntries(Object.entries(result_counter).sort((a, b) => compare_lists(a[1], b[1]) || compare_lists(a[0], b[0])))) } setTimeout(step, restart_secs * 1000 * !fast, grid, json, 0, max_tokens, result_counter, reset_counter) } else diff --git a/resen/petri/style.css b/resen/petri/style.css index 604b9aa..900c5c7 100644 --- a/resen/petri/style.css +++ b/resen/petri/style.css @@ -12,10 +12,6 @@ padding-bottom: 3em; } -.fullscreen petri { - margin-inline: var(--anti_margin); -} - .petri > div { display: grid; grid-template-columns: repeat(var(--cols), 13.5em);