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; namespace App\Http\Controllers;
use App\Models\Location; use App\Repositories\LocationRepository;
use App\Models\Source; use App\Models\Source;
class ExportController extends Controller class ExportController extends Controller
{ {
protected $locationRepository;
public function __construct(LocationRepository $locationRepository)
{
$this->locationRepository = $locationRepository;
}
public function exportIndex() 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', [ return view('front.exports', [
'title' => "Exports" 'title' => "Exports",
'list' => $list
]); ]);
} }
@ -20,7 +42,7 @@ class ExportController extends Controller
$columns = []; $columns = [];
$list = []; $list = [];
$locations = Location::where("active", true)->get(); $locations = $this->locationRepository->getActiveLocations();
$sources = Source::where("active", true)->get(); $sources = Source::where("active", true)->get();
if ($type == 'mastodon') { if ($type == 'mastodon') {
$columns = [ $columns = [
@ -34,9 +56,7 @@ class ExportController extends Controller
}; };
foreach ($locations as $location) { foreach ($locations as $location) {
$total = $location->block_count + $location->silence_count; $rate = $location->actions_count / count($sources);
if ($total >= 2) {
$rate = $total / count($sources);
if ($rate * 100 >= $percent) { if ($rate * 100 >= $percent) {
if ($type == 'mastodon') { if ($type == 'mastodon') {
//comman break teh CSV so just take them out //comman break teh CSV so just take them out
@ -50,7 +70,6 @@ class ExportController extends Controller
} }
} }
} }
}
header('Content-Type: text/csv'); header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename=' . $type . "-" . $percent); 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.* 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> <h3>For Mastodon</h3>
<a href="/exports/mastodon/90">Heat Rating 90%</a><br /> @foreach($list as $item)
<a href="/exports/mastodon/80">Heat Rating 80%</a><br />
<a href="/exports/mastodon/70">Heat Rating 70%</a><br /> <a href="/exports/mastodon/{{$item['heatRating']}}">Heat Rating: {{$item['heatRating']}}% - Location Count: {{$item['ratingCount']}}</a><br />
<a href="/exports/mastodon/60">Heat Rating 60%</a><br />
<a href="/exports/mastodon/50">Heat Rating 50%</a><br /> @endforeach
<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 />
<br /> <br />
<i>* Heating Ratings are still a work in progress so please review list before using.</i> <i>* Heating Ratings are still a work in progress so please review list before using.</i>
<br /><br /> <br /><br />
</article> </article>
</section> </section>
@endsection @endsection