Commit c1ffa461 authored by dmorley's avatar dmorley

use meta table vs old diasp.org hack as diasp.org is not 100% either

parent 51774590
......@@ -5,6 +5,7 @@ The format is based on [Keep a Changelog] and this project adheres to [Semantic
### Added
### Changed
- add.php test for pod meta like update.php
- use meta table for updating monthly stats not the diasp.org hack
### Deprecated
### Removed
### Fixed
......
......@@ -15,14 +15,28 @@ if (!is_cli()) {
exit;
}
try {
$total_runs = R::getAll("
SELECT
count(value),
to_char(date_created, 'yyyy-mm') as yymm
FROM meta
WHERE name = 'pods_updated'
GROUP BY yymm
");
} catch (\RedBeanPHP\RedException $e) {
debug('Error in SQL query: ' . sprintf($e->getMessage()));
}
try {
$monthly_totals = R::getAll("
SELECT
to_char(date_checked, 'yyyy-mm') AS yymm,
sum(total_users) / COUNT(DISTINCT CASE WHEN domain = 'diasp.org' THEN id ELSE NULL END) as users,
sum(local_posts) / COUNT(DISTINCT CASE WHEN domain = 'diasp.org' THEN id ELSE NULL END) as posts,
sum(comment_counts) / COUNT(DISTINCT CASE WHEN domain = 'diasp.org' THEN id ELSE NULL END) as comments,
count(domain) / COUNT(DISTINCT CASE WHEN domain = 'diasp.org' THEN id ELSE NULL END) as pods,
sum(total_users) as users,
sum(local_posts) as posts,
sum(comment_counts) as comments,
count(domain) as pods,
count(DISTINCT CASE WHEN domain = 'diasp.org' THEN id ELSE NULL END) as oldtotal,
count(nullif(online, false)) as uptime,
count(nullif(online, true)) as downtime
FROM checks
......@@ -36,13 +50,23 @@ foreach ($monthly_totals as $monthly) {
// Format date to timestamp.
$timestamp = $monthly['yymm'] . '-01 01:01:01-01';
$total = $monthly['oldtotal'];
foreach ($total_runs as $runs) {
if ($monthly['yymm'] === $runs['yymm']) {
$total = $runs['count'];
break;
}
}
if ($total === 0) {
$total = 1;
}
try {
$p = R::findOrCreate('monthlystats', ['date_checked' => $timestamp]);
$p['total_users'] = $monthly['users'];
$p['total_posts'] = $monthly['posts'];
$p['total_comments'] = $monthly['comments'];
$p['total_pods'] = $monthly['pods'];
$p['total_users'] = round($monthly['users'] / $total);
$p['total_posts'] = round($monthly['posts'] / $total);
$p['total_comments'] = round($monthly['comments'] / $total);
$p['total_pods'] = round($monthly['pods'] / $total);
if ($monthly['downtime']) {
$p['total_uptime'] = round($monthly['downtime'] / $monthly['uptime'] * 100);
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment