Compare commits

...

2 commits

3 changed files with 62 additions and 41 deletions

View file

@ -8,6 +8,7 @@
description: Description description: Description
} }
frequency_unit: kHz frequency_unit: kHz
frequency_fraction_digits: 0
comments: comments:
- Source Base: '<a href="https://www.iaru-r1.org/wp-content/uploads/2021/06/hf_r1_bandplan.pdf">https://www.iaru-r1.org/wp-content/uploads/2021/06/hf_r1_bandplan.pdf</a>' - Source Base: '<a href="https://www.iaru-r1.org/wp-content/uploads/2021/06/hf_r1_bandplan.pdf">https://www.iaru-r1.org/wp-content/uploads/2021/06/hf_r1_bandplan.pdf</a>'
- Source Base Date: "2021-06-09" - Source Base Date: "2021-06-09"

View file

@ -66,7 +66,7 @@ div>label {
location.search.substr(1).split("&").forEach((param) => { location.search.substr(1).split("&").forEach((param) => {
let p = param.split("="); let p = param.split("=");
let key = p[0]; let key = p[0];
["base", "extension", "css"].forEach((id) => { ["base", "regulation", "css"].forEach((id) => {
if (key === id) { if (key === id) {
document.getElementById(id + "_input").value = decodeURIComponent(p[1]); document.getElementById(id + "_input").value = decodeURIComponent(p[1]);
} }
@ -74,7 +74,7 @@ div>label {
}); });
update_inputs(); update_inputs();
["base", "extension", "css"].forEach((id) => { ["base", "regulation", "css"].forEach((id) => {
// download buttons // download buttons
create_element_link(document.getElementById("download_" + id), document.getElementById(id + "_input").value); create_element_link(document.getElementById("download_" + id), document.getElementById(id + "_input").value);
// enter on input fields // enter on input fields
@ -88,7 +88,7 @@ div>label {
create_element_link(document.getElementById("create_link"), function() { create_element_link(document.getElementById("create_link"), function() {
return window.location.href.split("?")[0] + "?" return window.location.href.split("?")[0] + "?"
+ "base=" + document.getElementById("base_input").value + "base=" + document.getElementById("base_input").value
+ "&extension=" + document.getElementById("extension_input").value + "&regulation=" + document.getElementById("regulation_input").value
+ "&css=" + document.getElementById("css_input").value; + "&css=" + document.getElementById("css_input").value;
}); });
}); });
@ -125,15 +125,27 @@ div>label {
return Number(number) >= Number(min) && Number(number) <= Number(max); return Number(number) >= Number(min) && Number(number) <= Number(max);
} }
function add_column(row, cols, header) { function add_column(row, cols, header, minimum_fraction_digits = 0) {
const formatter = new Intl.NumberFormat("en-US", {
minimumFractionDigits: minimum_fraction_digits,
maximumFractionDigits: 100,
});
header.columns.forEach((col) => { header.columns.forEach((col) => {
if (header.columns.includes(col)) { if (header.columns.includes(col)) {
if (typeof cols[col] === "object") { if (typeof cols[col] === "object") {
for (const [key, value] of Object.entries(cols[col])) { for (const [key, value] of Object.entries(cols[col])) {
row[col + "_" + key] = value; if ((key === "frequency") && (typeof value === "number")) {
row[col + "_" + key] = formatter.format(value);
} else {
row[col + "_" + key] = value;
}
} }
} else { } else {
row[col] = cols[col]; if ((col === "frequency") && (typeof cols[col] === "number")) {
row[col] = formatter.format(cols[col]);
} else {
row[col] = cols[col];
}
} }
} }
}); });
@ -149,11 +161,13 @@ div>label {
} }
}); });
document.getElementById("comments_" + key).innerHTML = s; document.getElementById("comments_" + key).innerHTML = s;
} else {
document.getElementById("comments_" + key).innerHTML = "";
} }
}; };
} }
function update_table(bases, extensions) { function update_table(bases, regulations) {
let tdata = []; let tdata = [];
let header = {}; let header = {};
@ -169,53 +183,53 @@ div>label {
if ((typeof base.header === "undefined") || (base.header == false)) { if ((typeof base.header === "undefined") || (base.header == false)) {
let row = {}; let row = {};
// first, fill ext_header // first, fill reg_header
extensions.forEach((ext) => { regulations.forEach((reg) => {
if ((typeof ext.header !== "undefined") && ext.header) { if ((typeof reg.header !== "undefined") && reg.header) {
header["extension"] = structuredClone(ext); header["regulation"] = structuredClone(reg);
} }
}); });
fill_comments(header); fill_comments(header);
// then fill tdata // then fill tdata
extensions.forEach((ext) => { regulations.forEach((reg) => {
if ((typeof ext.header === "undefined") || (ext.header == false)) { if ((typeof reg.header === "undefined") || (reg.header == false)) {
add_column(row, base, header["base"]); add_column(row, base, header["base"], header["base"].frequency_fraction_digits);
let [ext_start, ext_end] = ext.frequency.split("-"); let [reg_start, reg_end] = reg.frequency.split("-");
ext_start = Qty(Number(ext_start), header["extension"].frequency_unit).to(header["base"].frequency_unit).scalar; reg_start = Qty(Number(reg_start), header["regulation"].frequency_unit).to(header["base"].frequency_unit).scalar;
ext_end = Qty(Number(ext_end), header["extension"].frequency_unit).to(header["base"].frequency_unit).scalar; reg_end = Qty(Number(reg_end), header["regulation"].frequency_unit).to(header["base"].frequency_unit).scalar;
if (typeof base.frequency === "number") { if (typeof base.frequency === "number") {
// at single frequency // at single frequency
if (isInRange(base.frequency, ext_start, ext_end)) { if (isInRange(base.frequency, reg_start, reg_end)) {
add_column(row, ext, header["extension"]); add_column(row, reg, header["regulation"], header["base"].frequency_fraction_digits);
tdata.push(row); tdata.push(row);
} }
} else { } else {
// frequeny range // frequeny range
let [base_start, base_end] = base.frequency.split("-"); let [base_start, base_end] = base.frequency.split("-");
if (isInRange(base_start, ext_start, ext_end) && isInRange(base_end, ext_start, ext_end)) { if (isInRange(base_start, reg_start, reg_end) && isInRange(base_end, reg_start, reg_end)) {
// base range is inside of ext range or the same // base range is inside of reg range or the same
add_column(row, ext, header["extension"]); add_column(row, reg, header["regulation"]);
tdata.push(row); tdata.push(row);
} else { } else {
// base range is split by ext range // base range is split by reg range
if ((base_end > ext_start) && isInRange(ext_start, base_start, base_end)) { if ((base_end > reg_start) && isInRange(reg_start, base_start, base_end)) {
// base range starts below ext range // base range starts below reg range
let r = structuredClone(row); let r = structuredClone(row);
let start = ext_start; let start = reg_start;
let end = base_end < ext_end ? base_end : ext_end; let end = base_end < reg_end ? base_end : reg_end;
r["frequency"] = start + "-" + end; r["frequency"] = start + "-" + end;
add_column(r, ext, header["extension"]); add_column(r, reg, header["regulation"]);
tdata.push(r); tdata.push(r);
} else if ((ext_end > base_start) && isInRange(ext_end, base_start, base_end)) { } else if ((reg_end > base_start) && isInRange(reg_end, base_start, base_end)) {
// ext range starts below base range // reg range starts below base range
let r = structuredClone(row); let r = structuredClone(row);
let start = base_start; let start = base_start;
let end = ext_end; let end = reg_end;
r["frequency"] = start + "-" + end; r["frequency"] = start + "-" + end;
add_column(r, ext, header["extension"]); add_column(r, reg, header["regulation"]);
tdata.push(r); tdata.push(r);
} }
} }
@ -293,8 +307,8 @@ div>label {
if (typeof header["base"].titles[column.field] !== "undefined") { if (typeof header["base"].titles[column.field] !== "undefined") {
column.title = header["base"].titles[column.field]; column.title = header["base"].titles[column.field];
} }
if (typeof header["extension"].titles[column.field] !== "undefined") { if (typeof header["regulation"].titles[column.field] !== "undefined") {
column.title = header["extension"].titles[column.field]; column.title = header["regulation"].titles[column.field];
} }
// add css styles for formatting based on cell values // add css styles for formatting based on cell values
@ -366,7 +380,7 @@ div>label {
function update_inputs() { function update_inputs() {
Promise.all([ Promise.all([
fetch(document.getElementById("base_input").value, { mode: "cors" }), fetch(document.getElementById("base_input").value, { mode: "cors" }),
fetch(document.getElementById("extension_input").value, { mode: "cors" }), fetch(document.getElementById("regulation_input").value, { mode: "cors" }),
]).then((res) => { ]).then((res) => {
res.forEach((r) => { res.forEach((r) => {
if (!r.ok) { if (!r.ok) {
@ -375,7 +389,11 @@ div>label {
}); });
Promise.all([res[0].text(), res[1].text()]).then((d) => { Promise.all([res[0].text(), res[1].text()]).then((d) => {
try { try {
update_table(yaml.load(d[0]),yaml.load(d[1])); let reg = d[1];
if (reg === "") {
reg = "- header: true\n columns: []\n titles: []\n frequency_unit: GHz\n- frequency: 0-" + 9007199254740991;
}
update_table(yaml.load(d[0]), yaml.load(reg));
} catch (e) { } catch (e) {
display_error(e); display_error(e);
} }
@ -407,7 +425,9 @@ div>label {
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
function help() { function help() {
alert( alert(
"Base plan, extension plan and css: use your own files for the band plan and css, URLs are possible, CORS needs to be allowed for the files, download standard files for examples\n" "Base plan, regulation and css: use your own files for the band plan and css, URLs are possible, CORS needs to be allowed for the files, download standard files for examples\n"
+ "When Regulation is empty, all frequencies from base plan will be included\n"
+ "When CSS is empty or URL not available, colors, etc. will be gone\n"
+ "Filter rows with text in column headings, use filter starting with \"!\" as exclusion\n" + "Filter rows with text in column headings, use filter starting with \"!\" as exclusion\n"
+ "Download list: saves .pdf of the current list (selection of rows apply)\n" + "Download list: saves .pdf of the current list (selection of rows apply)\n"
+ "Selection of rows with mouse possible\n" + "Selection of rows with mouse possible\n"
@ -420,8 +440,8 @@ div>label {
<label>Base Plan: <label>Base Plan:
<input id="base_input" type="text" value="band-plan-iaru_r1_hf.yml"> <input id="base_input" type="text" value="band-plan-iaru_r1_hf.yml">
</label> </label>
<label>Extension: <label>Regulation:
<input id="extension_input" type="text" value="band-plan-de.yml"> <input id="regulation_input" type="text" value="regulations-de.yml">
</label> </label>
<label>CSS: <label>CSS:
<input id="css_input" type="text" value="standard.css"> <input id="css_input" type="text" value="standard.css">
@ -432,7 +452,7 @@ div>label {
<div> <div>
<button id="download">Download list</button> <button id="download">Download list</button>
<button id="download_base">Download base plan</button> <button id="download_base">Download base plan</button>
<button id="download_extension">Download extension plan</button> <button id="download_regulation">Download regulation</button>
<button id="download_css">Download css file</button> <button id="download_css">Download css file</button>
<button id="create_link">Create link</button> <button id="create_link">Create link</button>
<button onclick="help()">Help</button> <button onclick="help()">Help</button>
@ -440,7 +460,7 @@ div>label {
<div id="data-table"></div> <div id="data-table"></div>
<div id="error"></div> <div id="error"></div>
<div id="comments_base"></div> <div id="comments_base"></div>
<div id="comments_extension"></div> <div id="comments_regulation"></div>
<div> <div>
<p>This information is supplied without liability.</p> <p>This information is supplied without liability.</p>
<p>Source is at <a href="https://src.dm5wk.de/dm5wk/band-plan-web/">https://src.dm5wk.de/dm5wk/band-plan-web/</a></p> <p>Source is at <a href="https://src.dm5wk.de/dm5wk/band-plan-web/">https://src.dm5wk.de/dm5wk/band-plan-web/</a></p>