Add setting to include transfer hours in calculations (#350)
* Add setting to include transfer hours in calculations * Add some extra tests to check versions * A couple of more version test cases
This commit is contained in:
parent
ff6ba4c29a
commit
a08c9db284
@ -15,76 +15,6 @@ roles:
|
||||
- name: fleet-only
|
||||
display_name: Edit Fleet
|
||||
|
||||
users:
|
||||
- id: 1
|
||||
pilot_id: 1
|
||||
name: Admin User
|
||||
email: admin@phpvms.net
|
||||
password: admin
|
||||
api_key: testadminapikey
|
||||
airline_id: 1
|
||||
rank_id: 1
|
||||
country: us
|
||||
home_airport_id: KAUS
|
||||
curr_airport_id: KJFK
|
||||
last_pirep_id: pirepid_3
|
||||
flights: 3
|
||||
flight_time: 0
|
||||
timezone: America/Chicago
|
||||
state: 1
|
||||
opt_in: 1
|
||||
toc_accepted: 1
|
||||
created_at: now
|
||||
updated_at: now
|
||||
- id: 2
|
||||
pilot_id: 2
|
||||
name: Carla Walters
|
||||
email: carla.walters68@example.com
|
||||
password: admin
|
||||
api_key: testuserapikey1
|
||||
airline_id: 1
|
||||
rank_id: 1
|
||||
home_airport_id: KJFK
|
||||
curr_airport_id: KJFK
|
||||
flights: 1
|
||||
flight_time: 4320
|
||||
created_at: now
|
||||
updated_at: now
|
||||
state: 0
|
||||
opt_in: 1
|
||||
toc_accepted: 1
|
||||
- id: 3
|
||||
pilot_id: 3
|
||||
name: Raymond Pearson
|
||||
email: raymond.pearson56@example.com
|
||||
password: admin
|
||||
api_key: testuserapikey2
|
||||
airline_id: 1
|
||||
rank_id: 1
|
||||
home_airport_id: KJFK
|
||||
curr_airport_id: KAUS
|
||||
flights: 1
|
||||
flight_time: 4320
|
||||
created_at: now
|
||||
updated_at: now
|
||||
state: 1
|
||||
opt_in: 0
|
||||
toc_accepted: 1
|
||||
|
||||
role_user:
|
||||
- user_id: 1
|
||||
role_id: 1
|
||||
user_type: App\Models\User
|
||||
- user_id: 1
|
||||
role_id: 2
|
||||
user_type: App\Models\User
|
||||
- user_id: 2
|
||||
role_id: 2
|
||||
user_type: App\Models\User
|
||||
- user_id: 3
|
||||
role_id: 2
|
||||
user_type: App\Models\User
|
||||
|
||||
awards:
|
||||
- id: 1
|
||||
name: Pilot 50 flights
|
||||
|
71
app/Database/seeds/dev/users.yml
Normal file
71
app/Database/seeds/dev/users.yml
Normal file
@ -0,0 +1,71 @@
|
||||
users:
|
||||
- id: 1
|
||||
pilot_id: 1
|
||||
name: Admin User
|
||||
email: admin@phpvms.net
|
||||
password: admin
|
||||
api_key: testadminapikey
|
||||
airline_id: 1
|
||||
rank_id: 1
|
||||
country: us
|
||||
home_airport_id: KAUS
|
||||
curr_airport_id: KJFK
|
||||
last_pirep_id: pirepid_3
|
||||
flights: 3
|
||||
flight_time: 0
|
||||
timezone: America/Chicago
|
||||
state: 1
|
||||
opt_in: 1
|
||||
toc_accepted: 1
|
||||
created_at: now
|
||||
updated_at: now
|
||||
- id: 2
|
||||
pilot_id: 2
|
||||
name: Carla Walters
|
||||
email: carla.walters68@example.com
|
||||
password: admin
|
||||
api_key: testuserapikey1
|
||||
airline_id: 1
|
||||
rank_id: 1
|
||||
home_airport_id: KJFK
|
||||
curr_airport_id: KJFK
|
||||
flights: 1
|
||||
flight_time: 4320
|
||||
transfer_time: 360
|
||||
created_at: now
|
||||
updated_at: now
|
||||
state: 0
|
||||
opt_in: 1
|
||||
toc_accepted: 1
|
||||
- id: 3
|
||||
pilot_id: 3
|
||||
name: Raymond Pearson
|
||||
email: raymond.pearson56@example.com
|
||||
password: admin
|
||||
api_key: testuserapikey2
|
||||
airline_id: 1
|
||||
rank_id: 1
|
||||
home_airport_id: KJFK
|
||||
curr_airport_id: KAUS
|
||||
flights: 1
|
||||
flight_time: 4320
|
||||
transfer_time: 120
|
||||
created_at: now
|
||||
updated_at: now
|
||||
state: 1
|
||||
opt_in: 0
|
||||
toc_accepted: 1
|
||||
|
||||
role_user:
|
||||
- user_id: 1
|
||||
role_id: 1
|
||||
user_type: App\Models\User
|
||||
- user_id: 1
|
||||
role_id: 2
|
||||
user_type: App\Models\User
|
||||
- user_id: 2
|
||||
role_id: 2
|
||||
user_type: App\Models\User
|
||||
- user_id: 3
|
||||
role_id: 2
|
||||
user_type: App\Models\User
|
@ -194,3 +194,10 @@
|
||||
options: ''
|
||||
type: boolean
|
||||
description: 'Allow specifying transfer hours on registration page and displayed on profile page'
|
||||
- key: pilots.count_transfer_hours
|
||||
name: 'Count transfer hours in calculations'
|
||||
group: pilots
|
||||
value: false
|
||||
options: ''
|
||||
type: boolean
|
||||
description: 'Count transfer hours in calculations, like ranks and the total hours'
|
||||
|
@ -10,12 +10,12 @@ use App\Repositories\AirlineRepository;
|
||||
use App\Repositories\AirportRepository;
|
||||
use App\Services\UserService;
|
||||
use App\Support\Countries;
|
||||
use Illuminate\Contracts\Validation\Validator;
|
||||
use Illuminate\Foundation\Auth\RegistersUsers;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Jackiedo\Timezonelist\Facades\Timezonelist;
|
||||
use Log;
|
||||
use Validator;
|
||||
|
||||
/**
|
||||
* Class RegisterController
|
||||
|
@ -11,6 +11,7 @@ use App\Contracts\Model;
|
||||
* @property int hours
|
||||
* @property float manual_base_pay_rate
|
||||
* @property float acars_base_pay_rate
|
||||
* @property bool auto_promote
|
||||
*/
|
||||
class Rank extends Model
|
||||
{
|
||||
|
@ -22,7 +22,8 @@ use Laratrust\Traits\LaratrustUserTrait;
|
||||
* @property string home_airport_id
|
||||
* @property Airline airline
|
||||
* @property Flight[] flights
|
||||
* @property string flight_time
|
||||
* @property int flight_time
|
||||
* @property int transfer_time
|
||||
* @property string remember_token
|
||||
* @property \Carbon\Carbon created_at
|
||||
* @property \Carbon\Carbon updated_at
|
||||
|
@ -17,8 +17,8 @@ use App\Repositories\AircraftRepository;
|
||||
use App\Repositories\SubfleetRepository;
|
||||
use App\Support\Units\Time;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use function is_array;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class UserService
|
||||
@ -258,7 +258,12 @@ class UserService extends Service
|
||||
return $user;
|
||||
}
|
||||
|
||||
$pilot_hours = new Time($user->flight_time);
|
||||
// If we should count their transfer hours?
|
||||
if (setting('pilots.count_transfer_hours') === true) {
|
||||
$pilot_hours = new Time($user->flight_time + $user->transfer_time);
|
||||
} else {
|
||||
$pilot_hours = new Time($user->flight_time);
|
||||
}
|
||||
|
||||
// The current rank's hours are over the pilot's current hours,
|
||||
// so assume that they were "placed" here by an admin so don't
|
||||
|
@ -179,11 +179,10 @@ class VersionService extends Service
|
||||
$current_version = $this->cleanVersionString($current_version);
|
||||
}
|
||||
|
||||
$current_version = Version::fromString($current_version);
|
||||
$latest_version = Version::fromString($this->getLatestVersion());
|
||||
$latest_version = $this->getLatestVersion();
|
||||
|
||||
// Convert to semver
|
||||
if ($latest_version->isGreaterThan($current_version)) {
|
||||
if ($this->isGreaterThan($latest_version, $current_version)) {
|
||||
$this->kvpRepo->save('new_version_available', true);
|
||||
return true;
|
||||
}
|
||||
@ -191,4 +190,17 @@ class VersionService extends Service
|
||||
$this->kvpRepo->save('new_version_available', false);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $version1
|
||||
* @param string $version2
|
||||
*
|
||||
* @return bool If $version1 is greater than $version2
|
||||
*/
|
||||
public function isGreaterThan($version1, $version2): bool
|
||||
{
|
||||
$version1 = Version::fromString($version1);
|
||||
$version2 = Version::fromString($version2);
|
||||
return $version1->isGreaterThan($version2);
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,7 @@
|
||||
@if (setting('pilots.allow_transfer_hours') === true)
|
||||
<label for="transfer_time" class="control-label">@lang('auth.transferhours')</label>
|
||||
<div class="input-group form-group-no-border {{ $errors->has('transfer_time') ? 'has-danger' : '' }}">
|
||||
{{ Form::text('transfer_time', 0, ['class' => 'form-control']) }}
|
||||
{{ Form::number('transfer_time', 0, ['class' => 'form-control']) }}
|
||||
</div>
|
||||
@if ($errors->has('transfer_time'))
|
||||
<p class="text-danger">{{ $errors->first('transfer_time') }}</p>
|
||||
|
@ -196,6 +196,8 @@ class PIREPTest extends TestCase
|
||||
*/
|
||||
public function testPilotStatsIncr()
|
||||
{
|
||||
$this->updateSetting('pilots.count_transfer_hours', false);
|
||||
|
||||
$user = factory(User::class)->create([
|
||||
'flights' => 0,
|
||||
'flight_time' => 0,
|
||||
@ -254,6 +256,41 @@ class PIREPTest extends TestCase
|
||||
$this->assertNotEquals($last_pirep->id, $latest_pirep->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* check the stats/ranks, etc have incremented properly
|
||||
*/
|
||||
public function testPilotStatsIncrWithTransferHours()
|
||||
{
|
||||
$this->updateSetting('pilots.count_transfer_hours', true);
|
||||
|
||||
$user = factory(User::class)->create([
|
||||
'flights' => 0,
|
||||
'flight_time' => 0,
|
||||
'transfer_time' => 720,
|
||||
'rank_id' => 1,
|
||||
]);
|
||||
|
||||
// Submit two PIREPs
|
||||
// 1 hour flight times, but the rank should bump up because of the transfer hours
|
||||
$pireps = factory(Pirep::class, 2)->create([
|
||||
'airline_id' => $user->airline_id,
|
||||
'aircraft_id' => 1,
|
||||
'user_id' => $user->id,
|
||||
'flight_time' => 60,
|
||||
]);
|
||||
|
||||
foreach ($pireps as $pirep) {
|
||||
$this->pirepSvc->create($pirep);
|
||||
$this->pirepSvc->accept($pirep);
|
||||
}
|
||||
|
||||
$pilot = User::find($user->id);
|
||||
$last_pirep = Pirep::where('id', $pilot->last_pirep_id)->first();
|
||||
|
||||
// Make sure rank went up
|
||||
$this->assertGreaterThan($user->rank_id, $pilot->rank_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find and check for any duplicate PIREPs by a user
|
||||
*/
|
||||
|
@ -14,7 +14,26 @@ class VersionTest extends TestCase
|
||||
$this->kvpRepo = app(KvpRepository::class);
|
||||
}
|
||||
|
||||
public function testGetLatestVersion()
|
||||
/**
|
||||
* Test that the new versions (keys) are properly regarded as new versions
|
||||
*/
|
||||
public function testGreaterThanVersionStrings(): void
|
||||
{
|
||||
$test = [
|
||||
'7.0.0' => '6.0.0',
|
||||
'7.0.0-beta' => '7.0.0-alpha',
|
||||
'7.0.0-beta.1' => '7.0.0-beta',
|
||||
'7.0.0-beta.2' => '7.0.0-beta.1',
|
||||
'7.0.0-beta.1' => '7.0.0-alpha',
|
||||
];
|
||||
|
||||
$versionSvc = app(VersionService::class);
|
||||
foreach ($test as $newVersion => $currentVersion) {
|
||||
$this->assertTrue($versionSvc->isGreaterThan($newVersion, $currentVersion));
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetLatestVersion(): void
|
||||
{
|
||||
setting('general.check_prerelease_version', false);
|
||||
|
||||
@ -27,7 +46,7 @@ class VersionTest extends TestCase
|
||||
$this->assertEquals('7.0.0-alpha2', $this->kvpRepo->get('latest_version_tag'));
|
||||
}
|
||||
|
||||
public function testGetLatestPrereleaseVersion()
|
||||
public function testGetLatestPrereleaseVersion(): void
|
||||
{
|
||||
$this->updateSetting('general.check_prerelease_version', true);
|
||||
|
||||
@ -40,7 +59,7 @@ class VersionTest extends TestCase
|
||||
$this->assertEquals('7.0.0-beta', $this->kvpRepo->get('latest_version_tag'));
|
||||
}
|
||||
|
||||
public function testNewVersionNotAvailable()
|
||||
public function testNewVersionNotAvailable(): void
|
||||
{
|
||||
$this->updateSetting('general.check_prerelease_version', false);
|
||||
|
||||
@ -59,7 +78,10 @@ class VersionTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testNewVersionIsAvailable()
|
||||
/**
|
||||
* Version in the prerelease releases.json is v7.0.0-beta
|
||||
*/
|
||||
public function testNewVersionIsAvailable(): void
|
||||
{
|
||||
$this->updateSetting('general.check_prerelease_version', true);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user