722 lines
42 KiB
HTML
722 lines
42 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="de">
|
||
|
||
<head>
|
||
<meta charset="utf-8" />
|
||
<title>🌈 Rainbow Counter v2 (ohne Anbindung)</title>
|
||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||
<!-- Blockly + JS Generator + Deutsche Labels -->
|
||
<script src="https://unpkg.com/blockly/blockly.min.js"></script>
|
||
<script src="https://unpkg.com/blockly/javascript.min.js"></script>
|
||
<script src="https://unpkg.com/blockly/msg/de.js"></script>
|
||
<style>
|
||
:root {
|
||
--bg: #1e1e1e;
|
||
--panel: #121212;
|
||
--txt: #e8e8e8;
|
||
--accent: #4caf50;
|
||
--muted: #a0a0a0;
|
||
--line: #2a2a2a
|
||
}
|
||
|
||
* {
|
||
box-sizing: border-box
|
||
}
|
||
|
||
html,
|
||
body {
|
||
height: 100%;
|
||
margin: 0;
|
||
background: var(--bg);
|
||
color: var(--txt);
|
||
font-family: ui-monospace, SFMono-Regular, Menlo, monospace
|
||
}
|
||
|
||
header {
|
||
display: flex;
|
||
gap: .5rem;
|
||
align-items: center;
|
||
padding: .6rem .8rem;
|
||
border-bottom: 1px solid var(--line)
|
||
}
|
||
|
||
header h2 {
|
||
margin: 0;
|
||
font-size: 1rem;
|
||
font-weight: 700
|
||
}
|
||
|
||
header .sp {
|
||
flex: 1
|
||
}
|
||
|
||
button {
|
||
padding: .55rem .8rem;
|
||
background: var(--accent);
|
||
color: #fff;
|
||
border: 0;
|
||
border-radius: 10px;
|
||
font-weight: 700;
|
||
cursor: pointer
|
||
}
|
||
|
||
#wrap {
|
||
display: flex;
|
||
gap: .8rem;
|
||
height: calc(100vh - 56px);
|
||
padding: .6rem .8rem
|
||
}
|
||
|
||
#left {
|
||
flex: 3;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: .6rem
|
||
}
|
||
|
||
#right {
|
||
flex: 2;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: .6rem
|
||
}
|
||
|
||
#blocklyDiv {
|
||
height: 60vh;
|
||
width: 100%
|
||
}
|
||
|
||
#output {
|
||
flex: 1;
|
||
min-height: 28vh;
|
||
background: var(--panel);
|
||
padding: 10px;
|
||
border-radius: 10px;
|
||
white-space: pre-wrap;
|
||
word-break: break-word;
|
||
overflow: auto
|
||
}
|
||
|
||
#cfg {
|
||
background: var(--panel);
|
||
padding: 10px;
|
||
border-radius: 10px;
|
||
white-space: pre-wrap;
|
||
overflow: auto
|
||
}
|
||
|
||
.hint {
|
||
color: var(--muted);
|
||
font-size: .9rem
|
||
}
|
||
|
||
.row {
|
||
display: flex;
|
||
gap: .4rem;
|
||
flex-wrap: wrap
|
||
}
|
||
|
||
.btn-secondary {
|
||
background: #3c99dc
|
||
}
|
||
|
||
.btn-warn {
|
||
background: #e67e22
|
||
}
|
||
</style>
|
||
</head>
|
||
|
||
<body>
|
||
<header>
|
||
<h2>🧁 Crumbforest • Rainbow Counter v2</h2>
|
||
<div class="sp"></div>
|
||
<div class="row">
|
||
<button id="btnDoc" title="Doku/Beispiel laden">📄 Doku</button>
|
||
<button id="btnT1" class="btn-secondary" title="Testfall 1: Basisliste">T1</button>
|
||
<button id="btnT2" class="btn-secondary" title="Testfall 2: Gleichstand">T2</button>
|
||
<button id="btnT3" class="btn-secondary" title="Testfall 3: Debounce=1">T3</button>
|
||
<button id="btnRnd" class="btn-warn" title="Zufalls-Demo laden">🎲 Zufall</button>
|
||
<button id="btnClear" title="Leeren">🗑️ Neu</button>
|
||
<button id="btnRun" title="Blockly-Code ausführen">▶️ Ausführen</button>
|
||
<button id="btnCrew" style="background:#9c27b0" title="Ergebnis an die Crew senden">🚀 An Crew senden</button>
|
||
</div>
|
||
</header>
|
||
|
||
<div id="wrap">
|
||
<div id="left">
|
||
<div id="blocklyDiv"></div>
|
||
<pre id="output">🌲 Bereit. Lade „Doku“/„T1–T3“ oder baue eigene Logik und drücke ▶️.</pre>
|
||
</div>
|
||
<div id="right">
|
||
<div id="cfg"></div>
|
||
<div class="hint">
|
||
Ziel-JSON: {"total_events","classes","dominant","mapping"} •
|
||
Optional: Debounce (N), Gleichstand-Strategie (per Blocks).
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Minimal-Toolbox -->
|
||
<xml id="toolbox" style="display:none">
|
||
<category name="Variablen" custom="VARIABLE"></category>
|
||
<category name="Logik">
|
||
<block type="controls_if"></block>
|
||
<block type="logic_compare"></block>
|
||
</category>
|
||
<category name="Schleifen">
|
||
<block type="controls_repeat_ext"></block>
|
||
<block type="controls_forEach"></block>
|
||
<block type="controls_whileUntil"></block>
|
||
</category>
|
||
<category name="Mathe">
|
||
<block type="math_number"></block>
|
||
<block type="math_arithmetic"></block>
|
||
</category>
|
||
<category name="Listen">
|
||
<block type="lists_create_with"></block>
|
||
</category>
|
||
<category name="Text">
|
||
<block type="text"></block>
|
||
<block type="text_join"></block>
|
||
<block type="text_print"></block>
|
||
</category>
|
||
<category name="Funktionen" custom="PROCEDURE"></category>
|
||
</xml>
|
||
|
||
<script>
|
||
// === CFG: Parameter-Kit (nur Anzeige/Didaktik, kein Netzwerk) ===
|
||
const CFG = {
|
||
classes: ["red", "green", "blue", "yellow"],
|
||
synonyms: { "purple": "unknown", "orange": "unknown" },
|
||
normalize: "case_insensitive",
|
||
window_n: 12,
|
||
debounce_n: 0,
|
||
dominant_mode: "max",
|
||
tie_policy: "all",
|
||
emit_mode: "final_only",
|
||
reset_mode: "manual",
|
||
include_ts: true,
|
||
mapping: { red: "⚠️", green: "✅", blue: "ℹ️", yellow: "⏳", unknown: "❔" },
|
||
rng_seed: 42,
|
||
weights: { red: 1, green: 1, blue: 1, yellow: 1, unknown: 0.5 }
|
||
};
|
||
document.getElementById('cfg').textContent =
|
||
'CFG (Gedankenstütze):\\n' + JSON.stringify(CFG, null, 2);
|
||
|
||
// === Blockly Setup ===
|
||
const workspace = Blockly.inject('blocklyDiv', {
|
||
toolbox: document.getElementById('toolbox'),
|
||
theme: Blockly.Themes.Dark,
|
||
renderer: 'zelos',
|
||
grid: { spacing: 24, length: 3, colour: '#474747', snap: true },
|
||
trashcan: true,
|
||
zoom: { startScale: 1.1, maxScale: 2.0, minScale: .6, controls: false, wheel: true },
|
||
move: { scrollbars: true, drag: true, wheel: true }
|
||
});
|
||
|
||
// Vordefinierte Variablen (Zähler, Events, Dominant, optional last_ev)
|
||
['c_red', 'c_green', 'c_blue', 'c_yellow', 'c_unknown', 'total', 'ev', 'dominant', 'last_ev']
|
||
.forEach(v => { try { workspace.createVariable(v); } catch (_) { } });
|
||
|
||
// Output Helpers
|
||
const $ = s => document.querySelector(s);
|
||
function setOutput(t) { $('#output').textContent = t }
|
||
function appendOutput(t) {
|
||
const el = $('#output');
|
||
el.textContent += (el.textContent.endsWith('\\n') ? '' : '\\n') + t;
|
||
el.scrollTop = el.scrollHeight;
|
||
}
|
||
window.appendOutput = appendOutput; // für generierten Code
|
||
|
||
// text_print → Panel (statt alert)
|
||
// Wir suchen den Generator (je nach Version unterschiedlich)
|
||
const gen = (typeof Blockly.JavaScript !== 'undefined') ? Blockly.JavaScript :
|
||
(typeof javascript !== 'undefined' && javascript.javascriptGenerator) ? javascript.javascriptGenerator : null;
|
||
|
||
if (gen) {
|
||
gen['text_print'] = function (block) {
|
||
const argument0 = gen.valueToCode(block, 'TEXT', gen.ORDER_NONE) || '\'\'';
|
||
return 'appendOutput(String(' + argument0 + '));\\n';
|
||
};
|
||
} else {
|
||
console.error("CRUMBBLOCKS: Konnte JavaScript Generator nicht finden!");
|
||
}
|
||
|
||
// XML Parser Fallback
|
||
function textToDom(xmlText) {
|
||
try { if (Blockly.utils?.xml?.textToDom) return Blockly.utils.xml.textToDom(xmlText); } catch (_) { }
|
||
return new DOMParser().parseFromString(xmlText, 'text/xml').documentElement;
|
||
}
|
||
function loadXml(xml) { const dom = textToDom(xml); workspace.clear(); Blockly.Xml.domToWorkspace(dom, workspace); }
|
||
|
||
// === DOKU XML ===
|
||
const DOC_XML = `
|
||
<xml xmlns="https://developers.google.com/blockly/xml">
|
||
<variables>
|
||
<variable>c_red</variable><variable>c_green</variable><variable>c_blue</variable>
|
||
<variable>c_yellow</variable><variable>c_unknown</variable><variable>total</variable>
|
||
<variable>ev</variable><variable>dominant</variable>
|
||
</variables>
|
||
|
||
<!-- DOKU -->
|
||
<block type="text_print" x="20" y="20">
|
||
<value name="TEXT"><block type="text"><field name="TEXT">DOC: Regenbogen-Zähl-Maschine – zählt Farbereignisse und erzeugt JSON-Report.</field></block></value>
|
||
<next><block type="text_print"><value name="TEXT"><block type="text"><field name="TEXT">Eingabe (Demo): ["red","green","blue","blue","yellow","purple"]</field></block></value></block></next>
|
||
</block>
|
||
<block type="text_print" x="20" y="88">
|
||
<value name="TEXT"><block type="text"><field name="TEXT">Erwartet: {"total_events","classes":{"red","green","blue","yellow","unknown"},"dominant","mapping"}</field></block></value>
|
||
</block>
|
||
|
||
<!-- Init -->
|
||
<block type="variables_set" x="20" y="150">
|
||
<field name="VAR">c_red</field><value name="VALUE"><block type="math_number"><field name="NUM">0</field></block></value>
|
||
<next><block type="variables_set"><field name="VAR">c_green</field><value name="VALUE"><block type="math_number"><field name="NUM">0</field></block></value><next>
|
||
<block type="variables_set"><field name="VAR">c_blue</field><value name="VALUE"><block type="math_number"><field name="NUM">0</field></block></value><next>
|
||
<block type="variables_set"><field name="VAR">c_yellow</field><value name="VALUE"><block type="math_number"><field name="NUM">0</field></block></value><next>
|
||
<block type="variables_set"><field name="VAR">c_unknown</field><value name="VALUE"><block type="math_number"><field name="NUM">0</field></block></value><next>
|
||
<block type="variables_set"><field name="VAR">total</field><value name="VALUE"><block type="math_number"><field name="NUM">0</field></block></value>
|
||
</next></next></next></next></next>
|
||
</block>
|
||
|
||
<!-- Demo-Ereignisse -->
|
||
<block type="controls_forEach" x="20" y="320">
|
||
<field name="VAR">ev</field>
|
||
<value name="LIST"><block type="lists_create_with"><mutation items="6"></mutation>
|
||
<value name="ADD0"><block type="text"><field name="TEXT">red</field></block></value>
|
||
<value name="ADD1"><block type="text"><field name="TEXT">green</field></block></value>
|
||
<value name="ADD2"><block type="text"><field name="TEXT">blue</field></block></value>
|
||
<value name="ADD3"><block type="text"><field name="TEXT">blue</field></block></value>
|
||
<value name="ADD4"><block type="text"><field name="TEXT">yellow</field></block></value>
|
||
<value name="ADD5"><block type="text"><field name="TEXT">purple</field></block></value>
|
||
</block></value>
|
||
<statement name="DO">
|
||
<block type="variables_set">
|
||
<field name="VAR">total</field>
|
||
<value name="VALUE"><block type="math_arithmetic"><field name="OP">ADD</field>
|
||
<value name="A"><block type="variables_get"><field name="VAR">total</field></block></value>
|
||
<value name="B"><block type="math_number"><field name="NUM">1</field></block></value>
|
||
</block></value>
|
||
<next>
|
||
<block type="controls_if">
|
||
<mutation elseif="3" else="1"></mutation>
|
||
<value name="IF0"><block type="logic_compare"><field name="OP">EQ</field>
|
||
<value name="A"><block type="variables_get"><field name="VAR">ev</field></block></value>
|
||
<value name="B"><block type="text"><field name="TEXT">red</field></block></value>
|
||
</block></value>
|
||
<statement name="DO0"><block type="variables_set"><field name="VAR">c_red</field>
|
||
<value name="VALUE"><block type="math_arithmetic"><field name="OP">ADD</field>
|
||
<value name="A"><block type="variables_get"><field name="VAR">c_red</field></block></value>
|
||
<value name="B"><block type="math_number"><field name="NUM">1</field></block></value>
|
||
</block></value>
|
||
</block></statement>
|
||
|
||
<value name="IF1"><block type="logic_compare"><field name="OP">EQ</field>
|
||
<value name="A"><block type="variables_get"><field name="VAR">ev</field></block></value>
|
||
<value name="B"><block type="text"><field name="TEXT">green</field></block></value>
|
||
</block></value>
|
||
<statement name="DO1"><block type="variables_set"><field name="VAR">c_green</field>
|
||
<value name="VALUE"><block type="math_arithmetic"><field name="OP">ADD</field>
|
||
<value name="A"><block type="variables_get"><field name="VAR">c_green</field></block></value>
|
||
<value name="B"><block type="math_number"><field name="NUM">1</field></block></value>
|
||
</block></value>
|
||
</block></statement>
|
||
|
||
<value name="IF2"><block type="logic_compare"><field name="OP">EQ</field>
|
||
<value name="A"><block type="variables_get"><field name="VAR">ev</field></block></value>
|
||
<value name="B"><block type="text"><field name="TEXT">blue</field></block></value>
|
||
</block></value>
|
||
<statement name="DO2"><block type="variables_set"><field name="VAR">c_blue</field>
|
||
<value name="VALUE"><block type="math_arithmetic"><field name="OP">ADD</field>
|
||
<value name="A"><block type="variables_get"><field name="VAR">c_blue</field></block></value>
|
||
<value name="B"><block type="math_number"><field name="NUM">1</field></block></value>
|
||
</block></value>
|
||
</block></statement>
|
||
|
||
<value name="IF3"><block type="logic_compare"><field name="OP">EQ</field>
|
||
<value name="A"><block type="variables_get"><field name="VAR">ev</field></block></value>
|
||
<value name="B"><block type="text"><field name="TEXT">yellow</field></block></value>
|
||
</block></value>
|
||
<statement name="DO3"><block type="variables_set"><field name="VAR">c_yellow</field>
|
||
<value name="VALUE"><block type="math_arithmetic"><field name="OP">ADD</field>
|
||
<value name="A"><block type="variables_get"><field name="VAR">c_yellow</field></block></value>
|
||
<value name="B"><block type="math_number"><field name="NUM">1</field></block></value>
|
||
</block></value>
|
||
</block></statement>
|
||
|
||
<statement name="ELSE"><block type="variables_set"><field name="VAR">c_unknown</field>
|
||
<value name="VALUE"><block type="math_arithmetic"><field name="OP">ADD</field>
|
||
<value name="A"><block type="variables_get"><field name="VAR">c_unknown</field></block></value>
|
||
<value name="B"><block type="math_number"><field name="NUM">1</field></block></value>
|
||
</block></value>
|
||
</block></statement>
|
||
</block>
|
||
</next>
|
||
</block>
|
||
</statement>
|
||
</block>
|
||
|
||
<!-- Dominant (einfach) -->
|
||
<block type="variables_set" x="20" y="610">
|
||
<field name="VAR">dominant</field>
|
||
<value name="VALUE"><block type="text"><field name="TEXT">blue</field></block></value>
|
||
</block>
|
||
|
||
<!-- JSON Report -->
|
||
<block type="text_print" x="20" y="650">
|
||
<value name="TEXT">
|
||
<block type="text_join">
|
||
<mutation items="22"></mutation>
|
||
<value name="ADD0"><block type="text"><field name="TEXT">{ "total_events": </field></block></value>
|
||
<value name="ADD1"><block type="variables_get"><field name="VAR">total</field></block></value>
|
||
<value name="ADD2"><block type="text"><field name="TEXT">, "classes": { "red": </field></block></value>
|
||
<value name="ADD3"><block type="variables_get"><field name="VAR">c_red</field></block></value>
|
||
<value name="ADD4"><block type="text"><field name="TEXT">, "green": </field></block></value>
|
||
<value name="ADD5"><block type="variables_get"><field name="VAR">c_green</field></block></value>
|
||
<value name="ADD6"><block type="text"><field name="TEXT">, "blue": </field></block></value>
|
||
<value name="ADD7"><block type="variables_get"><field name="VAR">c_blue</field></block></value>
|
||
<value name="ADD8"><block type="text"><field name="TEXT">, "yellow": </field></block></value>
|
||
<value name="ADD9"><block type="variables_get"><field name="VAR">c_yellow</field></block></value>
|
||
<value name="ADD10"><block type="text"><field name="TEXT">, "unknown": </field></block></value>
|
||
<value name="ADD11"><block type="variables_get"><field name="VAR">c_unknown</field></block></value>
|
||
<value name="ADD12"><block type="text"><field name="TEXT"> }, "dominant": "</field></block></value>
|
||
<value name="ADD13"><block type="variables_get"><field name="VAR">dominant</field></block></value>
|
||
<value name="ADD14"><block type="text"><field name="TEXT">", "mapping": { "red": "⚠️", "green": "✅", "blue": "ℹ️", "yellow": "⏳", "unknown": "❔" } }</field></block></value>
|
||
</block>
|
||
</value>
|
||
</block>
|
||
</xml>
|
||
`.trim();
|
||
|
||
// === Testfälle ===
|
||
const T1_XML = DOC_XML; // Basisliste, dominant=blue (einfach)
|
||
|
||
const T2_XML = `
|
||
<xml xmlns="https://developers.google.com/blockly/xml">
|
||
<variables>
|
||
<variable>c_red</variable><variable>c_green</variable><variable>c_blue</variable>
|
||
<variable>c_yellow</variable><variable>c_unknown</variable><variable>total</variable>
|
||
<variable>ev</variable><variable>dominant</variable>
|
||
</variables>
|
||
<block type="text_print" x="20" y="20"><value name="TEXT"><block type="text"><field name="TEXT">T2: Gleichstand red vs blue</field></block></value></block>
|
||
|
||
<!-- Init -->
|
||
<block type="variables_set" x="20" y="70"><field name="VAR">c_red</field><value name="VALUE"><block type="math_number"><field name="NUM">0</field></block></value>
|
||
<next><block type="variables_set"><field name="VAR">c_green</field><value name="VALUE"><block type="math_number"><field name="NUM">0</field></block></value><next>
|
||
<block type="variables_set"><field name="VAR">c_blue</field><value name="VALUE"><block type="math_number"><field name="NUM">0</field></block></value><next>
|
||
<block type="variables_set"><field name="VAR">c_yellow</field><value name="VALUE"><block type="math_number"><field name="NUM">0</field></block></value><next>
|
||
<block type="variables_set"><field name="VAR">c_unknown</field><value name="VALUE"><block type="math_number"><field name="NUM">0</field></block></value><next>
|
||
<block type="variables_set"><field name="VAR">total</field><value name="VALUE"><block type="math_number"><field name="NUM">0</field></block></value>
|
||
</next></next></next></next></next>
|
||
</block>
|
||
|
||
<!-- Events: ["red","blue","red","blue"] -->
|
||
<block type="controls_forEach" x="20" y="230">
|
||
<field name="VAR">ev</field>
|
||
<value name="LIST"><block type="lists_create_with"><mutation items="4"></mutation>
|
||
<value name="ADD0"><block type="text"><field name="TEXT">red</field></block></value>
|
||
<value name="ADD1"><block type="text"><field name="TEXT">blue</field></block></value>
|
||
<value name="ADD2"><block type="text"><field name="TEXT">red</field></block></value>
|
||
<value name="ADD3"><block type="text"><field name="TEXT">blue</field></block></value>
|
||
</block></value>
|
||
<statement name="DO">
|
||
<block type="variables_set">
|
||
<field name="VAR">total</field>
|
||
<value name="VALUE"><block type="math_arithmetic"><field name="OP">ADD</field>
|
||
<value name="A"><block type="variables_get"><field name="VAR">total</field></block></value>
|
||
<value name="B"><block type="math_number"><field name="NUM">1</field></block></value>
|
||
</block></value>
|
||
<next>
|
||
<block type="controls_if">
|
||
<mutation elseif="1" else="1"></mutation>
|
||
<value name="IF0"><block type="logic_compare"><field name="OP">EQ</field>
|
||
<value name="A"><block type="variables_get"><field name="VAR">ev</field></block></value>
|
||
<value name="B"><block type="text"><field name="TEXT">red</field></block></value></block></value>
|
||
<statement name="DO0"><block type="variables_set"><field name="VAR">c_red</field>
|
||
<value name="VALUE"><block type="math_arithmetic"><field name="OP">ADD</field>
|
||
<value name="A"><block type="variables_get"><field name="VAR">c_red</field></block></value>
|
||
<value name="B"><block type="math_number"><field name="NUM">1</field></block></value></block></value></block></statement>
|
||
<value name="IF1"><block type="logic_compare"><field name="OP">EQ</field>
|
||
<value name="A"><block type="variables_get"><field name="VAR">ev</field></block></value>
|
||
<value name="B"><block type="text"><field name="TEXT">blue</field></block></value></block></value>
|
||
<statement name="DO1"><block type="variables_set"><field name="VAR">c_blue</field>
|
||
<value name="VALUE"><block type="math_arithmetic"><field name="OP">ADD</field>
|
||
<value name="A"><block type="variables_get"><field name="VAR">c_blue</field></block></value>
|
||
<value name="B"><block type="math_number"><field name="NUM">1</field></block></value></block></value></block></statement>
|
||
<statement name="ELSE"><block type="text_print"><value name="TEXT"><block type="text"><field name="TEXT">Ignoriere andere.</field></block></value></block></statement>
|
||
</block>
|
||
</next>
|
||
</block>
|
||
</statement>
|
||
</block>
|
||
|
||
<!-- Gleichstand: dominant = "red,blue" (Liste als Text) -->
|
||
<block type="variables_set" x="20" y="470"><field name="VAR">dominant</field>
|
||
<value name="VALUE"><block type="text"><field name="TEXT">["red","blue"]</field></block></value>
|
||
</block>
|
||
|
||
<!-- JSON Report -->
|
||
<block type="text_print" x="20" y="520">
|
||
<value name="TEXT">
|
||
<block type="text_join">
|
||
<mutation items="24"></mutation>
|
||
<value name="ADD0"><block type="text"><field name="TEXT">{ "total_events": </field></block></value>
|
||
<value name="ADD1"><block type="variables_get"><field name="VAR">total</field></block></value>
|
||
<value name="ADD2"><block type="text"><field name="TEXT">, "classes": { "red": </field></block></value>
|
||
<value name="ADD3"><block type="variables_get"><field name="VAR">c_red</field></block></value>
|
||
<value name="ADD4"><block type="text"><field name="TEXT">, "green": </field></block></value>
|
||
<value name="ADD5"><block type="variables_get"><field name="VAR">c_green</field></block></value>
|
||
<value name="ADD6"><block type="text"><field name="TEXT">, "blue": </field></block></value>
|
||
<value name="ADD7"><block type="variables_get"><field name="VAR">c_blue</field></block></value>
|
||
<value name="ADD8"><block type="text"><field name="TEXT">, "yellow": </field></block></value>
|
||
<value name="ADD9"><block type="variables_get"><field name="VAR">c_yellow</field></block></value>
|
||
<value name="ADD10"><block type="text"><field name="TEXT">, "unknown": </field></block></value>
|
||
<value name="ADD11"><block type="variables_get"><field name="VAR">c_unknown</field></block></value>
|
||
<value name="ADD12"><block type="text"><field name="TEXT"> }, "dominant_all": </field></block></value>
|
||
<value name="ADD13"><block type="variables_get"><field name="VAR">dominant</field></block></value>
|
||
<value name="ADD14"><block type="text"><field name="TEXT">, "mapping": { "red": "⚠️", "green": "✅", "blue": "ℹ️", "yellow": "⏳", "unknown": "❔" } }</field></block></value>
|
||
</block>
|
||
</value>
|
||
</block>
|
||
</xml>
|
||
`.trim();
|
||
|
||
const T3_XML = `
|
||
<xml xmlns="https://developers.google.com/blockly/xml">
|
||
<variables>
|
||
<variable>c_red</variable><variable>c_green</variable><variable>c_blue</variable>
|
||
<variable>c_yellow</variable><variable>c_unknown</variable><variable>total</variable>
|
||
<variable>ev</variable><variable>dominant</variable><variable>last_ev</variable>
|
||
</variables>
|
||
<block type="text_print" x="20" y="20"><value name="TEXT"><block type="text"><field name="TEXT">T3: Debounce 1 (identische Wiederholung wird ignoriert)</field></block></value></block>
|
||
|
||
<!-- Init -->
|
||
<block type="variables_set" x="20" y="70"><field name="VAR">c_red</field><value name="VALUE"><block type="math_number"><field name="NUM">0</field></block></value>
|
||
<next><block type="variables_set"><field name="VAR">c_green</field><value name="VALUE"><block type="math_number"><field name="NUM">0</field></block></value><next>
|
||
<block type="variables_set"><field name="VAR">c_blue</field><value name="VALUE"><block type="math_number"><field name="NUM">0</field></block></value><next>
|
||
<block type="variables_set"><field name="VAR">c_yellow</field><value name="VALUE"><block type="math_number"><field name="NUM">0</field></block></value><next>
|
||
<block type="variables_set"><field name="VAR">c_unknown</field><value name="VALUE"><block type="math_number"><field name="NUM">0</field></block></value><next>
|
||
<block type="variables_set"><field name="VAR">total</field><value name="VALUE"><block type="math_number"><field name="NUM">0</field></block></value>
|
||
</next></next></next></next></next>
|
||
</block>
|
||
<block type="variables_set" x="20" y="230"><field name="VAR">last_ev</field><value name="VALUE"><block type="text"><field name="TEXT">_none_</field></block></value></block>
|
||
|
||
<!-- Events: ["blue","blue","green"] -->
|
||
<block type="controls_forEach" x="20" y="280">
|
||
<field name="VAR">ev</field>
|
||
<value name="LIST"><block type="lists_create_with"><mutation items="3"></mutation>
|
||
<value name="ADD0"><block type="text"><field name="TEXT">blue</field></block></value>
|
||
<value name="ADD1"><block type="text"><field name="TEXT">blue</field></block></value>
|
||
<value name="ADD2"><block type="text"><field name="TEXT">green</field></block></value>
|
||
</block></value>
|
||
<statement name="DO">
|
||
<block type="controls_if">
|
||
<value name="IF0"><block type="logic_compare"><field name="OP">NEQ</field>
|
||
<value name="A"><block type="variables_get"><field name="VAR">ev</field></block></value>
|
||
<value name="B"><block type="variables_get"><field name="VAR">last_ev</field></block></value>
|
||
</block></value>
|
||
<statement name="DO0">
|
||
<block type="variables_set">
|
||
<field name="VAR">total</field>
|
||
<value name="VALUE"><block type="math_arithmetic"><field name="OP">ADD</field>
|
||
<value name="A"><block type="variables_get"><field name="VAR">total</field></block></value>
|
||
<value name="B"><block type="math_number"><field name="NUM">1</field></block></value>
|
||
</block></value>
|
||
<next>
|
||
<block type="controls_if">
|
||
<mutation elseif="3" else="1"></mutation>
|
||
<value name="IF0"><block type="logic_compare"><field name="OP">EQ</field>
|
||
<value name="A"><block type="variables_get"><field name="VAR">ev</field></block></value>
|
||
<value name="B"><block type="text"><field name="TEXT">red</field></block></value></block></value>
|
||
<statement name="DO0"><block type="variables_set"><field name="VAR">c_red</field>
|
||
<value name="VALUE"><block type="math_arithmetic"><field name="OP">ADD</field>
|
||
<value name="A"><block type="variables_get"><field name="VAR">c_red</field></block></value>
|
||
<value name="B"><block type="math_number"><field name="NUM">1</field></block></value></block></value></block></statement>
|
||
<value name="IF1"><block type="logic_compare"><field name="OP">EQ</field>
|
||
<value name="A"><block type="variables_get"><field name="VAR">ev</field></block></value>
|
||
<value name="B"><block type="text"><field name="TEXT">green</field></block></value></block></value>
|
||
<statement name="DO1"><block type="variables_set"><field name="VAR">c_green</field>
|
||
<value name="VALUE"><block type="math_arithmetic"><field name="OP">ADD</field>
|
||
<value name="A"><block type="variables_get"><field name="VAR">c_green</field></block></value>
|
||
<value name="B"><block type="math_number"><field name="NUM">1</field></block></value></block></value></block></statement>
|
||
<value name="IF2"><block type="logic_compare"><field name="OP">EQ</field>
|
||
<value name="A"><block type="variables_get"><field name="VAR">ev</field></block></value>
|
||
<value name="B"><block type="text"><field name="TEXT">blue</field></block></value></block></value>
|
||
<statement name="DO2"><block type="variables_set"><field name="VAR">c_blue</field>
|
||
<value name="VALUE"><block type="math_arithmetic"><field name="OP">ADD</field>
|
||
<value name="A"><block type="variables_get"><field name="VAR">c_blue</field></block></value>
|
||
<value name="B"><block type="math_number"><field name="NUM">1</field></block></value></block></value></block></statement>
|
||
<value name="IF3"><block type="logic_compare"><field name="OP">EQ</field>
|
||
<value name="A"><block type="variables_get"><field name="VAR">ev</field></block></value>
|
||
<value name="B"><block type="text"><field name="TEXT">yellow</field></block></value></block></value>
|
||
<statement name="DO3"><block type="variables_set"><field name="VAR">c_yellow</field>
|
||
<value name="VALUE"><block type="math_arithmetic"><field name="OP">ADD</field>
|
||
<value name="A"><block type="variables_get"><field name="VAR">c_yellow</field></block></value>
|
||
<value name="B"><block type="math_number"><field name="NUM">1</field></block></value></block></value></block></statement>
|
||
<statement name="ELSE"><block type="variables_set"><field name="VAR">c_unknown</field>
|
||
<value name="VALUE"><block type="math_arithmetic"><field name="OP">ADD</field>
|
||
<value name="A"><block type="variables_get"><field name="VAR">c_unknown</field></block></value>
|
||
<value name="B"><block type="math_number"><field name="NUM">1</field></block></value></block></value></block></statement>
|
||
</block>
|
||
</next>
|
||
</block>
|
||
</statement>
|
||
</block>
|
||
<next><block type="variables_set"><field name="VAR">last_ev</field><value name="VALUE"><block type="variables_get"><field name="VAR">ev</field></block></value></block></next>
|
||
</statement>
|
||
</block>
|
||
|
||
<!-- Dominant (einfach max-Entscheid) -->
|
||
<block type="variables_set" x="20" y="620"><field name="VAR">dominant</field>
|
||
<value name="VALUE"><block type="text"><field name="TEXT">unknown</field></block></value>
|
||
</block>
|
||
<block type="controls_if" x="20" y="660">
|
||
<mutation elseif="3" else="1"></mutation>
|
||
<value name="IF0"><block type="logic_compare"><field name="OP">GT</field>
|
||
<value name="A"><block type="variables_get"><field name="VAR">c_blue</field></block></value>
|
||
<value name="B"><block type="variables_get"><field name="VAR">c_red</field></block></value>
|
||
</block></value>
|
||
<statement name="DO0"><block type="variables_set"><field name="VAR">dominant</field><value name="VALUE"><block type="text"><field name="TEXT">blue</field></block></value></block></statement>
|
||
<value name="IF1"><block type="logic_compare"><field name="OP">GT</field>
|
||
<value name="A"><block type="variables_get"><field name="VAR">c_red</field></block></value>
|
||
<value name="B"><block type="variables_get"><field name="VAR">c_blue</field></block></value>
|
||
</block></value>
|
||
<statement name="DO1"><block type="variables_set"><field name="VAR">dominant</field><value name="VALUE"><block type="text"><field name="TEXT">red</field></block></value></block></statement>
|
||
<value name="IF2"><block type="logic_compare"><field name="OP">GT</field>
|
||
<value name="A"><block type="variables_get"><field name="VAR">c_green</field></block></value>
|
||
<value name="B"><block type="variables_get"><field name="VAR">c_blue</field></block></value>
|
||
</block></value>
|
||
<statement name="DO2"><block type="variables_set"><field name="VAR">dominant</field><value name="VALUE"><block type="text"><field name="TEXT">green</field></block></value></block></statement>
|
||
<value name="IF3"><block type="logic_compare"><field name="OP">GT</field>
|
||
<value name="A"><block type="variables_get"><field name="VAR">c_yellow</field></block></value>
|
||
<value name="B"><block type="variables_get"><field name="VAR">c_blue</field></block></value>
|
||
</block></value>
|
||
<statement name="DO3"><block type="variables_set"><field name="VAR">dominant</field><value name="VALUE"><block type="text"><field name="TEXT">yellow</field></block></value></block></statement>
|
||
<statement name="ELSE"><block type="variables_set"><field name="VAR">dominant</field><value name="VALUE"><block type="text"><field name="TEXT">blue</field></block></value></block></statement>
|
||
</block>
|
||
|
||
<!-- JSON -->
|
||
<block type="text_print" x="20" y="830">
|
||
<value name="TEXT">
|
||
<block type="text_join">
|
||
<mutation items="22"></mutation>
|
||
<value name="ADD0"><block type="text"><field name="TEXT">{ "total_events": </field></block></value>
|
||
<value name="ADD1"><block type="variables_get"><field name="VAR">total</field></block></value>
|
||
<value name="ADD2"><block type="text"><field name="TEXT">, "classes": { "red": </field></block></value>
|
||
<value name="ADD3"><block type="variables_get"><field name="VAR">c_red</field></block></value>
|
||
<value name="ADD4"><block type="text"><field name="TEXT">, "green": </field></block></value>
|
||
<value name="ADD5"><block type="variables_get"><field name="VAR">c_green</field></block></value>
|
||
<value name="ADD6"><block type="text"><field name="TEXT">, "blue": </field></block></value>
|
||
<value name="ADD7"><block type="variables_get"><field name="VAR">c_blue</field></block></value>
|
||
<value name="ADD8"><block type="text"><field name="TEXT">, "yellow": </field></block></value>
|
||
<value name="ADD9"><block type="variables_get"><field name="VAR">c_yellow</field></block></value>
|
||
<value name="ADD10"><block type="text"><field name="TEXT">, "unknown": </field></block></value>
|
||
<value name="ADD11"><block type="variables_get"><field name="VAR">c_unknown</field></block></value>
|
||
<value name="ADD12"><block type="text"><field name="TEXT"> }, "dominant": "</field></block></value>
|
||
<value name="ADD13"><block type="variables_get"><field name="VAR">dominant</field></block></value>
|
||
<value name="ADD14"><block type="text"><field name="TEXT">", "mapping": { "red": "⚠️", "green": "✅", "blue": "ℹ️", "yellow": "⏳", "unknown": "❔" } }</field></block></value>
|
||
</block>
|
||
</value>
|
||
</block>
|
||
</xml>
|
||
`.trim();
|
||
|
||
// === Zufalls-Demo-Generator (nur Vorstellung, keine Sensorik) ===
|
||
function randomDemoXml(n = CFG.window_n) {
|
||
const colors = ['red', 'green', 'blue', 'yellow', 'purple', 'orange'];
|
||
// einfacher RNG (konstant)
|
||
let seed = CFG.rng_seed;
|
||
function rnd() { seed = (seed * 1664525 + 1013904223) % 4294967296; return seed / 4294967296; }
|
||
const arr = Array.from({ length: n }, () => colors[Math.floor(rnd() * colors.length)]);
|
||
|
||
const items = arr.map((c, i) => `
|
||
<value name="ADD${i}"><block type="text"><field name="TEXT">${c}</field></block></value>`).join('');
|
||
return `
|
||
<xml xmlns="https://developers.google.com/blockly/xml">
|
||
<variables><variable>ev</variable><variable>total</variable><variable>c_red</variable><variable>c_green</variable><variable>c_blue</variable><variable>c_yellow</variable><variable>c_unknown</variable><variable>dominant</variable></variables>
|
||
<block type="text_print" x="20" y="20"><value name="TEXT"><block type="text"><field name="TEXT">🎲 Zufalls-Ereignisse: ${arr.join(', ')}</field></block></value></block>
|
||
<block type="variables_set" x="20" y="80"><field name="VAR">c_red</field><value name="VALUE"><block type="math_number"><field name="NUM">0</field></block></value>
|
||
<next><block type="variables_set"><field name="VAR">c_green</field><value name="VALUE"><block type="math_number"><field name="NUM">0</field></block></value><next>
|
||
<block type="variables_set"><field name="VAR">c_blue</field><value name="VALUE"><block type="math_number"><field name="NUM">0</field></block></value><next>
|
||
<block type="variables_set"><field name="VAR">c_yellow</field><value name="VALUE"><block type="math_number"><field name="NUM">0</field></block></value><next>
|
||
<block type="variables_set"><field name="VAR">c_unknown</field><value name="VALUE"><block type="math_number"><field name="NUM">0</field></block></value><next>
|
||
<block type="variables_set"><field name="VAR">total</field><value name="VALUE"><block type="math_number"><field name="NUM">0</field></block></value>
|
||
</next></next></next></next></next>
|
||
</block>
|
||
<block type="controls_forEach" x="20" y="260">
|
||
<field name="VAR">ev</field>
|
||
<value name="LIST"><block type="lists_create_with"><mutation items="${n}"></mutation>${items}</block></value>
|
||
<statement name="DO">
|
||
<block type="variables_set"><field name="VAR">total</field><value name="VALUE"><block type="math_arithmetic"><field name="OP">ADD</field>
|
||
<value name="A"><block type="variables_get"><field name="VAR">total</field></block></value>
|
||
<value name="B"><block type="math_number"><field name="NUM">1</field></block></value>
|
||
</block></value>
|
||
<next>
|
||
<block type="controls_if"><mutation elseif="3" else="1"></mutation>
|
||
<value name="IF0"><block type="logic_compare"><field name="OP">EQ</field><value name="A"><block type="variables_get"><field name="VAR">ev</field></block></value><value name="B"><block type="text"><field name="TEXT">red</field></block></value></block></value>
|
||
<statement name="DO0"><block type="variables_set"><field name="VAR">c_red</field><value name="VALUE"><block type="math_arithmetic"><field name="OP">ADD</field><value name="A"><block type="variables_get"><field name="VAR">c_red</field></block></value><value name="B"><block type="math_number"><field name="NUM">1</field></block></value></block></value></block></statement>
|
||
<value name="IF1"><block type="logic_compare"><field name="OP">EQ</field><value name="A"><block type="variables_get"><field name="VAR">ev</field></block></value><value name="B"><block type="text"><field name="TEXT">green</field></block></value></block></value>
|
||
<statement name="DO1"><block type="variables_set"><field name="VAR">c_green</field><value name="VALUE"><block type="math_arithmetic"><field name="OP">ADD</field><value name="A"><block type="variables_get"><field name="VAR">c_green</field></block></value><value name="B"><block type="math_number"><field name="NUM">1</field></block></value></block></value></block></statement>
|
||
<value name="IF2"><block type="logic_compare"><field name="OP">EQ</field><value name="A"><block type="variables_get"><field name="VAR">ev</field></block></value><value name="B"><block type="text"><field name="TEXT">blue</field></block></value></block></value>
|
||
<statement name="DO2"><block type="variables_set"><field name="VAR">c_blue</field><value name="VALUE"><block type="math_arithmetic"><field name="OP">ADD</field><value name="A"><block type="variables_get"><field name="VAR">c_blue</field></block></value><value name="B"><block type="math_number"><field name="NUM">1</field></block></value></block></value></block></statement>
|
||
<value name="IF3"><block type="logic_compare"><field name="OP">EQ</field><value name="A"><block type="variables_get"><field name="VAR">ev</field></block></value><value name="B"><block type="text"><field name="TEXT">yellow</field></block></value></block></value>
|
||
<statement name="DO3"><block type="variables_set"><field name="VAR">c_yellow</field><value name="VALUE"><block type="math_arithmetic"><field name="OP">ADD</field><value name="A"><block type="variables_get"><field name="VAR">c_yellow</field></block></value><value name="B"><block type="math_number"><field name="NUM">1</field></block></value></block></value></block></statement>
|
||
<statement name="ELSE"><block type="variables_set"><field name="VAR">c_unknown</field><value name="VALUE"><block type="math_arithmetic"><field name="OP">ADD</field><value name="A"><block type="variables_get"><field name="VAR">c_unknown</field></block></value><value name="B"><block type="math_number"><field name="NUM">1</field></block></value></block></value></block></statement>
|
||
</block>
|
||
</next>
|
||
</statement>
|
||
</block>
|
||
<block type="variables_set" x="20" y="560"><field name="VAR">dominant</field><value name="VALUE"><block type="text"><field name="TEXT">blue</field></block></value></block>
|
||
<block type="text_print" x="20" y="600"><value name="TEXT"><block type="text"><field name="TEXT">→ Ergänze IF-Kette oder eigene Funktion für „dominant“.</field></block></value></block>
|
||
</xml>
|
||
`.trim();
|
||
}
|
||
|
||
// === Actions ===
|
||
document.getElementById('btnDoc').onclick = () => { loadXml(DOC_XML); setOutput('📄 Doku geladen. Lies die DOC-Zeilen und drücke ▶️.'); };
|
||
document.getElementById('btnT1').onclick = () => { loadXml(T1_XML); setOutput('🧪 T1 geladen (Basisliste). ▶️ für Report.'); };
|
||
document.getElementById('btnT2').onclick = () => { loadXml(T2_XML); setOutput('🧪 T2 geladen (Gleichstand). ▶️ für Report mit dominant_all=["red","blue"].'); };
|
||
document.getElementById('btnT3').onclick = () => { loadXml(T3_XML); setOutput('🧪 T3 geladen (Debounce=1). ▶️ für Report.'); };
|
||
document.getElementById('btnRnd').onclick = () => { loadXml(randomDemoXml()); setOutput('🎲 Zufalls-Demo geladen. Ergänze Dominanz-Logik & ▶️.'); };
|
||
document.getElementById('btnClear').onclick = () => { workspace.clear(); setOutput('🧹 Workspace geleert.'); };
|
||
|
||
document.getElementById('btnRun').onclick = () => {
|
||
const gen = (typeof Blockly.JavaScript !== 'undefined') ? Blockly.JavaScript :
|
||
(typeof javascript !== 'undefined' && javascript.javascriptGenerator) ? javascript.javascriptGenerator : null;
|
||
|
||
if (!gen) { alert("Fehler: Generator nicht geladen."); return; }
|
||
|
||
const code = gen.workspaceToCode(workspace);
|
||
|
||
// Safety: Falls der Generator doch alert() nutzt, fangen wir das ab.
|
||
const oldAlert = window.alert;
|
||
window.alert = function (msg) { appendOutput(String(msg)); };
|
||
|
||
try {
|
||
new Function(code)();
|
||
appendOutput('\\n✅ Fertig.');
|
||
}
|
||
catch (e) { appendOutput('\\n❌ Fehler: ' + e); }
|
||
finally {
|
||
window.alert = oldAlert; // Restore
|
||
}
|
||
};
|
||
|
||
document.getElementById('btnCrew').onclick = async () => {
|
||
const outTxt = document.getElementById('output').textContent;
|
||
// Try to find the JSON part
|
||
const jsonMatch = outTxt.match(/\{[\s\S]*\}/);
|
||
if (jsonMatch) {
|
||
try {
|
||
await navigator.clipboard.writeText(jsonMatch[0]);
|
||
alert('🚀 Daten kopiert!\n\nGehe jetzt in dein Terminal und führe aus:\n./missions/evaluate_mission_data.sh\n\n(Dort kannst du die Daten dann einfügen)');
|
||
} catch (err) {
|
||
alert('❌ Konnte nicht in die Zwischenablage kopieren: ' + err);
|
||
}
|
||
} else {
|
||
alert('⚠️ Kein gültiges JSON-Ergebnis gefunden!\nBitte führe erst den Code aus (▶️).');
|
||
}
|
||
};
|
||
</script>
|
||
</body>
|
||
|
||
</html> |