Skip to content

Commit

Permalink
Release 2024-02-07 (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannaPeanut authored Feb 8, 2024
2 parents d551ac8 + 8afc8fe commit 1731ca9
Show file tree
Hide file tree
Showing 114 changed files with 2,208 additions and 383 deletions.
43 changes: 43 additions & 0 deletions db/calculate-subsection-subsubsection-lengthkm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require("dotenv").config({ path: "./.env.local" })
const { length, lineString } = require("@turf/turf")
const { PrismaClient } = require("@prisma/client")

const db = new PrismaClient()
/*
* This function is executed when you run `calc-lengthkm`.
*/
const calculateLengthKm = async () => {
const subsections = await db.subsection.findMany()
console.log("subsections successfully fetched")
subsections.forEach(async (subsection) => {
const calculatedLengthKm = Number(
length(lineString(subsection.geometry), { units: "kilometers" }).toFixed(3),
)
const updatedSubsection = await db.subsection.update({
where: { id: subsection.id },
data: { lengthKm: calculatedLengthKm },
})
console.log(
`updated subsection ${updatedSubsection.id} successfuly`,
updatedSubsection.lengthKm,
)
})
const subsubsections = await db.subsubsection.findMany()
console.log("subsubsections successfully fetched")
subsubsections.forEach(async (subsubsection) => {
const calculatedLengthKm =
subsubsection.type === "AREA"
? 0.1 // AREAs are SF, they have no length so they get a default
: Number(length(lineString(subsubsection.geometry), { units: "kilometers" }).toFixed(3))
const updatedSubsubsection = await db.subsubsection.update({
where: { id: subsubsection.id },
data: { lengthKm: calculatedLengthKm },
})
console.log(
`updated subsubsection ${updatedSubsubsection.id} successfuly`,
updatedSubsubsection.lengthKm,
)
})
}

calculateLengthKm()
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- CreateEnum
CREATE TYPE "SurveyResponseSourceEnum" AS ENUM ('EMAIL', 'LETTER', 'FORM');

-- AlterTable
ALTER TABLE "SurveyResponse" ADD COLUMN "source" "SurveyResponseSourceEnum" NOT NULL DEFAULT 'FORM';
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Subsubsection" ADD COLUMN "planningPeriod" DOUBLE PRECISION;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Subsubsection" ADD COLUMN "constructionPeriod" DOUBLE PRECISION;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Subsubsection" ADD COLUMN "quarterPlannedCompletion" TEXT;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
Warnings:
- Made the column `lengthKm` on table `Subsection` required. This step will fail if there are existing NULL values in that column.
- Made the column `lengthKm` on table `Subsubsection` required. This step will fail if there are existing NULL values in that column.
*/
-- AlterTable
ALTER TABLE "Subsection" ALTER COLUMN "lengthKm" SET NOT NULL;

-- AlterTable
ALTER TABLE "Subsubsection" ALTER COLUMN "lengthKm" SET NOT NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
Warnings:
- You are about to drop the column `quarterPlannedCompletion` on the `Subsubsection` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE "Subsubsection" DROP COLUMN "quarterPlannedCompletion",
ADD COLUMN "estimatedCompletionDate" TIMESTAMP(3);
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- AlterTable
ALTER TABLE "Subsection" ADD COLUMN "networkHierarchyId" INTEGER;

-- CreateTable
CREATE TABLE "NetworkHierarchy" (
"id" SERIAL NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"slug" TEXT NOT NULL,
"title" TEXT NOT NULL,
"projectId" INTEGER NOT NULL,

CONSTRAINT "NetworkHierarchy_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "NetworkHierarchy_projectId_slug_key" ON "NetworkHierarchy"("projectId", "slug");

-- AddForeignKey
ALTER TABLE "Subsection" ADD CONSTRAINT "Subsection_networkHierarchyId_fkey" FOREIGN KEY ("networkHierarchyId") REFERENCES "NetworkHierarchy"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "NetworkHierarchy" ADD CONSTRAINT "NetworkHierarchy_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "Project"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- CreateEnum
CREATE TYPE "PriorityEnum" AS ENUM ('OPEN', 'TOP', 'HIGH', 'MEDIUM', 'LOW');

-- AlterTable
ALTER TABLE "Subsection" ADD COLUMN "priority" "PriorityEnum" NOT NULL DEFAULT 'OPEN';
83 changes: 62 additions & 21 deletions db/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ model Project {
SubsubsectionTask SubsubsectionTask[]
SubsubsectionInfra SubsubsectionInfra[]
SubsubsectionSpecial SubsubsectionSpecial[]
NetworkHierarchy NetworkHierarchy[]
}

model Membership {
Expand Down Expand Up @@ -199,25 +200,28 @@ model Operator {
}

model Subsection {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
//
slug String // shortTitle and URL Slug
start String
end String
order Int @default(autoincrement())
geometry Json
labelPos LabelPositionEnum @default(top)
description String?
lengthKm Float?
//
project Project @relation(fields: [projectId], references: [id])
projectId Int
manager User? @relation(fields: [managerId], references: [id])
managerId Int?
operator Operator? @relation(fields: [operatorId], references: [id])
operatorId Int?
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
//
slug String // shortTitle and URL Slug
start String
end String
order Int @default(autoincrement())
geometry Json
labelPos LabelPositionEnum @default(top)
description String?
lengthKm Float // Kilometer
priority PriorityEnum @default(OPEN) // Priorität
//
project Project @relation(fields: [projectId], references: [id])
projectId Int
manager User? @relation(fields: [managerId], references: [id])
managerId Int?
operator Operator? @relation(fields: [operatorId], references: [id])
operatorId Int?
networkHierarchy NetworkHierarchy? @relation(fields: [networkHierarchyId], references: [id])
networkHierarchyId Int?
subsubsections Subsubsection[]
stakeholdernotes Stakeholdernote[]
Expand All @@ -227,6 +231,29 @@ model Subsection {
@@unique([projectId, order])
}

enum PriorityEnum {
OPEN
TOP //sehr hoch, hoch, mittel, niedrig
HIGH
MEDIUM
LOW
}

model NetworkHierarchy {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
//
slug String // shortTitle and URL Slug
title String
//
project Project @relation(fields: [projectId], references: [id])
projectId Int
Subsection Subsection[]
@@unique([projectId, slug])
}

model Subsubsection {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
Expand All @@ -238,10 +265,9 @@ model Subsubsection {
geometry Json
labelPos LabelPositionEnum @default(top)
task String? // Maßnahmentyp - UNUSED
lengthKm Float? // Kilometer
lengthKm Float // Kilometer
width Float? // Meter
widthExisting Float? // Meter
costEstimate Float? // Euro
description String? // Anmerkungen
mapillaryKey String?
isExistingInfra Boolean? @default(false) // Bestandsführung
Expand All @@ -250,13 +276,21 @@ model Subsubsection {
trafficLoad Int? // Verkehrsbelastung
trafficLoadDate DateTime? // Datum der Verkehrsbelastung
planningPeriod Float? // Planungsdauer
constructionPeriod Float? // Baudauer
estimatedCompletionDate DateTime? // Jahresquartal der geplanten Fertigstellung als string Form "1-2023"
//
costEstimate Float? // Euro
//
planningCosts Float? // Planungskosten
deliveryCosts Float? // Lieferkosten
constructionCosts Float? // Baukosten
landAcquisitionCosts Float? // Grunderwerbskosten
expensesOfficialOrders Float? // Ausgaben aufgrund behördlicher Anordnungen
expensesTechnicalVerification Float? // Ausgaben für den fachtechnischen Nachweis usw.
//
nonEligibleExpenses Float? // Nicht zuwendungsfähige Ausgaben
//
revenuesEconomicIncome Float? // Erlöse und wirtschafltiche Einnahmen
contributionsThirdParties Float? // Beiträge Dritter
grantsOtherFunding Float? // Zuwendungen aus anderen Förderprogrammen
Expand Down Expand Up @@ -437,6 +471,7 @@ model SurveyResponse {
data String
status SurveyResponseStatusEnum? @default(PENDING)
note String?
source SurveyResponseSourceEnum @default(FORM)
//
surveySession SurveySession @relation(fields: [surveySessionId], references: [id])
surveySessionId Int
Expand All @@ -445,6 +480,12 @@ model SurveyResponse {
surveyResponseTopics SurveyResponseTopicsOnSurveyResponses[]
}

enum SurveyResponseSourceEnum {
EMAIL
LETTER
FORM
}

model SurveyResponseTopic {
id Int @id @default(autoincrement())
title String
Expand Down
4 changes: 3 additions & 1 deletion db/seeds/subsection_subsubsections.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Prisma } from "@prisma/client"

// lengthKm is NOT calculated here but arbitrary values to satisfy the schema

export const subsubsections: Omit<Prisma.SubsubsectionUncheckedCreateInput, "subsectionId">[] = [
{
slug: "rf1",
Expand Down Expand Up @@ -110,7 +112,7 @@ export const subsubsections: Omit<Prisma.SubsubsectionUncheckedCreateInput, "sub
geometry: [13.329078172644188, 52.5225862734311],
labelPos: "top",
task: "Fahrbahnmarkierung mit Querung",
lengthKm: null,
lengthKm: 3,
width: 2,
costEstimate: 30_000,
qualityLevelId: 4,
Expand Down
11 changes: 11 additions & 0 deletions db/seeds/subsections.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import db, { Prisma } from "../index"
import { subsubsections } from "./subsection_subsubsections"

// lengthKm is NOT calculated here but arbitrary values to satisfy the schema

const seedSubsections = async () => {
const seedData: Prisma.SubsectionUncheckedCreateInput[] = [
// NORD:
Expand Down Expand Up @@ -31,6 +33,7 @@ const seedSubsections = async () => {
[13.357157800454104, 52.517204842057566],
[13.363361116374904, 52.519430986022115],
],
lengthKm: 56,
managerId: 1,
subsubsections: { create: subsubsections },
},
Expand All @@ -52,6 +55,7 @@ const seedSubsections = async () => {
[13.369246313529857, 52.52252804216468],
[13.36352017575777, 52.519430986022115],
],
lengthKm: 12,
managerId: null,
},
{
Expand All @@ -69,6 +73,7 @@ const seedSubsections = async () => {
[13.399308536836458, 52.521366671697535],
[13.392787102151175, 52.52252804216468],
],
lengthKm: 12,
managerId: null,
},
{
Expand All @@ -86,6 +91,7 @@ const seedSubsections = async () => {
[13.421258731631525, 52.51333301867112],
[13.451639073702552, 52.499875779590525],
],
lengthKm: 12,
managerId: 1,
},
// SÜD:
Expand All @@ -104,6 +110,7 @@ const seedSubsections = async () => {
[13.33697529376991, 52.51115272935999],
[13.35222310471977, 52.5057391067665],
],
lengthKm: 12,
managerId: 2,
},
{
Expand All @@ -124,6 +131,7 @@ const seedSubsections = async () => {
[13.379859762067383, 52.49916452570534],
[13.388754318454033, 52.49800420344744],
],
lengthKm: 12,
managerId: 2,
},
{
Expand All @@ -141,6 +149,7 @@ const seedSubsections = async () => {
[13.41278184895532, 52.4950788842759],
[13.41977042897335, 52.49614258494796],
],
lengthKm: 12,
managerId: 2,
},
{
Expand All @@ -157,6 +166,7 @@ const seedSubsections = async () => {
[13.439306686753582, 52.4902435569129],
[13.451695533149916, 52.49991367999152],
],
lengthKm: 3,
managerId: 2,
},
{
Expand All @@ -173,6 +183,7 @@ const seedSubsections = async () => {
[13.439306686753582, 52.4902435569129],
[13.451695533149916, 52.49991367999152],
],
lengthKm: 8,
managerId: 2,
},
]
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"seed": "npm run predev && npm run migrate && blitz prisma migrate reset && blitz db seed",
"updatePackages": "npx taze major --write",
"release": "gh pr create --base main --head develop --title \"Release $(date '+%Y-%m-%d')\" --body \"\"",
"prepare": "husky install"
"prepare": "husky install",
"calc-lengthkm": "node db/calculate-subsection-subsubsection-lengthkm.js"
},
"prisma": {
"schema": "db/schema.prisma"
Expand Down
7 changes: 2 additions & 5 deletions src/core/components/Map/SurveyStaticPin.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import * as React from "react"
type Props = {
color: string
}

const SurveyStaticPin: React.FC<Props> = ({ color }) => {
const SurveyStaticPin: React.FC = () => {
return (
<svg width="38" height="48" viewBox="0 0 38 48" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
fillRule="evenodd"
clipRule="evenodd"
d="M19 0C29.4934 0 38 8.82644 38 19.7144C38 22.3298 36.7984 25.629 34.5493 29.4168C32.8863 32.2175 30.7033 35.2017 28.1269 38.2825C25.9191 40.9225 23.5498 43.484 21.1804 45.8647L19.984 47.0508L19 48L18.016 47.0508C17.6338 46.6771 17.2342 46.2812 16.8196 45.8647C14.4502 43.484 12.0809 40.9225 9.87312 38.2825C7.2967 35.2017 5.11365 32.2175 3.4507 29.4168C1.20161 25.629 0 22.3298 0 19.7144C0 8.82644 8.50659 0 19 0Z"
fill={color}
className="fill-[var(--survey-primary-color)]"
/>
<path
d="M14 20.3846L17.4737 25L25 15"
Expand Down
Loading

0 comments on commit 1731ca9

Please sign in to comment.