From ea9762220165101c30b799eba7ea6c9eef8ef183 Mon Sep 17 00:00:00 2001 From: uplink42 Date: Sun, 23 Jul 2017 11:44:51 +0100 Subject: [PATCH] fix for daily reports error --- .../controllers/internal/Async_procedure.php | 60 ++++++++++--------- .../controllers/internal/Async_updater.php | 21 ++++--- .../internal/Autoexec_updater_model.php | 17 +++++- .../models/internal/ReportGenerator.php | 52 +++++++++++++--- 4 files changed, 101 insertions(+), 49 deletions(-) diff --git a/application/controllers/internal/Async_procedure.php b/application/controllers/internal/Async_procedure.php index 21f2d78f..fdd7dcaa 100644 --- a/application/controllers/internal/Async_procedure.php +++ b/application/controllers/internal/Async_procedure.php @@ -6,8 +6,12 @@ error_reporting(E_ALL); ini_set('display_errors', 1); +use Pheal\Core\Config; +use Pheal\Pheal; + class Async_procedure extends CI_Controller { + public function __construct() { parent::__construct(); @@ -25,7 +29,7 @@ public function index($iduser) if (!$this->input->is_cli_request()) { die('unauthorized'); } - + $this->db->where('iduser', $iduser); $username = $this->db->get('user')->row()->username; @@ -46,7 +50,7 @@ public function index($iduser) $this->Updater_model->updateTotals($username, true); // send email $this->db->where('iduser', $iduser); - $query = $this->db->get('user'); + $query = $this->db->get('user'); $report_type = $query->row()->reports; $this->sendReport($report_type, $username); @@ -61,50 +65,50 @@ public function index($iduser) public function sendReport(string $period, string $username) { - $period == 'daily' ? $interval = 1 : - ($period == 'weekly' ? $interval = 7 : - ($period == 'monthly' ? $interval = 30 : 'none')); + $period == 'daily' ? $interval = 1 : + ($period == 'weekly' ? $interval = 7 : + ($period == 'monthly' ? $interval = 30 : 'none')); // if today is sunday send weekly report // if today is the day of the month send monthly report - $day = date('D'); - $date = date('d'); + $day = date('D'); + $date = date('d'); $month = date('m'); switch ($period) { case 'none'; return; - break; + break; case 'weekly': if ($day != 'Mon') { return; } - break; + break; case 'monthly': if (!($day == 'Mon' && $date == '30') || !($day == 'Mon' && $date == '28' && $month == 'February')) { return; } - break; + break; } - + $data['period'] = $period; $data['interval'] = $interval; $data['recap_int'] = max($interval, 7); $this->db->where('username', $username); - $data['user_id'] = (int) $this->db->get('user')->row()->iduser; - $characters = $this->Login_model->getCharacterList($data['user_id']); - $chars = (string) $characters['aggr']; - $data['char_names'] = $characters['char_names']; + $data['user_id'] = (int) $this->db->get('user')->row()->iduser; + $characters = $this->Login_model->getCharacterList($data['user_id']); + $chars = (string) $characters['aggr']; + $data['char_names'] = $characters['char_names']; - if ($chars != '()') { + if($chars != '()') { $data['totals'] = $this->reports->calculateTotals($chars, $interval); if ($data['totals'][1][0]['total_profit'] == 0 && $data['totals'][1][0]['total_sell'] == 0 && $data['totals'][1][0]['total_buy'] == 0) { return; } - + // using the icons helper $data['best_raw'] = injectIcons($this->reports->calculateBestRaw($chars, $interval)); $data['best_margin'] = injectIcons($this->reports->calculateBestMargin($chars, $interval)); @@ -113,23 +117,23 @@ public function sendReport(string $period, string $username) $data['fastest'] = injectIcons($this->reports->calculateFastestTurnovers($chars, $interval)); $data['best_iph'] = injectIcons($this->reports->calculateBestIPH($chars, $interval)); //$data['blunders'] = $this->injectIcons($this->reports->calculateBlunders($chars, $interval)); - $data['best_stations'] = $this->reports->calculateBestStations($chars, $interval); - $data['recap'] = $this->reports->calculateRecap($chars, $data['recap_int']); - $data['username'] = $username; - $data['date_now'] = date('Y-m-d'); - $data['date_prev'] = date('Y-m-d', strtotime('-' . $interval * 24 . ' hours')); - $data['cl_recent'] = $this->Updater_model->getChangeLog(true); + $data['best_stations'] = $this->reports->calculateBestStations($chars, $interval); + $data['recap'] = $this->reports->calculateRecap($chars, $data['recap_int']); + $data['username'] = $username; + $data['date_now'] = date('Y-m-d'); + $data['date_prev'] = date('Y-m-d', strtotime('-' . $interval * 24 . ' hours')); + $data['cl_recent'] = $this->Updater_model->getChangeLog(true); $report = $this->load->view('reports/reports_v', $data, true); //mail data - $address = $this->User->getUserEmail($data['user_id']); - $from = "etmdevelopment42@gmail.com"; + $address = $this->User->getUserEmail($data['user_id']); + $from = "etmdevelopment42@gmail.com"; $from_name = "Eve Trade Master"; - $subject = "Eve Trade Master " . $period . " earnings report for " . $data['date_now']; - $body = $report; + $subject = "Eve Trade Master " . $period . " earnings report for " . $data['date_now']; + $body = $report; $mail = $this->Email->send($address, $from, $from_name, $subject, $body); } } -} +} \ No newline at end of file diff --git a/application/controllers/internal/Async_updater.php b/application/controllers/internal/Async_updater.php index 1e0640fb..fdb7f661 100644 --- a/application/controllers/internal/Async_updater.php +++ b/application/controllers/internal/Async_updater.php @@ -11,7 +11,7 @@ class Async_updater extends CI_Controller { - public function __construct() + public function __construct() { parent::__construct(); $this->db->cache_off(); @@ -25,13 +25,13 @@ public function __construct() public function index() { - if (!$this->input->is_cli_request()) { + if (!$this->input->is_cli_request()) { die('unauthorized'); } $chars = $this->Autoexec_updater_model->getAllUsers(); foreach ($chars as $row) { - $username = $row->username; + $username = $row->username; $iduser = (int) $row->iduser; if (!$this->ValidateRequest->testEndpoint()) { @@ -39,18 +39,17 @@ public function index() // check if user is already updating } else { // check if already updating - if ($this->Updater_model->isLocked($username)) { + if ($this->Updater_model->isLocked($username)) { } else { // count keys - $keys = $this->Updater_model->getKeys($username); + $keys = $this->Updater_model->getKeys($username); if (count($keys) == 0) { - return; + //return; } else { // check existing keys status $keys_status = $this->Updater_model->processAPIKeys($keys, $username); - if (!$keys_status) { + if (!$keys_status) { // failure - return; } else { // check each key if valid foreach($keys_status as $key => $val) { @@ -60,11 +59,11 @@ public function index() } } if (count($invalid_keys) > 0) { - return false; + //return false; } else { // no invalid keys - $this->Updater_model->lock($username); - sleep(1); + //$this->Updater_model->lock($username); + sleep(2); exec("php /var/www/html/v2 && php index.php internal/Async_procedure index " . $iduser . " > /dev/null &"); } } diff --git a/application/models/internal/Autoexec_updater_model.php b/application/models/internal/Autoexec_updater_model.php index ec45de69..0bba5856 100644 --- a/application/models/internal/Autoexec_updater_model.php +++ b/application/models/internal/Autoexec_updater_model.php @@ -19,8 +19,21 @@ public function getAllUsers() { $this->db->select('username, iduser'); $this->db->from('user'); - //$this->db->where('iduser <=', '1415'); - $this->db->order_by('iduser', 'asc'); + //$this->db->where('iduser', '3'); + $this->db->order_by('iduser', 'desc'); + $query = $this->db->get(); + + $result = $query->result(); + + return $result; + } + + public function getSomeUsers() + { + $this->db->select('username, iduser'); + $this->db->from('user'); + $this->db->where('iduser', '4780'); + $this->db->order_by('iduser', 'desc'); $query = $this->db->get(); $result = $query->result(); diff --git a/application/models/internal/ReportGenerator.php b/application/models/internal/ReportGenerator.php index 1d44c601..f9ef82a3 100644 --- a/application/models/internal/ReportGenerator.php +++ b/application/models/internal/ReportGenerator.php @@ -116,8 +116,17 @@ private function getTotalSales($character_id, $interval) : string */ public function calculateBestRaw(string $chars, int $interval): array { - $result = $this->stats->getBestItemsRaw($chars, $interval, false, 5); - return $result; + $configs = [ + 'interval' => $interval, + 'chars' => $chars, + 'defs' => [ + 'length' => 5, + 'start' => 0, + 'draw' => 1 + ] + ]; + $result = $this->stats->getBestItemsRaw($configs); + return json_decode($result, true)['data']; } /** @@ -128,8 +137,17 @@ public function calculateBestRaw(string $chars, int $interval): array */ public function calculateBestMargin(string $chars, int $interval): array { - $result = $this->stats->getBestItemsMargin($chars, $interval, 5); - return $result; + $configs = [ + 'interval' => $interval, + 'chars' => $chars, + 'defs' => [ + 'length' => 5, + 'start' => 0, + 'draw' => 1 + ] + ]; + $result = $this->stats->getBestItemsMargin($configs); + return json_decode($result, true)['data']; } /** @@ -140,8 +158,17 @@ public function calculateBestMargin(string $chars, int $interval): array */ public function calculateProblematicItems(string $chars, int $interval): array { - $result = $this->stats->getProblematicItems($chars, $interval, 5); - return $result; + $configs = [ + 'interval' => $interval, + 'chars' => $chars, + 'defs' => [ + 'length' => 5, + 'start' => 0, + 'draw' => 1 + ] + ]; + $result = $this->stats->getProblematicItems($configs); + return json_decode($result, true)['data']; } /** @@ -176,8 +203,17 @@ public function calculateFastestTurnovers(string $chars, int $interval): array */ public function calculateBestIPH(string $chars, int $interval): array { - $result = $this->stats->getBestIPH($chars, $interval, 5); - return $result; + $configs = [ + 'interval' => $interval, + 'chars' => $chars, + 'defs' => [ + 'length' => 5, + 'start' => 0, + 'draw' => 1 + ] + ]; + $result = $this->stats->getBestIPH($configs); + return json_decode($result, true)['data']; } /**