Skip to content

Commit

Permalink
Merge pull request #200 from uplink42/dev
Browse files Browse the repository at this point in the history
fix for daily reports error
  • Loading branch information
uplink42 authored Jul 23, 2017
2 parents 17797f7 + ea97622 commit 2ee375b
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 49 deletions.
60 changes: 32 additions & 28 deletions application/controllers/internal/Async_procedure.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;

Expand All @@ -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);
Expand All @@ -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));
Expand All @@ -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 = "[email protected]";
$address = $this->User->getUserEmail($data['user_id']);
$from = "[email protected]";
$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);
}
}
}
}
21 changes: 10 additions & 11 deletions application/controllers/internal/Async_updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class Async_updater extends CI_Controller
{
public function __construct()
public function __construct()
{
parent::__construct();
$this->db->cache_off();
Expand All @@ -25,32 +25,31 @@ 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()) {
log_message('error', 'global update->' . Msg::XML_CONNECT_FAILURE);
// 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) {
Expand All @@ -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 &");
}
}
Expand Down
17 changes: 15 additions & 2 deletions application/models/internal/Autoexec_updater_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
52 changes: 44 additions & 8 deletions application/models/internal/ReportGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}

/**
Expand All @@ -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'];
}

/**
Expand All @@ -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'];
}

/**
Expand Down Expand Up @@ -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'];
}

/**
Expand Down

0 comments on commit 2ee375b

Please sign in to comment.