-
Notifications
You must be signed in to change notification settings - Fork 1
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 #330 from Steinbeck-Lab/development
Development
- Loading branch information
Showing
50 changed files
with
3,346 additions
and
1,499 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,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); | ||
} | ||
} |
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,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'], | ||
]); | ||
} | ||
} |
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,21 @@ | ||
{ | ||
"name": "socialiteproviders/nfdi-aai", | ||
"description": "NFDIAAI OAuth2 Provider for Laravel Socialite", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "VCNainala", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": "^8.0", | ||
"ext-json": "*", | ||
"socialiteproviders/manager": "^4.4" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"SocialiteProviders\\NFDIAAI\\": "" | ||
} | ||
} | ||
} |
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,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'); | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.