/[projects]/android/MarketStats/src/dk/thoerup/marketstats/ShowStats.java
ViewVC logotype

Diff of /android/MarketStats/src/dk/thoerup/marketstats/ShowStats.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 704 by torben, Mon Apr 26 07:57:45 2010 UTC revision 705 by torben, Tue May 4 03:48:37 2010 UTC
# Line 48  public class ShowStats extends HttpServl Line 48  public class ShowStats extends HttpServl
48                  }                  }
49          }          }
50    
51          protected String doLookup(String appId) throws IOException {          protected String doLookup(String query) throws IOException {
52                                    
53    
54                  String key = "marketstats:" + appId;                  String key = "marketstats:" + query;
55                  String response = (String) memcache.get(key);                  String response = (String) memcache.get(key);
56    
57                  if (response == null) {                  if (response == null) {
58                          response = doLookupWorker(appId);                          response = doLookupWorker(query);
59                          memcache.set(key, TIMEOUT, response);                          memcache.set(key, TIMEOUT, response);
60                          response += "<!-- new lookup -->";                          response += "<!-- new lookup -->";
61                  } else {                  } else {
# Line 96  public class ShowStats extends HttpServl Line 96  public class ShowStats extends HttpServl
96          }          }
97    
98    
99          protected String doLookupWorker(String appId) {          protected String doLookupWorker(String query) {
100                  final StringBuilder sb = new StringBuilder();                  final StringBuilder sb = new StringBuilder();
101    
102    
# Line 105  public class ShowStats extends HttpServl Line 105  public class ShowStats extends HttpServl
105    
106    
107                  AppsRequest appsRequest = AppsRequest.newBuilder()                  AppsRequest appsRequest = AppsRequest.newBuilder()
108                  .setAppId(appId)                  .setQuery(query)
109                  .setStartIndex(0).setEntriesCount(10)                  .setStartIndex(0).setEntriesCount(10)
110                  .setWithExtendedInfo(true)                  .setWithExtendedInfo(true)
111                  .build();                  .build();
# Line 120  public class ShowStats extends HttpServl Line 120  public class ShowStats extends HttpServl
120    
121                  session.append(appsRequest, appsCb);                  session.append(appsRequest, appsCb);
122                  session.flush();                  session.flush();
123                    
124                    String appId = appsCb.getAppId();
125                    
126                    if (appId != null) {
127    
128                  loadComments(appId, session, "da", commentBeans);                          loadComments(appId, session, "da", commentBeans);
129                  loadComments(appId, session, "en", commentBeans);                          loadComments(appId, session, "en", commentBeans);
130            
131                  Collections.sort(commentBeans);                          Collections.sort(commentBeans);
132            
133                  sb.append("-----------------------------------------------------------------\n");                          sb.append("-----------------------------------------------------------------\n");
134                  for (CommentBean c : commentBeans) {                          for (CommentBean c : commentBeans) {
135                          sb.append("User: " + c.author + " ("  + c.locale + ")\n");                                  sb.append("User: " + c.author + " ("  + c.locale + ")\n");
136                          sb.append("Rating: " + c.rating + "\n");                                  sb.append("Rating: " + c.rating + "\n");
137                          sb.append("Time: " + new Date(c.time).toString() + "\n");                                  sb.append("Time: " + new Date(c.time).toString() + "\n");
138                          sb.append( c.text + "\n");                                  sb.append( c.text + "\n");
139                          sb.append("\n");                                  sb.append("\n");
140            
141                            }
142                            sb.append("Comments: " + commentBeans.size() + "\n");
143                  }                  }
144                  sb.append("Comments: " + commentBeans.size() + "\n");                  sb.append("Cache.Timeout=" + TIMEOUT/60 + " minutes");          
                 sb.append("Cache.Timeout=" + TIMEOUT/60 + " minutes");  
145    
146    
147                  return sb.toString();                  return sb.toString();
148          }          }
149    
150          protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {          protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
151                  String appId = request.getParameter("appId");                  String query = request.getParameter("query");
152    
153                  response.setContentType("text/html");                  response.setContentType("text/html");
154                  PrintWriter out = response.getWriter();                  PrintWriter out = response.getWriter();
155                  out.print( "<html><body><pre>" + doLookup(appId) + "</pre></body></html>" );                  out.print( "<html><body><pre>" + doLookup(query) + "</pre></body></html>" );
156          }          }
157    
158  }  }

Legend:
Removed from v.704  
changed lines
  Added in v.705

  ViewVC Help
Powered by ViewVC 1.1.20