Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Analyse relative sizes of economies on various goods
- Loading branch information
Showing
9 changed files
with
233 additions
and
14 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
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,59 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Commoditystat extends Model | ||
{ | ||
protected $fillable = ['commodity_id']; | ||
|
||
public function commodity() { | ||
return $this->belongsTo('App\Models\Commodity'); | ||
} | ||
|
||
public function getLevel($intensity) { | ||
if ($intensity < 0) { | ||
return $this->getDemandLevel(-$intensity); | ||
} else if ($intensity > 0) { | ||
return $this->getSupplyLevel($intensity); | ||
} else { | ||
return 0; | ||
} | ||
} | ||
|
||
protected function getDemandLevel($intensity) { | ||
if ($this->demandmin === null) { | ||
return 0; | ||
} | ||
if ($intensity < ($this->demandmin+$this->demandlowq)/2) { | ||
return 1; | ||
} else if ($intensity < ($this->demandlowq+$this->demandmed)/2) { | ||
return 2; | ||
} else if ($intensity <= ($this->demandmed+$this->demandhighq)/2) { | ||
return 3; | ||
} else if ($intensity <= ($this->demandhighq+$this->demandmax)/2) { | ||
return 4; | ||
} else { | ||
return 5; | ||
} | ||
} | ||
|
||
protected function getSupplyLevel($intensity) { | ||
if ($this->supplymin === null) { | ||
return 0; | ||
} | ||
if ($intensity < ($this->supplymin+$this->supplylowq)/2) { | ||
return 1; | ||
} else if ($intensity < ($this->supplylowq+$this->supplymed)/2) { | ||
return 2; | ||
} else if ($intensity <= ($this->supplymed+$this->supplyhighq)/2) { | ||
return 3; | ||
} else if ($intensity <= ($this->supplyhighq+$this->supplymax)/2) { | ||
return 4; | ||
} else { | ||
return 5; | ||
} | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
database/migrations/2018_08_13_074110_create_commoditystats_table.php
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,42 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
class CreateCommoditystatsTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('commoditystats', function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->integer('commodity_id')->index(); | ||
$table->float('demandmin')->nullable(); | ||
$table->float('demandlowq')->nullable(); | ||
$table->float('demandmed')->nullable(); | ||
$table->float('demandhighq')->nullable(); | ||
$table->float('demandmax')->nullable(); | ||
$table->float('supplymin')->nullable(); | ||
$table->float('supplylowq')->nullable(); | ||
$table->float('supplymed')->nullable(); | ||
$table->float('supplyhighq')->nullable(); | ||
$table->float('supplymax')->nullable(); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('commoditystats'); | ||
} | ||
} |
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,5 @@ | ||
@if (!$baseline) | ||
<td data-sort='0'></td> | ||
@else | ||
@include('components/intensitycell', ['level' => $stats->getLevel($baseline->intensity), 'labels' => ['', 'Very low', 'Low', 'Average', 'High', 'Very high'], 'exact' => $baseline->intensity]) | ||
@endif |
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,3 @@ | ||
<td title='{{$exact}}' data-sort='{{$level}}'> | ||
{{$labels[$level]}} | ||
</td> |
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