Skip to content

Commit

Permalink
Adding staff statistics page
Browse files Browse the repository at this point in the history
  • Loading branch information
llomgui committed Sep 5, 2018
1 parent 42295dd commit 2e2a2d7
Show file tree
Hide file tree
Showing 9 changed files with 310 additions and 0 deletions.
94 changes: 94 additions & 0 deletions app/Http/Controllers/Bot/StatisticsController.php
@@ -0,0 +1,94 @@
<?php

namespace xatbot\Http\Controllers\Bot;

use xatbot\Models\Bot;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use xatbot\Http\Controllers\Controller;

class StatisticsController extends Controller
{
public function show()
{
$bot = Bot::find(Session('onBotEdit'));
$statistics24Hours = DB::table('user_events')
->select(
'userinfo.regname',
'userinfo.xatid',
DB::raw('MAX(rank) as rank'),
DB::raw('SUM(amount_commands + amount_messages) as messages'),
DB::raw('SUM(amount_ranks + amount_bans + amount_kicks) as events'),
DB::raw('SUM(left_at - connected_at) as time_spent')
)
->join('userinfo', 'user_events.xatid', '=', 'userinfo.xatid')
->where([
['user_events.chatid', $bot->chatid],
['left_at', '>=', DB::raw('NOW() - INTERVAL \'24\' hour')]
])
->groupBy('userinfo.regname', 'userinfo.xatid')
->orderBy('rank', 'DESC')
->orderBy('time_spent', 'DESC')
->get();

$statistics7Days = DB::table('user_events')
->select(
'userinfo.regname',
'userinfo.xatid',
DB::raw('MAX(rank) as rank'),
DB::raw('SUM(amount_commands + amount_messages) as messages'),
DB::raw('SUM(amount_ranks + amount_bans + amount_kicks) as events'),
DB::raw('SUM(left_at - connected_at) as time_spent')
)
->join('userinfo', 'user_events.xatid', '=', 'userinfo.xatid')
->where([
['user_events.chatid', $bot->chatid],
['left_at', '>=', DB::raw('NOW() - INTERVAL \'7\' day')]
])
->groupBy('userinfo.regname', 'userinfo.xatid')
->orderBy('rank', 'DESC')
->orderBy('time_spent', 'DESC')
->get();

$statistics30Days = DB::table('user_events')
->select(
'userinfo.regname',
'userinfo.xatid',
DB::raw('MAX(rank) as rank'),
DB::raw('SUM(amount_commands + amount_messages) as messages'),
DB::raw('SUM(amount_ranks + amount_bans + amount_kicks) as events'),
DB::raw('SUM(left_at - connected_at) as time_spent')
)
->join('userinfo', 'user_events.xatid', '=', 'userinfo.xatid')
->where([
['user_events.chatid', $bot->chatid],
['left_at', '>=', DB::raw('NOW() - INTERVAL \'30\' day')]
])
->groupBy('userinfo.regname', 'userinfo.xatid')
->orderBy('rank', 'DESC')
->orderBy('time_spent', 'DESC')
->get();

$statisticsAllTime = DB::table('user_events')
->select(
'userinfo.regname',
'userinfo.xatid',
DB::raw('MAX(rank) as rank'),
DB::raw('SUM(amount_commands + amount_messages) as messages'),
DB::raw('SUM(amount_ranks + amount_bans + amount_kicks) as events'),
DB::raw('SUM(left_at - connected_at) as time_spent')
)
->join('userinfo', 'user_events.xatid', '=', 'userinfo.xatid')
->where('user_events.chatid', $bot->chatid)
->groupBy('userinfo.regname', 'userinfo.xatid')
->orderBy('rank', 'DESC')
->orderBy('time_spent', 'DESC')
->get();

return view('bot.statistics')
->with('statistics30Days', $statistics30Days)
->with('statistics7Days', $statistics7Days)
->with('statistics24Hours', $statistics24Hours)
->with('statisticsAllTime', $statisticsAllTime);
}
}
Binary file added resources/assets/images/pawns/guest.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/assets/images/pawns/member.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/assets/images/pawns/moderator.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/assets/images/pawns/owner.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
210 changes: 210 additions & 0 deletions resources/views/bot/statistics.blade.php
@@ -0,0 +1,210 @@
@extends('layouts.panel')

@section('content')

<div class="row">
<div class="col-sm-12">
<div class="page-title-box">
<h4 class="page-title">Statistics</h4>
</div>
</div>
</div>

<div class="row">
<div class="m-auto col-sm-8">
<div class="card-box">
<h4 class="m-t-0 header-title">Staff Activity list</h4>
<p class="text-muted font-14 m-b-20">This is the list of your staff and their activity during the last 30 days.</p>

<ul class="nav nav-tabs tabs-bordered">
<li class="nav-item">
<a href="#hours24" data-toggle="tab" aria-expanded="false" class="nav-link">
24 hours
</a>
</li>
<li class="nav-item">
<a href="#days7" data-toggle="tab" aria-expanded="true" class="nav-link active">
7 days
</a>
</li>
<li class="nav-item">
<a href="#days30" data-toggle="tab" aria-expanded="false" class="nav-link">
30 days
</a>
</li>
<li class="nav-item">
<a href="#allTime" data-toggle="tab" aria-expanded="false" class="nav-link">
All time
</a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane fade" id="hours24">
<table class="table table-hover">
<thead>
<tr>
<th>User</th>
<th>Rank</th>
<th>Messages</th>
<th>Events</th>
<th>Total time spent</th>
</tr>
</thead>
<tbody>
@foreach ($statistics24Hours as $statistics24Hour)
<tr>
<td>{{$statistics24Hour->regname}} ({{$statistics24Hour->xatid}})</td>
<td>
@if ($statistics24Hour->rank == 2)
<img src="/images/pawns/member.png">
@elseif ($statistics24Hour->rank == 3)
<img src="/images/pawns/moderator.png">
@elseif ($statistics24Hour->rank >= 4)
<img src="/images/pawns/owner.png">
@endif
</td>
<td>{{$statistics24Hour->messages}}</td>
<td>{{$statistics24Hour->events}}</td>
<td>{{$statistics24Hour->time_spent}}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<div class="tab-pane fade show active" id="days7">
<table class="table table-hover">
<thead>
<tr>
<th>User</th>
<th>Rank</th>
<th>Messages</th>
<th>Events</th>
<th>Total time spent</th>
</tr>
</thead>
<tbody>
@foreach ($statistics7Days as $statistics7Day)
<tr>
<td>{{$statistics7Day->regname}} ({{$statistics7Day->xatid}})</td>
<td>
@if ($statistics7Day->rank == 2)
<img src="/images/pawns/member.png">
@elseif ($statistics7Day->rank == 3)
<img src="/images/pawns/moderator.png">
@elseif ($statistics7Day->rank >= 4)
<img src="/images/pawns/owner.png">
@endif
</td>
<td>{{$statistics7Day->messages}}</td>
<td>{{$statistics7Day->events}}</td>
<td>{{$statistics7Day->time_spent}}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<div class="tab-pane fade" id="days30">
<table class="table table-hover">
<thead>
<tr>
<th>User</th>
<th>Rank</th>
<th>Messages</th>
<th>Events</th>
<th>Total time spent</th>
</tr>
</thead>
<tbody>
@foreach ($statistics30Days as $statistic30Day)
<tr>
<td>{{$statistic30Day->regname}} ({{$statistic30Day->xatid}})</td>
<td>
@if ($statistic30Day->rank == 2)
<img src="/images/pawns/member.png">
@elseif ($statistic30Day->rank == 3)
<img src="/images/pawns/moderator.png">
@elseif ($statistic30Day->rank >= 4)
<img src="/images/pawns/owner.png">
@endif
</td>
<td>{{$statistic30Day->messages}}</td>
<td>{{$statistic30Day->events}}</td>
<td>{{$statistic30Day->time_spent}}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<div class="tab-pane fade" id="allTime">
<table class="table table-hover">
<thead>
<tr>
<th>User</th>
<th>Rank</th>
<th>Messages</th>
<th>Events</th>
<th>Total time spent</th>
</tr>
</thead>
<tbody>
@foreach ($statisticsAllTime as $statisticAllTime)
<tr>
<td>{{$statisticAllTime->regname}} ({{$statisticAllTime->xatid}})</td>
<td>
@if ($statisticAllTime->rank == 2)
<img src="/images/pawns/member.png">
@elseif ($statisticAllTime->rank == 3)
<img src="/images/pawns/moderator.png">
@elseif ($statisticAllTime->rank >= 4)
<img src="/images/pawns/owner.png">
@endif
</td>
<td>{{$statisticAllTime->messages}}</td>
<td>{{$statisticAllTime->events}}</td>
<td>{{$statisticAllTime->time_spent}}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>

<!--<table class="table table-hover">
<thead>
<tr>
<th>User</th>
<th>Rank</th>
<th>Messages</th>
<th>Events</th>
<th>Total time spent</th>
</tr>
</thead>
<tbody>
@foreach ($statistics30Days as $statistic30Day)
<tr>
<td>{{$statistic30Day->regname}} ({{$statistic30Day->xatid}})</td>
<td>
@if ($statistic30Day->rank == 2)
<img src="/images/pawns/member.png">
@elseif ($statistic30Day->rank == 3)
<img src="/images/pawns/moderator.png">
@elseif ($statistic30Day->rank >= 4)
<img src="/images/pawns/owner.png">
@endif
</td>
<td>{{$statistic30Day->messages}}</td>
<td>{{$statistic30Day->events}}</td>
<td>{{$statistic30Day->time_spent}}</td>
</tr>
@endforeach
</tbody>
</table>
-->
</div>
</div>
</div>
@endsection

@section('footer')

@endsection
1 change: 1 addition & 0 deletions resources/views/includes/navbar.blade.php
Expand Up @@ -38,6 +38,7 @@
<li><a href="{{ route('bot.powers') }}">Bot Powers</a></li>
<li><a href="{{ route('bot.logs', Session('onBotEdit')) }}">Chat Logs</a></li>
<li><a href="{{ route('sharebot') }}">Share bot</a></li>
<li><a href="{{ route('bot.statistics') }}">Staff Statistics</a></li>
</ul>
</li>
<li class="has-submenu">
Expand Down
2 changes: 2 additions & 0 deletions routes/web.php
Expand Up @@ -106,6 +106,8 @@
Route::get('taken', 'TakenController@show')->name('taken');
Route::post('taken', 'TakenController@check')->name('posttaken');

Route::get('statistics', 'StatisticsController@show')->name('bot.statistics');

});

Route::group(['prefix' => 'support', 'middleware' => 'auth', 'namespace' => 'Support'], function () {
Expand Down
3 changes: 3 additions & 0 deletions webpack.mix.js
Expand Up @@ -48,6 +48,9 @@ mix.styles([
.copy([
'./resources/assets/pages'
], 'public/pages')
.copy([
'./resources/assets/images'
], 'public/images', false)
.copy([
'./resources/assets/js'
], 'public/js')
Expand Down

0 comments on commit 2e2a2d7

Please sign in to comment.