Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development #330

Merged
merged 24 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e16c822
fix: removed github icon from login button
CS76 Aug 14, 2024
a6fa2dc
Merge branch 'feature-regapp' into development
CS76 Dec 16, 2024
d4f672e
fix: added nfdi aai to login page with branding
CS76 Dec 16, 2024
16014e1
feat: new component to display entry details for the molecule in a pa…
sriramkanakam87 Dec 16, 2024
0acde67
fix: missing id error handling
CS76 Dec 16, 2024
304d9a6
fix: added missing imports
CS76 Dec 16, 2024
e0b8833
fix: enabled button groups, moved modal view functionality to referen…
sriramkanakam87 Dec 16, 2024
93f0224
Merge pull request #325 from Steinbeck-Lab/feat-display-molecule-coll…
CS76 Dec 16, 2024
ff830ae
feat: new command to generate heatmap data
sriramkanakam87 Dec 16, 2024
61a3efc
feat: new component to display heat map on the stats page
sriramkanakam87 Dec 16, 2024
3d74cf7
fix: added tool tip, corrected the names, and moved legend to the right.
sriramkanakam87 Dec 16, 2024
ffa816d
fix: changed title and margins
sriramkanakam87 Dec 17, 2024
1d0501c
fix: reduced the size of the data json
sriramkanakam87 Dec 17, 2024
c1d14a4
Merge pull request #326 from Steinbeck-Lab/feat-charts
CS76 Dec 17, 2024
4daa7a1
fix: various bug fixes
CS76 Dec 17, 2024
c75c65b
Merge branch 'development' of https://github.com/Steinbeck-Lab/coconu…
CS76 Dec 17, 2024
6398667
fix: added missing links in the sidebar menu on mobile screens and al…
CS76 Dec 18, 2024
c886dd5
fix: published livewire assets and composer update
CS76 Dec 18, 2024
c3ede0f
fix: composer bump
CS76 Dec 18, 2024
05c9c7a
fix: cache gets stale after every 2 days and gets refreshed after the…
sriramkanakam87 Jan 13, 2025
cc0be42
chore: published livewire assets and added slug mutation trait to the…
CS76 Jan 15, 2025
d87ed63
Merge pull request #349 from Steinbeck-Lab/fix-cache-refresh
CS76 Jan 15, 2025
a9140c8
chore: composer update
CS76 Jan 15, 2025
78e604c
Merge branch 'development' of https://github.com/Steinbeck-Lab/coconu…
CS76 Jan 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions SocialiteProviders/src/NFDIAAI/NFDIAAIExtendSocialite.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace SocialiteProviders\NFDIAAI;

use SocialiteProviders\Manager\SocialiteWasCalled;

class NFDIAAIExtendSocialite
{
/**
* Register the provider.
*
* @return void
*/
public function handle(SocialiteWasCalled $socialiteWasCalled)
{
$socialiteWasCalled->extendSocialite('nfdi-aai', Provider::class);
}
}
66 changes: 66 additions & 0 deletions SocialiteProviders/src/NFDIAAI/Provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace SocialiteProviders\NFDIAAI;

use GuzzleHttp\RequestOptions;
use InvalidArgumentException;
use SocialiteProviders\Manager\OAuth2\AbstractProvider;
use SocialiteProviders\Manager\OAuth2\User;

class Provider extends AbstractProvider
{
const IDENTIFIER = 'NFDI-AAI';

/**
* {@inheritdoc}
*/
protected $scopes = ['basic'];

/**
* {@inheritdoc}
*/
protected function getAuthUrl($state)
{
return $this->buildAuthUrlFromBase('https://regapp.nfdi-aai.de/oidc/realms/nfdi/protocol/openid-connect/auth', $state);
}

/**
* {@inheritdoc}
*/
protected function getTokenUrl()
{
return 'https://regapp.nfdi-aai.de/oidc/realms/nfdi/protocol/openid-connect/token';
}

/**
* {@inheritdoc}
*/
protected function getUserByToken($token)
{
$response = $this->getHttpClient()->get('https://regapp.nfdi-aai.de/oidc/realms/nfdi/protocol/openid-connect/userinfo', [
RequestOptions::HEADERS => [
'Authorization' => 'Bearer '.$token,
],
]);

return json_decode((string) $response->getBody(), true);
}

/**
* {@inheritdoc}
*/
protected function mapUserToObject(array $user)
{
if (! isset($user['id']) || empty($user['id'])) {
throw new InvalidArgumentException('The user data is invalid: a unique "id" is required.');
}

return (new User)->setRaw($user)->map([
'id' => $user['id'],
'nickname' => $user['username'],
'name' => $user['name'],
'email' => $user['email'],
'avatar' => $user['avatar'],
]);
}
}
21 changes: 21 additions & 0 deletions SocialiteProviders/src/NFDIAAI/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "socialiteproviders/nfdi-aai",
"description": "NFDIAAI OAuth2 Provider for Laravel Socialite",
"license": "MIT",
"authors": [
{
"name": "VCNainala",
"email": "chandu.nainala@uni-jena.de"
}
],
"require": {
"php": "^8.0",
"ext-json": "*",
"socialiteproviders/manager": "^4.4"
},
"autoload": {
"psr-4": {
"SocialiteProviders\\NFDIAAI\\": ""
}
}
}
18 changes: 9 additions & 9 deletions app/Console/Commands/DashWidgetsRefresh.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,49 +32,49 @@ public function handle()
// Cache::flush();

// Create the cache for all DashboardStats widgets
Cache::rememberForever('stats.collections', function () {
Cache::flexible('stats.collections', [172800, 259200], function () {
return DB::table('collections')->selectRaw('count(*)')->get()[0]->count;
});
$this->info('Cache for collections refreshed.');

Cache::rememberForever('stats.citations', function () {
Cache::flexible('stats.citations', [172800, 259200], function () {
return DB::table('citations')->selectRaw('count(*)')->get()[0]->count;
});
$this->info('Cache for citations refreshed.');

Cache::rememberForever('stats.organisms', function () {
Cache::flexible('stats.organisms', [172800, 259200], function () {
return DB::table('organisms')->selectRaw('count(*)')->get()[0]->count;
});
$this->info('Cache for organisms refreshed.');

Cache::rememberForever('stats.geo_locations', function () {
Cache::flexible('stats.geo_locations', [172800, 259200], function () {
return DB::table('geo_locations')->selectRaw('count(*)')->get()[0]->count;
});
$this->info('Cache for geo locations refreshed.');

Cache::rememberForever('stats.reports', function () {
Cache::flexible('stats.reports', [172800, 259200], function () {
return DB::table('reports')->selectRaw('count(*)')->get()[0]->count;
});
$this->info('Cache for reports refreshed.');

// Create the cache for all DashboardStatsMid widgets

Cache::rememberForever('stats.molecules.non_stereo', function () {
Cache::flexible('stats.molecules.non_stereo', [172800, 259200], function () {
return DB::table('molecules')->selectRaw('count(*)')->whereRaw('has_stereo=false and is_parent=false')->get()[0]->count;
});
$this->info('Cache for molecules non-stereo refreshed.');

Cache::rememberForever('stats.molecules.stereo', function () {
Cache::flexible('stats.molecules.stereo', [172800, 259200], function () {
return DB::table('molecules')->selectRaw('count(*)')->whereRaw('has_stereo=true')->get()[0]->count;
});
$this->info('Cache for molecules stereo refreshed.');

Cache::rememberForever('stats.molecules.parent', function () {
Cache::flexible('stats.molecules.parent', [172800, 259200], function () {
return DB::table('molecules')->selectRaw('count(*)')->whereRaw('has_stereo=false and is_parent=true')->get()[0]->count;
});
$this->info('Cache for molecules parent refreshed.');

Cache::rememberForever('stats.molecules', function () {
Cache::flexible('stats.molecules', [172800, 259200], function () {
return DB::table('molecules')->selectRaw('count(*)')->whereRaw('active=true and NOT (is_parent=true AND has_variants=true)')->get()[0]->count;
});
$this->info('Cache for molecules refreshed.');
Expand Down
79 changes: 79 additions & 0 deletions app/Console/Commands/GenerateHeatMapData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

namespace App\Console\Commands;

use App\Models\Collection;
use Illuminate\Console\Command;

class GenerateHeatMapData extends Command
{
protected $signature = 'coconut:generate-heat-map-data';

protected $description = 'This generates Heat Map data for collection overlaps.';

public function handle()
{
$heat_map_data = [];
$collections = Collection::all();

// Store molecule identifiers
foreach ($collections as $collection) {
$molecule_identifiers = $collection->molecules()->pluck('identifier')->toArray();
$molecule_identifiers = array_map(function ($item) {
return preg_replace('/^CNP/i', '', $item);
}, $molecule_identifiers);
$heat_map_data['ids'][$collection->id . '|' . $collection->title] = $molecule_identifiers;
}

// Calculate percentage overlaps -> ol_d = overlap data
$heat_map_data['ol_d'] = [];
$collection_keys = array_keys($heat_map_data['ids']);

foreach ($collection_keys as $collection1_key) {
$heat_map_data['ol_d'][$collection1_key] = [];
$set1 = array_unique($heat_map_data['ids'][$collection1_key]);
$set1_count = count($set1);

foreach ($collection_keys as $collection2_key) {
$set2 = array_unique($heat_map_data['ids'][$collection2_key]);
$set2_count = count($set2);

// Calculate intersection
$intersection = array_intersect($set1, $set2);
$intersection_count = count($intersection);

// Calculate percentage overlap
if ($set1_count > 0 && $set2_count > 0) {
// Using Jaccard similarity: intersection size / union size
$union_count = $set1_count + $set2_count - $intersection_count;
$overlap_percentage = ($intersection_count / $union_count) * 100;
} else {
$overlap_percentage = 0;
}

$heat_map_data['ol_d'][$collection1_key][$collection2_key] = round($overlap_percentage, 2);

// Add additional overlap statistics -> ol_s = overlap_stats
$heat_map_data['ol_s'][$collection1_key][$collection2_key] = [
// ol = overlap count
'ol' => $intersection_count,
'c1_count' => $set1_count,
'c2_count' => $set2_count,
'p' => round($overlap_percentage, 2),
];
}
}
unset($heat_map_data['ids']);

$json = json_encode($heat_map_data, JSON_UNESCAPED_SLASHES);

// Save the JSON to a file
$filePath = public_path('reports/heat_map_metadata.json');
if (! file_exists(dirname($filePath))) {
mkdir(dirname($filePath), 0777, true);
}
file_put_contents($filePath, $json);

$this->info('JSON metadata saved to public/reports/heat_map_metadata.json');
}
}
5 changes: 4 additions & 1 deletion app/Filament/Dashboard/Resources/CitationResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Tapp\FilamentAuditing\RelationManagers\AuditsRelationManager;

class CitationResource extends Resource
Expand Down Expand Up @@ -76,6 +77,8 @@ public static function getPages(): array

public static function getNavigationBadge(): ?string
{
return Cache::get('stats.citations');
return Cache::flexible('stats.citations', [172800, 259200], function () {
return DB::table('citations')->selectRaw('count(*)')->get()[0]->count;
});
}
}
5 changes: 4 additions & 1 deletion app/Filament/Dashboard/Resources/CollectionResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Tapp\FilamentAuditing\RelationManagers\AuditsRelationManager;

Expand Down Expand Up @@ -161,6 +162,8 @@ public static function getWidgets(): array

public static function getNavigationBadge(): ?string
{
return Cache::get('stats.collections');
return Cache::flexible('stats.collections', [172800, 259200], function () {
return DB::table('collections')->selectRaw('count(*)')->get()[0]->count;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
namespace App\Filament\Dashboard\Resources\CollectionResource\Pages;

use App\Filament\Dashboard\Resources\CollectionResource;
use App\Models\Collection;
use Filament\Resources\Pages\CreateRecord;

class CreateCollection extends CreateRecord
{
protected static string $resource = CollectionResource::class;

protected function mutateFormDataBeforeCreate(array $data): array
{
return Collection::mutateFormData($data);
}
}
5 changes: 4 additions & 1 deletion app/Filament/Dashboard/Resources/GeoLocationResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Tapp\FilamentAuditing\RelationManagers\AuditsRelationManager;

class GeoLocationResource extends Resource
Expand Down Expand Up @@ -83,6 +84,8 @@ public static function getWidgets(): array

public static function getNavigationBadge(): ?string
{
return Cache::get('stats.geo_locations');
return Cache::flexible('stats.geo_locations', [172800, 259200], function () {
return DB::table('geo_locations')->selectRaw('count(*)')->get()[0]->count;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class GeoLocationStats extends BaseWidget
protected function getStats(): array
{
return [
Stat::make('Total Molecules', Cache::rememberForever('stats.geo_locations'.$this->record->id.'molecules.count', function () {
Stat::make('Total Molecules', Cache::flexible('stats.geo_locations'.$this->record->id.'molecules.count', [172800, 259200], function () {
return DB::table('geo_location_molecule')->selectRaw('count(*)')->whereRaw('geo_location_id='.$this->record->id)->get()[0]->count;
})),
Stat::make('Total Organisms', Cache::rememberForever('stats.geo_locations'.$this->record->id.'organisms.count', function () {
Stat::make('Total Organisms', Cache::flexible('stats.geo_locations'.$this->record->id.'organisms.count', [172800, 259200], function () {
return DB::table('geo_location_molecule')->selectRaw('count(*)')->whereRaw('geo_location_id='.$this->record->id)->Join('molecule_organism', 'geo_location_molecule.molecule_id', '=', 'molecule_organism.molecule_id')->get()[0]->count;
})),
];
Expand Down
6 changes: 4 additions & 2 deletions app/Filament/Dashboard/Resources/MoleculeResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use App\Filament\Dashboard\Resources\MoleculeResource\Widgets\MoleculeStats;
use App\Models\Molecule;
use Archilex\AdvancedTables\Filters\AdvancedFilter;
use DB;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
Expand All @@ -30,6 +29,7 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\HtmlString;
use pxlrbt\FilamentExcel\Actions\Tables\ExportBulkAction;
Expand Down Expand Up @@ -249,7 +249,9 @@ public static function getWidgets(): array

public static function getNavigationBadge(): ?string
{
return Cache::get('stats.molecules');
return Cache::flexible('stats.molecules', [172800, 259200], function () {
return DB::table('molecules')->selectRaw('count(*)')->whereRaw('active=true and NOT (is_parent=true AND has_variants=true)')->get()[0]->count;
});
}

public static function changeMoleculeStatus($record, $reason)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class MoleculeStats extends BaseWidget
protected function getStats(): array
{
return [
Stat::make('Total Organisms', Cache::remember('stats.molecules'.$this->record->id.'organisms.count', 172800, function () {
Stat::make('Total Organisms', Cache::flexible('stats.molecules'.$this->record->id.'organisms.count', [172800, 259200], function () {
return DB::table('molecule_organism')->selectRaw('count(*)')->whereRaw('molecule_id='.$this->record->id)->get()[0]->count;
})),
Stat::make('Total Geo Locations', Cache::remember('stats.molecules'.$this->record->id.'geo_locations.count', 172800, function () {
Stat::make('Total Geo Locations', Cache::flexible('stats.molecules'.$this->record->id.'geo_locations.count', [172800, 259200], function () {
return DB::table('geo_location_molecule')->selectRaw('count(*)')->whereRaw('molecule_id='.$this->record->id)->get()[0]->count;
})),
];
Expand Down
5 changes: 4 additions & 1 deletion app/Filament/Dashboard/Resources/OrganismResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use GuzzleHttp\Client;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Log;
use Tapp\FilamentAuditing\RelationManagers\AuditsRelationManager;

Expand Down Expand Up @@ -130,7 +131,9 @@ public static function getWidgets(): array

public static function getNavigationBadge(): ?string
{
return Cache::get('stats.organisms');
return Cache::flexible('stats.organisms', [172800, 259200], function () {
return DB::table('organisms')->selectRaw('count(*)')->get()[0]->count;
});
}

protected static function getGNFMatches($name, $organism)
Expand Down
Loading
Loading