Export Update

Updated CSV export methodology to use the Location Repo class. Also
updated export links show location counts for each rating
This commit is contained in:
ro 2024-02-11 12:26:54 -06:00
parent 2bcb887d19
commit f1995d2163
2 changed files with 42 additions and 24 deletions

View file

@ -2,15 +2,37 @@
namespace App\Http\Controllers;
use App\Models\Location;
use App\Repositories\LocationRepository;
use App\Models\Source;
class ExportController extends Controller
{
protected $locationRepository;
public function __construct(LocationRepository $locationRepository)
{
$this->locationRepository = $locationRepository;
}
public function exportIndex()
{
$heatArray = [90, 80, 70, 60, 50, 40, 30, 20];
$sources = Source::where("active", true)->get();
$locations = $this->locationRepository->getActiveLocations();
$list = [];
foreach ($heatArray as $rating) {
$count = 0;
foreach ($locations as $location) {
$rate = $location->actions_count / count($sources);
if ($rate * 100 >= $rating) {
$count++;
}
}
array_push($list, ["heatRating" => $rating, "ratingCount" => $count]);
}
return view('front.exports', [
'title' => "Exports"
'title' => "Exports",
'list' => $list
]);
}
@ -20,7 +42,7 @@ class ExportController extends Controller
$columns = [];
$list = [];
$locations = Location::where("active", true)->get();
$locations = $this->locationRepository->getActiveLocations();
$sources = Source::where("active", true)->get();
if ($type == 'mastodon') {
$columns = [
@ -34,9 +56,7 @@ class ExportController extends Controller
};
foreach ($locations as $location) {
$total = $location->block_count + $location->silence_count;
if ($total >= 2) {
$rate = $total / count($sources);
$rate = $location->actions_count / count($sources);
if ($rate * 100 >= $percent) {
if ($type == 'mastodon') {
//comman break teh CSV so just take them out
@ -50,7 +70,6 @@ class ExportController extends Controller
}
}
}
}
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename=' . $type . "-" . $percent);

View file

@ -8,17 +8,16 @@
Heat Rating is the percentage of Current Sources that have taken action against an instance. The higher the number of Sources that have silenced and/or suspended an instance, the higher the Heat Rating.*
<h3>For Mastodon</h3>
<a href="/exports/mastodon/90">Heat Rating 90%</a><br />
<a href="/exports/mastodon/80">Heat Rating 80%</a><br />
<a href="/exports/mastodon/70">Heat Rating 70%</a><br />
<a href="/exports/mastodon/60">Heat Rating 60%</a><br />
<a href="/exports/mastodon/50">Heat Rating 50%</a><br />
<a href="/exports/mastodon/40">Heat Rating 40%</a><br />
<a href="/exports/mastodon/30">Heat Rating 30%</a><br />
<a href="/exports/mastodon/20">Heat Rating 20%</a><br />
@foreach($list as $item)
<a href="/exports/mastodon/{{$item['heatRating']}}">Heat Rating: {{$item['heatRating']}}% - Location Count: {{$item['ratingCount']}}</a><br />
@endforeach
<br />
<i>* Heating Ratings are still a work in progress so please review list before using.</i>
<br /><br />
</article>
</section>
@endsection