// GoogleAPI object // Load stats for script not included in $CONFIG['FM_SCHED_SCRIPTS_2_SUM'] $qval = array(0, FM_SCHED_TYPE); $stmt = "SELECT SessionId, DATE_FORMAT(StartDate,'%Y-%m-%d %H:%i:%S') as stDate,DATE_FORMAT(EndDate,'%Y-%m-%d %H:%i:%S') as enDate, " . "TIMESTAMPDIFF(SECOND,StartDate,EndDate) as ExecTime, FmClient as SchedName " . "FROM FmClientSession " . "WHERE Processed=? and SessionType=? "; if (array_key_exists('FM_SCHED_SCRIPTS_2_SUM', $CONFIG) && count($CONFIG['FM_SCHED_SCRIPTS_2_SUM'])) { $stmt .= " AND FmClient NOT IN (?" . str_repeat(",?", count($CONFIG['FM_SCHED_SCRIPTS_2_SUM']) - 1) . ") "; $qval = array_merge($qval, $CONFIG['FM_SCHED_SCRIPTS_2_SUM']); } $stmt .= "ORDER BY SessionId"; $sth = $DB->dbh->prepare($stmt); $sth->execute($qval); if ($sth->errorInfo()[1]) { printLogAndDie("DB error: " . $sth->errorInfo()[2]); } while ($rec = $sth->fetch(PDO::FETCH_ASSOC)) { $res = $googleAPI->add_event(array('start' => $rec['stDate'], 'end' => $rec['enDate'], 'msg' => $rec['SchedName'] . ". Exec time: " . formatSec($rec["ExecTime"]))); if ($res) { $LOG->message("Event for session " . $rec['SessionId'] . " created. EventId: " . $res); markRecProcessed($rec['SessionId']); // Mark session as processed } else { printLogAndDie("Error creating event for session " . $rec['SessionId']); } } if (array_key_exists('FM_SCHED_SCRIPTS_2_SUM', $CONFIG) && count($CONFIG['FM_SCHED_SCRIPTS_2_SUM'])) { // Load stat for scripts in $CONFIG['FM_SCHED_SCRIPTS_2_SUM'] $curStartDate = $curEndDate = $curDescr = ''; $curExecTime = $curExecCount = 0; $qval = array_merge(array(0, FM_SCHED_TYPE), $CONFIG['FM_SCHED_SCRIPTS_2_SUM']); $stmt = "SELECT FmClient as SchedName, SUM(TIMESTAMPDIFF(SECOND,StartDate,EndDate)) as ExecTime, COUNT(SessionId) as ExecCount, " . "CONCAT(DATE_FORMAT(StartDate,'%Y-%m-%d %H:'), DATE_FORMAT(StartDate,'%i') - DATE_FORMAT(StartDate,'%i') MOD 30,':00') as stDate, " . "CONCAT(DATE_FORMAT(date_add(StartDate, INTERVAL 30 minute),'%Y-%m-%d %H:'), DATE_FORMAT(date_add(StartDate, INTERVAL 30 minute),'%i') - DATE_FORMAT(date_add(StartDate, INTERVAL 30 minute),'%i') MOD 30,':00') as enDate " . "FROM FmClientSession " . "WHERE Processed=? AND SessionType=? AND FmClient IN (?" . str_repeat(",?", count($CONFIG['FM_SCHED_SCRIPTS_2_SUM']) - 1) . ") " . "GROUP BY FmClient, stDate order by stDate"; $sth = $DB->dbh->prepare($stmt);
if (!$startDate) { // First run $st = date_parse("{$rdate} {$rtime}"); $startDate = $st['year'] . '-' . $st['month'] . '-' . $st['day'] . ' ' . $st['hour'] . ':' . ($st['minute'] > $PERIOD_MIN ? '30:00' : '00:00'); $endDate = date('Y-m-d H:i:s', strtotime($startDate . ' + ' . $PERIOD_MIN . ' minute')); } if ($endDate <= "{$rdate} {$rtime}") { // New date - save data and collect new max value if ($max_clients_connected) { // Save max value in DB and calendar $sth = $DB->dbh->prepare("INSERT INTO FmClientStats SET StartDate=?, EndDate=?, MaxClients=?"); $sth->execute(array($startDate, $endDate, $max_clients_connected)); if ($sth->errorInfo()[1]) { printLogAndDie("DB error: " . $sth->errorInfo()[2]); } $res = $googleAPI->add_event(array('start' => $startDate, 'end' => $endDate, 'msg' => "Clients: {$max_clients_connected}", 'colorId' => $CONFIG['FM_SUM_CLIENTS_COLOR'])); $LOG->message("Max number of clients {$startDate} - {$endDate} is {$max_clients_connected}. Saved in event Id {$res}"); } $max_clients_connected = 0; $startDate = $endDate; $endDate = date('Y-m-d H:i:s', strtotime($startDate . ' + ' . $PERIOD_MIN . ' minute')); } if ($reportEndDate < "{$rdate} {$rtime}") { // Exit here, do not process further records break; } if ($startDate > "{$rdate} {$rtime}") { // Check date/time of the record continue; // we already have these values in DB - go to next line(record) }