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