From 5893c54981b4379f9769b66d5bf8f637b07896e9 Mon Sep 17 00:00:00 2001 From: Sagar Date: Tue, 19 Nov 2024 14:57:38 +0100 Subject: [PATCH] fix: fixed the file name issue --- app/Console/Commands/Import3DSDFs.php | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/app/Console/Commands/Import3DSDFs.php b/app/Console/Commands/Import3DSDFs.php index 1f07a557..6dc5c2ab 100644 --- a/app/Console/Commands/Import3DSDFs.php +++ b/app/Console/Commands/Import3DSDFs.php @@ -20,19 +20,25 @@ class Import3DSDFs extends Command * * @var string */ - protected $description = 'Imports 3D SDFs from a JSON file into Structures table'; + protected $description = 'Imports 3D SDFs from multiple JSON file into Structures table'; /** * Execute the console command. */ public function handle() { + $batchSize = 10000; // Number of molecules to process in each batch + $file = storage_path($this->argument('file')); $file_suffix = (int) $file[strpos($file, '.json') - 1]; $file_name_without_id = substr($file, 0, strpos($file, '.json') - 1); // loop runs though all the files for (; $file_suffix <= 18; $file_suffix++) { + + $json = null; + $json_data = []; + $file_name = $file_name_without_id.$file_suffix.'.json'; $this->info('Starting loop for file '.$file_name); if (! file_exists($file_name) || ! is_readable($file_name)) { @@ -41,33 +47,25 @@ public function handle() return 1; } - $batchSize = 1000; - $header = null; - $data = []; - $rowCount = 0; - - $json = file_get_contents($file); + $json = file_get_contents($file_name); if ($json === false) { exit('Error reading the JSON file'); } $this->info('File read'); $json_data = json_decode($json, true); - $this->info('Total elements successfully read: '.count($json_data)); - - $batchSize = 10000; // Number of molecules to process in each batch - $data = []; // Array to store data for batch updating + $keys = array_keys($json_data); + $this->info(end($keys)); $totalElements = count($json_data); $this->info('Total elements: '.$totalElements); + for ($i = 0; $i < $totalElements; $i += $batchSize) { $this->info('Processing batch '.($i / $batchSize + 1).' of '.ceil($totalElements / $batchSize)); $batch = array_slice($json_data, $i, $totalElements - $i < $batchSize ? $totalElements - $i : $batchSize); $this->insertBatch($batch); } - } - $this->info('Annotation scores generated successfully.'); }