testing moon worth job

This commit is contained in:
2021-05-30 22:37:16 +09:00
parent 2e159063b5
commit 1a24d95d31
6 changed files with 135 additions and 76 deletions

View File

@@ -29,7 +29,7 @@ class MoonRentalController extends Controller
* Display moon rental request form
*/
public function displayMoonRentalRequestForm() {
}
/**

View File

@@ -13,8 +13,11 @@ use Illuminate\Support\Str;
//Application Library
use App\Library\Helpers\LookupHelper;
use App\Library\Esi\Esi;
use App\Library\Moons\MoonCalc;
//Models
use App\Models\MoonRental\AllianceMoon;
use App\Models\MoonRental\AllianceMoonOre;
use App\Models\MiningTax\Invoice;
use App\Models\MiningTax\Ledger;
use App\Models\MiningTax\Observer;
@@ -33,6 +36,31 @@ class TestController extends Controller
return view('test.char.display')->with('char', $char);
}
public function TestAllianceMoonWorth() {
//Declare variables
$lookup = new LookupHelper;
$mHelper = new MoonCalc;
$months = 3;
$rentalTax = 0.25;
$moons = AllianceMoon::all();
foreach($moons as $moon) {
//Declare the arrays needed
$ores = array();
$ores = AllianceMoonOre::where([
'moon_id' => $moon->moon_id,
])->get(['ore_id', 'quantity'])->toArray();
//one of these two ways will work
$worth = $mHelper->MoonTotalWorth($ores[0][0], $ores[0][1], $ores[1][0], $ores[1][1], $ores[2][0], $ores[2][1], $ores[3][0], $ores[3[1]]);
dd($worth);
$worth = $mHelper->MoonTotalWorth($ores[0], $ores[1], $ores[2], $ores[3], $ores[4], $ores[5], $ores[6], $ores[7]);
return view('test.moonworth.moon')->with('worth', $worth);
}
public function DebugMiningTaxesInvoices() {
$lookup = new LookupHelper;
$ledgers = new Collection;

View File

@@ -0,0 +1,74 @@
<?php
namespace App\Jobs\Commands\MoonRental;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Log;
use Carbon\Carbon;
//Internal Library
use App\Library\Moons\MoonCalc;
use App\Library\Helpers\LookupHelper;
//Models
use App\Models\MoonRental\AllianceMoon;
use App\Models\MoonRental\AllianceMoonOre;
class UpdateAllianceMoonRentalWorth implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
$this->connection('redis');
$this->onQueue('default');
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
//Declare variables
$lookup = new LookupHelper;
$mHelper = new MoonCalc;
$months = 3;
$rentalTax = 0.25;
$moons = AllianceMoon::all();
foreach($moons as $moon) {
//Declare the arrays needed
$ores = array();
$ores = AllianceMoonOre::where([
'moon_id' => $moon->moon_id,
])->get(['ore_id', 'quantity'])->toArray();
//one of these two ways will work
$worth = $mHelper->MoonTotalWorth($ores[0][0], $ores[0][1], $ores[1][0], $ores[1][1], $ores[2][0], $ores[2][1], $ores[3][0], $ores[3[1]]);
dd($worth);
$worth = $mHelper->MoonTotalWorth($ores[0], $ores[1], $ores[2], $ores[3], $ores[4], $ores[5], $ores[6], $ores[7]);
$rentalAmount = $worth * $rentalTax * $months;
AllianceMoon::where([
'moon_id' => $moon->moon_id,
])->update([
'worth_amount' => $worth,
'rental_amount' => $rentalAmount,
]);
}
}
}

View File

@@ -43,67 +43,29 @@ class MoonCalc {
/**
* Calculate the total worth of a moon
*/
public function SpatialMoonsTotalWorth($firstOre, $firstQuan, $secondOre, $secondQuan, $thirdOre, $thirdQuan, $fourthOre, $fourthQuan) {
public function MoonTotalWorth($firstOre = null, $firstQuan = 0.00, $secondOre = null, $secondQuan = 0.00, $thirdOre = null, $thirdQuan = 0.00, $fourthOre = null, $fourthQuan = 0.00) {
//Declare variables
$totalPriceMined = 0.00;
//Get the configuration for pricing calculations
$config = DB::table('Config')->get();
$total = 0.00;
//Convert the quantities into numbers we want to utilize
$this->ConvertPercentages($firstPerc, $firstQuan, $secondPerc, $secondQuan, $thirdPerc, $thirdQuan, $fourthPerc, $fourthQuan);
$this->ConvertPercentages($firstQuan, $secondQuan, $thirdQuan, $fourthQuan);
//Calculate the prices from the ores
if($firstOre != 'None') {
$totalPriceMined += $this->CalcMoonPrice($firstOre, $firstPerc);
if($firstOre != null) {
$total += $this->CalcMoonPrice($firstOre, $firstPerc);
}
if($secondOre != 'None') {
$totalPriceMined += $this->CalcMoonPrice($secondOre, $secondPerc);
if($secondOre != null) {
$total += $this->CalcMoonPrice($secondOre, $secondPerc);
}
if($thirdOre != 'None') {
$totalPriceMined += $this->CalcMoonPrice($thirdOre, $thirdPerc);
if($thirdOre != null) {
$total += $this->CalcMoonPrice($thirdOre, $thirdPerc);
}
if($fourthOre != 'None') {
$totalPriceMined += $this->CalcMoonPrice($fourthOre, $fourthPerc);
if($fourthOre != null) {
$total += $this->CalcMoonPrice($fourthOre, $fourthPerc);
}
//Return the rental price to the caller
return $totalPriceMined;
}
/**
* Calculate the rental price
*/
public function SpatialMoons($firstOre, $firstQuan, $secondOre, $secondQuan, $thirdOre, $thirdQuan, $fourthOre, $fourthQuan) {
//Declare variables
$totalPrice = 0.00;
//Get the configuration for pricing calculations
$config = DB::table('Config')->get();
//Convert the quantities into numbers we want to utilize
$this->ConvertPercentages($firstPerc, $firstQuan, $secondPerc, $secondQuan, $thirdPerc, $thirdQuan, $fourthPerc, $fourthQuan);
//Calculate the prices from the ores
if($firstOre != 'None') {
$totalPrice += $this->CalcRentalPrice($firstOre, $firstPerc);
}
if($secondOre != 'None') {
$totalPrice += $this->CalcRentalPrice($secondOre, $secondPerc);
}
if($thirdOre != 'None') {
$totalPrice += $this->CalcRentalPrice($thirdOre, $thirdPerc);
}
if($fourthOre != 'None') {
$totalPrice += $this->CalcRentalPrice($fourthOre, $fourthPerc);
}
//Calculate the rental price. Refined rate is already included in the price from rental composition
$rentalPrice['alliance'] = $totalPrice * ($config[0]->RentalTax / 100.00);
$rentalPrice['outofalliance'] = $totalPrice * ($config[0]->AllyRentalTax / 100.00);
//Return the rental price to the caller
return $rentalPrice;
return $total;
}
/**
@@ -480,7 +442,7 @@ class MoonCalc {
/**
* Calculate the moon's total price
*/
private function CalcMoonPrice($ore, $percentage) {
public function CalcMoonPrice($ore, $percentage) {
//Specify the total pull amount
$totalPull = $this->CalculateTotalMoonPull();
@@ -612,34 +574,24 @@ class MoonCalc {
/**
* Convert percentages from quantities into a normalized percentage
*/
private function ConvertPercentages(&$firstPerc, $firstQuan, &$secondPerc, $secondQuan, &$thirdPerc, $thirdQuan, &$fourthPerc, $fourthQuan) {
//Set the base percentages for the if statements
$firstPerc = 0.00;
$secondPerc = 0.00;
$thirdPerc = 0.00;
$fourthPerc = 0.00;
public function ConvertPercentages(&$firstPerc, &$secondPerc, &$thirdPerc, &$fourthPerc) {
//Convert the quantities into numbers we want to utilize
if($firstQuan >= 1.00) {
$firstPerc = $this->ConvertToPercentage($firstQuan);
} else {
$firstPerc = $firstQuan;
}
if($firstPerc >= 1.00) {
$firstPerc = $this->ConvertToPercentage($firstPerc);
}
if($secondQuan >= 1.00) {
$secondPerc = $this->ConvertToPercentage($secondQuan);
} else {
$secondPerc = $secondQuan;
}
$secondPerc = $this->ConvertToPercentage($secondPerc);
}
if($thirdQuan >= 1.00) {
$thirdPerc = $this->ConvertToPercentage($thirdQuan);
} else {
$thirdPerc = $thirdQuan;
}
$thirdPerc = $this->ConvertToPercentage($thirdPerc);
}
if($fourthQuan >= 1.00) {
$fourthPerc = $this->ConvertToPercentage($fourthQuan);
} else {
$fourthPerc = $fourthQuan;
}
$fourthPerc = $this->ConvertToPercentage($fourthPerc);
}
//Add up all the percentages
$totalPerc = $firstPerc + $secondPerc + $thirdPerc + $fourthPerc;

View File

@@ -0,0 +1,4 @@
@extends('layouts.user.dashb4')
@section('content')
{{ var_dump($worth) }}
@endsection

View File

@@ -150,6 +150,7 @@ Route::group(['middleware' => ['auth']], function(){
Route::get('/test/char/display', 'Test\TestController@displayCharTest');
Route::get('/test/miningtax/invoice', 'Test\TestController@DebugMiningTaxesInvoices');
Route::get('/test/miningtax/observers', 'Test\TestController@DebugMiningObservers');
Route::get('/test/moon/worth', 'Test\TestController@TestAllianceMoonWorth');
});