OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/history/scored_history_match.h" | 5 #include "chrome/browser/history/scored_history_match.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <iterator> | 9 #include <iterator> |
10 #include <numeric> | 10 #include <numeric> |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
437 // Linearly extrapolate between 1 and 7 days so 7 days has a score of 70. | 437 // Linearly extrapolate between 1 and 7 days so 7 days has a score of 70. |
438 unnormalized_recency_score = 70 + (7 - days_ago) * (100 - 70) / (7 - 1); | 438 unnormalized_recency_score = 70 + (7 - days_ago) * (100 - 70) / (7 - 1); |
439 } else if (days_ago <= 30) { | 439 } else if (days_ago <= 30) { |
440 // Linearly extrapolate between 7 and 30 days so 30 days has a score | 440 // Linearly extrapolate between 7 and 30 days so 30 days has a score |
441 // of 50. | 441 // of 50. |
442 unnormalized_recency_score = 50 + (30 - days_ago) * (70 - 50) / (30 - 7); | 442 unnormalized_recency_score = 50 + (30 - days_ago) * (70 - 50) / (30 - 7); |
443 } else if (days_ago <= 90) { | 443 } else if (days_ago <= 90) { |
444 // Linearly extrapolate between 30 and 90 days so 90 days has a score | 444 // Linearly extrapolate between 30 and 90 days so 90 days has a score |
445 // of 20. | 445 // of 20. |
446 unnormalized_recency_score = 20 + (90 - days_ago) * (50 - 20) / (90 - 30); | 446 unnormalized_recency_score = 20 + (90 - days_ago) * (50 - 20) / (90 - 30); |
447 } else if (days_ago <= 365) { | 447 } else { |
448 // Linearly extrapolate between 90 and 365 days so 365 days has a score | 448 // Linearly extrapolate between 90 and 365 days so 365 days has a score |
449 // of 10. | 449 // of 10. |
450 unnormalized_recency_score = | 450 unnormalized_recency_score = |
451 10 + (365 - days_ago) * (20 - 10) / (365 - 90); | 451 10 + (365 - days_ago) * (20 - 10) / (365 - 90); |
452 } else { | |
453 // greater than a year. | |
454 unnormalized_recency_score = 10; | |
kmadhusu
2012/06/08 19:51:14
Since days_ago is always between 0 and 365, execut
James Hawkins
2012/06/12 20:38:57
Hmm I looked at this Coverity defect, and had rese
| |
455 } | 452 } |
456 days_ago_to_recency_score[days_ago] = unnormalized_recency_score / 100.0; | 453 days_ago_to_recency_score[days_ago] = unnormalized_recency_score / 100.0; |
457 if (days_ago > 0) { | 454 if (days_ago > 0) { |
458 DCHECK_LE(days_ago_to_recency_score[days_ago], | 455 DCHECK_LE(days_ago_to_recency_score[days_ago], |
459 days_ago_to_recency_score[days_ago - 1]); | 456 days_ago_to_recency_score[days_ago - 1]); |
460 } | 457 } |
461 } | 458 } |
462 } | 459 } |
463 | 460 |
464 // static | 461 // static |
465 float ScoredHistoryMatch::GetPopularityScore(int typed_count, | 462 float ScoredHistoryMatch::GetPopularityScore(int typed_count, |
466 int visit_count) { | 463 int visit_count) { |
467 // The max()s are to guard against database corruption. | 464 // The max()s are to guard against database corruption. |
468 return (std::max(typed_count, 0) * 5.0 + std::max(visit_count, 0) * 3.0) / | 465 return (std::max(typed_count, 0) * 5.0 + std::max(visit_count, 0) * 3.0) / |
469 (5.0 + 3.0); | 466 (5.0 + 3.0); |
470 } | 467 } |
471 | 468 |
472 } // namespace history | 469 } // namespace history |
OLD | NEW |