aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/sorting
diff options
context:
space:
mode:
authorKiwiStone <Kiwi.Stone@web.de>2013-10-23 01:10:07 +0200
committerKiwiStone <Kiwi.Stone@web.de>2013-10-25 23:52:58 +0200
commit3baf056b683db2f8a39452ddb0ef298a365a4a5a (patch)
treefc30cce9a4ff6b958adebd841a6c2c10164e86b3 /main/src/cgeo/geocaching/sorting
parent3fe97b8a53c8aac0e3a65226010326847c8a08f3 (diff)
downloadcgeo-3baf056b683db2f8a39452ddb0ef298a365a4a5a.zip
cgeo-3baf056b683db2f8a39452ddb0ef298a365a4a5a.tar.gz
cgeo-3baf056b683db2f8a39452ddb0ef298a365a4a5a.tar.bz2
- Added new comparator to handle popularity ratios
- Added required resource strings - Added teh new comparator to the user interface option
Diffstat (limited to 'main/src/cgeo/geocaching/sorting')
-rw-r--r--main/src/cgeo/geocaching/sorting/ComparatorUserInterface.java1
-rw-r--r--main/src/cgeo/geocaching/sorting/PopularityRatioComparator.java56
2 files changed, 57 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/sorting/ComparatorUserInterface.java b/main/src/cgeo/geocaching/sorting/ComparatorUserInterface.java
index 3cdd393..99a535a 100644
--- a/main/src/cgeo/geocaching/sorting/ComparatorUserInterface.java
+++ b/main/src/cgeo/geocaching/sorting/ComparatorUserInterface.java
@@ -47,6 +47,7 @@ public class ComparatorUserInterface {
register(R.string.caches_sort_inventory, InventoryComparator.class);
register(R.string.caches_sort_name, NameComparator.class);
register(R.string.caches_sort_favorites, PopularityComparator.class);
+ register(R.string.caches_sort_favorites_ratio, PopularityRatioComparator.class);
register(R.string.caches_sort_rating, RatingComparator.class);
register(R.string.caches_sort_size, SizeComparator.class);
register(R.string.caches_sort_state, StateComparator.class);
diff --git a/main/src/cgeo/geocaching/sorting/PopularityRatioComparator.java b/main/src/cgeo/geocaching/sorting/PopularityRatioComparator.java
new file mode 100644
index 0000000..fab7bb1
--- /dev/null
+++ b/main/src/cgeo/geocaching/sorting/PopularityRatioComparator.java
@@ -0,0 +1,56 @@
+/**
+ *
+ */
+package cgeo.geocaching.sorting;
+
+import cgeo.geocaching.DataStore;
+import cgeo.geocaching.Geocache;
+import cgeo.geocaching.enumerations.LogType;
+
+/**
+ * sorts caches by popularity ratio (favorites per find in %).
+ * only caches with 10 finds and more are counted to obtain meaningful statistics
+ */
+public class PopularityRatioComparator extends AbstractCacheComparator {
+
+ @Override
+ protected boolean canCompare(final Geocache cache1, final Geocache cache2) {
+ return true;
+ }
+
+ @Override
+ protected int compareCaches(final Geocache cache1, final Geocache cache2) {
+
+ float ratio1 = 0.0f;
+ float ratio2 = 0.0f;
+
+ int finds1 = getFindsCount(cache1);
+ int finds2 = getFindsCount(cache2);
+
+ if (finds1 != 0 && finds1 > 9) {
+ ratio1 = (((float) cache1.getFavoritePoints()) / ((float) finds1));
+ }
+ if (finds2 != 0 && finds2 > 9) {
+ ratio2 = (((float) cache2.getFavoritePoints()) / ((float) finds2));
+ }
+
+ if ((ratio2 - ratio1) > 0.0f) {
+ return 1;
+ } else if ((ratio2 - ratio1) < 0.0f) {
+ return -1;
+ }
+
+ return 0;
+ }
+
+ private static int getFindsCount(Geocache cache) {
+ if (cache.getLogCounts().isEmpty()) {
+ cache.setLogCounts(DataStore.loadLogCounts(cache.getGeocode()));
+ }
+ Integer logged = cache.getLogCounts().get(LogType.FOUND_IT);
+ if (logged != null) {
+ return logged;
+ }
+ return 0;
+ }
+}