Skip to content

Commit

Permalink
fix issue kw matching; update petri
Browse files Browse the repository at this point in the history
  • Loading branch information
eyaler committed Jan 8, 2024
1 parent 6df6814 commit 518eec7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
10 changes: 5 additions & 5 deletions resen/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions resen/petri/petri.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
],

"מבצע": [
["זעם ישראל", "עזה", "ארגון טרור", "צבא"],
["צבא", "כלא", "בית עלמין עזה", "זעם עזה"]
["זעם ישראל", "צבא", "ארגון טרור", "עזה", "עזה"],
["צבא", "בית עלמין עזה", "בית עלמין עזה", "בית עלמין עזה", "זעם עזה"]
],
"פיגוע": [
["ישראל", "ארגון טרור"],
["בית עלמין עזה", "בית עלמין ישראל", "זעם ישראל"]
["כלא", "בית עלמין ישראל", "זעם ישראל", "זעם עזה"]
],

"חטיפה": [
Expand All @@ -47,9 +47,8 @@
},

"marking": {
"ישראל": 10,
"עזה": 3,
"זעם ישראל": 1,
"ישראל": 20,
"עזה": 10,
"זעם עזה": 1
},

Expand Down
12 changes: 6 additions & 6 deletions resen/petri/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@ 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
const label_location = '' // Can be: 'half' (half above and half below, favoring the below), 'above', or anything else to indicate below
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;
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions resen/petri/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 518eec7

Please sign in to comment.