mirror of
https://github.com/RaspbianFrance/raspisms.git
synced 2025-04-20 16:37:48 +02:00
Improve dashboard rendering speed by using ajax for graphs. Improve perfs by using more index on query. Add function to find invalid numbers and export as csv
This commit is contained in:
parent
52c849e043
commit
2be8242d5e
16 changed files with 494 additions and 56 deletions
|
@ -74,7 +74,7 @@ namespace models;
|
|||
WHERE
|
||||
total >= :min_volume
|
||||
AND
|
||||
(unreliable / total) > :rate_limit;
|
||||
(unreliable / total) >= :rate_limit;
|
||||
", [
|
||||
'id_user' => $id_user,
|
||||
'sms_status' => $sms_status,
|
||||
|
|
|
@ -267,27 +267,33 @@ namespace models;
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_discussions_for_user(int $id_user)
|
||||
public function get_discussions_for_user(int $id_user, ?int $nb_entry = null, ?int $page = null)
|
||||
{
|
||||
$query = '
|
||||
SELECT discussions.at, discussions.number, contact.name as contact_name
|
||||
FROM (
|
||||
SELECT at, destination as number FROM sended
|
||||
WHERE id_user = :id_user
|
||||
UNION (
|
||||
SELECT at, origin as number FROM received
|
||||
WHERE id_user = :id_user
|
||||
)
|
||||
) as discussions
|
||||
LEFT JOIN contact
|
||||
ON discussions.number = contact.number AND id_user = :id_user
|
||||
GROUP BY number
|
||||
ORDER BY at DESC
|
||||
SELECT at, destination AS number, contact.name AS contact_name
|
||||
FROM sended
|
||||
LEFT JOIN contact ON contact.number = sended.destination
|
||||
WHERE sended.id_user = :id_user
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT at, origin AS number, contact.name AS contact_name
|
||||
FROM received
|
||||
LEFT JOIN contact ON contact.number = received.origin
|
||||
WHERE received.id_user = :id_user
|
||||
|
||||
ORDER BY at DESC
|
||||
';
|
||||
|
||||
$params = ['id_user' => $id_user];
|
||||
|
||||
return $this->_run_query($query, $params);
|
||||
if ($nb_entry !== null)
|
||||
{
|
||||
$query .= 'LIMIT ' . intval($nb_entry) * intval($page) . ', ' . intval($nb_entry);
|
||||
}
|
||||
|
||||
$results = $this->_run_query($query, $params);
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -338,6 +338,45 @@ namespace models;
|
|||
return $this->_run_query($query, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of invalid phone number we've sent message to
|
||||
*
|
||||
* @param int $id_user : user id
|
||||
* @param int $volume : Minimum number of sms sent to the number
|
||||
* @param float $percent_failed : Minimum ratio of failed message
|
||||
* @param float $percent_unknown : Minimum ratio of unknown message
|
||||
* @param int $limit : Limit of results
|
||||
* @param int $page : Page of results (offset = page * limit)
|
||||
*
|
||||
*/
|
||||
public function get_invalid_numbers (int $id_user, int $volume, float $percent_failed, float $percent_unknown, int $limit, int $page)
|
||||
{
|
||||
$query = "
|
||||
SELECT
|
||||
destination,
|
||||
COUNT(*) AS total_sms_sent,
|
||||
ROUND(SUM(CASE WHEN status = 'failed' THEN 1 ELSE 0 END) / COUNT(*), 2) AS failed_percentage,
|
||||
ROUND(SUM(CASE WHEN status = 'unknown' THEN 1 ELSE 0 END) / COUNT(*), 2) AS unknown_percentage
|
||||
FROM
|
||||
sended
|
||||
GROUP BY
|
||||
destination
|
||||
HAVING
|
||||
total_sms_sent >= :volume
|
||||
AND failed_percentage >= :percent_failed
|
||||
AND unknown_percentage >= :percent_unknown
|
||||
LIMIT " . intval($page * $limit) . "," . intval($limit) . "
|
||||
";
|
||||
|
||||
$params = [
|
||||
'volume' => $volume,
|
||||
'percent_failed' => $percent_failed,
|
||||
'percent_unknown' => $percent_unknown
|
||||
];
|
||||
|
||||
return $this->_run_query($query, $params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return table name.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue