r7458 - dumbhippo/trunk/server/src/com/dumbhippo/server/dm



Author: otaylor
Date: 2008-04-28 17:15:54 -0500 (Mon, 28 Apr 2008)
New Revision: 7458

Modified:
   dumbhippo/trunk/server/src/com/dumbhippo/server/dm/UserDMO.java
Log:
Make UserDMO.topApplications an ordered list of:
 A) First - applications ordered by usage within the last 30 days; 
    if that isn't  the full count of 15 applications:
 B) Second - applications ordered by all-time usage


Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/dm/UserDMO.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/dm/UserDMO.java	2008-04-26 00:14:33 UTC (rev 7457)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/dm/UserDMO.java	2008-04-28 22:15:54 UTC (rev 7458)
@@ -407,21 +407,36 @@
 		return identitySpider.getMusicSharingPrimed(user);
 	}	
 	
+	private static final int MAX_APPLICATION_RESULTS = 15;
+
 	@DMProperty
 	@DMFilter("viewer.canSeePrivate(this)")
-	public Set<ApplicationDMO> getTopApplications() {
+	public List<ApplicationDMO> getTopApplications() {
 		UserViewpoint viewpoint = new UserViewpoint(user, Site.NONE);
 		
-		Set<ApplicationDMO> result = new HashSet<ApplicationDMO>();
-	
-		// returned "since" here can be null, which is OK
-		Date since = applicationSystem.getMyApplicationUsageStart(viewpoint);
+		List<ApplicationDMO> result = new ArrayList<ApplicationDMO>();
 
-		List<String> appIds = applicationSystem.getMyMostUsedApplicationIds(viewpoint, since, 15);
+		// We first get applications from the default timescale (last 30 days); this
+		// gives priority to applications that the user has used recently.
+		List<String> appIds = applicationSystem.getMyMostUsedApplicationIds(viewpoint, null, MAX_APPLICATION_RESULTS);
 		for (String appId : appIds) {
 			result.add(session.findUnchecked(ApplicationDMO.class, appId));
 		}
 		
+		// If that doesn't give us the full number of apps we want to return, extend that
+		// list with apps usage from the beginning of time
+		if (result.size() < MAX_APPLICATION_RESULTS) {
+			Set<String> seen = new HashSet<String>(appIds);
+			List<String> olderAppIds = applicationSystem.getMyMostUsedApplicationIds(viewpoint, new Date(0), 15);
+			for (String appId : olderAppIds) {
+				if (!seen.contains(appId)) {
+					result.add(session.findUnchecked(ApplicationDMO.class, appId));
+					if (result.size() == MAX_APPLICATION_RESULTS)
+						break;
+				}
+			}
+		}
+		
 		return result;
 	}
 	



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]