Skip to content

Commit

Permalink
commit plenty of broken code, I am sure I will regret it
Browse files Browse the repository at this point in the history
  • Loading branch information
pierreaubert committed Apr 28, 2024
1 parent e3f07ec commit 03acca9
Show file tree
Hide file tree
Showing 84 changed files with 1,867 additions and 1,409 deletions.
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ repos:
- id: fix-encoding-pragma
- id: requirements-txt-fixer
- repo: https://github.com/psf/black
rev: 23.12.0
rev: 24.3.0
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
rev: 7.0.0
hooks:
- id: flake8
- repo: https://github.com/pre-commit/mirrors-csslint
rev: v1.0.5
hooks:
- id: csslint
- repo: https://github.com/pre-commit/mirrors-eslint
rev: 'v8.53.0' # Use the sha / tag you want to point at
rev: 'v9.0.0-rc.0' # Use the sha / tag you want to point at
hooks:
- id: eslint
additional_dependencies:
Expand All @@ -34,12 +34,12 @@ repos:
- [email protected]
- [email protected]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: 'v3.0.3' # Use the sha / tag you want to point at
rev: 'v4.0.0-alpha.8' # Use the sha / tag you want to point at
hooks:
- id: prettier
types_or: [javascript]
- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: 'v0.1.8'
rev: 'v0.3.4'
hooks:
- id: ruff
4 changes: 2 additions & 2 deletions generate_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ def custom_ray_init(args):
sys.exit(1)
try:
ray_port = int(check_port)
if ray_port < 0 or ray__port > 2**16 - 1:
if ray_port < 0 or ray_port > 2**16 - 1:
print("ray port {} is out of bounds".format(check_port))
sys.exit(1)
except ValueError:
print("ray port is not an integer".format(check_port))
sys.exit(1)
ray_address = check_adress
ray_address = check_address

if ray_address is not None:
print(
Expand Down
26 changes: 16 additions & 10 deletions generate_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@

"""
usage: generate_html.py [--help] [--version] [--dev] [--optim]\
[--sitedev=<http>] [--log-level=<level>]
[--sitedev=<http>] [--log-level=<level>] [--skip-speakers]
Options:
--help display usage()
--version script version number
--sitedev=<http> default: http://localhost:8000/docs
--dev if you want to generate the dev websites
--optim if you want an optimised built
--optim if you want an optimised built
--skip-speakers skip speaker html page generation (useful for debugging)
--log-level=<level> default is WARNING, options are DEBUG INFO ERROR.
"""
from glob import glob
Expand Down Expand Up @@ -389,14 +390,17 @@ def main():
sys.exit(1)

# write a file per speaker
logger.info("Write a file per speaker")
try:
generate_speakers(
mako_templates, main_df, meta=meta, site=site, use_search=False, versions=versions
)
except KeyError as key_error:
print("Generating a file per speaker failed with {}".format(key_error))
sys.exit(1)
if not skip_speakers:
logger.info("Write a file per speaker")
try:
generate_speakers(
mako_templates, main_df, meta=meta, site=site, use_search=False, versions=versions
)
except KeyError as key_error:
print("Generating a file per speaker failed with {}".format(key_error))
sys.exit(1)
else:
logger.info("Skip speaker html generation!")

# copy favicon(s) and logos
for f in [
Expand Down Expand Up @@ -582,13 +586,15 @@ def main():
flag_dev = args["--dev"]
flag_optim = args["--optim"]
site = SITEPROD
skip_speakers = False
if flag_dev:
site = SITEDEV
if args["--sitedev"] is not None:
site = args["--sitedev"]
if len(site) < 4 or site[0:4] != "http":
print("sitedev {} does not start with http!".format(site))
sys.exit(1)
skip_speakers = args["--skip-speakers"]

logger = get_custom_logger(level=args2level(args), duplicate=True)
main()
45 changes: 45 additions & 0 deletions scripts/svg2symbols.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/python3

from glob import glob
from os.path import basename
import xml.etree.ElementTree as ET


def xml_pre():
print('<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">')


def xml_post():
print("</svg>")


def process(filename, xml):
id = basename(filename).lower().split(".")[0]
view_box = xml.attrib.get("viewBox", "0 0 40 40")
print(' <symbol id="icon-{}" viewBox="{}">'.format(id, view_box))
for child in xml:
tag = child.tag.split("}")[1]
if tag not in ("path", "circle", "rect", "g"):
# print("to do: " + tag)
continue
print(" <{}".format(tag), end="")
for k, v in child.attrib.items():
print(' {}="{}"'.format(k, v), end="")
print("/>")
print(" </symbol>")


if __name__ == "__main__":
svg_paths = [
"src/website/icons/*.svg",
]

xml_pre()
for svg_path in svg_paths:
svg_files = glob(svg_path)
for svg_file in svg_files:
with open(svg_file, "r") as fd:
lines = fd.read()
xml = ET.fromstring(lines)
process(svg_file, xml)
xml_post()
1 change: 1 addition & 0 deletions src/website/brands.html
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
<option value="Seeburg">Seeburg</option>
<option value="Sehlin">Sehlin</option>
<option value="Selah Audio">Selah Audio</option>
<option value="Shivaudyo">Shivaudyo</option>
<option value="Sigberg Audio">Sigberg Audio</option>
<option value="SONBS">SONBS</option>
<option value="Sonos">Sonos</option>
Expand Down
2 changes: 1 addition & 1 deletion src/website/compare.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<div class="plot2" id="plot2"></div>
</div>
</div>
<script type="module" src="./compare${min}.js"></script>
<script type="module" src="./compare-${versions['CACHE']}${min}.js"></script>
<%include file="footer.html"/>
</body>
</html>
16 changes: 12 additions & 4 deletions src/website/compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,17 @@
/*global Plotly */
/*eslint no-undef: "error"*/

import { urlSite } from './meta${min}.js';
import { getMetadata, assignOptions, getAllSpeakers, getSpeakerData } from './download${min}.js';
import { knownMeasurements, setContour, setGlobe, setGraph, setCEA2034, setRadar, setSurface } from './plot${min}.js';
import { urlSite } from './meta-${versions["CACHE"]}${min}.js';
import { getMetadata, assignOptions, getAllSpeakers, getSpeakerData } from './download-${versions["CACHE"]}${min}.js';
import {
knownMeasurements,
setContour,
setGlobe,
setGraph,
setCEA2034,
setRadar,
setSurface,
} from './plot-${versions["CACHE"]}${min}.js';

function updateVersion(metaSpeakers, speaker, selector, origin, version) {
// update possible version(s) for matching speaker and origin
Expand Down Expand Up @@ -377,7 +385,7 @@ getMetadata()
speakersSelector[0].focus();
} else if (key === 'b' || key === '2') {
speakersSelector[1].focus();
} else if (key === 'g') {
} else if (key === 'g' || key === 'c') {
graphsSelector.focus();
}
});
Expand Down
37 changes: 21 additions & 16 deletions src/website/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

import { urlSite, metadataFilename, metadataFilenameHead, metadataFilenameChunks, eqdataFilename } from './meta${min}.js';
import { getID } from './misc${min}.js';
import {
urlSite,
metadataFilename,
metadataFilenameHead,
metadataFilenameChunks,
eqdataFilename,
} from './meta-${versions["CACHE"]}${min}.js';
import { getID } from './misc-${versions["CACHE"]}${min}.js';

function processOrigin(origin) {
if (origin.includes('Vendors-')) {
Expand Down Expand Up @@ -134,25 +140,24 @@ export function getMetadataHead() {
return fetchDataAndMap(url, 'bz2, zip, deflate');
}

export function getMetadataOld() {
export function getMetadata() {
const url = urlSite + metadataFilename;
return fetchDataAndMap(url, 'bz2, zip, deflate');
}

export function getMetadata() {
const promisedHead = getMetadataHead();
const promisedChunks = [promisedHead];
export function getMetadataTail(metadataHead) {
const promisedChunks = [];
for (let i in metadataFilenameChunks) {
const url = urlSite + metadataFilenameChunks[i];
promisedChunks.push(fetchDataAndMap(url));
}
return Promise.all(promisedChunks).then((chunks) => {
const merged = new Map();
for (const chunk of chunks) {
for (const [key, value] of chunk) {
merged.set(key, value);
}
}
const merged = new Map(metadataHead);
for (const chunk of chunks) {
for (const [key, value] of chunk) {
merged.set(key, value);
}
}
return merged;
});
}
Expand Down Expand Up @@ -186,11 +191,11 @@ export function assignOptions(textArray, selector, textSelected) {
while (selector.firstChild) {
selector.firstChild.remove();
}
for (let i = 0; i < textArray.length; i++) {
for (const element of textArray) {
const currentOption = document.createElement('option');
currentOption.value = textArray[i];
currentOption.text = textArray[i].replace('Vendors-', '').replace('vendor-pattern-', 'Pattern ');
if (textArray[i] === textSelected) {
currentOption.value = element;
currentOption.text = element.replace('Vendors-', '').replace('vendor-pattern-', 'Pattern ');
if (element === textSelected) {
currentOption.selected = true;
}
if (textArray.length === 1) {
Expand Down
13 changes: 8 additions & 5 deletions src/website/eqs.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<%include file="head.html"/>
</head>
<body>
<%include file="icons.html"/>
<%include file="nav_search.html"/>
<%namespace name="util" module="website.utils" import="*"/>

Expand All @@ -22,11 +23,11 @@
{{model}}
</th>
</tr>
{{#if (isNotEmpty othereq)}}
<tr>
<td class="has-text-centered">
<nav class="level">
<div class="level-left">
{{#if (isNotEmpty othereq)}}
<div class="control">
<div class="select is-small">
<select id="eq-select-{{id}}">
Expand All @@ -37,6 +38,9 @@
</select>
</div>
</div>
{{else}}
<span>{{autoeq.name}}</span>
{{/if}}
</div>
<div class="level-item">
<button
Expand All @@ -46,14 +50,13 @@
data-target="eq-modal-compare-{{id}}"
>
<span class="icon">
<i class="fa-solid fa-image"></i>
<svg width="16px" height="16px"><use href="#icon-image"/></svg>
</span>
</button>
</div>
</nav>
</td>
</tr>
{{/if}}
<tr id="eq-{{id}}-autoeq">
<td>
<table class="table is-striped">
Expand Down Expand Up @@ -331,15 +334,15 @@
</div>
</script>

<%include file="search.html"/>
<div class="section">
<!-- Speakers -->
<div class="searchresults">
<div class="columns is-multiline is-mobile is-centered is-variable" id="speakers" data-num="0">
<script type="module" src="./eqs${min}.js"></script>
<script type="module" src="./eqs-${versions['CACHE']}${min}.js"></script>
</div>
</div>
</div>
<%include file="search.html"/>
<%include file="footer.html"/>

</body>
Expand Down
7 changes: 3 additions & 4 deletions src/website/eqs.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
/*global Handlebars*/
/*eslint no-undef: "error"*/

import { getEQdata } from './download${min}.js';
import { openModal, closeModal, getPeq, getID } from './misc${min}.js';
import { process } from './sort${min}.js';
import { urlParameters2Sort } from './params${min}.js';
import { getEQdata } from './download-${versions["CACHE"]}${min}.js';
import { openModal, closeModal, getPeq, getID } from './misc-${versions["CACHE"]}${min}.js';
import { process, urlParameters2Sort } from './search-${versions["CACHE"]}${min}.js';

function getPictureEqCompare(brand, model, suffix) {
return encodeURI('speakers/' + brand + ' ' + model + '/eq_compare.' + suffix);
Expand Down
3 changes: 1 addition & 2 deletions src/website/graph.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<title>Graphs and Measurements for ${speaker}</title>
<%include file="head.html"/>
<%include file="head_vega.html"/>
<script type="module" src="${site}/graph${min}.js"></script>
</head>
<body>
<%include file="nav_simple.html"/>
Expand All @@ -13,7 +12,7 @@
<div id="visGraph" class="graph"></div>

<script type="module">
import { displayGraph } from "${site}/graph.js";
import { displayGraph } from "${site}/graph-${versions['CACHE']}${min}.js";
const spec = fetch("${graph | space2url}.json")
.then( (response) => response.json() )
.then( (spec) => {
Expand Down
2 changes: 1 addition & 1 deletion src/website/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/*global Plotly*/
/*eslint no-undef: "error"*/

import { setGraph } from './plot${min}.js';
import { setGraph } from './plot-${versions["CACHE"]}${min}.js';

export function displayGraph(divName, graphSpec) {
async function run() {
Expand Down
Loading

0 comments on commit 03acca9

Please sign in to comment.