File: /var/www/html/david/index.php
Design idea:
<a href='/theme/html/'>Theme</a>
<br><br><br>
Layout:
<table border=1>
<tr>
<td>User Search</td>
<td>Date Search</td>
</tr>
<tr>
<td>Recent Emails Received<br>Table with last 10, Fields: Name/Email, Subject, Received Date, Score</td>
<td>Recent Emails Sent<br>Table with last 10, Fields: Name/Email, Subject, Received Date, Score</td>
</tr>
<tr>
<td>Top Positive Emails<br>Table with last 10, Fields: Name/Email, Subject, Received Date, Score</td>
<td>Top Negative Emails<br>Table with last 10, Fields: Name/Email, Subject, Received Date, Score</td>
</tr>
<tr>
<td>Top Positive Domains<br>Table with last 10, Fields: Domain, Count , Score</td>
<td>Top Negative Domains<br>Table with last 10, Fields: Domain, Count, Score</td>
</tr>
<tr>
<td colspan=2>Bar Chart of Count of Emails but hour of day from 0 - 23, and line chart with avg score between 0.0 - 1.0</td>
</tr>
<tr>
<td colspan=2>Bar Chart of Count of Emails but day of week Monday - Sunday, and line chart with avg score between 0.0 - 1.0</td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
<br><br><br>
Data Tables:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require __DIR__ . '/vendor/autoload.php';
Use Doctrine\DBAL\DriverManager;
use Oct8pus\ArrayToTable\ArrayToTable;
use Khill\Lavacharts\Lavacharts;
$lava = new Lavacharts; // See note below for Laravel
$temperatures = $lava->DataTable();
$temperatures->addNumberColumn('Date')
->addNumberColumn('Max Positive')
->addNumberColumn('Mean Positive')
->addNumberColumn('Min Positive')
->addRow(['1', 67, 65, 62])
->addRow(['2', 67, 65, 62])
->addRow(['2014-10-2', 68, 65, 61])
->addRow(['2014-10-3', 68, 62, 55])
->addRow(['2014-10-4', 72, 62, 52])
->addRow(['2014-10-5', 61, 54, 47])
->addRow(['2014-10-6', 70, 58, 45])
->addRow(['2014-10-7', 74, 70, 65])
->addRow(['2014-10-8', 75, 69, 62])
->addRow(['2014-10-9', 69, 63, 56])
->addRow(['2014-10-10', 64, 58, 52])
->addRow(['2014-10-11', 59, 55, 50])
->addRow(['2014-10-12', 65, 56, 46])
->addRow(['2014-10-13', 66, 56, 46])
->addRow(['2014-10-14', 75, 70, 64])
->addRow(['2014-10-15', 76, 72, 68])
->addRow(['2014-10-16', 71, 66, 60])
->addRow(['2014-10-17', 72, 66, 60])
->addRow(['2014-10-18', 63, 62, 62]);
//$temperatures->addRow(['2014-10-8', 75, 5, 62]);
$lava->LineChart('Temps', $temperatures, [
'title' => 'Weather in October'
]);
?>
<div id="temps_div"></div>
<?php
echo $lava->render('LineChart', 'Temps', 'temps_div');
?>
<?php
//exit;
$data = [
[
'id' => 1,
'firstName' => 'John',
'transactionId' => 'A1-2019',
'refunded' => 0,
'purchaseDate' => '2019-12-01 00:00:00',
'expiryDate' => '2020-12-01 00:00:00',
], [
'id' => 2,
'firstName' => 'Mark',
'transactionId' => 'A1-2020',
'refunded' => 0,
'purchaseDate' => '2020-12-05 00:00:00',
'expiryDate' => '2021-12-05 00:00:00',
], [
'id' => 3,
'firstName' => 'Joe',
'transactionId' => 'A1-2022',
'refunded' => 1,
'purchaseDate' => '2022-12-05 00:00:00',
'expiryDate' => '2023-12-05 00:00:00',
],
];
//http://162.223.195.25/
$connectionParams = [
'dbname' => 'foundati_ren',
'user' => 'foundati_ren',
'password' => 'Rglenco1',
'host' => '162.223.195.25',
'driver' => 'pdo_mysql',
];
$conn = DriverManager::getConnection($connectionParams);
$sqlType = "email_to";
$sqlType = "email_to_domain";
$dateStart = '2023-01-01';
$dateEnd = '2023-08-30';
$sqlSelect = "*";
$sqlwhere = "email_date between '$dateStart' AND '$dateEnd'";
$sqlfieldsGroup = "
, count(email_id) as record_count,
AVG( email_score_compound ) as email_score_compound_avg,
MIN( email_score_compound ) as email_score_compound_min,
MAX( email_score_compound ) as email_score_compound_max
";
/*
AVG( email_score_positive ) as email_score_positive_avg,
AVG( email_score_negative ) as email_score_negative_avg,
AVG( email_score_neutral ) as email_score_neutral_avg,
MIN( email_score_positive ) as email_score_positive_min,
MIN( email_score_negative ) as email_score_negative_min,
MIN( email_score_neutral ) as email_score_neutral_min,
MAX( email_score_positive ) as email_score_positive_max,
MAX( email_score_negative ) as email_score_negative_max,
MAX( email_score_neutral ) as email_score_neutral_max,
*/
$GroupByDate= ',email_date';
$GroupByDate= ',DATE(email_date)';
$sql = "
SELECT
$sqlType $GroupByDate,
DATE(email_date),
email_score_positive,
email_score_negative,
email_score_neutral,
email_score_compound
FROM
emails
WHERE
$sqlwhere
GROUP BY
$sqlType $GroupByDate
ORDER BY
$sqlType ASC
";
//Recent email
$sqlEmail = "
SELECT email_to, email_from, email_subject, email_date, email_score_compound
FROM emails
WHERE $sqlwhere
Order By email_id DESC
LIMIT 10
";
$dataset = $conn->query($sqlEmail)->fetchAll();
echo (new ArrayToTable($dataset))->render();
if($raw==1){
print_r($dataset);
}
// sqltotable($sqlEmail);
//Most Positive Emails
$sqlEmailPositive = "
SELECT email_to, email_from, email_subject, email_date, email_score_compound
FROM emails
WHERE $sqlwhere
Order By email_score_compound DESC
LIMIT 10
";
$dataset = $conn->query($sqlEmailPositive)->fetchAll();
echo (new ArrayToTable($dataset))->render();
//Most Negitive Emails
$sqlEmailNegitive = "
SELECT email_to, email_from, email_subject, email_date, email_score_compound
FROM emails
WHERE $sqlwhere
Order By email_score_compound ASC
LIMIT 10
";
$dataset = $conn->query($sqlEmailNegitive)->fetchAll();
echo (new ArrayToTable($dataset))->render();
//Email stats by People
$sqlEmailStatsByPeople = "
SELECT
email_to_name $sqlfieldsGroup
FROM
emails
WHERE
$sqlwhere
GROUP BY
email_to_name
ORDER BY
email_to_name DESC
LIMIT 10
";
$dataset = $conn->query($sqlEmailStatsByPeople)->fetchAll();
echo (new ArrayToTable($dataset))->render();
//Email stats by Domain
$sqlEmailStatsByDomain = "
SELECT
email_from_domain $sqlfieldsGroup
FROM
emails
WHERE
$sqlwhere
GROUP BY
email_from_domain
ORDER BY
email_score_compound_avg DESC
";
$dataset = $conn->query($sqlEmailStatsByDomain)->fetchAll();
echo (new ArrayToTable($dataset))->render();
//Group By Hour
$sqlEmailStatsByHour = "
SELECT HOUR( email_date ) as hour $sqlfieldsGroup
FROM
emails
WHERE $sqlwhere
GROUP BY
HOUR ( email_date )
ORDER BY
HOUR ( email_date ) ASC
";
$dataset = $conn->query($sqlEmailStatsByHour)->fetchAll();
echo (new ArrayToTable($dataset))->render();
$lava = '';
$lava = new Lavacharts; // See note below for Laravel
$finances = $lava->DataTable();
$finances->addStringColumn('Hour')
->addNumberColumn('Avg')
->addNumberColumn('Min')
->addNumberColumn('Max')
;
foreach($dataset as $data){
$finances->addRow([$data['hour'], $data['email_score_compound_avg'], $data['email_score_compound_min'], $data['email_score_compound_max']]);
//print_r($data);exit;
}
//print_r($finances);
$lava->LineChart('Finances', $finances, [
'title' => '',
'titleTextStyle' => [
'color' => '#eb6b2c',
'fontSize' => 14
]
]);
?>
<div id="perf_div"></div>
<?= $lava->render('LineChart', 'Finances', 'perf_div') ?>
<?php
//Group By Day of Week
$sqlEmailStatsByDay = "
SELECT
DATE_FORMAT(email_date, '%W' ) as dayname ,
DATE_FORMAT(email_date , '%w' ) as daynumber
$sqlfieldsGroup
FROM
emails
WHERE $sqlwhere
GROUP BY
DATE_FORMAT(email_date , '%W' ), DATE_FORMAT(email_date , '%w' )
ORDER BY
DATE_FORMAT(email_date , '%w' ) ASC
";
$dataset = $conn->query($sqlEmailStatsByDay)->fetchAll();
echo (new ArrayToTable($dataset))->render();
$lava = '';
$lava = new Lavacharts; // See note below for Laravel
$finances1 = $lava->DataTable();
$finances1->addStringColumn('Hour')
->addNumberColumn('Avg')
->addNumberColumn('Min')
->addNumberColumn('Max')
;
foreach($dataset as $data){
$finances1->addRow([$data['dayname'], $data['email_score_compound_avg'], $data['email_score_compound_min'], $data['email_score_compound_max']]);
//print_r($data);exit;
}
//print_r($finances);
$lava->LineChart('Finances1', $finances1, [
'title' => '',
'titleTextStyle' => [
'color' => '#eb6b2c',
'fontSize' => 14
]
]);
?>
<div id="perf_div1"></div>
<?= $lava->render('LineChart', 'Finances1', 'perf_div1') ?>
<?php
// print_r($user);
/*
$resultSet = $conn->executeQuery('SELECT * FROM emails');
$user = $resultSet->fetchAll();
print_r($$user);
*/