Skip to content

Commit 1b52592

Browse files
author
Antonios Pavlakis
committed
Fixex afer merge.
1 parent 9472147 commit 1b52592

File tree

6 files changed

+156
-21
lines changed

6 files changed

+156
-21
lines changed

app/Http/Controllers/DataController.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,11 @@ public function most($userId, $type)
8181
);
8282
}
8383

84+
public function radar($userId)
85+
{
86+
return new JsonResponse(
87+
$this->dataService->getRadar($userId)
88+
);
89+
}
90+
8491
}

app/Http/routes.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,14 @@
149149
]
150150
);
151151

152+
Route::get(
153+
'data/{userId}/radar',
154+
[
155+
'uses' => 'DataController@radar'
156+
]
157+
);
158+
159+
152160
Route::controllers([
153161
'auth' => 'Auth\AuthController',
154162
'password' => 'Auth\PasswordController',

app/Repository/VoteRepository.php

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,45 @@ public function getManagersVotedFor(array $teamManagers)
3939
return $this->db->table('votes')->whereIn('user_id', $managerIDs)->get();
4040
}
4141

42-
public function getTotalNumberVotes($teamId)
42+
public function getTotalNumberVotes($teamId, $type = 'all', $criteriaId = null)
4343
{
44-
return $this->db->table('votes')->where('team_id', '=', $teamId)->count();
44+
$query = $this->db->table('votes')->where('team_id', '=', $teamId);
45+
46+
if(!is_null($criteriaId))
47+
{
48+
$query->where('criteria_id', '=', $criteriaId);
49+
}
50+
51+
switch($type) {
52+
case 'positive':
53+
$query->where('score', '>=', 4);
54+
break;
55+
case 'neutral':
56+
$query->where('score', '=', 3);
57+
break;
58+
case 'negative':
59+
$query->where('score', '<=', 2);
60+
break;
61+
default:
62+
break;
63+
}
64+
return $query->count();
4565
}
4666

47-
public function getTotalNumberPositive($teamId)
67+
public function getTotalNumberPositive($teamId, $criteriaId = null)
4868
{
49-
return $this->db->table('votes')->where('team_id', '=', $teamId)->where('score', '>=', 4)->count();
69+
return $this->getTotalNumberVotes($teamId, "positive", $criteriaId);
5070
}
5171

52-
public function getTotalNumberNegative($teamId)
72+
public function getTotalNumberNegative($teamId, $criteriaId = null)
5373
{
54-
return $this->db->table('votes')->where('team_id', '=', $teamId)->where('score', '<=', 2)->count();
74+
return $this->getTotalNumberVotes($teamId, "negative", $criteriaId);
5575
}
5676

57-
public function getTotalNumberNeutral($teamId)
77+
public function getTotalNumberNeutral($teamId, $criteriaId = null)
5878
{
59-
return $this->db->table('votes')->where('team_id', '=', $teamId)->where('score', '=', 3)->count();
79+
return $this->getTotalNumberVotes($teamId, "neutral", $criteriaId);
6080
}
81+
82+
6183
}

app/Services/Data.php

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ public function getVotesAll($userId)
7575
);
7676
foreach ($teams as $team) {
7777
$stats[$team->id]['team_name'] = $team->team_name;
78-
$stats[$team->id]['total'] = $this->voteRepository->getTotalNumberVotes($team->id);
79-
$stats[$team->id]['positive'] = $this->voteRepository->getTotalNumberPositive($team->id);
80-
$stats[$team->id]['neutral'] = $this->voteRepository->getTotalNumberNeutral($team->id);
81-
$stats[$team->id]['negative'] = $this->voteRepository->getTotalNumberNegative($team->id);
78+
$stats[$team->id]['total'] = $this->voteRepository->getTotalNumberVotes($team->id, "all");
79+
$stats[$team->id]['positive'] = $this->voteRepository->getTotalNumberVotes($team->id, "positive");
80+
$stats[$team->id]['neutral'] = $this->voteRepository->getTotalNumberVotes($team->id, "neutral");
81+
$stats[$team->id]['negative'] = $this->voteRepository->getTotalNumberVotes($team->id, "negative");
8282
}
8383

8484
return $stats;
@@ -95,9 +95,9 @@ public function getVotesPositive($userId)
9595
);
9696
foreach ($teams as $team) {
9797
$stats[$team->id]['team_name'] = $team->team_name;
98-
$stats[$team->id]['total'] = $this->voteRepository->getTotalNumberVotes($team->id);
98+
$stats[$team->id]['total'] = $this->voteRepository->getTotalNumberVotes($team->id, "all");
9999
$total = ($stats[$team->id]['total'] > 0) ? $stats[$team->id]['total'] : 1;
100-
$stats[$team->id]['percentage'] = ceil(($this->voteRepository->getTotalNumberPositive($team->id) / $total) * 100 );
100+
$stats[$team->id]['percentage'] = ceil(($this->voteRepository->getTotalNumberVotes($team->id, "positive") / $total) * 100 );
101101
}
102102

103103
return $stats;
@@ -112,9 +112,9 @@ public function getVotesNegative($userId)
112112
);
113113
foreach ($teams as $team) {
114114
$stats[$team->id]['team_name'] = $team->team_name;
115-
$stats[$team->id]['total'] = $this->voteRepository->getTotalNumberVotes($team->id);
115+
$stats[$team->id]['total'] = $this->voteRepository->getTotalNumberVotes($team->id, "all");
116116
$total = ($stats[$team->id]['total'] > 0) ? $stats[$team->id]['total'] : 1;
117-
$stats[$team->id]['percentage'] = ceil(($this->voteRepository->getTotalNumberNegative($team->id) / $total) * 100 );
117+
$stats[$team->id]['percentage'] = ceil(($this->voteRepository->getTotalNumberVotes($team->id, "negative") / $total) * 100 );
118118
}
119119

120120
return $stats;
@@ -129,9 +129,9 @@ public function getVotesNeutral($userId)
129129
);
130130
foreach ($teams as $team) {
131131
$stats[$team->id]['team_name'] = $team->team_name;
132-
$stats[$team->id]['total'] = $this->voteRepository->getTotalNumberVotes($team->id);
132+
$stats[$team->id]['total'] = $this->voteRepository->getTotalNumberVotes($team->id, "all");
133133
$total = ($stats[$team->id]['total'] > 0) ? $stats[$team->id]['total'] : 1;
134-
$stats[$team->id]['percentage'] = ceil(($this->voteRepository->getTotalNumberNeutral($team->id) / $total) * 100 );
134+
$stats[$team->id]['percentage'] = ceil(($this->voteRepository->getTotalNumberVotes($team->id, "neutral") / $total) * 100 );
135135
}
136136

137137
return $stats;
@@ -150,4 +150,23 @@ public function getMost($userId, $type = "positive")
150150
{
151151

152152
}
153+
154+
public function getRadar($userId)
155+
{
156+
$teams = $this->usersRepository->getTeamsForUser(
157+
$this->usersRepository->getUserById($userId)
158+
);
159+
160+
$stats = [];
161+
162+
foreach ($teams as $team) {
163+
$criteria = $this->criteriaRepository->getAllCriteria();
164+
foreach ($criteria as $criterion) {
165+
$stats[$team->id][$criterion->criterion]['total'] = $this->voteRepository->getTotalNumberVotes($team->id, "all", $criterion->id);
166+
$stats[$team->id][$criterion->criterion]['positive'] = ceil(($this->voteRepository->getTotalNumberVotes($team->id, "positive", $criterion->id) / $stats[$team->id][$criterion->criterion]['total']) * 100);
167+
168+
}
169+
}
170+
return $stats;
171+
}
153172
}

resources/views/partials/statspanel.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
<div class="small-12 medium-4 large-3 columns end">
2+
<div class="small-12 medium-6 large-3 columns end">
33
<div class="panel panel--{{ $modifier }}" data-evenup-item>
44
<div class="panel__body">
55
<div class="panel__stats">

resources/views/profile/index.blade.php

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
@section('content')
1212
<div class="clearfix" data-evenup data-options='{ "small": 1, "medium": 3, "large": 4 }'>
1313
@include('partials.statspanel', [
14-
'statsValue' => $data['overall']['percentage'] . '%',
14+
'statsValue' => ($data['overall']['percentage'] > 100) ? 100 . '%' : $data['overall']['percentage'] . '%',
1515
'statsLabel' => 'of members voted.',
1616
'modifier' => Teamnfc\Helpers\ValueBracketCSSModifier::get($data['overall']['percentage'])
1717
])
@@ -41,6 +41,13 @@
4141
</div>
4242
</div>
4343
</div>
44+
<div class="small-12 medium-6 large-6 columns end">
45+
<div class="panel" data-evenup-item>
46+
<div class="panel__body">
47+
<div id="pie2container"></div>
48+
</div>
49+
</div>
50+
</div>
4451
</div>
4552
@endsection
4653

@@ -59,6 +66,16 @@
5966
redraw: function(event) {
6067
evenupItems()
6168
}
69+
},
70+
style: {
71+
color: "#fff"
72+
}
73+
},
74+
xAxis: {
75+
labels: {
76+
style: {
77+
color: '#fff'
78+
}
6279
}
6380
},
6481
title: {
@@ -78,7 +95,8 @@
7895
series: [{
7996
data: [
8097
['Positive', {{ $data['all']['positive'] }}],
81-
['Neutral', {{ $data['all']['neutral'] }}],
98+
['Neutral', {{
99+
$data['all']['neutral'] }}],
82100
['Negative', {{ $data['all']['negative'] }}]
83101
]}]
84102
},
@@ -107,5 +125,66 @@ function(chart) { // on complete
107125
}).add();
108126
});
109127
});
128+
129+
130+
131+
132+
133+
$(function () {
134+
135+
$('#pie2container').highcharts({
136+
137+
chart: {
138+
polar: true,
139+
type: 'line',
140+
backgroundColor: 'rgba(0,0,0,0)',
141+
},
142+
143+
title: {
144+
text: 'Budget vs spending',
145+
x: -80
146+
},
147+
148+
pane: {
149+
size: '80%'
150+
},
151+
152+
xAxis: {
153+
categories: ['Sales', 'Marketing', 'Development', 'Customer Support',
154+
'Information Technology', 'Administration'],
155+
tickmarkPlacement: 'on',
156+
lineWidth: 0
157+
},
158+
159+
yAxis: {
160+
gridLineInterpolation: 'polygon',
161+
lineWidth: 0,
162+
min: 0
163+
},
164+
165+
tooltip: {
166+
shared: true,
167+
pointFormat: '<span style="color:{series.color}">{series.name}: <b>${point.y:,.0f}</b><br/>'
168+
},
169+
170+
legend: {
171+
align: 'right',
172+
verticalAlign: 'top',
173+
y: 70,
174+
layout: 'vertical'
175+
},
176+
177+
series: [{
178+
name: 'Allocated Budget',
179+
data: [43000, 19000, 60000, 35000, 17000, 10000],
180+
pointPlacement: 'on'
181+
}, {
182+
name: 'Actual Spending',
183+
data: [50000, 39000, 42000, 31000, 26000, 14000],
184+
pointPlacement: 'on'
185+
}]
186+
187+
});
188+
});
110189
</script>
111190
@endsection

0 commit comments

Comments
 (0)