compatibility_report.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <?php
  2. /* ***** BEGIN LICENSE BLOCK *****
  3. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. * http://www.mozilla.org/MPL/
  9. *
  10. * Software distributed under the License is distributed on an "AS IS" basis,
  11. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. * for the specific language governing rights and limitations under the
  13. * License.
  14. *
  15. * The Original Code is addons.mozilla.org site.
  16. *
  17. * The Initial Developer of the Original Code is
  18. * The Mozilla Foundation.
  19. * Portions created by the Initial Developer are Copyright (C) 2008
  20. * the Initial Developer. All Rights Reserved.
  21. *
  22. * Contributor(s):
  23. * Justin Scott <fligtar@mozilla.com> (Original Author)
  24. *
  25. *
  26. * Alternatively, the contents of this file may be used under the terms of
  27. * either the GNU General Public License Version 2 or later (the "GPL"), or
  28. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  29. * in which case the provisions of the GPL or the LGPL are applicable instead
  30. * of those above. If you wish to allow use of your version of this file only
  31. * under the terms of either the GPL or the LGPL, and not to allow others to
  32. * use your version of this file under the terms of the MPL, indicate your
  33. * decision by deleting the provisions above and replace them with the notice
  34. * and other provisions required by the GPL or the LGPL. If you do not delete
  35. * the provisions above, a recipient may use your version of this file under
  36. * the terms of any one of the MPL, the GPL or the LGPL.
  37. *
  38. * ***** END LICENSE BLOCK ***** */
  39. // Prevent running from the web
  40. if (isset($_SERVER['HTTP_HOST'])) {
  41. exit;
  42. }
  43. // Include class files
  44. require_once('database.class.php');
  45. require_once('../site/app/controllers/components/versioncompare.php');
  46. // for VersionCompare
  47. class Object {}
  48. $db = new Database();
  49. $versioncompare = new VersioncompareComponent();
  50. /**
  51. * Returns the SQL where-clause to find versions (and aliases) compatible
  52. * with $compatibility_version.
  53. */
  54. function compatibleVersions($compatibility_version) {
  55. global $version_aliases, $versioncompare;
  56. $aliases = $versioncompare->_versionAlias($compatibility_version, $version_aliases);
  57. $compat_versions = array();
  58. foreach ($aliases as $alias) {
  59. $compat_versions[] = "version like '{$alias}%'";
  60. }
  61. return implode(' OR ', $compat_versions);
  62. }
  63. // Get latest update pings date
  64. $date_qry = $db->query("SELECT date FROM update_counts ORDER BY date DESC LIMIT 1");
  65. $date_array = mysql_fetch_assoc($date_qry);
  66. $latest_date = $date_array['date'];
  67. // Get all add-ons with Firefox compatibility ordered by active users descending
  68. $addon_qry = $db->query("
  69. SELECT
  70. addons.id,
  71. translations.localized_string AS name,
  72. versions.version,
  73. appversions.version AS maxversion,
  74. update_counts.count AS updatepings,
  75. IF(features.id IS NULL, '0', '1') AS featured
  76. FROM update_counts
  77. INNER JOIN addons ON addons.id = update_counts.addon_id
  78. INNER JOIN versions ON versions.addon_id = addons.id
  79. INNER JOIN applications_versions ON applications_versions.version_id = versions.id
  80. INNER JOIN translations ON addons.name = translations.id
  81. INNER JOIN appversions ON applications_versions.max = appversions.id
  82. LEFT JOIN features ON addons.id = features.addon_id
  83. WHERE
  84. update_counts.date = '{$latest_date}' AND
  85. applications_versions.application_id = 1 AND
  86. translations.locale = 'en-US' AND
  87. versions.id = (
  88. SELECT id FROM versions WHERE addon_id = addons.id ORDER BY created DESC LIMIT 1
  89. )
  90. GROUP BY
  91. addons.id
  92. ORDER BY
  93. update_counts.count DESC
  94. ");
  95. $all_addons = array();
  96. // Sum all update pings to establish total active users
  97. while ($addon = mysql_fetch_assoc($addon_qry)) {
  98. $all_addons[] = $addon;
  99. }
  100. // set in site/app/config/config.php
  101. global $compatibility_versions;
  102. // Previous version defaults to 2.0 because 3.0 is the first compat version we have available
  103. $previous_version = '2.0';
  104. /**
  105. * iterate through each major compatibility version and make an individual
  106. * report based on above general info
  107. */
  108. foreach ($compatibility_versions as $compatibility_version) {
  109. $compat_addons = array();
  110. $adu_total = 0;
  111. foreach ($all_addons as $addon) {
  112. // Only count this add-on if it is compatible with the major/minor release before
  113. if (!empty($previous_version) &&
  114. $versioncompare->compareVersions($addon['maxversion'], $previous_version) < 0)
  115. continue;
  116. $compat_addons[] = $addon;
  117. $adu_total += $addon['updatepings'];
  118. }
  119. $adu_top95 = floor($adu_total * .95);
  120. $totals = array(
  121. COMPAT_LATEST => array(
  122. 'count' => 0,
  123. 'adu' => 0
  124. ),
  125. COMPAT_BETA => array(
  126. 'count' => 0,
  127. 'adu' => 0
  128. ),
  129. COMPAT_ALPHA => array(
  130. 'count' => 0,
  131. 'adu' => 0
  132. ),
  133. COMPAT_OTHER => array(
  134. 'count' => 0,
  135. 'adu' => 0
  136. )
  137. );
  138. $versions_qry = $db->query("SELECT id, version
  139. FROM appversions
  140. WHERE application_id = ".APP_INSTANTBIRD." AND
  141. (".compatibleVersions($compatibility_version).")
  142. ORDER BY version");
  143. $versions = array();
  144. while ($version = mysql_fetch_assoc($versions_qry)) {
  145. $versions[$version['id']] = $version['version'];
  146. }
  147. $appversions = $versioncompare->getCompatibilityGrades($compatibility_version, $versions);
  148. $adu_counter = 0;
  149. $addons = array();
  150. // Iterate through each add-on
  151. foreach ($compat_addons as $addon) {
  152. // Only include add-ons that make up the top 95%
  153. if ($adu_counter >= $adu_top95) break;
  154. $classification = $versioncompare->gradeCompatibility($addon['maxversion'], $compatibility_version, $appversions);
  155. $totals[$classification]['count']++;
  156. $totals[$classification]['adu'] += $addon['updatepings'];
  157. $addons[] = array(
  158. 'id' => $addon['id'],
  159. 'name' => $addon['name'],
  160. 'maxversion' => $addon['maxversion'],
  161. 'featured' => $addon['featured'],
  162. 'percentage' => ($addon['updatepings'] / $adu_top95),
  163. 'classification' => $classification
  164. );
  165. $adu_counter += $addon['updatepings'];
  166. }
  167. $totals['adu95'] = $adu_top95;
  168. $totals['adu'] = $adu_total;
  169. $totals['addons95'] = count($addons);
  170. $totals['addons'] = mysql_num_rows($addon_qry);
  171. echo "Report for Firefox {$compatibility_version}\n";
  172. echo "Using data from {$latest_date}\n";
  173. echo "{$totals['adu']} total active users; {$totals['adu95']} making up top 95%\n";
  174. echo "{$totals['addons']} rows returned; {$totals['addons95']} addons counted\n\n";
  175. $output = array(
  176. 'addons' => $addons,
  177. 'totals' => $totals,
  178. 'appversions' => $appversions
  179. );
  180. print_r($output);
  181. file_put_contents(NETAPP_STORAGE.'/compatibility-fx-'.$compatibility_version.'.serialized', serialize($output));
  182. $previous_version = $compatibility_version;
  183. }
  184. ?>