Skip to content

Commit

Permalink
fix errors, clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannaPeanut committed Sep 11, 2024
1 parent 91dad69 commit 3ad27b0
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 52 deletions.
73 changes: 33 additions & 40 deletions scripts/geometryDataHelpers/dataHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,74 +1,67 @@
// @ts-nocheck
// This file is a collection of helper functions for manually fixing our data e.g. add missing values or renaming keys
import { writeFileSync, readdirSync, readFileSync } from 'fs';
import { length } from '@turf/turf';
import { length } from '@turf/turf'
import { readdirSync, readFileSync, writeFileSync } from 'fs'

type GeoType<T = GeoJSON.GeoJsonProperties> = GeoJSON.FeatureCollection<
GeoJSON.MultiLineString,
T
> & { id: any };
> & { id: any }

// calculate the length (m) for all geometries with unknown length
export const calcMissingLength = (fc: GeoType<{ length?: any }>) => {
fc.features.map((ml) => {
if (!ml.properties.length) {
return { ...ml, length: length(ml) * 1000 };
return { ...ml, length: length(ml) * 1000 }
}
return ml;
});
return fc;
};
return ml
})
return fc
}

export const renameAttribute = (
x: { id: any } & object,
key: string,
newKey: string
) => {
const { ...copy } = x;
export const renameAttribute = (x: { id: any } & object, key: string, newKey: string) => {
const { ...copy } = x
if (!(newKey in copy)) {
if (!copy[key]) {
throw new Error(`key ${key} not found on ${x.id}`);
throw new Error(`key ${key} not found on ${x.id}`)
}
copy[newKey] = copy[key];
delete copy[key];
copy[newKey] = copy[key]
delete copy[key]
}
return copy;
};
return copy
}

// apply `f` on nested property defined through `path`
export const applyNested = (
obj: object,
path: string[],
f: (x: object) => object
) => {
let attr = obj;
export const applyNested = (obj: object, path: string[], f: (x: object) => object) => {
let attr = obj
for (let i = 0; i < path.length - 1; i += 1) {
attr = attr[path[i]];
attr = attr[path[i]]
}
const leafKey = path[path.length - 1];
attr[leafKey] = f(attr[leafKey]);
return obj;
};
const leafKey = path[path.length - 1]
attr[leafKey] = f(attr[leafKey])
return obj
}

// apply `f` to all geometries
export const processGeometries = (
f: (fc: GeoType) => GeoType,
path = 'src/radschnellwege/geometry/',
filter: (x: string) => boolean = () => true
filter: (x: string) => boolean = () => true,
) => {
readdirSync(path).forEach((fileName) => {
const filePath = `${path}${fileName}`;
const filePath = `${path}${fileName}`
if (filter(fileName)) {
const data: GeoType = JSON.parse(readFileSync(filePath).toString());
writeFileSync(filePath, JSON.stringify(f(data)));
const data: GeoType = JSON.parse(readFileSync(filePath).toString())
writeFileSync(filePath, JSON.stringify(f(data)))
}
});
};
})
}

// apply `f` to all meta data
export const processMeta = (
f: (x: object) => object,
filePath = 'src/radschnellwege/meta/meta.json'
filePath = 'src/radschnellwege/meta/meta.json',
) => {
const data = JSON.parse(readFileSync(filePath).toString());
writeFileSync(filePath, JSON.stringify(data.map(f)));
};
const data = JSON.parse(readFileSync(filePath).toString())
writeFileSync(filePath, JSON.stringify(data.map(f)))
}
2 changes: 1 addition & 1 deletion src/assets/general/tsx/PlanningIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const PlanningIcon = () => {
return (
<svg
style={{ enableBackground: 'new 0 0 40 40' }}
style={{}}
fill="currentColor"
viewBox="0 0 40 40"
xmlns="http://www.w3.org/2000/svg"
Expand Down
2 changes: 1 addition & 1 deletion src/assets/general/tsx/ProgressIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const ProgressIcon = () => {
return (
<svg
style={{ enableBackground: 'new 0 0 40 40' }}
style={{}}
fill="currentColor"
viewBox="0 0 40 40"
xmlns="http://www.w3.org/2000/svg"
Expand Down
7 changes: 3 additions & 4 deletions src/pages/impressum.astro
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
---
import { BMDVFoerderung } from '@assets/general/tsx/BMDVFoerderung'
import Link from '@components/links/Link.astro'
import { MailLink } from '@components/links/MailLink'
import { BMDVFoerderung } from '@assets/general/tsx/BMDVFoerderung'
import LayoutPage from 'src/layouts/LayoutPage.astro'
import Section from '@components/Section.astro'
import PageHeader from '@components/PageHeader.astro'
import ProseMarkdown from '@components/ProseMarkdown.astro'
import Section from '@components/Section.astro'
import LayoutPage from 'src/layouts/LayoutPage.astro'
---

<LayoutPage title="Impressum" noindex>
Expand Down
6 changes: 3 additions & 3 deletions src/pages/steckbriefe/[federalstate].astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
import SteckbriefePage from '@components/SteckbriefePage/SteckbriefePage.astro'
import type { RsvTeaser } from '@components/SteckbriefePage/SteckbriefePageTeasers.astro'
import type { MetaSchema } from 'data/schema/metaSchemaema'
import type { MetaSchema } from 'data/schema/meta.schema'
import LayoutPage from 'src/layouts/LayoutPage.astro'
import { getRsvTeasersFromMeta } from 'src/radschnellwege/meta/getRsvTeasersFromMeta'
import meta from 'src/radschnellwege/meta/meta.json'
export async function getStaticPaths() {
const uniqueFederalStates = Array.from(
new Set(meta.flatMap((rsv) => [rsv.general.from.federalState, rsv.general.to.federalState]))
new Set(meta.flatMap((rsv) => [rsv.general.from.federalState, rsv.general.to.federalState])),
)
return uniqueFederalStates.map((state) => {
// @ts-expect-error todo
const filteredRsvs: MetaSchema[] = meta.filter(
(rsv) => rsv.general.from.federalState === state || rsv.general.to.federalState === state
(rsv) => rsv.general.from.federalState === state || rsv.general.to.federalState === state,
)
if (!filteredRsvs) return
const rsvTeasers: RsvTeaser[] = getRsvTeasersFromMeta(filteredRsvs)
Expand Down
6 changes: 3 additions & 3 deletions src/utils/mapColors.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { GeometrySchema } from 'data/schema/geometry.schema'

export const mapColors = {
main: '#34D399',
side: '#CBDC65',
discarded: '#5B5C5D',
}

export const segmentColor = (
properties: Queries.SteckbriefQuery['geometry']['features'][number]['properties'],
) => {
export const segmentColor = (properties: GeometrySchema['features'][number]['properties']) => {
if (properties.discarded) return mapColors.discarded
if (properties.variant === 'Vorzugstrasse') return mapColors.main
return mapColors.side
Expand Down

0 comments on commit 3ad27b0

Please sign in to comment.