/[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 705 by torben, Tue May 4 03:48:37 2010 UTC revision 949 by torben, Mon Jul 5 06:17:05 2010 UTC
# Line 4  import java.io.IOException; Line 4  import java.io.IOException;
4  import java.io.PrintWriter;  import java.io.PrintWriter;
5  import java.net.InetSocketAddress;  import java.net.InetSocketAddress;
6  import java.util.ArrayList;  import java.util.ArrayList;
 import java.util.Collections;  
7  import java.util.Date;  import java.util.Date;
8  import java.util.Locale;  import java.util.Locale;
9    import java.util.concurrent.TimeUnit;
10  import java.util.logging.Logger;  import java.util.logging.Logger;
11    
12  import javax.servlet.ServletException;  import javax.servlet.ServletException;
# Line 25  import com.gc.android.market.api.model.M Line 25  import com.gc.android.market.api.model.M
25  public class ShowStats extends HttpServlet {  public class ShowStats extends HttpServlet {
26          private static final long serialVersionUID = 1L;          private static final long serialVersionUID = 1L;
27    
28          final int TIMEOUT = 30*60;          static final int MAXCOMMENTS = 50;
29            static final int TIMEOUT = 30*60;
30            
31          static final Logger log = Logger.getLogger(ShowStats.class.getName());          static final Logger log = Logger.getLogger(ShowStats.class.getName());
32    
33          String login;          String login;
# Line 48  public class ShowStats extends HttpServl Line 50  public class ShowStats extends HttpServl
50                  }                  }
51          }          }
52    
53            @Override
54            public void destroy() {
55                    super.destroy();
56                    
57                    memcache.shutdown(3, TimeUnit.SECONDS);
58                    memcache = null;
59            }
60    
61          protected String doLookup(String query) throws IOException {          protected String doLookup(String query) throws IOException {
62                                    
63    
64                  String key = "marketstats:" + query;                  String key = "marketstats:" + query.replace(' ', '_');
65                  String response = (String) memcache.get(key);                  String response = (String) memcache.get(key);
66    
67                  if (response == null) {                  if (response == null) {
# Line 64  public class ShowStats extends HttpServl Line 74  public class ShowStats extends HttpServl
74                  return response;                  return response;
75          }          }
76                    
77          private void loadComments(String appId, MarketSession session, String locale, ArrayList<CommentBean> commentBeans) {                      private void loadComments(String appId, MarketSession session, ArrayList<CommentBean> commentBeans) {          
78                  CommentCallback commentsCb = new CommentCallback();                  CommentCallback commentsCb = new CommentCallback();
79                  commentsCb.setList( commentBeans );                  commentsCb.setList( commentBeans );
80    
81                  commentsCb.setLocale( locale );                  session.setLocale( Locale.ROOT );
82                  session.setLocale( new Locale(locale) );                  
83                                    
84                                    
85                  int start = 0;                  int start = 0;
# Line 78  public class ShowStats extends HttpServl Line 88  public class ShowStats extends HttpServl
88                          if (start > 0)                                                    if (start > 0)                          
89                                  count = Math.min(10, commentsCb.getEntryCount() );                                  count = Math.min(10, commentsCb.getEntryCount() );
90                                                    
91                          //log.warning("count=" + count + " start=" + start + " " + locale);                          //log.warning("count=" + count + " start=" + start + " entryCount=" + commentsCb.getEntryCount() );
92                          CommentsRequest commentsRequest = CommentsRequest.newBuilder()                          CommentsRequest commentsRequest = CommentsRequest.newBuilder()
93                          .setAppId(appId)                          .setAppId(appId)
94                          .setStartIndex(start)                          .setStartIndex(start)
# Line 89  public class ShowStats extends HttpServl Line 99  public class ShowStats extends HttpServl
99                          session.flush();                          session.flush();
100                          start +=10;                          start +=10;
101                                                    
102                          if (start >= 20)                          if (start >= MAXCOMMENTS)
103                                  break; //emergency brake                                  break; //emergency brake
104                                                    
105                  } while ( start < commentsCb.getEntryCount() );                  } while ( start < commentsCb.getEntryCount() );
# Line 125  public class ShowStats extends HttpServl Line 135  public class ShowStats extends HttpServl
135                                    
136                  if (appId != null) {                  if (appId != null) {
137    
138                          loadComments(appId, session, "da", commentBeans);                          loadComments(appId, session, commentBeans);
                         loadComments(appId, session, "en", commentBeans);  
           
                         Collections.sort(commentBeans);  
139                    
140                          sb.append("-----------------------------------------------------------------\n");                          sb.append("-----------------------------------------------------------------\n");
141                          for (CommentBean c : commentBeans) {                          for (CommentBean c : commentBeans) {
142                                  sb.append("User: " + c.author + " ("  + c.locale + ")\n");                                  sb.append("User: " + c.author + "\n");
143                                  sb.append("Rating: " + c.rating + "\n");                                  sb.append("Rating: " + c.rating + "\n");
144                                  sb.append("Time: " + new Date(c.time).toString() + "\n");                                  sb.append("Time: " + new Date(c.time).toString() + "\n");
145                                  sb.append( c.text + "\n");                                  sb.append( c.text + "\n");
# Line 141  public class ShowStats extends HttpServl Line 148  public class ShowStats extends HttpServl
148                          }                          }
149                          sb.append("Comments: " + commentBeans.size() + "\n");                          sb.append("Comments: " + commentBeans.size() + "\n");
150                  }                  }
151                  sb.append("Cache.Timeout=" + TIMEOUT/60 + " minutes");                            sb.append("<!--Cache.Timeout=" + TIMEOUT/60 + " minutes-->\n");        
152    
153    
154                  return sb.toString();                  return sb.toString();

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

  ViewVC Help
Powered by ViewVC 1.1.20