Skip to content

Commit

Permalink
diagram with score over time added (#31)
Browse files Browse the repository at this point in the history
* first commit

* time issue fixed closes#28

* score chart updated

* getting data for user scoreboard

* diagram with scores over time added closes #11

* .env.example added
  • Loading branch information
dome4 authored and lorey committed Nov 11, 2016
1 parent b49b2af commit da13af5
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .env.example
Expand Up @@ -26,4 +26,4 @@ MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_ENCRYPTION=null
4 changes: 3 additions & 1 deletion app/Http/Controllers/DashboardController.php
Expand Up @@ -24,6 +24,8 @@ public function index()
public function userDetail($username)
{
$user = SlackUser::find($username);
$scoreboard = $user->getReceivedPropsPerMonth();

$propsReceived = $user->receivedProps()
->orderBy('created_at', 'DESC')
->take(10)
Expand All @@ -34,7 +36,7 @@ public function userDetail($username)
->take(10)
->get();

return view('users.view', compact('user', 'propsReceived', 'propsGiven'));
return view('users.view', compact('user', 'propsReceived', 'propsGiven','scoreboard'));
}

public function slack()
Expand Down
6 changes: 6 additions & 0 deletions app/SlackUser.php
Expand Up @@ -3,6 +3,7 @@
namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class SlackUser extends Model
{
Expand All @@ -24,4 +25,9 @@ public function getName()
{
return ($this->real_name ? $this->real_name : '@' . $this->name);
}

public function getReceivedPropsPerMonth()
{
return (DB::query()->where('receiver_id', $this->id)->from('slack_props')->groupBy(DB::raw('WEEK(created_at)'))->select(DB::raw('WEEK(created_at) AS kw, count(*) AS ranking'))->get());
}
}
2 changes: 1 addition & 1 deletion config/app.php
Expand Up @@ -52,7 +52,7 @@
|
*/

'timezone' => 'UTC',
'timezone' => 'Europe/Berlin',

/*
|--------------------------------------------------------------------------
Expand Down
Expand Up @@ -3,6 +3,28 @@

<canvas id="scoreChart"></canvas>


<?php
$labels = array();
$data = array();
$sum = null;
foreach ($scoreboard AS $score)
{
//summation of the ranking
$sum = $sum + $score->ranking;
array_push($labels, $score->kw);
array_push($data, $sum);
}
$labels_fin = json_encode($labels);
$data_fin = json_encode($data);
//dd($labels_fin);
//dd($labels_fin);
?>

<script type="text/javascript">
var ctx = document.getElementById("scoreChart");
Expand All @@ -11,22 +33,14 @@
data: {
// TODO insert php variable with timestamp (array[string])
labels: ["January", "February", "March", "April", "May", "June", "July"],
labels: <?php echo $labels_fin; ?>,
datasets: [{
label: "Score",
backgroundColor: 'rgba(221, 75, 57, 1)',
borderColor: 'rgba(221, 75, 57, 0.4)',
// TODO insert php variable with score values (array[object})
data: [
2,
5,
7,
15,
21,
25,
27,
],
data: <?php echo $data_fin; ?>,
fill: false,
}]
},
Expand Down Expand Up @@ -55,7 +69,7 @@
display: true,
scaleLabel: {
display: true,
labelString: 'Date'
labelString: 'KW'
}
}],
yAxes: [{
Expand Down
6 changes: 4 additions & 2 deletions resources/views/users/view.blade.php
Expand Up @@ -62,8 +62,10 @@

<div class="row">
<div class="col-md-12">
<!-- Chart area -->
@include('users.partials.chart')
<div class="box box-solid" style="padding: 20px;">
<!-- Chart area -->
@include('users.partials.userscore')
</div>
</div>
</div>
@endsection

0 comments on commit da13af5

Please sign in to comment.