Made a lotta small fixes

This commit is contained in:
Tim Howitz 2025-05-26 22:16:46 +01:00
parent 801b72eb67
commit 92d8f9af81
14 changed files with 1739 additions and 1360 deletions

View File

@ -1,7 +1,7 @@
Name,Type,WarehouseArea,Description,EarthquakeCode,Price,Required,PickedUp,Picture
Echo Bomb,Lava,ShelvingAreaA,A dense glossy black volcanic bomb with minor vesicles.,EV-7.4-Mexico-00035,120,no,no,EchoBomb.PNG
Silvershade Ash,Ash,ShelvingAreaD,Fine light-grey volcanic ash collected near a village.,EV-6.0-Iceland-00018,40,no,no,SilvershadeAsh.PNG
Strata Core,Soil,LoggingArea,Soil core with visible stratification showing evidence of liquefaction.,ET-6.9-Brazil-00046,30,no,no,StrataCore.PNG
Strata Core,Soil,LoggingArea,Soil core with visible stratification showing evidence of liquefaction.,EE-8.3-Brazil-01208,30,no,no,StrataCore.PNG
Opal Clast,Tephra,ShelvingAreaM,Pumice clast with sharp edges and clear layering.,EV-8.3-Iceland-00127,65,no,no,OpalClast.PNG
Magnetite Ash,Ash,PalletDeliveryArea,Bagged black ash sample with high magnetic content.,EV-5.3-Myanmar-00088,28,yes,no,MagnetiteAsh.PNG
Ropeform Fragment,Lava,ShelvingAreaR,Ropey pahoehoe lava fragment with preserved ripples.,EV-6.9-Ethiopia-00012,85,no,no,RopeformFragment.PNG

1 Name Type WarehouseArea Description EarthquakeCode Price Required PickedUp Picture
2 Echo Bomb Lava ShelvingAreaA A dense glossy black volcanic bomb with minor vesicles. EV-7.4-Mexico-00035 120 no no EchoBomb.PNG
3 Silvershade Ash Ash ShelvingAreaD Fine light-grey volcanic ash collected near a village. EV-6.0-Iceland-00018 40 no no SilvershadeAsh.PNG
4 Strata Core Soil LoggingArea Soil core with visible stratification showing evidence of liquefaction. ET-6.9-Brazil-00046 EE-8.3-Brazil-01208 30 no no StrataCore.PNG
5 Opal Clast Tephra ShelvingAreaM Pumice clast with sharp edges and clear layering. EV-8.3-Iceland-00127 65 no no OpalClast.PNG
6 Magnetite Ash Ash PalletDeliveryArea Bagged black ash sample with high magnetic content. EV-5.3-Myanmar-00088 28 yes no MagnetiteAsh.PNG
7 Ropeform Fragment Lava ShelvingAreaR Ropey pahoehoe lava fragment with preserved ripples. EV-6.9-Ethiopia-00012 85 no no RopeformFragment.PNG

1558
public/Earthquakes-Long.csv Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +1,10 @@
import { NextResponse } from 'next/server';
import { NextResponse } from "next/server";
import { prisma } from '@utils/prisma';
// todo add specification of date range in request
import { prisma } from "@utils/prisma";
export async function POST(req: Request) {
try {
const json = await req.json();
const { rangeDaysPrev } = json.body;
const { rangeDaysPrev } = await req.json();
const now = new Date();
const rangeBeginning = new Date();

View File

@ -2,9 +2,10 @@ import { parse } from "csv-parse/sync";
import fs from "fs/promises";
import { NextResponse } from "next/server";
import path from "path";
import { getRandomNumber } from "@utils/maths";
import { stringToBool } from "@utils/parsingUtils";
import { prisma } from "@utils/prisma";
import { getRandomNumber } from "@utils/maths";
const csvFilePath = path.resolve(process.cwd(), "public/Artefacts.csv");
@ -54,11 +55,11 @@ export async function POST() {
type: row.Type,
warehouseArea: row.WarehouseArea,
earthquakeId: earthquake.id,
required: stringToBool(row.Required, true),
isRequired: stringToBool(row.Required, true),
shopPrice: row.Price && row.Price !== "" ? parseFloat(row.Price) : getRandomNumber(20, 500),
pickedUp: stringToBool(row.PickedUp, false),
isSold: false,
isCollected: false,
creatorId: randomCreator.id,
purchasedById: null,
imageName: row.Picture,
};
})

View File

@ -105,7 +105,8 @@ export async function POST() {
);
// Bulk insert earthquakes and connect observatories in a transaction
await prisma.$transaction(async (tx) => {
await prisma.$transaction(
async (tx) => {
// Insert earthquakes
await tx.earthquake.createMany({
data: validEarthquakes.map((eq) => eq.data),
@ -133,7 +134,9 @@ export async function POST() {
}
})
);
});
},
{ timeout: 1000000 }
);
if (failedImports.length > 0) {
console.warn("Failed imports:", failedImports);

View File

@ -3,8 +3,8 @@ import { SignJWT } from "jose";
import { NextResponse } from "next/server";
import { env } from "@utils/env";
import { prisma } from "@utils/prisma";
import { findUserByEmail, readUserCsv, User } from "../functions/csvReadWrite";
export async function POST(req: Request) {
@ -28,17 +28,18 @@ export async function POST(req: Request) {
// get user and relations
user = await prisma.user.findUnique({
where: { id: user.id },
include: {
scientist: {
include: {
earthquakes: true,
observatories: true,
artefacts: true,
purchasedOrders: true,
requests: true,
scientist: {
include: {
superior: true,
subordinates: true,
},
},
purchasedArtefacts: true,
},
});

View File

@ -2,46 +2,15 @@ import { NextResponse } from "next/server";
import { prisma } from "@utils/prisma";
// todo remove if (usingPrisma) code
// todo add specification of date range in request
export async function GET(request: Request) {
try {
const events = [
{
id: "1234",
title: "Earthquake - Berlin Observatory",
text1: "Logged by ",
text2: "30 minutes ago",
longitude: 10.4515, // Near Berlin, Germany
latitude: 52.52,
},
{
id: "2134",
title: "New Observatory - Phuket, Thailand",
text1: "Dr. Neil Armstrong",
text2: "2 weeks ago",
longitude: -122.4194,
latitude: 37.7749,
},
{
id: "2314",
title: "Observatory Scientist Change",
text1: "Dr. Samantha Green new lead scientist",
text2: "1 month ago",
longitude: 139.6917,
latitude: 35.6762,
},
];
// todo get earthquakes associated with observatories
const observatories = await prisma.observatory.findMany();
if (observatories) {
return NextResponse.json({ message: "Got observatories successfully", observatories }, { status: 200 });
} else {
return NextResponse.json({ message: "Got observatories successfully", observatories: events }, { status: 200 });
// return NextResponse.json({ message: "Failed to get observatories" }, { status: 401 });
return NextResponse.json({ message: "Failed to get observatories" }, { status: 401 });
}
} catch (error) {
console.error("Error in observatories endpoint:", error);

View File

@ -5,13 +5,13 @@ import useSWR from "swr";
import Map from "@components/Map";
import Sidebar from "@components/Sidebar";
import { fetcher } from "@utils/fetcher";
import { createPoster, fetcher } from "@utils/axiosHelpers";
export default function Earthquakes() {
const [selectedEventId, setSelectedEventId] = useState("");
const [hoveredEventId, setHoveredEventId] = useState("");
// todo properly integrate loading
const { data, error, isLoading } = useSWR("/api/earthquakes", fetcher);
const { data, error, isLoading } = useSWR("/api/earthquakes", createPoster({ rangeDaysPrev: 5 }));
return (
<div className="h-full flex overflow-hidden">
@ -38,7 +38,6 @@ export default function Earthquakes() {
button2Name="Search Earthquakes"
></Sidebar>
{/* <SidebarTest></SidebarTest> */}
</div>
);
}

View File

@ -1,7 +1,7 @@
// app/learn/page.tsx
"use client";
import Navbar from "@/components/Navbar";
import BottomFooter from "@components/BottomFooter";
import Navbar from "@components/Navbar";
export default function LearnPage() {
return (
@ -10,22 +10,19 @@ export default function LearnPage() {
{/* <Navbar /> */}
<main className="flex-1 flex flex-col items-center justify-start pt-12 px-4">
<h1 className="text-4xl font-bold mb-4 text-blue-800 text-center">
Earthquakes
</h1>
<h1 className="text-4xl font-bold mb-4 text-blue-800 text-center">Earthquakes</h1>
<p className="max-w-2xl text-lg text-gray-700 mb-6 text-center">
<span className="font-bold">In this page, you can learn all about what earthquakes are, and how to keep safe!</span>
</p>
<div className="max-w-3xl text-base text-gray-600 text-left space-y-8">
{/* Section 1 */}
<section>
<p>
<span className="font-semibold text-blue-800">What are earthquakes?</span>
<br />
Earthquakes are a shaking of the earth's surface caused by a sudden release of energy underground.
They can range in size, from tiny trembles to large quakes, which can cause destruction and even tsunamis.
Hundreds of earthquakes happen every daybut most are too small to feel.
Earthquakes are a shaking of the earth's surface caused by a sudden release of energy underground. They can range in
size, from tiny trembles to large quakes, which can cause destruction and even tsunamis. Hundreds of earthquakes
happen every daybut most are too small to feel.
</p>
</section>
@ -47,7 +44,8 @@ export default function LearnPage() {
<ul className="list-disc list-inside pl-6 space-y-2">
<li>
<span className="font-bold text-gray-800">Assemble an emergency kit:</span>
This should be stored in your earthquake emergency zone. It may be useful, as in an earthquake, you may lose electricity or water supplies.
This should be stored in your earthquake emergency zone. It may be useful, as in an earthquake, you may lose
electricity or water supplies.
{/* SUB BULLETS */}
<ul className="list-disc list-inside pl-6 mt-1 space-y-1 text-gray-700">
<li>First aid kit and emergency medication</li>
@ -76,7 +74,8 @@ export default function LearnPage() {
</li>
<li>
<span className="font-bold text-gray-800">Identify a safe zone:</span>
This should be a sturdy place where all members of your household can shelter, such as under a strong table, in a structurally sound room, or your local communitys shared space.
This should be a sturdy place where all members of your household can shelter, such as under a strong table, in a
structurally sound room, or your local communitys shared space.
</li>
<li>
<span className="font-bold text-gray-800">Discuss what to do:</span>

View File

@ -5,13 +5,13 @@ import useSWR from "swr";
import Sidebar from "@/components/Sidebar";
import Map from "@components/Map";
import { fetcher } from "@utils/fetcher";
import { fetcher } from "@utils/axiosHelpers";
export default function Observatories() {
const [selectedEventId, setSelectedEventId] = useState("");
const [hoveredEventId, setHoveredEventId] = useState("");
// todo properly integrate loading
const { data, error, isLoading } = useSWR("/api/earthquakes", fetcher);
const { data, error, isLoading } = useSWR("/api/observatories", fetcher);
return (
<div className="h-full flex overflow-hidden">

View File

@ -0,0 +1,7 @@
import axios from "axios";
export const fetcher = (url: string) => axios.get(url).then((res) => res.data);
export function createPoster(data: object) {
return (url: string) => axios.post(url, data).then((res) => res.data);
}

16
src/utils/countRows.ts Normal file
View File

@ -0,0 +1,16 @@
import { PrismaClient } from "../generated/prisma/client";
const prisma = new PrismaClient();
async function countRows() {
try {
const count = await prisma.earthquake.count();
console.log(`Row count: ${count}`);
} catch (error) {
console.error("Error:", error);
} finally {
await prisma.$disconnect();
}
}
countRows();

View File

@ -1,3 +0,0 @@
import axios from "axios";
export const fetcher = (url: string) => axios.get(url).then((res) => res.data);