mirror of
https://koodu.h-i.works/projects/thebadspace
synced 2025-06-25 16:04:37 -05:00
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:
@ -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,20 +56,17 @@ class ExportController extends Controller
|
||||
};
|
||||
|
||||
foreach ($locations as $location) {
|
||||
$total = $location->block_count + $location->silence_count;
|
||||
if ($total >= 2) {
|
||||
$rate = $total / count($sources);
|
||||
if ($rate * 100 >= $percent) {
|
||||
if ($type == 'mastodon') {
|
||||
//comman break teh CSV so just take them out
|
||||
$comments = str_replace(",", ";", $location->description);
|
||||
$rate = $location->actions_count / count($sources);
|
||||
if ($rate * 100 >= $percent) {
|
||||
if ($type == 'mastodon') {
|
||||
//comman break teh CSV so just take them out
|
||||
$comments = str_replace(",", ";", $location->description);
|
||||
|
||||
//remove extra white space
|
||||
$comments = str_replace(["\n\r", "\n", "\r"], " ", $comments);
|
||||
$comments = str_replace(['"', "'"], "", $comments);
|
||||
//add to the export list
|
||||
array_push($list, [$location->url, $location->rating, $comments, "FALSE", "FALSE", "FALSE"]);
|
||||
}
|
||||
//remove extra white space
|
||||
$comments = str_replace(["\n\r", "\n", "\r"], " ", $comments);
|
||||
$comments = str_replace(['"', "'"], "", $comments);
|
||||
//add to the export list
|
||||
array_push($list, [$location->url, $location->rating, $comments, "FALSE", "FALSE", "FALSE"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user