Commit b3f3db42 authored by cividesk's avatar cividesk

Moving from country names to country codes for the pingbacks

parent 4a221a11
......@@ -293,6 +293,7 @@ INSERT INTO `common_country` (`name`, `iso2`, `iso3`) VALUES
('Cote d''Ivoire', 'CI', 'CIV'),
('Croatia', 'HR', 'HRV'),
('Cuba', 'CU', 'CUB'),
('Curaçao', 'CW', 'CUW'),
('Cyprus', 'CY', 'CYP'),
('Czech Republic', 'CZ', 'CZE'),
('Denmark', 'DK', 'DNK'),
......@@ -334,13 +335,11 @@ INSERT INTO `common_country` (`name`, `iso2`, `iso3`) VALUES
('Jamaica', 'JM', 'JAM'),
('Japan', 'JP', 'JPN'),
('Jordan', 'JO', 'JOR'),
('Hashemite Kingdom of Jordan', 'JO', 'JOR'),
('Kazakhstan', 'KZ', 'KAZ'),
('Kenya', 'KE', 'KEN'),
('Kiribati', 'KI', 'KIR'),
('Korea, North', 'KP', 'PRK'),
('Korea, South', 'KR', 'KOR'),
('Republic of Korea', 'KR', 'KOR'),
('Kuwait', 'KW', 'KWT'),
('Kyrgyzstan', 'KG', 'KGZ'),
('Laos', 'LA', 'LAO'),
......@@ -351,9 +350,9 @@ INSERT INTO `common_country` (`name`, `iso2`, `iso3`) VALUES
('Libya', 'LY', 'LBY'),
('Liechtenstein', 'LI', 'LIE'),
('Lithuania', 'LT', 'LTU'),
('Republic of Lithuania', 'LT', 'LTU'),
('Luxembourg', 'LU', 'LUX'),
('Macedonia, Republic of', 'MK', 'MKD'),
('Macao', 'MO', 'MAC'),
('Madagascar', 'MG', 'MDG'),
('Malawi', 'MW', 'MWI'),
('Malaysia', 'MY', 'MYS'),
......@@ -385,6 +384,7 @@ INSERT INTO `common_country` (`name`, `iso2`, `iso3`) VALUES
('Oman', 'OM', 'OMN'),
('Pakistan', 'PK', 'PAK'),
('Palau', 'PW', 'PLW'),
('Palestine', 'PS', 'PSE'),
('Panama', 'PA', 'PAN'),
('Papua New Guinea', 'PG', 'PNG'),
('Paraguay', 'PY', 'PRY'),
......@@ -393,6 +393,7 @@ INSERT INTO `common_country` (`name`, `iso2`, `iso3`) VALUES
('Poland', 'PL', 'POL'),
('Portugal', 'PT', 'PRT'),
('Qatar', 'QA', 'QAT'),
('Réunion', 'RE', 'REU'),
('Romania', 'RO', 'ROU'),
('Russia', 'RU', 'RUS'),
('Russian Federation', 'RU', 'RUS'),
......@@ -423,6 +424,7 @@ INSERT INTO `common_country` (`name`, `iso2`, `iso3`) VALUES
('Sweden', 'SE', 'SWE'),
('Switzerland', 'CH', 'CHE'),
('Syria', 'SY', 'SYR'),
('Taiwan, Province of China', 'TW', 'TWN'),
('Tajikistan', 'TJ', 'TJK'),
('Tanzania, United Republic of', 'TZ', 'TZA'),
('Thailand', 'TH', 'THA'),
......@@ -448,13 +450,7 @@ INSERT INTO `common_country` (`name`, `iso2`, `iso3`) VALUES
('Yemen', 'YE', 'YEM'),
('Zambia', 'ZM', 'ZMB'),
('Zimbabwe', 'ZW', 'ZWE'),
('Abkhazia', 'GE', 'GEO'),
('Taiwan', 'TW', 'TWN'),
('China, Republic of (Taiwan)', 'TW', 'TWN'),
('Nagorno-Karabakh', 'AZ', 'AZE'),
('Northern Cyprus', 'CY', 'CYP'),
('Pridnestrovie (Transnistria)', 'MD', 'MDA'),
('Somaliland', 'SO', 'SOM'),
('South Ossetia', 'GE', 'GEO'),
('Ashmore and Cartier Islands', 'AU', 'AUS'),
('Christmas Island', 'CX', 'CXR'),
......@@ -668,7 +664,7 @@ CREATE TABLE IF NOT EXISTS `pingback_site` (
`uf` text COLLATE ascii_bin,
`ufv` text COLLATE ascii_bin,
`civi_country` VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL,
`geoip_country` VARCHAR(50) COLLATE ascii_bin DEFAULT NULL,
`geoip_isoCode` VARCHAR(2) COLLATE ascii_bin DEFAULT NULL,
`DB` char(2) COLLATE ascii_bin DEFAULT NULL,
`MySQL` text COLLATE ascii_bin,
`PHP` text COLLATE ascii_bin,
......@@ -60,10 +60,10 @@ $queries[] = array(
'file' => 'active-sites-server-country.json',
'archive' => 'monthly',
'query' => "
SELECT geoip_country AS country, c.iso2, c.iso3, COUNT(*) AS num_sites
SELECT AS country, geoip_isoCode, c.iso3, COUNT(*) AS num_sites
FROM pingback_site s
LEFT JOIN common_country c ON = geoip_country
WHERE is_active = 1 AND geoip_country IS NOT NULL
LEFT JOIN common_country c ON c.iso2 = geoip_isoCode
WHERE is_active = 1 AND geoip_isoCode IS NOT NULL
GROUP BY country
HAVING num_sites > 10 -- privacy: do not report marginal countries
ORDER BY num_sites DESC
......@@ -13,12 +13,12 @@ echo "Starting from stat_id: $result[0]" . PHP_EOL;
$query = "
INSERT INTO pingback_site
(`hash`, `version`, `lang`, `uf`, `ufv`, `civi_country`,
`geoip_country`, `MySQL`, `PHP`,
`geoip_isoCode`, `MySQL`, `PHP`,
`first_ping_id`, `first_timestamp`, `last_ping_id`, `last_timestamp`, `num_pings`,
`Contact`, `Contribution`, `Participant`)
hash, version, lang, uf, ufv,,
geoip_country, MySQL, PHP,
geoip_isoCode, MySQL, PHP,, s.time,, s.time, 1,
e1.size AS Contact, e2.size AS Contribution, e3.size as Participant
FROM " . DBPING . ".stats s
......@@ -31,7 +31,7 @@ INSERT INTO pingback_site
LIMIT 30000
version = s.version, lang = s.lang, uf = s.uf, ufv = s.ufv, civi_country =,
geoip_country = s.geoip_country, MySQL = s.MySQL, PHP = s.PHP,
geoip_isoCode = s.geoip_isoCode, MySQL = s.MySQL, PHP = s.PHP,
last_ping_id =, last_timestamp = s.time, num_pings = num_pings + 1,
Contact = e1.size, Contribution = e2.size, Participant = e3.size
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