Spaces:
Running
Running
File size: 1,489 Bytes
907b200 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | <?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\File;
class AdmetsTableSeeder extends Seeder
{
public function run(): void
{
Schema::disableForeignKeyConstraints();
DB::table('admets')->truncate();
Schema::enableForeignKeyConstraints();
$csvFile = database_path('seeders/data/parallel_admet_report.csv');
if (!File::exists($csvFile)) {
$this->command->error("CSV file not found at: {$csvFile}");
return;
}
$file = fopen($csvFile, 'r');
$header = fgetcsv($file);
$data = [];
while (($row = fgetcsv($file)) !== false) {
$data[] = [
'smiles' => $row[0],
'absorption' => (float) $row[1],
'distribution' => (float) $row[2],
'metabolism' => (float) $row[3],
'excretion' => (float) $row[4],
'toxicity' => (float) $row[5],
'created_at' => now(),
'updated_at' => now(),
];
}
fclose($file);
if (!empty($data)) {
DB::table('admets')->insert($data);
$this->command->info('Successfully imported ' . count($data) . ' records from CSV.');
} else {
$this->command->warn('No data found in CSV file.');
}
}
}
|