-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #317 from Steinbeck-Lab/feat-charts
Feat charts
- Loading branch information
Showing
8 changed files
with
394 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Facades\File; | ||
|
||
class GenerateBubbleFrequencyCharts extends Command | ||
{ | ||
protected $signature = 'coconut:generate-bubble-frequency-charts'; | ||
|
||
protected $description = 'Generate bubble frequency charts data for molecular tables and columns'; | ||
|
||
private $columnsForCharts = [ | ||
[ | ||
'first_column' => 'chemical_class', | ||
'first_table' => 'properties', | ||
'second_column' => 'np_classifier_class', | ||
'second_table' => 'properties', | ||
], | ||
]; | ||
|
||
public function handle() | ||
{ | ||
$bubbleFrequencyPlotData = []; | ||
|
||
foreach ($this->columnsForCharts as $columnsInfo) { | ||
$first_column = $columnsInfo['first_column']; | ||
$second_column = $columnsInfo['second_column']; | ||
$first_table = $columnsInfo['first_table']; | ||
$second_table = $columnsInfo['second_table']; | ||
|
||
$query1 = "SELECT DISTINCT f.$first_column col, COUNT(*) count FROM $first_table f WHERE f.$first_column IS NOT NULL AND f.$first_column!='' "; | ||
$first_table == 'properties' ? $query1.'JOIN molecules m ON f.molecule_id=m.id WHERE m.active = TRUE AND NOT (m.is_parent = TRUE AND m.has_variants = TRUE) ' : ''; | ||
$query2 = "SELECT DISTINCT s.$second_column col, COUNT(*) count FROM $second_table s WHERE s.$second_column IS NOT NULL AND s.$second_column!='' "; | ||
$second_table == 'properties' ? $query2.'JOIN molecules m ON s.molecule_id=m.id WHERE m.active = TRUE AND NOT (m.is_parent = TRUE AND m.has_variants = TRUE) ' : ''; | ||
|
||
$query1 .= 'GROUP BY 1'; | ||
$query2 .= 'GROUP BY 1'; | ||
|
||
$bubbleFrequencyPlotData[$first_column.'|'.$second_column.'|'.uniqid()] = DB::select(" | ||
WITH | ||
t1 as ($query1) | ||
SELECT t1.col column_values, t1.count first_column_count from t1 order by 2 desc limit 170; | ||
"); | ||
|
||
$bubbleFrequencyPlotData[$first_column.'|'.$second_column.'|'.uniqid()] = DB::select(" | ||
WITH | ||
t1 as ($query2) | ||
SELECT t1.col column_values, t1.count second_column_count from t1 order by 2 desc limit 170; | ||
"); | ||
|
||
// $bubbleFrequencyPlotData[$first_column.'|'.$second_column.'|'.uniqid()] = DB::select(" | ||
// WITH | ||
// t1 as ($query1), | ||
// t2 as ($query2) | ||
// SELECT COALESCE(t1.col, t2.col) column_values , t1.count first_column_count, t2.count second_column_count FROM t1 LEFT JOIN t2 ON t1.col=t2.col WHERE t2.col IS NULL | ||
// ; | ||
// "); | ||
|
||
// $bubbleFrequencyPlotData[$first_column.'|'.$second_column.'|'.uniqid()] = DB::select(" | ||
// WITH | ||
// t1 as ($query1), | ||
// t2 as ($query2) | ||
// SELECT COALESCE(t1.col, t2.col) column_values , t1.count first_column_count, t2.count second_column_count FROM t1 RIGHT JOIN t2 ON t1.col=t2.col WHERE t1.col IS NULL | ||
// ; | ||
// "); | ||
|
||
} | ||
|
||
$filePath = public_path('reports/bubble_frequency_charts.json'); | ||
if (! file_exists(dirname($filePath))) { | ||
mkdir(dirname($filePath), 0777, true); | ||
} | ||
|
||
File::put($filePath, json_encode($bubbleFrequencyPlotData, JSON_UNESCAPED_SLASHES)); | ||
|
||
$this->info('Bubble Frequency charts data saved to: public/reports/bubble_frequency_charts.json'); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace App\Livewire; | ||
|
||
use Livewire\Component; | ||
|
||
class BubbleFrequencyPlot extends Component | ||
{ | ||
public $chartData; | ||
|
||
public $firstColumnName; | ||
|
||
public $secondColumnName; | ||
|
||
public $chartId; | ||
|
||
public $name_corrections = [ | ||
|
||
]; | ||
|
||
public function mount($chartName, $chartData) | ||
{ | ||
// Extract column names | ||
[$this->firstColumnName, $this->secondColumnName] = explode('|', $chartName); | ||
|
||
// Ensure data is properly formatted | ||
$this->chartData = array_map(function ($item) { | ||
return [ | ||
'column_values' => $item['column_values'], | ||
'first_column_count' => $item['first_column_count'] ?? 0, | ||
'second_column_count' => $item['second_column_count'] ?? 0, | ||
]; | ||
}, $chartData); | ||
|
||
$this->chartId = 'bubble-chart-'.uniqid(); | ||
} | ||
|
||
public function render() | ||
{ | ||
return view('livewire.bubble-frequency-plot'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.