-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Granular esi scheduling for characters (#684)
* squads: trigger filter check using events * squads: move to one common definition for rules This also allows plugins to register their own rules! * add scheduling rule migration * add scheduling rule migration * add scheduling rule user interface prototype This commit also contains a lot of unrelated changes in the view since I had to refactor some things for the layout, which introduces identation changes for almost everything * Finish character scheduling rule interface * character filters: trigger data update event with character instead of user * schedule: apply character scheduling rules to tokens * styleci * make some tests pass * fix setting a scheduling rule for new tokens
- Loading branch information
1 parent
b13d283
commit 57f17c2
Showing
25 changed files
with
781 additions
and
220 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,33 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of SeAT | ||
* | ||
* Copyright (C) 2015 to present Leon Jacobs | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
return [ | ||
['name' => 'scopes', 'src' => 'seatcore::fastlookup.scopes', 'path' => 'refresh_token', 'field' => 'scopes', 'label' => 'Scopes'], | ||
['name' => 'character', 'src' => 'seatcore::fastlookup.characters', 'path' => '', 'field' => 'character_id', 'label' => 'Character'], | ||
['name' => 'title', 'src' => 'seatcore::fastlookup.titles', 'path' => 'titles', 'field' => 'id', 'label' => 'Title'], | ||
['name' => 'corporation', 'src' => 'seatcore::fastlookup.corporations', 'path' => 'affiliation', 'field' => 'corporation_id', 'label' => 'Corporation'], | ||
['name' => 'alliance', 'src' => 'seatcore::fastlookup.alliances', 'path' => 'affiliation', 'field' => 'alliance_id', 'label' => 'Alliance'], | ||
['name' => 'skill', 'src' => 'seatcore::fastlookup.skills', 'path' => 'skills', 'field' => 'skill_id', 'label' => 'Skill'], | ||
['name' => 'skill_level', 'src' => [['id' => 1, 'text' => 'Level 1'], ['id' => 2, 'text' => 'Level 2'], ['id' => 3, 'text' => 'Level 3'], ['id' => 4, 'text' => 'Level 4'], ['id' => 5, 'text' => 'Level 5']], 'path' => 'skills', 'field' => 'trained_skill_level', 'label' => 'Skill Level'], | ||
['name' => 'type', 'src' => 'seatcore::fastlookup.items', 'path' => 'assets', 'field' => 'type_id', 'label' => 'Item'], | ||
['name' => 'role', 'src' => 'seatcore::fastlookup.roles', 'path' => 'corporation_roles', 'field' => 'role', 'label' => 'Role'], | ||
]; |
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,45 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of SeAT | ||
* | ||
* Copyright (C) 2015 to present Leon Jacobs | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
namespace Seat\Web\Events; | ||
|
||
use Illuminate\Queue\SerializesModels; | ||
use Seat\Eveapi\Models\Character\CharacterInfo; | ||
use Seat\Web\Models\User; | ||
|
||
/** | ||
* This event is fired when character filters, like used in squads, need to recompute because the data they are based on changed. | ||
*/ | ||
class CharacterFilterDataUpdate | ||
{ | ||
use SerializesModels; | ||
|
||
public CharacterInfo $character; | ||
|
||
/** | ||
* @param User $user | ||
*/ | ||
public function __construct(CharacterInfo $character) | ||
{ | ||
$this->character = $character; | ||
} | ||
} |
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,45 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of SeAT | ||
* | ||
* Copyright (C) 2015 to present Leon Jacobs | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
namespace Seat\Web\Http\Composers; | ||
|
||
use Illuminate\View\View; | ||
|
||
class CharacterFilter | ||
{ | ||
public function compose(View $view) | ||
{ | ||
$rules = config('web.characterfilter'); | ||
|
||
// work with raw arrays since the filter code requires an array of objects, and laravel collections don't like to give us that | ||
$newrules = []; | ||
foreach ($rules as $rule) { | ||
// convert route names to urls, but keep arrays with hardcoded options | ||
if(is_string($rule['src'])){ | ||
$rule['src'] = route($rule['src']); | ||
} | ||
$newrules[] = (object) $rule; | ||
} | ||
|
||
$view->with('characterFilterRules', $newrules); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of SeAT | ||
* | ||
* Copyright (C) 2015 to present Leon Jacobs | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
namespace Seat\Web\Listeners; | ||
|
||
use Seat\Web\Events\CharacterFilterDataUpdate; | ||
use Seat\Web\Models\CharacterSchedulingRule; | ||
|
||
class CharacterFilterDataUpdatedTokens | ||
{ | ||
public static function handle(CharacterFilterDataUpdate $update) | ||
{ | ||
CharacterSchedulingRule::updateRefreshTokenSchedule($update->character->refresh_token); | ||
} | ||
} |
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,93 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of SeAT | ||
* | ||
* Copyright (C) 2015 to present Leon Jacobs | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
namespace Seat\Web\Models; | ||
|
||
use Seat\Eveapi\Models\Character\CharacterInfo; | ||
use Seat\Eveapi\Models\RefreshToken; | ||
use Seat\Eveapi\Models\RefreshTokenSchedule; | ||
use Seat\Services\Models\ExtensibleModel; | ||
use stdClass; | ||
|
||
/** | ||
* @property int $id | ||
* @property string name | ||
* @property string filter | ||
* @property int interval | ||
*/ | ||
class CharacterSchedulingRule extends ExtensibleModel | ||
{ | ||
use Filterable; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
public $timestamps = false; | ||
|
||
/** | ||
* The filters to use. | ||
* | ||
* @return \stdClass | ||
*/ | ||
public function getFilters(): stdClass | ||
{ | ||
return json_decode($this->filter); | ||
} | ||
|
||
/** | ||
* Recomputes the update interval of a character and saves it in the refresh_token_schedules table. | ||
* | ||
* @param RefreshToken $token | ||
* @return void | ||
*/ | ||
public static function updateRefreshTokenSchedule(RefreshToken $token): void | ||
{ | ||
$schedule = $token->token_schedule; | ||
|
||
if($schedule === null) { | ||
$schedule = new RefreshTokenSchedule(); | ||
$schedule->character_id = $token->character_id; | ||
} | ||
|
||
$schedule->update_interval = self::getCharacterSchedulingInterval($token->character); | ||
$schedule->save(); | ||
} | ||
|
||
/** | ||
* Computes the scheduling interval from the character scheduling rules for a character. | ||
* | ||
* @param CharacterInfo $character | ||
* @return int | ||
*/ | ||
private static function getCharacterSchedulingInterval(CharacterInfo $character): int | ||
{ | ||
$scheduling_rules = CharacterSchedulingRule::orderBy('interval', 'asc')->get(); | ||
|
||
foreach ($scheduling_rules as $rule) { | ||
if($rule->isEligible($character)) { | ||
return $rule->interval; | ||
} | ||
} | ||
|
||
return 60 * 60; // 1 hour | ||
} | ||
} |
Oops, something went wrong.