Skip to content

Commit

Permalink
Merge pull request #18 from will-moore/fix_dtypes_check_versions
Browse files Browse the repository at this point in the history
Fix versions for dtype checks. Don't check v0.4
  • Loading branch information
joshmoore committed Oct 31, 2023
2 parents fe75b52 + 4acfaaa commit 7403f46
Showing 1 changed file with 43 additions and 16 deletions.
59 changes: 43 additions & 16 deletions src/JsonValidator/MultiscaleArrays/Multiscale.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,25 @@
export let source;
export let multiscale;
const WARNING = "warning";
// We check that all multiscale Datasets have same dtype and
// shape.length (number of dimensions)
// If multiscale.axes (version > 0.3) check it matches shape
const {axes, datasets, version} = multiscale;
const { axes, datasets, version } = multiscale;
// TODO: add "0.4" to this list once tested!
const checkDtypes = !["0.1", "0.2", "0.3"].includes(version);
const permitDtypeMismatch = ["0.1", "0.2", "0.3", "0.4"].includes(version);
const checkDimSeparator = ["0.2", "0.3", "0.4"].includes(version);
function allEqual(items) {
return items.every((value) => value == items[0]);
}
function containsError(checks) {
return checks.some((check) => check.status != WARNING);
}
async function loadAndValidate() {
let dtypes = [];
let dimCounts = [];
Expand All @@ -34,51 +39,73 @@
dimSeparators.push(zarray.dimension_separator);
}
let errors = [];
// Each check is {msg: "Message"}, with status: "warning" if it isn't an Error.
let checks = [];
if (dtypes.length === 0) {
errors.push("No multiscale datasets")
checks.push({ msg: "No multiscale datasets" });
}
if (checkDtypes && !allEqual(dtypes)) {
errors.push(`dtypes mismatch: ${dtypes.join(", ")}`)
if (!allEqual(dtypes)) {
if (permitDtypeMismatch) {
checks.push({
msg: `dtypes mismatch: ${dtypes.join(
", "
)} not valid after version 0.4`,
status: WARNING,
});
} else {
checks.push({ msg: `dtypes mismatch: ${dtypes.join(", ")}` });
}
}
if (!allEqual(dimCounts)) {
errors.push(`number of dimensions mismatch: ${dimCounts.join(", ")}`)
checks.push({
msg: `number of dimensions mismatch: ${dimCounts.join(", ")}`,
});
}
if (axes) {
shapes.forEach((shape) => {
if (shape.length != axes.length) {
errors.push(`Shape (${shape.join(", ")}) doesn't match axes length: ${axes.length}`)
checks.push({
msg: `Shape (${shape.join(", ")}) doesn't match axes length: ${
axes.length
}`,
});
}
});
}
if (checkDimSeparator) {
dimSeparators.forEach((sep) => {
if (sep != "/") {
errors.push(`Dimension separator must be / for version ${version}`)
checks.push({
msg: `Dimension separator must be / for version ${version}`,
});
}
});
}
return errors;
return checks;
}
const promise = loadAndValidate();
</script>

{#await promise}
<p>loading...</p>
{:then errors}
{#if errors.length > 0}
{:then checks}
{#if containsError(checks)}
<!-- only show X if not valid - no tick if valid -->
<CheckMark valid={false} />
{#each errors as error}
<p style="color: red">Error: {error}</p>
{/each}
{:else}
<p title="dtypes match and shapes are consistent">
{datasets.length} Datasets checked <span style="color:green">✓</span>
</p>
{/if}
{#each checks as check}
{#if check.status == "warning"}
<p style="color: orange">Warning: {check.msg}</p>
{:else}
<p style="color: red">Error: {check.msg}</p>
{/if}
{/each}
{:catch error}
<p style="color: red">{error.message}</p>
{/await}

0 comments on commit 7403f46

Please sign in to comment.