Skip to content

Commit

Permalink
fix: fixed the file name issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sriramkanakam87 committed Nov 19, 2024
1 parent be708bc commit 5893c54
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions app/Console/Commands/Import3DSDFs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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.');
}

Expand Down

0 comments on commit 5893c54

Please sign in to comment.