earthquake file updated
This commit is contained in:
parent
3c31b2187b
commit
8fa8f6c5cd
@ -42,17 +42,22 @@ model Scientist {
|
||||
}
|
||||
|
||||
model Earthquake {
|
||||
id Int @id @default(autoincrement())
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
date DateTime
|
||||
location String
|
||||
latitude String
|
||||
longitude String
|
||||
magnitude Float
|
||||
depth Float
|
||||
creatorId Int?
|
||||
creator Scientist? @relation("ScientistEarthquakeCreator", fields: [creatorId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
||||
id Int @id @default(autoincrement())
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
date DateTime
|
||||
code String @unique
|
||||
magnitude Float
|
||||
type String // e.g. 'volcanic'
|
||||
latitude Float
|
||||
longitude Float
|
||||
location String
|
||||
depth String
|
||||
|
||||
creatorId Int?
|
||||
creator Scientist? @relation("ScientistEarthquakeCreator", fields: [creatorId], references: [id])
|
||||
|
||||
artefacts Artefact[]
|
||||
observatories Observatory[] @relation("EarthquakeObservatory")
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -4,55 +4,47 @@ import fs from "fs/promises";
|
||||
import path from "path";
|
||||
import { parse } from "csv-parse/sync";
|
||||
|
||||
// Define the path to your CSV file.
|
||||
// Place your earthquakes.csv in your project root or `public` directory
|
||||
// Path to your earthquakes.csv
|
||||
const csvFilePath = path.resolve(process.cwd(), "public/earthquakes.csv");
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
type CsvRow = {
|
||||
Date: string;
|
||||
Code: string;
|
||||
Magnitude: string;
|
||||
Type: string;
|
||||
Latitude: string;
|
||||
Longitude: string;
|
||||
Location: string;
|
||||
Depth: string;
|
||||
Depth: string;
|
||||
};
|
||||
|
||||
export async function POST() {
|
||||
try {
|
||||
// 1. Read the CSV file
|
||||
const fileContent = await fs.readFile(csvFilePath, "utf8");
|
||||
|
||||
// 2. Parse the CSV
|
||||
const records: CsvRow[] = parse(fileContent, {
|
||||
columns: true,
|
||||
skip_empty_lines: true
|
||||
});
|
||||
|
||||
// 3. Transform each CSV row to Earthquake model
|
||||
// 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),
|
||||
location: row.Location,
|
||||
magnitude: parseFloat(row.Magnitude),
|
||||
latitude: row.Latitude,
|
||||
longitude: row.Longitude,
|
||||
depth: parseFloat(row.Depth.replace(" km", "")),
|
||||
// todo add creatorId
|
||||
creatorId: null
|
||||
};
|
||||
});
|
||||
|
||||
// 3. Transform to fit Earthquake model
|
||||
const earthquakes = records.map(row => ({
|
||||
date: new Date(row.Date),
|
||||
code: row.Code,
|
||||
magnitude: parseFloat(row.Magnitude),
|
||||
type: row.Type,
|
||||
latitude: parseFloat(row.Latitude),
|
||||
longitude: parseFloat(row.Longitude),
|
||||
location: row.Location,
|
||||
depth: row.Depth, // store as received
|
||||
creatorId: null
|
||||
}));
|
||||
// 4. Bulk create earthquakes in database:
|
||||
// Consider chunking if your CSV is large!
|
||||
await prisma.earthquake.createMany({
|
||||
data: earthquakes,
|
||||
skipDuplicates: true, // in case the route is called twice
|
||||
skipDuplicates: true,
|
||||
});
|
||||
|
||||
return NextResponse.json({ success: true, count: earthquakes.length });
|
||||
} catch (error: any) {
|
||||
console.error(error);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -2,59 +2,56 @@ import random
|
||||
import datetime
|
||||
|
||||
def generate_earthquake_data(start_date, end_date, file_name):
|
||||
# List of 200 real-world seismic locations, reformatted to remove commas
|
||||
locations = [
|
||||
"San Andreas Fault USA", "Cascade Range USA", "Denali Fault System Alaska USA",
|
||||
"New Madrid Seismic Zone USA", "Wasatch Fault Zone USA", "Hayward Fault California USA",
|
||||
"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",
|
||||
"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",
|
||||
"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",
|
||||
"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",
|
||||
"Taiwan Collision Zone Taiwan", "Ryukyu Trench Japan", "Kanto Region Fault Japan",
|
||||
"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",
|
||||
"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",
|
||||
"Hellenic Arc Greece", "Mediterranean Subduction Complex Italy", "Pyrenees Fault System Spain",
|
||||
"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",
|
||||
"Reykjanes Ridge Iceland", "Scandinavian Fault Zone Norway", "Barents Sea Rift Norway",
|
||||
"East African Rift Ethiopia", "South Madagascar Seismic Zone Madagascar", "Cape Verde Rift Atlantic",
|
||||
"Victoria Seismic Belt Australia", "Bismarck Plate Subduction Zone Papua New Guinea",
|
||||
"Fiji Plate Boundary Pacific Ocean", "Solomon Islands Seismic Zone Solomon Islands",
|
||||
"New Hebrides Subduction Vanuatu", "Tonga Kermadec Arc Tonga", "Samoa Seismic Zone Pacific Ocean",
|
||||
"South Sandwich Plate Collision Zone South Sandwich Islands", "Drake Passage Convergence Zone Antarctica",
|
||||
"Scotia Plate Boundary Antarctica", "Antarctic Seismic Belt Antarctica", "Ross Sea Fault Zone Antarctica",
|
||||
"Carlsberg Ridge Indian Ocean", "East Pacific Rise Pacific Ocean", "Indian Ocean Ridge Indian Ocean",
|
||||
"Macquarie Plate Boundary Australia", "Chagos Laccadive Ridge Indian Ocean", "Moho Tectonic Zone Ethiopia",
|
||||
"Azores Cape Verde Fault Line Atlantic Ocean", "South Shetland Trench Antarctica",
|
||||
"Luale Tectonic Boundary Angola", "Banda Sea Subduction Zone Indonesia",
|
||||
"Guinea Ridge Zone Guinea", "Mauritius Seismic Area Indian Ocean", "Moluccas Sea Plate Collision Indonesia",
|
||||
"Yucatan Fault Zone Central America", "Offshore Nicaragua Subduction Zone Nicaragua",
|
||||
"Central Honduras Earthquake Belt Honduras", "Puerto Rico Trench Caribbean Plate",
|
||||
"Trinidad Seismic Zone Trinidad and Tobago", "Barbadian Subduction Area Barbados",
|
||||
"Northern Andes Seismic Belt Venezuela", "South Atlantic Rift Brazil", "Acre Seismic Boundary Brazil",
|
||||
"Rio Grande Rift Zone USA", "Offshore Baja California USA", "Guarare Seismic Region Panama",
|
||||
"Offshore Vancouver Island Subduction Canada", "Yellowstone Volcanic Zone USA",
|
||||
"Adelaide Fold Belt Australia", "Tasman Plate Boundary New Zealand", "Offshore Queensland Australia",
|
||||
"Gansu Fault Zone China", "Xian Seismic Belt China", "Tibet Rift Zone China",
|
||||
"Chengdu Seismic Zone China", "Fujian Fault Zone China", "Jiuzhaigou Seismic Area China",
|
||||
"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"
|
||||
"San Andreas Fault: USA", "Cascade Range: USA", "Denali Fault System: 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",
|
||||
"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",
|
||||
"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",
|
||||
"Nias Islands Earthquake Zone: Indonesia", "Java Trench: Indonesia", "Banda Arc: Indonesia",
|
||||
"Sumatra Andaman Megathrust: Indonesia", "Kashmir Region: India", "Himalayan Subduction Zone: Nepal",
|
||||
"Chiang Mai Rift Zone: Thailand", "Active Faults: Myanmar", "Red River Fault Zone: Vietnam",
|
||||
"Taiwan Collision Zone: Taiwan", "Ryukyu Trench: Japan", "Kanto Region Fault: Japan",
|
||||
"Kyushu Subduction Zone: Japan", "Kuril Kamchatka Trench: Russia", "Lake Baikal Rift Zone: Russia",
|
||||
"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",
|
||||
"Jordan Rift Valley: Jordan", "Dead Sea Fault Zone: Israel", "Eastern Anatolian Fault: Turkey",
|
||||
"Hellenic Arc: Greece", "Mediterranean Subduction Complex: Italy", "Pyrenees Fault System: Spain",
|
||||
"Aegean Seismic Zone: Greece", "Alborz Mountains Fault Zone: Iran", "Ligurian Alps: Italy",
|
||||
"Iceland Seismic Zone: Iceland", "Mid Atlantic Ridge: Iceland",
|
||||
"Azores Triple Junction: Portugal", "Reykjanes Ridge: Iceland", "Scandinavian Fault Zone: Norway",
|
||||
"Barents Sea Rift: Norway", "East African Rift: Ethiopia", "South Madagascar Seismic Zone: Madagascar",
|
||||
"Cape Verde Rift: Cape Verde", "Victoria Seismic Belt: Australia",
|
||||
"Bismarck Plate Subduction Zone: Papua New Guinea", "Fiji Plate Boundary: Fiji",
|
||||
"Solomon Islands Seismic Zone: Solomon Islands", "New Hebrides Subduction: Vanuatu",
|
||||
"Tonga Kermadec Arc: Tonga", "Samoa Seismic Zone: Samoa",
|
||||
"South Sandwich Plate Collision Zone: South Georgia and the South Sandwich Islands",
|
||||
"Drake Passage Convergence Zone: Argentina", "Scotia Plate Boundary: Argentina",
|
||||
"Antarctic Seismic Belt: Antarctica", "Ross Sea Fault Zone: Antarctica", "Carlsberg Ridge: Maldives",
|
||||
"East Pacific Rise: Chile", "Indian Ocean Ridge: Mauritius", "Macquarie Plate Boundary: Australia",
|
||||
"Chagos Laccadive Ridge: Maldives", "Moho Tectonic Zone: Ethiopia",
|
||||
"Azores Cape Verde Fault Line: Portugal", "South Shetland Trench: Antarctica",
|
||||
"Luale Tectonic Boundary: Angola", "Banda Sea Subduction Zone: Indonesia",
|
||||
"Guinea Ridge Zone: Guinea", "Mauritius Seismic Area: Mauritius", "Moluccas Sea Plate Collision: Indonesia",
|
||||
"Yucatan Fault Zone: Mexico", "Offshore Nicaragua Subduction Zone: Nicaragua",
|
||||
"Central Honduras Earthquake Belt: Honduras", "Puerto Rico Trench: Puerto Rico",
|
||||
"Trinidad Seismic Zone: Trinidad and Tobago", "Barbadian Subduction Area: Barbados",
|
||||
"Northern Andes Seismic Belt: Venezuela", "South Atlantic Rift: Brazil",
|
||||
"Acre Seismic Boundary: Brazil", "Rio Grande Rift Zone: USA", "Offshore Baja California: Mexico",
|
||||
"Guarare Seismic Region: Panama", "Offshore Vancouver Island Subduction: Canada",
|
||||
"Yellowstone Volcanic Zone: USA"
|
||||
]
|
||||
types = ["tectonic", "volcanic", "collapse", "explosion"]
|
||||
type_prefix = {"tectonic": "ET", "volcanic": "EV", "collapse": "EC", "explosion": "EE"}
|
||||
|
||||
start = datetime.datetime.strptime(start_date, '%Y-%m-%d')
|
||||
end = datetime.datetime.strptime(end_date, '%Y-%m-%d')
|
||||
delta = end - start
|
||||
|
||||
earthquake_list = []
|
||||
unique_counter = 1 # For sequential unique codes
|
||||
|
||||
for i in range(delta.days + 1):
|
||||
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)
|
||||
lon = round(random.uniform(-180, 180), 4)
|
||||
location = random.choice(locations)
|
||||
country = location.split(": ")[1]
|
||||
place = location.split(": ")[0]
|
||||
depth = random.randint(5, 150)
|
||||
# Format data using comma-separated values (CSV)
|
||||
earthquake_list.append(f"{date.date()},{magnitude},{lat},{lon},{location},{depth} km")
|
||||
eq_type = random.choice(types)
|
||||
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:
|
||||
file.write("\n".join(earthquake_list))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user