Skip to content

Commit

Permalink
feat: landing page updates
Browse files Browse the repository at this point in the history
  • Loading branch information
CS76 committed May 31, 2024
1 parent cddf6ce commit 036eb3d
Show file tree
Hide file tree
Showing 5 changed files with 278 additions and 2 deletions.
94 changes: 94 additions & 0 deletions app/Console/Commands/ExportMoleculesWithOrganisms.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;

class ExportMoleculesWithOrganisms extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:export-molecules-with-organisms';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';

/**
* Execute the console command.
*/
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
// Fetch the data
$data = DB::table('molecule_organism')
->join('molecules', 'molecule_organism.molecule_id', '=', 'molecules.id')
->join('organisms', 'molecule_organism.organism_id', '=', 'organisms.id')
->select('molecule_organism.molecule_id', 'molecules.cas', 'molecules.canonical_smiles', 'molecules.identifier',
'organisms.name as organism_name', 'organisms.iri as organism_iri', 'organisms.rank as organism_rank',
'molecule_organism.*')
->get();

// Group by molecule_id and concatenate values
$groupedData = $data->groupBy('molecule_id')->map(function ($rows) {
$firstRow = $rows->first();
$moleculeId = $firstRow->molecule_id;
$moleculeCasArray = json_decode($firstRow->cas, true);
$moleculeCas = is_array($moleculeCasArray) && ! empty($moleculeCasArray) ? $moleculeCasArray[0] : null;
$canonicalSmiles = $firstRow->canonical_smiles;
$identifier = $firstRow->identifier;

$organisms = $rows->map(function ($row) {
$organismDetail = $row->organism_name;
if (! empty($row->organism_iri)) {
$organismDetail .= ' ('.urldecode($row->organism_iri).'|'.$row->organism_rank.')';
}

return $organismDetail;
})->implode('|');

// Get pivot columns, assuming the pivot table has additional columns like 'attribute1' and 'attribute2'
$pivotColumns = ['attribute1', 'attribute2'];
$pivotData = [];
foreach ($pivotColumns as $column) {
$pivotData[$column] = $rows->pluck($column)->unique()->implode('|');
}

return array_merge([
'molecule_id' => $moleculeId,
'identifier' => $identifier,
'molecule_cas' => $moleculeCas,
'canonical_smiles' => $canonicalSmiles,
'organisms' => $organisms,
], $pivotData);
});

// Convert to CSV format
$csvContent = $groupedData->map(function ($row) {
return implode(',', array_map(function ($value) {
return '"'.str_replace('"', '""', $value).'"';
}, $row));
})->prepend(implode(',', array_keys($groupedData->first())))->implode("\n");

// Save to a CSV file
// The file will be created in the storage/app directory
Storage::put('molecules_with_organisms.csv', $csvContent);

// Alternatively, to save in the storage/app/public directory:
// Storage::put('public/molecules_with_organisms.csv', $csvContent);

$this->info('Export completed successfully.');
}
}
22 changes: 21 additions & 1 deletion app/Livewire/Welcome.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,34 @@

namespace App\Livewire;

use Cache;
use Livewire\Attributes\Layout;
use Livewire\Component;

class Welcome extends Component
{
public $totalMolecules;

public $totalCollections;

public $uniqueOrganisms;

public $citationsMapped;

#[Layout('layouts.guest')]
public function render()
{
return view('livewire.welcome');
// Assign values to the variables
$this->totalMolecules = Cache::get('stats.molecules', 0);
$this->totalCollections = Cache::get('stats.collections', 0);
$this->uniqueOrganisms = Cache::get('stats.organisms', 0);
$this->citationsMapped = Cache::get('stats.citations', 0);

return view('livewire.welcome', [
'totalMolecules' => $this->totalMolecules,
'totalCollections' => $this->totalCollections,
'uniqueOrganisms' => $this->uniqueOrganisms,
'citationsMapped' => $this->citationsMapped,
]);
}
}
21 changes: 21 additions & 0 deletions resources/views/layouts/guest.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,25 @@
@livewireScripts
@include('cookie-consent::index')
</body>
<script>
document.addEventListener('DOMContentLoaded', function() {
function animateValue(element, start, end, duration) {
let startTimestamp = null;
const step = (timestamp) => {
if (!startTimestamp) startTimestamp = timestamp;
const progress = Math.min((timestamp - startTimestamp) / duration, 1);
element.innerText = Math.floor(progress * (end - start) + start);
if (progress < 1) {
window.requestAnimationFrame(step);
}
};
window.requestAnimationFrame(step);
}
document.querySelectorAll('.number').forEach((element) => {
const endValue = parseFloat(element.getAttribute('data-value').replace(/,/g, ''));
animateValue(element, 0, endValue, 500);
});
});
</script>
</html>
141 changes: 141 additions & 0 deletions resources/views/livewire/welcome.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,147 @@ class="absolute inset-0 -z-10 scale-75 rounded-lg bg-white/5 opacity-0 transitio
</div>
</div>
</div>

<div class="bg-gray-900">
<div class="mx-auto max-w-7xl">
<div class="grid grid-cols-1 gap-px bg-white/5 sm:grid-cols-2 lg:grid-cols-4">
<!-- Total Molecules Section -->
<div class="bg-gray-900 px-4 py-6 sm:px-6 lg:px-8">
<p class="text-sm font-medium leading-6 text-gray-400">
<svg fill="currentColor" version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" class="w-5 h-5 inline" viewBox="0 0 399.998 399.997"
xml:space="preserve">
<g>
<g>
<path d="M292.41,236.617l-42.814-27.769c5.495-15.665,4.255-33.162-3.707-48.011l35.117-31.373
c19.292,12.035,45.001,9.686,61.771-7.085c19.521-19.52,19.521-51.171,0-70.692c-19.522-19.521-51.175-19.521-70.694,0
c-15.378,15.378-18.632,38.274-9.788,56.848l-35.121,31.378c-16.812-11.635-38.258-13.669-56.688-6.078l-40.5-55.733
c14.528-19.074,13.095-46.421-4.331-63.849c-19.004-19.004-49.816-19.004-68.821,0c-19.005,19.005-19.005,49.818,0,68.822
c13.646,13.646,33.374,17.491,50.451,11.545l40.505,55.738c-20.002,23.461-18.936,58.729,3.242,80.906
c0.426,0.426,0.864,0.825,1.303,1.237l-39.242,68.874c-16.31-3.857-34.179,0.564-46.899,13.286
c-19.521,19.522-19.521,51.175,0,70.694c19.521,19.521,51.173,19.521,70.693,0c19.317-19.315,19.508-50.503,0.593-70.069
l39.239-68.867c19.705,5.658,41.737,0.978,57.573-14.033l42.855,27.79c-2.736,12.706,0.821,26.498,10.696,36.372
c15.469,15.469,40.544,15.469,56.012,0c15.468-15.466,15.468-40.543,0-56.011C329.831,226.518,307.908,225.209,292.41,236.617z
M83.129,338.906c-0.951,1.078-1.846,2.096-2.724,2.973c-1.094,1.093-2.589,2.425-4.444,2.998
c-2.33,0.719-4.711,0.086-6.536-1.739c-4.772-4.771-2.947-13.799,4.246-20.989c7.195-7.195,16.219-9.021,20.993-4.247
c1.824,1.822,2.457,4.205,1.737,6.536c-0.572,1.855-1.904,3.354-2.997,4.444c-0.878,0.876-1.896,1.771-2.975,2.722
c-1.245,1.096-2.535,2.229-3.805,3.497C85.355,336.37,84.224,337.66,83.129,338.906z M279.56,59.17
c7.193-7.193,16.219-9.02,20.991-4.247c1.823,1.823,2.458,4.205,1.737,6.537c-0.572,1.856-1.905,3.354-2.997,4.446
c-0.876,0.875-1.894,1.77-2.974,2.72c-1.246,1.097-2.534,2.229-3.805,3.498c-1.271,1.271-2.403,2.562-3.5,3.808
c-0.948,1.076-1.846,2.097-2.72,2.973c-1.093,1.093-2.591,2.425-4.446,2.998c-2.332,0.719-4.712,0.086-6.536-1.739
C270.541,75.391,272.366,66.362,279.56,59.17z M73.322,37.854c-0.928,1.05-1.799,2.042-2.648,2.895
c-1.063,1.063-2.521,2.358-4.329,2.919c-2.269,0.698-4.587,0.083-6.364-1.691c-4.646-4.647-2.866-13.436,4.138-20.438
c7.003-7.004,15.788-8.782,20.436-4.135c1.776,1.776,2.395,4.095,1.692,6.363c-0.561,1.807-1.854,3.265-2.918,4.326
c-0.854,0.854-1.846,1.727-2.896,2.648c-1.213,1.066-2.469,2.17-3.704,3.406C75.492,35.384,74.387,36.642,73.322,37.854z
M159.967,155.76c8.593-8.594,19.371-10.774,25.073-5.073c2.18,2.181,2.937,5.024,2.078,7.81
c-0.688,2.218-2.277,4.005-3.583,5.312c-1.047,1.047-2.265,2.112-3.553,3.248c-1.486,1.311-3.026,2.662-4.544,4.179
c-1.518,1.519-2.87,3.058-4.178,4.547c-1.136,1.287-2.205,2.505-3.251,3.55c-1.306,1.31-3.093,2.896-5.311,3.582
c-2.784,0.859-5.628,0.104-7.811-2.077C149.189,175.132,151.374,164.354,159.967,155.76z M299.11,262.103
c-0.868,0.866-2.056,1.923-3.524,2.376c-1.846,0.569-3.729,0.068-5.178-1.377c-3.783-3.781-2.338-10.933,3.365-16.633
c5.697-5.7,12.849-7.146,16.632-3.362c1.443,1.443,1.945,3.33,1.376,5.179c-0.453,1.471-1.51,2.656-2.375,3.521
c-0.694,0.692-1.5,1.402-2.355,2.155c-0.984,0.866-2.008,1.766-3.013,2.771c-1.007,1.006-1.907,2.026-2.771,3.016
C300.512,260.604,299.802,261.409,299.11,262.103z"/>
</g>
</g>
</svg>
Total Molecules
</p>
<p class="mt-2 flex items-baseline gap-x-2">
<span class="text-4xl font-semibold tracking-tight text-white number" data-value="{{ $totalMolecules }}"></span>
</p>
</div>
<!-- Total Collections Section -->
<div class="bg-gray-900 px-4 py-6 sm:px-6 lg:px-8">
<p class="text-sm font-medium leading-6 text-gray-400">
<svg class="w-5 h-5 inline" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" fill="currentColor">
<path d="M2.5 3.5a.5.5 0 0 1 0-1h11a.5.5 0 0 1 0 1h-11zm2-2a.5.5 0 0 1 0-1h7a.5.5 0 0 1 0 1h-7zM0 13a1.5 1.5 0 0 0 1.5 1.5h13A1.5 1.5 0 0 0 16 13V6a1.5 1.5 0 0 0-1.5-1.5h-13A1.5 1.5 0 0 0 0 6v7zm1.5.5A.5.5 0 0 1 1 13V6a.5.5 0 0 1 .5-.5h13a.5.5 0 0 1 .5.5v7a.5.5 0 0 1-.5.5h-13z"/>
</svg>
Total Collections
</p>
<p class="mt-2 flex items-baseline gap-x-2">
<span class="text-4xl font-semibold tracking-tight text-white number" data-value="{{ $totalCollections }}"></span>
</p>
</div>
<!-- Unique Organisms Section -->
<div class="bg-gray-900 px-4 py-6 sm:px-6 lg:px-8">
<p class="text-sm font-medium leading-6 text-gray-400">
<svg fill="currentColor" class="w-5 h-5 inline" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="0 0 512 512" xml:space="preserve">
<g>
<g>
<circle cx="162.914" cy="197.818" r="11.636"/>
</g>
</g>
<g>
<g>
<circle cx="221.095" cy="221.091" r="11.636"/>
</g>
</g>
<g>
<g>
<circle cx="209.459" cy="139.636" r="11.636"/>
</g>
</g>
<g>
<g>
<path d="M453.823,290.909c-6.435,0-11.636,5.213-11.636,11.636c0,25.67-20.876,46.545-46.545,46.545
c-44.905,0-81.455,36.538-81.455,81.455c0,32.081-26.1,58.182-58.182,58.182c-32.081,0-58.182-26.1-58.182-58.182v-11.636
c0-6.423-5.201-11.636-11.636-11.636c-44.905,0-81.455-36.538-81.455-81.455V139.636c0-44.916,36.55-81.455,81.455-81.455
s81.455,36.538,81.455,81.455v186.182c0,28.998-15.604,56.017-40.727,70.54c-5.574,3.212-7.471,10.333-4.259,15.895l17.455,30.231
c3.212,5.562,10.345,7.459,15.895,4.259c5.574-3.212,7.482-10.333,4.259-15.895l-11.951-20.713
c8.518-6.295,15.825-13.905,22.004-22.307l20.911,12.067c1.827,1.059,3.828,1.559,5.807,1.559c4.026,0,7.936-2.083,10.089-5.818
c3.212-5.574,1.303-12.684-4.259-15.895l-20.911-12.067c4.585-10.473,7.494-21.679,8.448-33.292l27.462-9.158
c6.086-2.036,9.391-8.623,7.354-14.72c-2.036-6.086-8.553-9.414-14.72-7.354l-19.584,6.516v-30.394h23.273
c6.435,0,11.636-5.213,11.636-11.636S320.621,256,314.186,256h-23.273v-49.792l26.95-8.983c6.086-2.036,9.391-8.622,7.354-14.72
c-2.036-6.097-8.553-9.414-14.72-7.354l-19.584,6.516v-30.394h23.273c6.435,0,11.636-5.213,11.636-11.636S320.621,128,314.186,128
h-23.959c-1.187-10.659-3.991-20.841-8.134-30.301l20.771-11.985c5.562-3.212,7.471-10.321,4.259-15.895
c-3.223-5.574-10.345-7.482-15.895-4.259l-20.852,12.044c-6.237-8.448-13.696-15.895-22.144-22.144l12.044-20.852
c3.212-5.574,1.303-12.684-4.259-15.895c-5.562-3.212-12.684-1.303-15.895,4.259l-11.985,20.771
c-9.472-4.166-19.654-6.959-30.313-8.145V11.636C197.823,5.213,192.621,0,186.186,0S174.55,5.213,174.55,11.636v23.959
c-11.497,1.28-22.388,4.48-32.465,9.181l-23.156-24.064c-4.445-4.631-11.811-4.771-16.442-0.314
c-4.631,4.457-4.771,11.823-0.314,16.454l19.607,20.375c-7.482,5.865-14.115,12.719-19.77,20.364L81.156,65.559
c-5.562-3.223-12.684-1.315-15.907,4.259c-3.223,5.574-1.303,12.684,4.271,15.895l20.771,11.985
c-4.154,9.46-6.959,19.642-8.145,30.301H58.186c-6.435,0-11.636,5.213-11.636,11.636s5.201,11.636,11.636,11.636h23.273v38.156
l-26.95,8.983c-6.086,2.036-9.391,8.623-7.354,14.72c1.617,4.876,6.156,7.959,11.031,7.959c1.21,0,2.455-0.198,3.677-0.605
l19.596-6.516V256H58.186c-6.435,0-11.636,5.213-11.636,11.636s5.201,11.636,11.636,11.636h23.273v30.394l-19.596-6.528
c-6.144-2.06-12.684,1.268-14.72,7.354c-2.036,6.097,1.257,12.684,7.354,14.72l27.357,9.123c0.954,11.799,3.91,23.005,8.46,33.385
l-20.806,12.009c-5.562,3.223-7.471,10.333-4.259,15.907c2.164,3.735,6.063,5.818,10.089,5.818c1.978,0,3.98-0.5,5.807-1.559
l20.783-11.997c6.505,8.809,14.394,16.5,23.284,22.9l-13.766,33.036c-2.479,5.935,0.326,12.742,6.26,15.22
c1.466,0.617,2.979,0.908,4.48,0.908c4.561,0,8.879-2.7,10.74-7.168l12.695-30.452c9.076,3.828,18.769,6.447,28.928,7.575v0.628
c0,44.916,36.55,81.455,81.455,81.455s81.455-36.538,81.455-81.455c0-32.081,26.1-58.182,58.182-58.182
c38.505,0,69.818-31.313,69.818-69.818C465.459,296.122,460.258,290.909,453.823,290.909z"/>
</g>
</g>
<g>
<g>
<path d="M174.55,256c-25.67,0-46.545,20.876-46.545,46.545s20.876,46.545,46.545,46.545c25.67,0,46.545-20.876,46.545-46.545
S200.22,256,174.55,256z M174.55,325.818c-12.835,0-23.273-10.438-23.273-23.273s10.438-23.273,23.273-23.273
s23.273,10.438,23.273,23.273S187.385,325.818,174.55,325.818z"/>
</g>
</g>
</svg>
Unique Organisms
</p>
<p class="mt-2 flex items-baseline gap-x-2">
<span class="text-4xl font-semibold tracking-tight text-white number" data-value="{{ $uniqueOrganisms }}"></span>
</p>
</div>
<!-- Citations Mapped Section -->
<div class="bg-gray-900 px-4 py-6 sm:px-6 lg:px-8">
<p class="text-sm font-medium leading-6 text-gray-400">
<svg class="w-5 h-5 inline" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" fill="currentColor">
<path fill-rule="evenodd" d="M6 1h6v7a.5.5 0 0 1-.757.429L9 7.083 6.757 8.43A.5.5 0 0 1 6 8V1z"/>
<path d="M3 0h10a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2v-1h1v1a1 1 0 0 0 1 1h10a1 1 0 0 0 1-1V2a1 1 0 0 0-1-1H3a1 1 0 0 0-1 1v1H1V2a2 2 0 0 1 2-2z"/>
<path d="M1 5v-.5a.5.5 0 0 1 1 0V5h.5a.5.5 0 0 1 0 1h-2a.5.5 0 0 1 0-1H1zm0 3v-.5a.5.5 0 0 1 1 0V8h.5a.5.5 0 0 1 0 1h-2a.5.5 0 0 1 0-1H1zm0 3v-.5a.5.5 0 0 1 1 0v.5h.5a.5.5 0 0 1 0 1h-2a.5.5 0 0 1 0-1H1z"/>
</svg>
Citations Mapped
</p>
<p class="mt-2 flex items-baseline gap-x-2">
<span class="text-4xl font-semibold tracking-tight text-white number" data-value="{{ $citationsMapped }}"></span>
</p>
</div>
</div>
</div>
</div>
<livewire:recent-molecules />
<livewire:compound-classes />
<livewire:data-sources />
Expand Down
2 changes: 1 addition & 1 deletion tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default {
light: '#92400e'
},
secondary: {
dark: '#3ab449',
dark: '#99674d',
light: '#22c55e'
},
text: {
Expand Down

0 comments on commit 036eb3d

Please sign in to comment.