Userlog_data.php
12.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<?php namespace App\Console\Commands;
use Illuminate\Console\Command;
use DB;
use Config;
use App\Models\User;
use App\Models\Accesslog;
use App\Models\CRMCall;
use Schema;
use PDO;
use Illuminate\Database\Schema\Blueprint;
class Userlog_data extends Command {
/**
* The console command name.
*
* @var string
*/
protected $signature = 'Userlog_data';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Userlog_data';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$nowts=time();
echo "\n".date('Y-m-d')."\n";
$logdate=strtotime('-1 day');
//$date=date('F_Y');
echo date("Y-m-d",$logdate);
$tcol=0;$fieldsarr=array();$extrahdrarr=array();
$server_ip=env('DB_HOST');
$central_ip=env('central_ip');
$conn = array(
'driver' => 'mysql',
'host' => $central_ip,
'database' => env('CENTRAL_DB'),
'username' => env('CENTRAL_USERNAME'),
'password' => env('CENTRAL_PASSWORD'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'options' => array(
PDO::ATTR_TIMEOUT => 5,
),
);
Config::set("database.connections.conn", $conn);
if(DB::connection("conn")->getDatabaseName())
{
$serverclist=DB::connection("conn")->select(DB::raw("select id from server_details where server_ip='$server_ip'"));
$server_id=$serverclist[0]->id;
if($server_id<10){
$server_id="0".$server_id;
}
$i=0;
$ulist=DB::select(DB::raw("select * from users WHERE 1"));
foreach($ulist as $uline) {
$users[$uline->id] = $uline->username;
}
if($alist=DB::select(DB::raw("select * from userlogs WHERE created_at>'".date("Y-m-d",$logdate)."' and created_at<'".date("Y-m-d",$logdate+24*60*60)."'"))){
foreach($alist as $aline) {
$i++;
$global_id = $server_id . $i;
if($aline->enddate=='0000-00-00'|| $aline->endtime=='00:00:00' || $aline->durationsec=='0')
{
$enddatetime=date("Y-m-d H:i:s",strtotime($aline->updated_at));
$enddate=explode(" ",$enddatetime)[0];
$endtime=explode(" ",$enddatetime)[1];
//echo "endtime".$endtime;
//$durationsec=date("Y-m-d H:i:s",strtotime($endtime-$aline->starttime));
$durationsec=strtotime(date("Y-m-d H:i:s",strtotime($endtime)-strtotime($aline->starttime)));
//echo "durationsec".$durationsec;
if($aline->created_at==$aline->updated_at){ $durationsec=0; }
}
else
{
$enddate=$aline->enddate;
$endtime=$aline->endtime;
$durationsec=$aline->durationsec;
}
//echo $endtime."^".$enddate."^".$durationsec;
$rowdata = array('server'=>$server_id,'server_ip'=>$server_ip,'global_id'=>$global_id,'id'=>$aline->id,
'created_at'=>$aline->created_at,'updated_at'=>$aline->updated_at,'user_id'=>$aline->user_id,'user'=>$users[$aline->user_id],
'startdate'=>$aline->startdate,'starttime'=>$aline->starttime,'enddate'=>$enddate,'endtime'=>$endtime,
'durationsec'=>$durationsec,'group'=>$aline->group,'login'=>'','dialnext'=>'','manual'=>'','paused'=>'','paused-agentbriefing'=>'','paused-downtime'=>'','paused-floorannouncements'=>'','paused-incoming'=>'','paused-lunchbreak'=>'','paused-manual'=>'','paused-notready'=>'','paused-qualityfeedback'=>'','paused-wrapup'=>'','paused-teabreak'=>'','paused-teammeeting'=>'','paused-utilitybreak'=>'','paused-autowrapup'=>'','progressive'=>'','ready-incoming'=>''
);
$data=json_decode($aline->data,true);
foreach($data as $sipid=>$sdata)
{
$prets= isset($sdata[1]) ? $sdata[1] : (strtotime($aline->startdate . " " . $aline->starttime)+19600)*1000;
if(isset($sdata['states']))
{
$previous="login";
foreach($sdata['states'] as $fts=>$states)
{
if($states[0] != 1)
{
//if($previous!='paused-wrapup'){
$rowdata[$previous] +=round(($fts-$prets)/1000,2);
$previous = (trim($states[1]) != '') ? strtolower($states[0]."-".$states[1]) : strtolower($states[0]);
$prets=$fts;
//}
}
}
$rowdata[$previous] += round(($sdata['ts']-$prets)/1000,2);
}
}
//$rowdata["login"] = $aline->durationsec;
$rowdata["login"] = $durationsec;
//$rowdata['not-ready']=$rowdata['paused-agentbriefing']+$rowdata['paused-autowrapup']+$rowdata['paused-downtime']+$rowdata['paused-floorannouncements']+$rowdata['paused-lunchbreak']+$rowdata['paused-notready']+$rowdata['paused-qualityfeedback']+$rowdata['paused-teammeeting']+$rowdata['paused-teabreak']+$rowdata['paused-utilitybreak'];
/*$rowdata["not-ready"] = $durationsec-($rowdata['dialnext']+$rowdata['manual']+$rowdata['paused']+$rowdata['paused-agentbriefing']+$rowdata['paused-downtime']+$rowdata['paused-floorannouncements']+$rowdata['paused-incoming']+$rowdata['paused-lunchbreak']+$rowdata['paused-manual']+$rowdata['paused-notready']+$rowdata['paused-qualityfeedback']+$rowdata['paused-teabreak']+$rowdata['paused-teammeeting']+$rowdata['paused-utilitybreak']+$rowdata['paused-autowrapup']+$rowdata['progressive']+$rowdata['ready-incoming']);*/
$key_value = '';
/*foreach($rowdata AS $key=>$value) {
//if($key == 1){ $key }
if($key != 1 && $key != 'paused-wrapup'){
$key_value .= "`$key` = '$value', ";
}
}*/
$startTime=$aline->startdate." ".$aline->starttime;
//$endTime=$aline->enddate." ".$aline->endtime;
if($aline->enddate=='0000-00-00'|| $aline->endtime=='00:00:00' || $aline->durationsec=='0')
{
$endTime=date("Y-m-d H:i:s",strtotime($aline->updated_at));
}else{
$endTime=$aline->enddate." ".$aline->endtime;
}
//$crmCalls=DB::select(DB::raw("select user_id,type,ts_Wait,ts_Call,ts_Talk,ts_Recstart,ts_Recend,ts_Dispo,ts_Close,waitSec,callSec,talkSec,recstartSec,recendSec,dispoSec from crmcalls WHERE created_at>='".$startTime."' and updated_at<'".$endTime."' and user_id='".$aline->user_id."'"));
$crmCalls=DB::select(DB::raw("select updated_at,user_id,type,userstatus,ts_Wait,ts_Call,ts_Talk,ts_Recstart,ts_Recend,ts_Dispo,ts_Close from crmcalls WHERE created_at>='".$startTime."' and created_at<'".$endTime."' and user_id='".$aline->user_id."'"));
$ts_Wait=0;$ts_Call=0;$ts_Talk=0;$ts_Dispo=0;
$progTs_Wait=0;$progTs_Call=0;$progTs_Talk=0;$progTs_Dispo=0;
$manTs_Wait=0;$manTs_Call=0;$manTs_Talk=0;$manTs_Dispo=0;
$inbTs_Wait=0;$inbTs_Call=0;$inbTs_Talk=0;$inbTs_Dispo=0;
$tt_prog=0;$tt_man=0;$tt_inb=0;
$force_Close=0;$force_Wait=0;$force_Call=0;$force_Talk=0;$force_Dispo=0;
if($crmCalls!=null){
foreach($crmCalls as $crmCall){
/*$ts_Wait += round(($crmCall->ts_Call - $crmCall->ts_Wait)/1000,2);
$ts_Call += round(($crmCall->ts_Talk - $crmCall->ts_Call)/1000,2);
$ts_Talk += round(($crmCall->ts_Dispo - $crmCall->ts_Talk)/1000,2);
$ts_Dispo += round(($crmCall->ts_Close - $crmCall->ts_Dispo)/1000,2);*/
if($crmCall->userstatus =='FORCEDCLOSE' || $crmCall->updated_at > $endTime)
{
$force_Wait += round(($crmCall->ts_Call - $crmCall->ts_Wait)/1000,2);
$force_Call += round(($crmCall->ts_Talk - $crmCall->ts_Call)/1000,2);
$force_Talk += round(($crmCall->ts_Dispo - $crmCall->ts_Talk)/1000,2);
// $force_Dispo += round(($crmCall->ts_Close - $crmCall->ts_Dispo)/1000,2);
}else{
$ts_Wait += round(($crmCall->ts_Call - $crmCall->ts_Wait)/1000,2);
$ts_Call += round(($crmCall->ts_Talk - $crmCall->ts_Call)/1000,2);
$ts_Talk += round(($crmCall->ts_Dispo - $crmCall->ts_Talk)/1000,2);
$ts_Dispo += round(($crmCall->ts_Close - $crmCall->ts_Dispo)/1000,2);
if($crmCall->type == 'Progressive')
{
$progTs_Wait += round(($crmCall->ts_Call - $crmCall->ts_Wait)/1000,2);
$progTs_Call += round(($crmCall->ts_Talk - $crmCall->ts_Call)/1000,2);
$progTs_Talk += round(($crmCall->ts_Dispo - $crmCall->ts_Talk)/1000,2);
$progTs_Dispo += round(($crmCall->ts_Close - $crmCall->ts_Dispo)/1000,2);
}
if($crmCall->type == 'Manual')
{
/*$manTs_Wait += round($crmCall->waitSec/1000,2);
$manTs_Call += round($crmCall->callSec/1000,2);
$manTs_Talk += round(($crmCall->talkSec+$crmCall->recstartSec+$crmCall->recendSec)/1000,2);
$manTs_Dispo += round($crmCall->dispoSec/1000,2);*/
$manTs_Wait += round(($crmCall->ts_Call - $crmCall->ts_Wait)/1000,2);
$manTs_Call += round(($crmCall->ts_Talk - $crmCall->ts_Call)/1000,2);
$manTs_Talk += round(($crmCall->ts_Dispo - $crmCall->ts_Talk)/1000,2);
$manTs_Dispo += round(($crmCall->ts_Close - $crmCall->ts_Dispo)/1000,2);
//echo round($crmCall->dispoSec/1000,2).":";
}
if($crmCall->type == 'Inbound')
{
$inbTs_Wait += round(($crmCall->ts_Call - $crmCall->ts_Wait)/1000,2);
$inbTs_Call += round(($crmCall->ts_Talk - $crmCall->ts_Call)/1000,2);
$inbTs_Talk += round(($crmCall->ts_Dispo - $crmCall->ts_Talk)/1000,2);
$inbTs_Dispo += round(($crmCall->ts_Close - $crmCall->ts_Dispo)/1000,2);
}
}
}
}
$inbTs_Call =0;
//print_r($manTs_Dispo);
$tt_prog = $progTs_Wait + $progTs_Call + $progTs_Talk + $progTs_Dispo;
$tt_man = $manTs_Wait + $manTs_Call + $manTs_Talk + $manTs_Dispo;
$tt_inb = $inbTs_Wait + $inbTs_Call + $inbTs_Talk + $inbTs_Dispo;
$tt_act_inb=$tt_inb-$inbTs_Call;
// $prod_TOS = $ts_Wait + $ts_Call + $ts_Talk + $ts_Dispo;
$force_Close = $force_Wait + $force_Call + $force_Talk + $force_Dispo;
$prod_TOS = $tt_prog+$tt_man+$tt_inb+$force_Close;
$key_value .= "`tt_prog` = '$tt_prog', ";
$key_value .= "`tt_man` = '$tt_man', ";
$key_value .= "`tt_inb` = '$tt_inb', ";
$key_value .= "`force_Close` = '$force_Close',";
$key_value .= "`ts_Wait` = '$ts_Wait', ";
$key_value .= "`ts_Call` = '$ts_Call', ";
$key_value .= "`ts_Talk` = '$ts_Talk', ";
$key_value .= "`ts_Dispo` = '$ts_Dispo', ";
$key_value .= "`progts_Wait` = '$progTs_Wait', ";
$key_value .= "`progts_Call` = '$progTs_Call', ";
$key_value .= "`progts_Talk` = '$progTs_Talk', ";
$key_value .= "`progts_Dispo` = '$progTs_Dispo', ";
$key_value .= "`mants_Wait` = '$manTs_Wait', ";
$key_value .= "`mants_Call` = '$manTs_Call', ";
$key_value .= "`mants_Talk` = '$manTs_Talk', ";
$key_value .= "`mants_Dispo` = '$manTs_Dispo', ";
$key_value .= "`incts_Wait` = '$inbTs_Wait', ";
$key_value .= "`incts_Call` = '$inbTs_Call', ";
$key_value .= "`incts_Talk` = '$inbTs_Talk', ";
$key_value .= "`incts_Dispo` = '$inbTs_Dispo', ";
$key_value .= "`prod_tos` = '$prod_TOS', ";
$key_value .= "`manual` = '$tt_man',";
$key_value .= "`progressive` = '$tt_prog',";
$key_value .= "`ready-incoming` = '$tt_act_inb',";
$rowdata["not-ready"] = $durationsec-($rowdata['dialnext']+$rowdata['paused']+$rowdata['paused-agentbriefing']+$rowdata['paused-downtime']+$rowdata['paused-floorannouncements']+$rowdata['paused-incoming']+$rowdata['paused-lunchbreak']+$rowdata['paused-manual']+$rowdata['paused-notready']+$rowdata['paused-qualityfeedback']+$rowdata['paused-teabreak']+$rowdata['paused-teammeeting']+$rowdata['paused-utilitybreak']+$rowdata['paused-autowrapup']+$tt_man+$tt_prog+$tt_act_inb+$force_Close);
//$key_value = '';
foreach($rowdata AS $key=>$value) {
//if($key == 1){ $key }
if($key != 1 && $key != 'paused-wrapup' && $key != 'progressive' && $key != 'manual' && $key != 'ready-incoming'){
//if($key != 1 && $key != 'paused-wrapup' && $key != 'progressive' && $key != 'manual'){
$key_value .= "`$key` = '$value', ";
}
}
$key_value = substr($key_value, 0, -2);
//print_r($key_value);
$userlogsTable = "userlogs_".date("d_m_Y",$logdate);;
//echo $userlogsTable;
DB::connection("conn")->insert(DB::raw("INSERT INTO ".$userlogsTable." SET $key_value"));
//DB::connection("conn")->insert(DB::raw("INSERT INTO userlogs_13_11_2018_bk SET $key_value"));
}
}
}
}
}