earthquake file updated

This commit is contained in:
IZZY 2025-05-19 13:25:10 +01:00
parent 3c31b2187b
commit 8fa8f6c5cd
5 changed files with 1642 additions and 3229 deletions

View File

@ -45,14 +45,19 @@ model Earthquake {
id Int @id @default(autoincrement()) id Int @id @default(autoincrement())
createdAt DateTime @default(now()) createdAt DateTime @default(now())
updatedAt DateTime @updatedAt updatedAt DateTime @updatedAt
date DateTime date DateTime
location String code String @unique
latitude String
longitude String
magnitude Float magnitude Float
depth Float type String // e.g. 'volcanic'
latitude Float
longitude Float
location String
depth String
creatorId Int? creatorId Int?
creator Scientist? @relation("ScientistEarthquakeCreator", fields: [creatorId], references: [id], onDelete: NoAction, onUpdate: NoAction) creator Scientist? @relation("ScientistEarthquakeCreator", fields: [creatorId], references: [id])
artefacts Artefact[] artefacts Artefact[]
observatories Observatory[] @relation("EarthquakeObservatory") observatories Observatory[] @relation("EarthquakeObservatory")
} }

File diff suppressed because it is too large Load Diff

View File

@ -4,15 +4,15 @@ import fs from "fs/promises";
import path from "path"; import path from "path";
import { parse } from "csv-parse/sync"; import { parse } from "csv-parse/sync";
// Define the path to your CSV file. // Path to your earthquakes.csv
// Place your earthquakes.csv in your project root or `public` directory
const csvFilePath = path.resolve(process.cwd(), "public/earthquakes.csv"); const csvFilePath = path.resolve(process.cwd(), "public/earthquakes.csv");
const prisma = new PrismaClient(); const prisma = new PrismaClient();
type CsvRow = { type CsvRow = {
Date: string; Date: string;
Code: string;
Magnitude: string; Magnitude: string;
Type: string;
Latitude: string; Latitude: string;
Longitude: string; Longitude: string;
Location: string; Location: string;
@ -23,36 +23,28 @@ export async function POST() {
try { try {
// 1. Read the CSV file // 1. Read the CSV file
const fileContent = await fs.readFile(csvFilePath, "utf8"); const fileContent = await fs.readFile(csvFilePath, "utf8");
// 2. Parse the CSV // 2. Parse the CSV
const records: CsvRow[] = parse(fileContent, { const records: CsvRow[] = parse(fileContent, {
columns: true, columns: true,
skip_empty_lines: true skip_empty_lines: true
}); });
// 3. Transform to fit Earthquake model
// 3. Transform each CSV row to Earthquake model const earthquakes = records.map(row => ({
// Since your prisma model expects: name, date (DateTime), location, magnitude (float), depth (float). We'll fill casualties/creatorId as zero/null for now.
const earthquakes = records.map(row => {
// You may want to add better parsing & validation depending on your actual data
return {
date: new Date(row.Date), date: new Date(row.Date),
location: row.Location, code: row.Code,
magnitude: parseFloat(row.Magnitude), magnitude: parseFloat(row.Magnitude),
latitude: row.Latitude, type: row.Type,
longitude: row.Longitude, latitude: parseFloat(row.Latitude),
depth: parseFloat(row.Depth.replace(" km", "")), longitude: parseFloat(row.Longitude),
// todo add creatorId location: row.Location,
depth: row.Depth, // store as received
creatorId: null creatorId: null
}; }));
});
// 4. Bulk create earthquakes in database: // 4. Bulk create earthquakes in database:
// Consider chunking if your CSV is large!
await prisma.earthquake.createMany({ await prisma.earthquake.createMany({
data: earthquakes, data: earthquakes,
skipDuplicates: true, // in case the route is called twice skipDuplicates: true,
}); });
return NextResponse.json({ success: true, count: earthquakes.length }); return NextResponse.json({ success: true, count: earthquakes.length });
} catch (error: any) { } catch (error: any) {
console.error(error); console.error(error);

File diff suppressed because it is too large Load Diff

View File

@ -2,59 +2,56 @@ import random
import datetime import datetime
def generate_earthquake_data(start_date, end_date, file_name): def generate_earthquake_data(start_date, end_date, file_name):
# List of 200 real-world seismic locations, reformatted to remove commas
locations = [ locations = [
"San Andreas Fault USA", "Cascade Range USA", "Denali Fault System Alaska USA", "San Andreas Fault: USA", "Cascade Range: USA", "Denali Fault System: USA",
"New Madrid Seismic Zone USA", "Wasatch Fault Zone USA", "Hayward Fault California USA", "New Madrid Seismic Zone: USA", "Wasatch Fault Zone: USA", "Hayward Fault: USA",
"Guerrero Gap Mexico", "Cocos Plate Subduction Zone Mexico", "Motagua Fault Zone Guatemala", "Guerrero Gap: Mexico", "Cocos Plate Subduction Zone: Mexico", "Motagua Fault Zone: Guatemala",
"Caribbean North American Plate Boundary", "Los Angeles Basin USA", "Seattle Tacoma Fault Zone USA", "Caribbean Plate Boundary: Jamaica", "Los Angeles Basin: USA", "Seattle Tacoma Fault Zone: USA",
"San Juan Fault Zone Argentina", "Nazca Ridge Subduction Peru", "Cotopaxi Region Ecuador", "San Juan Fault Zone: Argentina", "Nazca Ridge Subduction: Peru", "Cotopaxi Region: Ecuador",
"Colombian Andes Plate Boundary Colombia", "Atacama Fault Zone Chile", "Cape Fold Belt South Africa", "Colombian Andes Plate Boundary: Colombia", "Atacama Fault Zone: Chile", "Cape Fold Belt: South Africa",
"Alpine Fault New Zealand", "Hikurangi Subduction Zone New Zealand", "Papua Fold Belt Papua New Guinea", "Alpine Fault: New Zealand", "Hikurangi Subduction Zone: New Zealand", "Papua Fold Belt: Papua New Guinea",
"Nias Islands Earthquake Zone Indonesia", "Java Trench Indonesia", "Banda Arc Indonesia", "Nias Islands Earthquake Zone: Indonesia", "Java Trench: Indonesia", "Banda Arc: Indonesia",
"Sumatra Andaman Megathrust Indonesia", "Kashmir Region India", "Himalayan Subduction Zone Nepal", "Sumatra Andaman Megathrust: Indonesia", "Kashmir Region: India", "Himalayan Subduction Zone: Nepal",
"Chiang Mai Rift Zone Thailand", "Active Faults in Myanmar", "Red River Fault Zone Vietnam", "Chiang Mai Rift Zone: Thailand", "Active Faults: Myanmar", "Red River Fault Zone: Vietnam",
"Taiwan Collision Zone Taiwan", "Ryukyu Trench Japan", "Kanto Region Fault Japan", "Taiwan Collision Zone: Taiwan", "Ryukyu Trench: Japan", "Kanto Region Fault: Japan",
"Kyushu Subduction Zone Japan", "Kuril Kamchatka Trench Russia", "Lake Baikal Rift Zone Russia", "Kyushu Subduction Zone: Japan", "Kuril Kamchatka Trench: Russia", "Lake Baikal Rift Zone: Russia",
"Berbera Rift System Somalia", "Armenian Highlands Collision Zone Armenia", "Zagros Mountains Fault Iran", "Berbera Rift System: Somalia", "Armenian Highlands: Armenia", "Zagros Mountains Fault: Iran",
"Makran Subduction Zone Pakistan", "Hindu Kush Earthquake Belt Afghanistan", "Caspian Sea Collision Zone Iran", "Makran Subduction Zone: Pakistan", "Hindu Kush Earthquake Belt: Afghanistan", "Caspian Sea Collision Zone: Iran",
"Jordan Rift Valley Israel", "Dead Sea Fault Zone Israel", "Eastern Anatolian Fault Turkey", "Jordan Rift Valley: Jordan", "Dead Sea Fault Zone: Israel", "Eastern Anatolian Fault: Turkey",
"Hellenic Arc Greece", "Mediterranean Subduction Complex Italy", "Pyrenees Fault System Spain", "Hellenic Arc: Greece", "Mediterranean Subduction Complex: Italy", "Pyrenees Fault System: Spain",
"Aegean Seismic Zone Greece", "Alborz Mountains Fault Zone Iran", "Ligurian Alps Italy", "Aegean Seismic Zone: Greece", "Alborz Mountains Fault Zone: Iran", "Ligurian Alps: Italy",
"Iceland Seismic Zone Iceland", "Mid Atlantic Ridge Atlantic Ocean", "Azores Triple Junction Portugal", "Iceland Seismic Zone: Iceland", "Mid Atlantic Ridge: Iceland",
"Reykjanes Ridge Iceland", "Scandinavian Fault Zone Norway", "Barents Sea Rift Norway", "Azores Triple Junction: Portugal", "Reykjanes Ridge: Iceland", "Scandinavian Fault Zone: Norway",
"East African Rift Ethiopia", "South Madagascar Seismic Zone Madagascar", "Cape Verde Rift Atlantic", "Barents Sea Rift: Norway", "East African Rift: Ethiopia", "South Madagascar Seismic Zone: Madagascar",
"Victoria Seismic Belt Australia", "Bismarck Plate Subduction Zone Papua New Guinea", "Cape Verde Rift: Cape Verde", "Victoria Seismic Belt: Australia",
"Fiji Plate Boundary Pacific Ocean", "Solomon Islands Seismic Zone Solomon Islands", "Bismarck Plate Subduction Zone: Papua New Guinea", "Fiji Plate Boundary: Fiji",
"New Hebrides Subduction Vanuatu", "Tonga Kermadec Arc Tonga", "Samoa Seismic Zone Pacific Ocean", "Solomon Islands Seismic Zone: Solomon Islands", "New Hebrides Subduction: Vanuatu",
"South Sandwich Plate Collision Zone South Sandwich Islands", "Drake Passage Convergence Zone Antarctica", "Tonga Kermadec Arc: Tonga", "Samoa Seismic Zone: Samoa",
"Scotia Plate Boundary Antarctica", "Antarctic Seismic Belt Antarctica", "Ross Sea Fault Zone Antarctica", "South Sandwich Plate Collision Zone: South Georgia and the South Sandwich Islands",
"Carlsberg Ridge Indian Ocean", "East Pacific Rise Pacific Ocean", "Indian Ocean Ridge Indian Ocean", "Drake Passage Convergence Zone: Argentina", "Scotia Plate Boundary: Argentina",
"Macquarie Plate Boundary Australia", "Chagos Laccadive Ridge Indian Ocean", "Moho Tectonic Zone Ethiopia", "Antarctic Seismic Belt: Antarctica", "Ross Sea Fault Zone: Antarctica", "Carlsberg Ridge: Maldives",
"Azores Cape Verde Fault Line Atlantic Ocean", "South Shetland Trench Antarctica", "East Pacific Rise: Chile", "Indian Ocean Ridge: Mauritius", "Macquarie Plate Boundary: Australia",
"Luale Tectonic Boundary Angola", "Banda Sea Subduction Zone Indonesia", "Chagos Laccadive Ridge: Maldives", "Moho Tectonic Zone: Ethiopia",
"Guinea Ridge Zone Guinea", "Mauritius Seismic Area Indian Ocean", "Moluccas Sea Plate Collision Indonesia", "Azores Cape Verde Fault Line: Portugal", "South Shetland Trench: Antarctica",
"Yucatan Fault Zone Central America", "Offshore Nicaragua Subduction Zone Nicaragua", "Luale Tectonic Boundary: Angola", "Banda Sea Subduction Zone: Indonesia",
"Central Honduras Earthquake Belt Honduras", "Puerto Rico Trench Caribbean Plate", "Guinea Ridge Zone: Guinea", "Mauritius Seismic Area: Mauritius", "Moluccas Sea Plate Collision: Indonesia",
"Trinidad Seismic Zone Trinidad and Tobago", "Barbadian Subduction Area Barbados", "Yucatan Fault Zone: Mexico", "Offshore Nicaragua Subduction Zone: Nicaragua",
"Northern Andes Seismic Belt Venezuela", "South Atlantic Rift Brazil", "Acre Seismic Boundary Brazil", "Central Honduras Earthquake Belt: Honduras", "Puerto Rico Trench: Puerto Rico",
"Rio Grande Rift Zone USA", "Offshore Baja California USA", "Guarare Seismic Region Panama", "Trinidad Seismic Zone: Trinidad and Tobago", "Barbadian Subduction Area: Barbados",
"Offshore Vancouver Island Subduction Canada", "Yellowstone Volcanic Zone USA", "Northern Andes Seismic Belt: Venezuela", "South Atlantic Rift: Brazil",
"Adelaide Fold Belt Australia", "Tasman Plate Boundary New Zealand", "Offshore Queensland Australia", "Acre Seismic Boundary: Brazil", "Rio Grande Rift Zone: USA", "Offshore Baja California: Mexico",
"Gansu Fault Zone China", "Xian Seismic Belt China", "Tibet Rift Zone China", "Guarare Seismic Region: Panama", "Offshore Vancouver Island Subduction: Canada",
"Chengdu Seismic Zone China", "Fujian Fault Zone China", "Jiuzhaigou Seismic Area China", "Yellowstone Volcanic Zone: USA"
"Karakoram Fault Zone India", "Andaman Nicobar Subduction India", "Mumbai Rift Zone India",
"Cape York Seismic Zone Papua New Guinea", "Merewether Fault Australia", "Gulf of Aden Rift Zone",
"Oman Subduction Zone", "Ras Al Khaimah Fault Zone UAE", "Djibouti Rift Zone Africa",
"Mogadishu Seismic Zone Somalia", "Mozambique Channel Rift Mozambique", "Botswana Seismic Zone Africa",
"Victoria Lake Microplate Africa", "Nairobi Rift Axis Kenya", "Sumba Island Subduction Zone Indonesia"
] ]
types = ["tectonic", "volcanic", "collapse", "explosion"]
type_prefix = {"tectonic": "ET", "volcanic": "EV", "collapse": "EC", "explosion": "EE"}
start = datetime.datetime.strptime(start_date, '%Y-%m-%d') start = datetime.datetime.strptime(start_date, '%Y-%m-%d')
end = datetime.datetime.strptime(end_date, '%Y-%m-%d') end = datetime.datetime.strptime(end_date, '%Y-%m-%d')
delta = end - start delta = end - start
earthquake_list = [] earthquake_list = []
unique_counter = 1 # For sequential unique codes
for i in range(delta.days + 1): for i in range(delta.days + 1):
date = start + datetime.timedelta(days=i) date = start + datetime.timedelta(days=i)
@ -63,9 +60,16 @@ def generate_earthquake_data(start_date, end_date, file_name):
lat = round(random.uniform(-90, 90), 4) lat = round(random.uniform(-90, 90), 4)
lon = round(random.uniform(-180, 180), 4) lon = round(random.uniform(-180, 180), 4)
location = random.choice(locations) location = random.choice(locations)
country = location.split(": ")[1]
place = location.split(": ")[0]
depth = random.randint(5, 150) depth = random.randint(5, 150)
# Format data using comma-separated values (CSV) eq_type = random.choice(types)
earthquake_list.append(f"{date.date()},{magnitude},{lat},{lon},{location},{depth} km") prefix = type_prefix[eq_type]
code = f"{prefix}-{magnitude}-{country}-{unique_counter:05d}"
# Output: Date,Code,Magnitude,Type,Lat,Lon,Location,Depth
earthquake_list.append(f"{date.date()},{code},{magnitude},{eq_type},{lat},{lon},{place},{depth} km")
unique_counter += 1
with open(file_name, "w") as file: with open(file_name, "w") as file:
file.write("\n".join(earthquake_list)) file.write("\n".join(earthquake_list))