Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/suggestions/SuggestionsRanker.java

Issue 2640443003: 📰 Use first seen position in suggestion UMA (Closed)
Patch Set: rebase Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.suggestions; 5 package org.chromium.chrome.browser.suggestions;
6 6
7 import org.chromium.chrome.browser.ntp.cards.ActionItem; 7 import org.chromium.chrome.browser.ntp.cards.ActionItem;
8 import org.chromium.chrome.browser.ntp.cards.SuggestionsSection; 8 import org.chromium.chrome.browser.ntp.cards.SuggestionsSection;
9 import org.chromium.chrome.browser.ntp.snippets.CategoryInt; 9 import org.chromium.chrome.browser.ntp.snippets.CategoryInt;
10 import org.chromium.chrome.browser.ntp.snippets.SnippetArticle; 10 import org.chromium.chrome.browser.ntp.snippets.SnippetArticle;
(...skipping 19 matching lines...) Expand all
30 if (actionItem.getPerSectionRank() != -1) return; // Item was already ra nked. 30 if (actionItem.getPerSectionRank() != -1) return; // Item was already ra nked.
31 actionItem.setPerSectionRank(section.getSuggestionsCount()); 31 actionItem.setPerSectionRank(section.getSuggestionsCount());
32 } 32 }
33 33
34 /** 34 /**
35 * Attributes global and per section rank to the provided suggestion. 35 * Attributes global and per section rank to the provided suggestion.
36 * @see SnippetArticle#getPerSectionRank() 36 * @see SnippetArticle#getPerSectionRank()
37 * @see SnippetArticle#getGlobalRank() 37 * @see SnippetArticle#getGlobalRank()
38 */ 38 */
39 public void rankSuggestion(SnippetArticle suggestion) { 39 public void rankSuggestion(SnippetArticle suggestion) {
40 if (suggestion.getPerSectionRank() != -1) return; // Suggestion was alre ady ranked.
41
40 int globalRank = mTotalAddedSuggestions++; 42 int globalRank = mTotalAddedSuggestions++;
41 int perSectionRank = mSuggestionsAddedPerSection.get(suggestion.mCategor y); 43 int perSectionRank = mSuggestionsAddedPerSection.get(suggestion.mCategor y);
42 mSuggestionsAddedPerSection.put(suggestion.mCategory, perSectionRank + 1 ); 44 mSuggestionsAddedPerSection.put(suggestion.mCategory, perSectionRank + 1 );
43 45
44 suggestion.setRank(perSectionRank, globalRank); 46 suggestion.setRank(perSectionRank, globalRank);
45 } 47 }
46 48
47 public void registerCategory(@CategoryInt int category) { 49 public void registerCategory(@CategoryInt int category) {
48 // Check we are not simply resetting an already registered category. 50 // Check we are not simply resetting an already registered category.
49 if (mSuggestionsAddedPerSection.containsKey(category)) return; 51 if (mSuggestionsAddedPerSection.containsKey(category)) return;
50 mSuggestionsAddedPerSection.put(category, 0); 52 mSuggestionsAddedPerSection.put(category, 0);
51 } 53 }
52 54
53 public int getCategoryRank(@CategoryInt int category) { 55 public int getCategoryRank(@CategoryInt int category) {
54 int rank = 0; 56 int rank = 0;
55 for (Integer key : mSuggestionsAddedPerSection.keySet()) { 57 for (Integer key : mSuggestionsAddedPerSection.keySet()) {
56 if (key == category) return rank; 58 if (key == category) return rank;
57 ++rank; 59 ++rank;
58 } 60 }
59 return -1; 61 return -1;
60 } 62 }
61 } 63 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698