Commit f1f932ce authored by cividesk's avatar cividesk

Added cohort analysis.

parent f94a38f7
......@@ -90,32 +90,6 @@ INSERT INTO `common_contactrange` (`range`, `low`, `high`) VALUES
('100,000 to 250,000', 100000, 250000),
('250,000 and up', 250000, 90000000);
--
-- Dumping data for table `common_language`
--
INSERT INTO `common_language` (`iso`, `language`) VALUES
('en', 'English'),
('fr', 'French'),
('de', 'German'),
('nl', 'Dutch'),
('es', 'Spanish'),
('it', 'Italian'),
('pt', 'Portuguese'),
('pl', 'Polish'),
('ru', 'Russian'),
('da', 'Danish'),
('hu', 'Hungarian'),
('sv', 'Swedish'),
('nb', 'Norwegian Bokmål'),
('fi', 'Finnish'),
('zh', 'Chinese'),
('el', 'Greek'),
('he', 'Hebrew'),
('ja', 'Japanese'),
('lt', 'Lithuanian'),
('ca', 'Catalan');
--
-- Table structure for table `github_commit`
--
......@@ -257,6 +231,18 @@ CREATE TABLE IF NOT EXISTS `pingback_site` (
-- --------------------------------------------------------
--
-- Table structure for table `pingback_cohort`
--
CREATE TABLE IF NOT EXISTS `pingback_cohort` (
`cohort` char(7) COLLATE ascii_bin NOT NULL,
`month` char(7) COLLATE ascii_bin NOT NULL,
`num_sites` int(11) unsigned NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=ascii COLLATE=ascii_bin;
-- --------------------------------------------------------
--
-- Table structure for table `sourceforge_download`
--
......
......@@ -10,6 +10,7 @@ $queries[] = array(
);
$queries[] = array(
'file' => 'active-sites-version.json',
'archive' => 'weekly, monthly',
'query' => "
SELECT CONCAT(LEFT(version, LOCATE('.', version, 4)), 'x') AS short_version, COUNT(*) AS num_sites
FROM pingback_site
......@@ -21,6 +22,7 @@ $queries[] = array(
);
$queries[] = array(
'file' => 'active-sites-lang.json',
'archive' => 'monthly',
'query' => "
SELECT COALESCE(l.language, 'Other') AS language, COUNT(*) AS num_sites
FROM pingback_site s
......@@ -33,6 +35,7 @@ $queries[] = array(
);
$queries[] = array(
'file' => 'active-sites-country.json',
'archive' => 'monthly',
'query' => "
SELECT COALESCE(civi_country, 'N/A') AS country, COUNT(*) AS num_sites
FROM pingback_site s
......@@ -44,6 +47,7 @@ $queries[] = array(
);
$queries[] = array(
'file' => 'active-sites-uf.json',
'archive' => 'monthly',
'query' => "
SELECT uf, COUNT(*) AS num_sites
FROM pingback_site
......@@ -55,6 +59,7 @@ $queries[] = array(
);
$queries[] = array(
'file' => 'active-sites-server-country.json',
'archive' => 'monthly',
'query' => "
SELECT geoip_country AS country, COUNT(*) AS num_sites
FROM pingback_site s
......@@ -66,6 +71,7 @@ $queries[] = array(
);
$queries[] = array(
'file' => 'active-sites-server-php.json',
'archive' => 'monthly',
'query' => "
SELECT LEFT(PHP, LOCATE('.', PHP, 4) - 1) AS short_version, COUNT(*) AS num_sites
FROM pingback_site
......@@ -77,6 +83,7 @@ $queries[] = array(
);
$queries[] = array(
'file' => 'active-sites-server-mysql.json',
'archive' => 'monthly',
'query' => "
SELECT CONCAT(LEFT(MySQL, LOCATE('.', MySQL, 4) - 1), ' (', DB, ')') AS short_version, COUNT(*) AS num_sites
FROM pingback_site
......@@ -88,14 +95,27 @@ $queries[] = array(
);
$queries[] = array(
'file' => 'active-sites-stats.json',
'archive' => 'monthly',
'query' => "
SELECT COUNT(*) AS active_sites, SUM(Contact) AS total_contacts, SUM(Contribution) AS total_contributions, SUM(Participant) AS total_participants
FROM pingback_site
WHERE is_active = 1
",
);
$queries[] = array(
'file' => 'active-sites-aging.json',
'description' => 'Shows the number of sites still active by month they were created. Note the peak on August 2014, it is due to a change in how the anonymized site id is created and processed.',
'query' => "
SELECT LEFT(first_timestamp, 7) AS `month`, COUNT(*) AS num_sites
FROM pingback_site
WHERE is_active = 1
GROUP BY `month`
ORDER BY `month` ASC
",
);
$queries[] = array(
'file' => 'extensions-stats.json',
'archive' => 'monthly',
'query' => "
SELECT COUNT(*) AS num_extensions, SUM(num_sites) AS num_installs
FROM pingback_extension
......@@ -103,6 +123,7 @@ $queries[] = array(
);
$queries[] = array(
'file' => 'extensions-detail.json',
'archive' => 'weekly, monthly',
'query' => "
SELECT * FROM pingback_extension
ORDER BY num_sites DESC
......@@ -111,6 +132,7 @@ $queries[] = array(
);
$queries[] = array(
'file' => 'contacts-range.json',
'archive' => 'monthly',
'query' => "
SELECT
r.range, (
......@@ -118,4 +140,12 @@ $queries[] = array(
) AS `count`
FROM common_contactrange r
",
);
\ No newline at end of file
);
$queries[] = array(
'file' => 'cohort-analysis.json',
'query' => "
SELECT cohort, month, num_sites
FROM pingback_cohort
ORDER BY cohort, month
",
);
......@@ -60,6 +60,21 @@ UPDATE pingback_site
$result = $dbh->query("SELECT COUNT(*) FROM pingback_site WHERE is_active = 1;")->fetch();
echo "Total active sites: $result[0]" . PHP_EOL;
// Create the cohort data on the first of each month
if (date('j') == 1) {
// Loop over all previous cohorts and calculate last month's data
$cohort = '2014-09';
$lmonth = date('Y-m', strtotime('-1 week'));
while ($cohort <= $lmonth) {
$dbh->query("
INSERT INTO pingback_cohort (cohort, month, num_sites)
VALUES ('$cohort', '$lmonth', (
SELECT COUNT(*) FROM pingback_site
WHERE LEFT(first_timestamp,7) = '$cohort' AND last_timestamp >= '$lmonth'))");
$cohort = date('Y-m', strtotime($cohort.'-01 +1 month'));
}
}
// Now calculate the extension stats
$dbh->query("TRUNCATE pingback_extension");
$query = "
......
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