diff options
author | Ben Burgess <88810029+bx80@users.noreply.github.com> | 2021-11-19 13:39:19 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-19 13:39:19 +0300 |
commit | b426c7b71aca9a4f77d6e676f1bd5fb9decbd5b0 (patch) | |
tree | 466c3d946b61dbabc4c31378a2ac6fc4199cc2f7 | |
parent | a36eb5bdf9834fc40cbe1a992f7a230bd90f3b9b (diff) |
Sort segment static lists by usage (#18321)
* Sort segment static lists by usage for countryCode, browserName and operatingSystemName
* Test fixes and updates
* Count unknown list values and only include unknown if enough visits
* Added segment property to indicate if most frequent values are required
* Remove new segment needsMostFrequentValues implementation value from final API output
10 files changed, 149 insertions, 689 deletions
diff --git a/core/Plugin/Dimension/VisitDimension.php b/core/Plugin/Dimension/VisitDimension.php index 9ba0206113..030ec18f9f 100644 --- a/core/Plugin/Dimension/VisitDimension.php +++ b/core/Plugin/Dimension/VisitDimension.php @@ -12,6 +12,7 @@ use Piwik\CacheId; use Piwik\Cache as PiwikCache; use Piwik\Columns\Dimension; use Piwik\Common; +use Piwik\DataTable; use Piwik\Db; use Piwik\DbHelper; use Piwik\Plugin\Manager as PluginManager; @@ -346,4 +347,51 @@ abstract class VisitDimension extends Dimension return $instances; } + + /** + * Sort a key => value array descending by the number of occurances of the key in the supplied table and column + * + * @param array $array Key value array + * @param DataTable $table Datatable from which to count occurances + * @param string $keyColumn Column in the datatable to match against the array key + * @param int $maxValuesToReturn Limit the return array to this number of elements + * + * @return array An array of values from the source array sorted by most occurances, descending + */ + public function sortStaticListByUsage(array $array, DataTable $table, string $keyColumn, int $maxValuesToReturn) : array + { + // Convert to multi-dimensional array and count the number of visits for each browser name + foreach ($array as $k => $v) { + $array[$k] = ['count' => 0, 'name' => $v]; + } + $array['xx'] = ['count' => 0, 'name' => 'Unknown']; + + foreach ($table->getRows() as $row) { + if (isset($row[$keyColumn])) { + if (isset($array[$row[$keyColumn]])) { + $array[$row[$keyColumn]]['count']++; + } else { + $array['xx']['count']++; + } + } + } + // Sort by most visits descending + uasort($array, function($a, $b) { + return $a <=> $b; + }); + $array = array_reverse($array, true); + + // Flatten and limit the return array + $flat = []; + $i = 0; + foreach ($array as $k => $v) { + $flat[$k] = $v['name']; + $i++; + if ($i == ($maxValuesToReturn)) { + break; + } + } + + return array_values($flat); + } } diff --git a/core/Plugin/Segment.php b/core/Plugin/Segment.php index 5059357559..8fd27241b2 100644 --- a/core/Plugin/Segment.php +++ b/core/Plugin/Segment.php @@ -56,6 +56,7 @@ class Segment private $unionOfSegments; private $isInternalSegment = false; private $suggestedValuesApi = ''; + private $needsMostFrequentValues = true; /** * If true, this segment will only be visible to a registered user (see API.getSegmentsMetadata). @@ -324,6 +325,14 @@ class Segment } /** + * @param bool $value + */ + public function setNeedsMostFrequentValues(bool $value) + { + $this->needsMostFrequentValues = $value; + } + + /** * You can restrict the access to this segment by passing a boolean `false`. For instance if you want to make * a certain segment only available to users having super user access you could do the following: * `$segment->setPermission(Piwik::hasUserSuperUserAccess());` @@ -342,11 +351,12 @@ class Segment public function toArray() { $segment = array( - 'type' => $this->type, - 'category' => $this->category, - 'name' => $this->name, - 'segment' => $this->segment, - 'sqlSegment' => $this->sqlSegment, + 'type' => $this->type, + 'category' => $this->category, + 'name' => $this->name, + 'segment' => $this->segment, + 'sqlSegment' => $this->sqlSegment, + 'needsMostFrequentValues' => $this->needsMostFrequentValues, ); if (!empty($this->unionOfSegments)) { diff --git a/plugins/API/API.php b/plugins/API/API.php index 5a80d22478..743cdfd12f 100644 --- a/plugins/API/API.php +++ b/plugins/API/API.php @@ -614,7 +614,9 @@ class API extends \Piwik\Plugin\API $values = $this->getSuggestedValuesForSegmentName($idSite, $segment, $maxSuggestionsToReturn); } - $values = $this->getMostFrequentValues($values); + if ($segment['needsMostFrequentValues']) { + $values = $this->getMostFrequentValues($values); + } $values = array_slice($values, 0, $maxSuggestionsToReturn); $values = array_map(array('Piwik\Common', 'unsanitizeInputValue'), $values); diff --git a/plugins/API/SegmentMetadata.php b/plugins/API/SegmentMetadata.php index cb6ed80d18..9d33e12d82 100644 --- a/plugins/API/SegmentMetadata.php +++ b/plugins/API/SegmentMetadata.php @@ -62,6 +62,7 @@ class SegmentMetadata unset($segment['sqlFilter']); unset($segment['sqlFilterValue']); unset($segment['sqlSegment']); + unset($segment['needsMostFrequentValues']); if (isset($segment['suggestedValuesCallback']) && !is_string($segment['suggestedValuesCallback']) diff --git a/plugins/API/tests/System/expected/test_AutoSuggestAPITest_browserName__API.getSuggestedValuesForSegment.xml b/plugins/API/tests/System/expected/test_AutoSuggestAPITest_browserName__API.getSuggestedValuesForSegment.xml index b070278325..59d863927e 100644 --- a/plugins/API/tests/System/expected/test_AutoSuggestAPITest_browserName__API.getSuggestedValuesForSegment.xml +++ b/plugins/API/tests/System/expected/test_AutoSuggestAPITest_browserName__API.getSuggestedValuesForSegment.xml @@ -1,344 +1,33 @@ <?xml version="1.0" encoding="utf-8" ?> <result> - <row>115 Browser</row> - <row>2345 Browser</row> - <row>360 Phone Browser</row> - <row>360 Browser</row> - <row>7654 Browser</row> - <row>Avant Browser</row> - <row>ABrowse</row> - <row>ANT Fresco</row> - <row>ANTGalio</row> - <row>Aloha Browser</row> - <row>Aloha Browser Lite</row> - <row>Amaya</row> - <row>Amigo</row> - <row>Android Browser</row> - <row>AOL Desktop</row> - <row>AOL Shield</row> - <row>Arora</row> - <row>Arctic Fox</row> - <row>Amiga Voyager</row> - <row>Amiga Aweb</row> - <row>Arvin</row> - <row>Atom</row> - <row>Atomic Web Browser</row> - <row>Avast Secure Browser</row> - <row>AVG Secure Browser</row> - <row>Avira Scout</row> - <row>AwoX</row> - <row>Beaker Browser</row> - <row>Beamrise</row> - <row>BlackBerry Browser</row> - <row>Baidu Browser</row> - <row>Baidu Spark</row> - <row>Basilisk</row> - <row>Beonex</row> - <row>BlackHawk</row> - <row>Bunjalloo</row> - <row>B-Line</row> - <row>Blue Browser</row> - <row>Bonsai</row> - <row>Borealis Navigator</row> - <row>Brave</row> - <row>BriskBard</row> - <row>BrowseX</row> - <row>Browzar</row> - <row>Biyubi</row> - <row>Byffox</row> - <row>Camino</row> - <row>CCleaner</row> - <row>Chedot</row> - <row>Centaury</row> - <row>Coc Coc</row> - <row>CoolBrowser</row> - <row>Colibri</row> - <row>Comodo Dragon</row> - <row>Coast</row> - <row>Charon</row> - <row>CM Browser</row> - <row>Chrome Frame</row> - <row>Headless Chrome</row> - <row>Chrome</row> - <row>Chrome Mobile iOS</row> - <row>Conkeror</row> - <row>Chrome Mobile</row> - <row>CoolNovo</row> - <row>CometBird</row> - <row>COS Browser</row> - <row>Cornowser</row> - <row>Chim Lac</row> - <row>ChromePlus</row> - <row>Chromium</row> - <row>Chromium GOST</row> - <row>Cyberfox</row> - <row>Cheshire</row> - <row>Crusta</row> - <row>Craving Explorer</row> - <row>Crazy Browser</row> - <row>Cunaguaro</row> - <row>Chrome Webview</row> - <row>dbrowser</row> - <row>Peeps dBrowser</row> - <row>Deepnet Explorer</row> - <row>deg-degan</row> - <row>Deledao</row> - <row>Delta Browser</row> - <row>DeskBrowse</row> - <row>Dolphin</row> - <row>Dorado</row> - <row>Dot Browser</row> - <row>Dooble</row> - <row>Dillo</row> - <row>DuckDuckGo Privacy Browser</row> - <row>Ecosia</row> - <row>Edge WebView</row> - <row>Epic</row> - <row>Elinks</row> - <row>Element Browser</row> - <row>Elements Browser</row> - <row>eZ Browser</row> - <row>EUI Browser</row> - <row>GNOME Web</row> - <row>Espial TV Browser</row> - <row>Falkon</row> - <row>Faux Browser</row> - <row>Firefox Mobile iOS</row> - <row>Firebird</row> - <row>Fluid</row> - <row>Fennec</row> <row>Firefox</row> - <row>Firefox Focus</row> - <row>Firefox Reality</row> - <row>Firefox Rocket</row> - <row>Flock</row> - <row>Flow</row> - <row>Firefox Mobile</row> - <row>Fireweb</row> - <row>Fireweb Navigator</row> - <row>Flash Browser</row> - <row>Flast</row> - <row>FreeU</row> - <row>Galeon</row> - <row>Ghostery Privacy Browser</row> - <row>GinxDroid Browser</row> - <row>Glass Browser</row> - <row>Google Earth</row> - <row>GOG Galaxy</row> - <row>GoBrowser</row> - <row>Harman Browser</row> - <row>HasBrowser</row> - <row>Hawk Turbo Browser</row> - <row>Helio</row> - <row>hola! Browser</row> - <row>HotJava</row> - <row>Huawei Browser</row> - <row>IBrowse</row> - <row>iCab</row> - <row>iCab Mobile</row> - <row>Iridium</row> - <row>Iron Mobile</row> - <row>IceCat</row> - <row>IceDragon</row> - <row>Isivioo</row> - <row>Iceweasel</row> <row>Internet Explorer</row> - <row>IE Mobile</row> - <row>Iron</row> - <row>Japan Browser</row> - <row>Jasmine</row> - <row>JavaFX</row> - <row>Jig Browser</row> - <row>Jig Browser Plus</row> - <row>Jio Browser</row> - <row>K.Browser</row> - <row>Kindle Browser</row> - <row>K-meleon</row> - <row>Konqueror</row> - <row>Kapiko</row> - <row>Kinza</row> - <row>Kiwi</row> - <row>Kode Browser</row> - <row>Kylo</row> - <row>Kazehakase</row> - <row>Cheetah Browser</row> - <row>Lagatos Browser</row> - <row>LieBaoFast</row> - <row>LG Browser</row> - <row>Light</row> - <row>Links</row> - <row>Lolifox</row> - <row>Lovense Browser</row> - <row>LT Browser</row> - <row>LuaKit</row> - <row>Lulumi</row> - <row>Lunascape</row> - <row>Lunascape Lite</row> - <row>Lynx</row> - <row>Mandarin</row> - <row>mCent</row> - <row>MicroB</row> - <row>NCSA Mosaic</row> - <row>Meizu Browser</row> - <row>Mercury</row> - <row>Mobile Safari</row> - <row>Midori</row> - <row>Mobicip</row> - <row>MIUI Browser</row> - <row>Mobile Silk</row> - <row>Minimo</row> - <row>Mint Browser</row> - <row>Maxthon</row> - <row>Maelstrom</row> - <row>MxNitro</row> - <row>Mypal</row> - <row>Monument Browser</row> - <row>MAUI WAP Browser</row> - <row>Navigateur Web</row> - <row>NFS Browser</row> - <row>Nokia Browser</row> - <row>Nokia OSS Browser</row> - <row>Nokia Ovi Browser</row> - <row>Nox Browser</row> - <row>NetSurf</row> - <row>NetFront</row> - <row>NetFront Life</row> - <row>NetPositive</row> - <row>Netscape</row> - <row>NTENT Browser</row> - <row>Oculus Browser</row> - <row>Opera Mini iOS</row> - <row>Obigo</row> - <row>Odin</row> - <row>OceanHero</row> - <row>Odyssey Web Browser</row> - <row>Off By One</row> - <row>OhHai Browser</row> - <row>ONE Browser</row> - <row>Opera GX</row> - <row>Opera Neon</row> - <row>Opera Devices</row> - <row>Opera Mini</row> - <row>Opera Mobile</row> - <row>Opera</row> - <row>Opera Next</row> - <row>Opera Touch</row> - <row>Orca</row> - <row>Ordissimo</row> - <row>Oregano</row> - <row>Origin In-Game Overlay</row> - <row>Origyn Web Browser</row> - <row>Openwave Mobile Browser</row> - <row>OpenFin</row> - <row>OmniWeb</row> - <row>Otter Browser</row> - <row>Palm Blazer</row> - <row>Pale Moon</row> - <row>Polypane</row> - <row>Oppo Browser</row> - <row>Palm Pre</row> - <row>Puffin</row> - <row>Palm WebPro</row> - <row>Palmscape</row> - <row>Perfect Browser</row> - <row>Phantom Browser</row> - <row>Phoenix</row> - <row>Phoenix Browser</row> - <row>PlayFree Browser</row> - <row>Polaris</row> - <row>Polarity</row> - <row>PolyBrowser</row> - <row>PrivacyWall</row> - <row>PSI Secure Browser</row> - <row>Microsoft Edge</row> - <row>Qazweb</row> - <row>QQ Browser Lite</row> - <row>QQ Browser Mini</row> + <row>Chrome</row> <row>QQ Browser</row> - <row>Qutebrowser</row> - <row>Quark</row> - <row>QupZilla</row> - <row>Qwant Mobile</row> - <row>QtWebEngine</row> - <row>Realme Browser</row> - <row>Rekonq</row> - <row>RockMelt</row> - <row>Samsung Browser</row> - <row>Sailfish Browser</row> - <row>Seewo Browser</row> - <row>SEMC-Browser</row> - <row>Sogou Explorer</row> + <row>Chrome Mobile</row> + <row>Android Browser</row> <row>Safari</row> - <row>Safe Exam Browser</row> - <row>SalamWeb</row> - <row>Secure Browser</row> - <row>SFive</row> - <row>Shiira</row> - <row>SimpleBrowser</row> - <row>Sizzy</row> - <row>Skyfire</row> - <row>Seraphic Sraf</row> - <row>Sleipnir</row> - <row>Slimjet</row> - <row>SP Browser</row> - <row>Stampy Browser</row> - <row>7Star</row> - <row>Smart Lenovo Browser</row> - <row>Smooz</row> - <row>Snowshoe</row> - <row>Sogou Mobile Browser</row> - <row>Spectre Browser</row> - <row>Splash</row> - <row>Sputnik Browser</row> - <row>Sunrise</row> - <row>SuperBird</row> - <row>Super Fast Browser</row> - <row>Sushi Browser</row> - <row>surf</row> - <row>Stargon</row> - <row>START Internet Browser</row> - <row>Steam In-Game Overlay</row> - <row>Streamy</row> - <row>Swiftfox</row> - <row>Seznam Browser</row> - <row>T-Browser</row> - <row>t-online.de Browser</row> - <row>Tao Browser</row> - <row>TenFourFox</row> - <row>Tenta Browser</row> - <row>Tizen Browser</row> - <row>Tungsten</row> - <row>ToGate</row> - <row>TweakStyle</row> - <row>TV Bro</row> - <row>UBrowser</row> - <row>UC Browser</row> - <row>UC Browser HD</row> - <row>UC Browser Mini</row> - <row>UC Browser Turbo</row> - <row>UR Browser</row> - <row>Uzbl</row> - <row>Venus Browser</row> - <row>Vivaldi</row> - <row>vivo Browser</row> - <row>Vision Mobile Browser</row> - <row>VMware AirWatch</row> - <row>Wear Internet Browser</row> - <row>Web Explorer</row> - <row>WebPositive</row> - <row>Waterfox</row> - <row>Whale Browser</row> + <row>xStand</row> <row>wOSBrowser</row> - <row>WeTab Browser</row> - <row>Yahoo! Japan Browser</row> - <row>Yandex Browser</row> + <row>vivo Browser</row> + <row>t-online.de Browser</row> + <row>surf</row> + <row>mCent</row> + <row>iCab Mobile</row> + <row>iCab</row> + <row>hola! Browser</row> + <row>eZ Browser</row> + <row>deg-degan</row> + <row>dbrowser</row> + <row>Zvu</row> + <row>Zetakey</row> + <row>Yolo Browser</row> <row>Yandex Browser Lite</row> + <row>Yandex Browser</row> + <row>Yahoo! Japan Browser</row> <row>Yaani Browser</row> - <row>Yolo Browser</row> - <row>xStand</row> - <row>Xiino</row> <row>Xvast</row> - <row>Zetakey</row> - <row>Zvu</row> - <row>Unknown</row> + <row>Xiino</row> + <row>Whale Browser</row> + <row>WebPositive</row> </result>
\ No newline at end of file diff --git a/plugins/API/tests/System/expected/test_AutoSuggestAPITest_countryName__API.getSuggestedValuesForSegment.xml b/plugins/API/tests/System/expected/test_AutoSuggestAPITest_countryName__API.getSuggestedValuesForSegment.xml index ecb2da7eb5..227fc07172 100644 --- a/plugins/API/tests/System/expected/test_AutoSuggestAPITest_countryName__API.getSuggestedValuesForSegment.xml +++ b/plugins/API/tests/System/expected/test_AutoSuggestAPITest_countryName__API.getSuggestedValuesForSegment.xml @@ -1,253 +1,33 @@ <?xml version="1.0" encoding="utf-8" ?> <result> - <row>Andorra</row> - <row>United Arab Emirates</row> - <row>Afghanistan</row> - <row>Antigua & Barbuda</row> - <row>Anguilla</row> - <row>Albania</row> - <row>Armenia</row> - <row>Angola</row> - <row>Antarctica</row> - <row>Argentina</row> - <row>American Samoa</row> - <row>Austria</row> - <row>Australia</row> - <row>Aruba</row> - <row>Åland Islands</row> - <row>Azerbaijan</row> - <row>Bosnia & Herzegovina</row> - <row>Barbados</row> - <row>Bangladesh</row> - <row>Belgium</row> - <row>Burkina Faso</row> - <row>Bulgaria</row> - <row>Bahrain</row> - <row>Burundi</row> - <row>Benin</row> - <row>St. Barthélemy</row> - <row>Bermuda</row> - <row>Brunei</row> - <row>Bolivia</row> - <row>Caribbean Netherlands</row> - <row>Brazil</row> - <row>Bahamas</row> - <row>Bhutan</row> - <row>Bouvet Island</row> - <row>Botswana</row> - <row>Belarus</row> - <row>Belize</row> + <row>United Kingdom</row> <row>Canada</row> - <row>Cocos (Keeling) Islands</row> - <row>Congo - Kinshasa</row> - <row>Central African Republic</row> - <row>Congo - Brazzaville</row> - <row>Switzerland</row> - <row>Côte d’Ivoire</row> - <row>Cook Islands</row> - <row>Chile</row> - <row>Cameroon</row> + <row>Russia</row> + <row>United States</row> + <row>Unknown</row> + <row>North Macedonia</row> + <row>Italy</row> + <row>Indonesia</row> + <row>France</row> <row>China</row> - <row>Colombia</row> - <row>Costa Rica</row> - <row>Cuba</row> - <row>Cape Verde</row> - <row>Curaçao</row> - <row>Christmas Island</row> - <row>Cyprus</row> - <row>Czechia</row> - <row>Germany</row> - <row>Djibouti</row> - <row>Denmark</row> - <row>Dominica</row> - <row>Dominican Republic</row> - <row>Algeria</row> - <row>Ecuador</row> - <row>Estonia</row> - <row>Egypt</row> + <row>Åland Islands</row> + <row>Zimbabwe</row> + <row>Zambia</row> + <row>Yemen</row> <row>Western Sahara</row> - <row>Eritrea</row> - <row>Spain</row> - <row>Ethiopia</row> - <row>Finland</row> - <row>Fiji</row> - <row>Falkland Islands</row> - <row>Micronesia</row> - <row>Faroe Islands</row> - <row>France</row> - <row>Gabon</row> - <row>United Kingdom</row> - <row>Grenada</row> - <row>Georgia</row> - <row>French Guiana</row> - <row>Guernsey</row> - <row>Ghana</row> - <row>Gibraltar</row> - <row>Greenland</row> - <row>Gambia</row> - <row>Guinea</row> - <row>Guadeloupe</row> - <row>Equatorial Guinea</row> - <row>Greece</row> - <row>South Georgia & South Sandwich Islands</row> - <row>Guatemala</row> - <row>Guam</row> - <row>Guinea-Bissau</row> - <row>Guyana</row> - <row>Hong Kong SAR China</row> - <row>Heard & McDonald Islands</row> - <row>Honduras</row> - <row>Croatia</row> - <row>Haiti</row> - <row>Hungary</row> - <row>Indonesia</row> - <row>Ireland</row> - <row>Israel</row> - <row>Isle of Man</row> - <row>India</row> - <row>British Indian Ocean Territory</row> - <row>Iraq</row> - <row>Iran</row> - <row>Iceland</row> - <row>Italy</row> - <row>Jersey</row> - <row>Jamaica</row> - <row>Jordan</row> - <row>Japan</row> - <row>Kenya</row> - <row>Kyrgyzstan</row> - <row>Cambodia</row> - <row>Kiribati</row> - <row>Comoros</row> - <row>St. Kitts & Nevis</row> - <row>North Korea</row> - <row>South Korea</row> - <row>Kuwait</row> - <row>Cayman Islands</row> - <row>Kazakhstan</row> - <row>Laos</row> - <row>Lebanon</row> - <row>St. Lucia</row> - <row>Liechtenstein</row> - <row>Sri Lanka</row> - <row>Liberia</row> - <row>Lesotho</row> - <row>Lithuania</row> - <row>Luxembourg</row> - <row>Latvia</row> - <row>Libya</row> - <row>Morocco</row> - <row>Monaco</row> - <row>Moldova</row> - <row>Montenegro</row> - <row>St. Martin</row> - <row>Madagascar</row> - <row>Marshall Islands</row> - <row>North Macedonia</row> - <row>Mali</row> - <row>Myanmar (Burma)</row> - <row>Mongolia</row> - <row>Macao SAR China</row> - <row>Northern Mariana Islands</row> - <row>Martinique</row> - <row>Mauritania</row> - <row>Montserrat</row> - <row>Malta</row> - <row>Mauritius</row> - <row>Maldives</row> - <row>Malawi</row> - <row>Mexico</row> - <row>Malaysia</row> - <row>Mozambique</row> - <row>Namibia</row> - <row>New Caledonia</row> - <row>Niger</row> - <row>Norfolk Island</row> - <row>Nigeria</row> - <row>Nicaragua</row> - <row>Netherlands</row> - <row>Norway</row> - <row>Nepal</row> - <row>Nauru</row> - <row>Niue</row> - <row>New Zealand</row> - <row>Oman</row> - <row>Panama</row> - <row>Peru</row> - <row>French Polynesia</row> - <row>Papua New Guinea</row> - <row>Philippines</row> - <row>Pakistan</row> - <row>Poland</row> - <row>St. Pierre & Miquelon</row> - <row>Pitcairn Islands</row> - <row>Puerto Rico</row> - <row>Palestinian Territories</row> - <row>Portugal</row> - <row>Palau</row> - <row>Paraguay</row> - <row>Qatar</row> - <row>Réunion</row> - <row>Romania</row> - <row>Serbia</row> - <row>Russia</row> - <row>Rwanda</row> - <row>Saudi Arabia</row> - <row>Solomon Islands</row> - <row>Seychelles</row> - <row>Sudan</row> - <row>Sweden</row> - <row>Singapore</row> - <row>St. Helena</row> - <row>Slovenia</row> - <row>Svalbard & Jan Mayen</row> - <row>Slovakia</row> - <row>Sierra Leone</row> - <row>San Marino</row> - <row>Senegal</row> - <row>Somalia</row> - <row>Suriname</row> - <row>South Sudan</row> - <row>São Tomé & Príncipe</row> - <row>El Salvador</row> - <row>Sint Maarten</row> - <row>Syria</row> - <row>Eswatini</row> - <row>Turks & Caicos Islands</row> - <row>Chad</row> - <row>French Southern Territories</row> - <row>Togo</row> - <row>Thailand</row> - <row>Tajikistan</row> - <row>Tokelau</row> - <row>Timor-Leste</row> - <row>Turkmenistan</row> - <row>Tunisia</row> - <row>Tonga</row> - <row>Turkey</row> - <row>Trinidad & Tobago</row> - <row>Tuvalu</row> - <row>Taiwan</row> - <row>Tanzania</row> + <row>Wallis & Futuna</row> + <row>Vietnam</row> + <row>Venezuela</row> + <row>Vatican City</row> + <row>Vanuatu</row> + <row>Uzbekistan</row> + <row>Uruguay</row> + <row>United Arab Emirates</row> <row>Ukraine</row> <row>Uganda</row> - <row>U.S. Outlying Islands</row> - <row>United States</row> - <row>Uruguay</row> - <row>Uzbekistan</row> - <row>Vatican City</row> - <row>St. Vincent & Grenadines</row> - <row>Venezuela</row> - <row>British Virgin Islands</row> <row>U.S. Virgin Islands</row> - <row>Vietnam</row> - <row>Vanuatu</row> - <row>Wallis & Futuna</row> - <row>Samoa</row> - <row>Yemen</row> - <row>Mayotte</row> - <row>South Africa</row> - <row>Zambia</row> - <row>Zimbabwe</row> - <row>Unknown</row> + <row>U.S. Outlying Islands</row> + <row>Tuvalu</row> + <row>Turks & Caicos Islands</row> + <row>Turkmenistan</row> </result>
\ No newline at end of file diff --git a/plugins/API/tests/System/expected/test_AutoSuggestAPITest_operatingSystemName__API.getSuggestedValuesForSegment.xml b/plugins/API/tests/System/expected/test_AutoSuggestAPITest_operatingSystemName__API.getSuggestedValuesForSegment.xml index 44a4ccff5f..821083ba5c 100644 --- a/plugins/API/tests/System/expected/test_AutoSuggestAPITest_operatingSystemName__API.getSuggestedValuesForSegment.xml +++ b/plugins/API/tests/System/expected/test_AutoSuggestAPITest_operatingSystemName__API.getSuggestedValuesForSegment.xml @@ -1,108 +1,33 @@ <?xml version="1.0" encoding="utf-8" ?> <result> - <row>AIX</row> + <row>Windows</row> <row>Android</row> - <row>AmigaOS</row> - <row>tvOS</row> - <row>Arch Linux</row> - <row>BackTrack</row> - <row>Bada</row> - <row>BeOS</row> - <row>BlackBerry OS</row> - <row>BlackBerry Tablet OS</row> - <row>Brew</row> - <row>Caixa Mágica</row> - <row>CentOS</row> - <row>Chrome OS</row> - <row>CyanogenMod</row> - <row>Debian</row> - <row>Deepin</row> - <row>DragonFly</row> - <row>DVKBuntu</row> - <row>Fedora</row> - <row>Fenix</row> - <row>Firefox OS</row> - <row>Fire OS</row> - <row>Freebox</row> - <row>FreeBSD</row> - <row>FydeOS</row> - <row>Gentoo</row> - <row>GridOS</row> - <row>Google TV</row> - <row>HP-UX</row> - <row>Haiku OS</row> - <row>iPadOS</row> - <row>HarmonyOS</row> - <row>HasCodingOS</row> - <row>IRIX</row> - <row>Inferno</row> - <row>Java ME</row> - <row>KaiOS</row> - <row>Knoppix</row> - <row>Kubuntu</row> - <row>GNU/Linux</row> - <row>Lubuntu</row> - <row>Lumin OS</row> - <row>VectorLinux</row> - <row>Mac</row> - <row>Maemo</row> - <row>Mageia</row> - <row>Mandriva</row> - <row>MeeGo</row> - <row>MocorDroid</row> - <row>Mint</row> - <row>MildWild</row> - <row>MorphOS</row> - <row>NetBSD</row> - <row>MTK / Nucleus</row> - <row>MRE</row> - <row>Nintendo</row> - <row>Nintendo Mobile</row> - <row>OS/2</row> - <row>OSF1</row> - <row>OpenBSD</row> - <row>OpenWrt</row> - <row>Ordissimo</row> - <row>PCLinuxOS</row> - <row>PlayStation Portable</row> - <row>PlayStation</row> - <row>Red Hat</row> - <row>RISC OS</row> - <row>Roku OS</row> - <row>Rosa</row> - <row>Remix OS</row> - <row>REX</row> - <row>RazoDroiD</row> - <row>Sabayon</row> - <row>SUSE</row> - <row>Sailfish OS</row> - <row>SeewoOS</row> - <row>Slackware</row> - <row>Solaris</row> - <row>Syllable</row> - <row>Symbian</row> - <row>Symbian OS</row> - <row>Symbian OS Series 40</row> - <row>Symbian OS Series 60</row> - <row>Symbian^3</row> - <row>ThreadX</row> - <row>Tizen</row> - <row>TmaxOS</row> <row>Ubuntu</row> + <row>MildWild</row> + <row>webOS</row> <row>watchOS</row> - <row>WebTV</row> - <row>Whale OS</row> - <row>Windows</row> - <row>Windows CE</row> - <row>Windows IoT</row> - <row>Windows Mobile</row> - <row>Windows Phone</row> - <row>Windows RT</row> - <row>Xbox</row> - <row>Xubuntu</row> - <row>YunOs</row> - <row>iOS</row> + <row>tvOS</row> <row>palmOS</row> - <row>webOS</row> + <row>iPadOS</row> + <row>iOS</row> + <row>YunOs</row> + <row>Xubuntu</row> + <row>Xbox</row> + <row>Windows RT</row> + <row>Windows Phone</row> + <row>Windows Mobile</row> + <row>Windows IoT</row> + <row>Windows CE</row> + <row>Whale OS</row> + <row>WebTV</row> + <row>VectorLinux</row> <row>Unknown</row> + <row>TmaxOS</row> + <row>Tizen</row> + <row>ThreadX</row> + <row>Symbian^3</row> + <row>Symbian OS Series 60</row> + <row>Symbian OS Series 40</row> + <row>Symbian OS</row> + <row>Symbian</row> </result>
\ No newline at end of file diff --git a/plugins/DevicesDetection/Columns/BrowserName.php b/plugins/DevicesDetection/Columns/BrowserName.php index fa997d6f84..6e2f2ae49b 100644 --- a/plugins/DevicesDetection/Columns/BrowserName.php +++ b/plugins/DevicesDetection/Columns/BrowserName.php @@ -38,6 +38,7 @@ class BrowserName extends Base $segment->setSegment('browserName'); $segment->setName('DevicesDetection_ColumnBrowser'); $segment->setAcceptedValues('FireFox, Internet Explorer, Chrome, Safari, Opera etc.'); + $segment->setNeedsMostFrequentValues(false); $segment->setSqlFilterValue(function ($val) { $browsers = Browser::getAvailableBrowsers(); $browsers = array_map(function($val) { @@ -51,8 +52,9 @@ class BrowserName extends Base return $result; }); - $segment->setSuggestedValuesCallback(function ($idSite, $maxValuesToReturn) { - return array_values(Browser::getAvailableBrowsers() + ['Unknown']); + $segment->setSuggestedValuesCallback(function ($idSite, $maxValuesToReturn, $table) { + $browserList = Browser::getAvailableBrowsers(); + return $this->sortStaticListByUsage($browserList, $table, 'browserCode', $maxValuesToReturn); }); $segmentsList->addSegment($dimensionSegmentFactory->createSegment($segment)); } diff --git a/plugins/DevicesDetection/Columns/Os.php b/plugins/DevicesDetection/Columns/Os.php index 80ef344194..4e5bf84418 100644 --- a/plugins/DevicesDetection/Columns/Os.php +++ b/plugins/DevicesDetection/Columns/Os.php @@ -40,6 +40,7 @@ class Os extends Base $segment->setSegment('operatingSystemName'); $segment->setName('DevicesDetection_ColumnOperatingSystem'); $segment->setAcceptedValues('Windows, Linux, Mac, Android, iOS etc.'); + $segment->setNeedsMostFrequentValues(false); $segment->setSqlFilterValue(function ($val) { $oss = OperatingSystem::getAvailableOperatingSystems(); $oss = array_map(function($val) { @@ -53,8 +54,9 @@ class Os extends Base return $result; }); - $segment->setSuggestedValuesCallback(function ($idSite, $maxValuesToReturn) { - return array_values(OperatingSystem::getAvailableOperatingSystems() + ['Unknown']); + $segment->setSuggestedValuesCallback(function ($idSite, $maxValuesToReturn, $table) { + return $this->sortStaticListByUsage(OperatingSystem::getAvailableOperatingSystems(), $table, + 'operatingSystemCode', $maxValuesToReturn); }); $segmentsList->addSegment($dimensionSegmentFactory->createSegment($segment)); } diff --git a/plugins/UserCountry/Columns/Country.php b/plugins/UserCountry/Columns/Country.php index 1f8544ae6e..9a13f68790 100644 --- a/plugins/UserCountry/Columns/Country.php +++ b/plugins/UserCountry/Columns/Country.php @@ -50,6 +50,7 @@ class Country extends Base $segment->setSegment('countryName'); $segment->setName('UserCountry_Country'); $segment->setAcceptedValues('Germany, France, Spain, ...'); + $segment->setNeedsMostFrequentValues(false); $regionDataProvider = StaticContainer::get('Piwik\Intl\Data\Provider\RegionDataProvider'); $countryList = $regionDataProvider->getCountryList(); array_walk($countryList, function(&$item, $key) { @@ -63,8 +64,8 @@ class Country extends Base } return $result; }); - $segment->setSuggestedValuesCallback(function ($idSite, $maxValuesToReturn) use ($countryList) { - return array_values($countryList + ['Unknown']); + $segment->setSuggestedValuesCallback(function ($idSite, $maxValuesToReturn, $table) use ($countryList) { + return $this->sortStaticListByUsage($countryList, $table, 'countryCode', $maxValuesToReturn); }); $segmentsList->addSegment($dimensionSegmentFactory->createSegment($segment)); } |