Skip to content

Commit

Permalink
Merge pull request #694 from TheRestartProject/RES-1947_group_stats_p…
Browse files Browse the repository at this point in the history
…ercentage

Group stats percentages are wrong
  • Loading branch information
edwh authored Oct 23, 2023
2 parents c6d47b0 + 72cf09a commit c54328f
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 21 deletions.
15 changes: 8 additions & 7 deletions app/Http/Controllers/GroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,15 @@ public function view($groupid)

$counts = $Device->countByClustersYearStatus($group->idgroups);
$template = [
0 => (object)[
0 => [
'counter' => 0,
'repair_status' => 1,
],
1 => (object)[
1 => [
'counter' => 0,
'repair_status' => 2,
],
2 => (object)[
2 => [
'counter' => 0,
'repair_status' => 3,
],
Expand All @@ -228,11 +228,12 @@ public function view($groupid)
$year = $count->year;
$cluster = $count->cluster;
$repair_status = $count->repair_status;
$counter = $count->counter;

if ($repair_status && $cluster) {
if (array_key_exists($cluster, $clusters['all'])) {
$clusters['all'][$cluster][$repair_status - 1]->counter += $count->counter;
$clusters['all'][$cluster]['total'] += $count->counter;
$clusters['all'][$cluster][$repair_status - 1]['counter'] += $counter;
$clusters['all'][$cluster]['total'] += $counter;

if (!array_key_exists($year, $clusters)) {
$clusters[$year] = [
Expand All @@ -243,8 +244,8 @@ public function view($groupid)
];
}

$clusters[$year][$cluster][$repair_status - 1]->counter += $count->counter;
$clusters[$year][$cluster]['total'] += $count->counter;
$clusters[$year][$cluster][$repair_status - 1]['counter'] += $counter;
$clusters[$year][$cluster]['total'] += $counter;
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions app/Party.php
Original file line number Diff line number Diff line change
Expand Up @@ -588,13 +588,13 @@ public function getEventStats($eEmissionRatio = null, $uEmissionratio = null, $i
}

switch ($device->repair_status) {
case 1:
case Device::REPAIR_STATUS_FIXED:
$result['fixed_devices']++;
break;
case 2:
case Device::REPAIR_STATUS_REPAIRABLE:
$result['repairable_devices']++;
break;
case 3:
case Device::REPAIR_STATUS_ENDOFLIFE:
$result['dead_devices']++;
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion lang/en/groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
'no_upcoming_events' => 'There are currently no upcoming events.',
'no_past_events' => 'There are currently no past events for this group',
'device_breakdown' => 'Device breakdown',
'total_devices' => 'Total devices worked on',
'total_devices' => 'Total items worked on',
'most_repaired_devices' => 'Most repaired devices',
'host' => 'Host',
'website' => 'Website',
Expand Down
2 changes: 1 addition & 1 deletion lang/fr-BE/groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
'past' => 'Passé',
'read_more' => 'Lire plus',
'share_group_stats' => 'Partager les statistiques du Repair Café',
'total_devices' => 'Total des appareils qui ont été pris en charge',
'total_devices' => 'Total des éléments qui ont été pris en charge',
'participants' => 'Participants',
'hours_volunteered' => 'Heures de bénévolat',
'waste_prevented' => 'Déchets évités',
Expand Down
2 changes: 1 addition & 1 deletion lang/fr/groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
'past' => 'Passé',
'read_more' => 'Lire plus',
'share_group_stats' => 'Partager les statistiques du Repair Café',
'total_devices' => 'Total des appareils qui ont été pris en charge',
'total_devices' => 'Total des éléments qui ont été pris en charge',
'participants' => 'Participants',
'hours_volunteered' => 'Heures de bénévolat',
'waste_prevented' => 'Déchets évités',
Expand Down
7 changes: 6 additions & 1 deletion resources/js/components/GroupDevicesBreakdownCluster.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ export default {
required: true
}
},
computed: {
total() {
return this.stats.fixed + this.stats.repairable + this.stats.dead
},
},
methods: {
pc(val) {
return this.stats.total ? (Math.round(10000 * val / this.stats.total) / 100) : 0
return this.total ? (Math.round(10000 * val / this.total) / 100) : 0
},
translate(category) {
// Need to translate categories. Might be null if there were no items.
Expand Down
24 changes: 17 additions & 7 deletions resources/views/group/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,20 @@
$showCalendar = Auth::check() && (($group && $group->isVolunteer()) || App\Helpers\Fixometer::hasRole(Auth::user(), 'Administrator'));
$device_stats = [
'fixed' => isset($group_device_count_status[0]) ? (int) $group_device_count_status[0]->counter : 0,
'repairable' => isset($group_device_count_status[1]) ? (int) $group_device_count_status[1]->counter : 0,
'dead' => isset($group_device_count_status[2]) ? (int) $group_device_count_status[2]->counter : 0,
];
'fixed' => 0,
'repairable' => 0,
'dead' => 0
];
foreach ($group_device_count_status as $count) {
if ($count->status == \App\Device::REPAIR_STATUS_FIXED) {
$device_stats['fixed'] = $count->counter;
} else if ($count->status == \App\Device::REPAIR_STATUS_REPAIRABLE) {
$device_stats['repairable'] = $count->counter;
} else if ($count->status == \App\Device::REPAIR_STATUS_ENDOFLIFE) {
$device_stats['dead'] = $count->counter;
}
}
$category_clusters = [
1 => 'Computers and Home Office',
Expand All @@ -64,9 +74,9 @@
$cluster_stats = [];
foreach ($category_clusters as $key => $category_cluster) {
$fixed = isset($clusters['all'][$key][0]) ? (int) $clusters['all'][$key][0]->counter : 0;
$repairable = isset($clusters['all'][$key][1]) ? (int) $clusters['all'][$key][1]->counter : 0;
$dead = isset($clusters['all'][$key][2]) ? (int) $clusters['all'][$key][2]->counter : 0;
$fixed = isset($clusters['all'][$key][0]) ? (int) $clusters['all'][$key][0]['counter'] : 0;
$repairable = isset($clusters['all'][$key][1]) ? (int) $clusters['all'][$key][1]['counter'] : 0;
$dead = isset($clusters['all'][$key][2]) ? (int) $clusters['all'][$key][2]['counter'] : 0;
$total = $clusters['all'][$key]['total'] ? $clusters['all'][$key]['total'] : 0;
//Seen and repaired stats
Expand Down

0 comments on commit c54328f

Please sign in to comment.