コード例 #1
0
  public void requestPersonalization(HashMap<String, Object> payload) {
    String url, result;
    int endPos;

    // Communication with Emma's server
    List<NewsArticle> tempList = null;
    if (rankingOption == 1 || rankingOption == 3) {
      url =
          Util.loadConfigAssets(mApp, Constants.CONFIG_NEWS_PROPERTIES)
              .getProperty(Constants.CONFIG_PERSONALIZATION_MULTIBANDIT_LEARNING);
      result = HttpController.getHttpPostResponse(url, payload, null, 0);
      NewsArticleVector.setList1(NewsArticleVector.fromJson(result, false));
      tempList = NewsArticleVector.getList1();
    }
    // Communication with William's server
    if (rankingOption == 2 || rankingOption == 3) {
      url =
          Util.loadConfigAssets(mApp, Constants.CONFIG_NEWS_PROPERTIES)
              .getProperty(Constants.CONFIG_PERSONALIZATION_LEARNING_FROM_ADVISE);
      result = HttpController.getHttpPostResponse(url, payload, null, 0);
      NewsArticleVector.setList2(NewsArticleVector.fromJson(result, false));
      tempList = NewsArticleVector.getList2();
    }

    if (rankingOption == 3) {
      tempList = NewsArticleVector.mergeLists();
    }
    endPos = tempList.size();
    NewsArticleVector.sortNews(tempList);
    NewsArticleVector.setIsRecommendedBy(tempList);
    NewsArticleVector.increaseEndPosBatch(endPos);

    sendRefreshNewsEvent();
  }
コード例 #2
0
 public HashMap<String, String> createPersonalizationRequest() {
   HashMap<String, String> map = new HashMap<>();
   map.put("news", Util.toJson(NewsArticleVector.getInstance().getRemaining()));
   map.put("user_info", Util.toJson(userProfile));
   map.put("num_articles", "" + NewsArticleVector.getBatchArticlesToShow());
   map.put("device_id", deviceId);
   return map;
 }
コード例 #3
0
  public void sendFeedback(String list1, String list2) {
    HashMap<String, Object> payload = new HashMap();
    payload.put("user_info", Util.toJson(userProfile));
    payload.put("device_id", deviceId);

    String url;
    // Emma's server
    if (list1 != null) {
      payload.put("news_feedback", list1);
      url =
          Util.loadConfigAssets(mApp, Constants.CONFIG_NEWS_PROPERTIES)
              .getProperty(Constants.CONFIG_FEEDBACK_MULTIBANDIT_LEARNING);
      HttpController.getHttpPostResponse(url, payload, null, 0);
    }

    // William's server
    if (list2 != null) {
      payload.put("news_feedback", list2);
      url =
          Util.loadConfigAssets(mApp, Constants.CONFIG_NEWS_PROPERTIES)
              .getProperty(Constants.CONFIG_FEEDBACK_LEARNING_FROM_ADVISE);
      HttpController.getHttpPostResponse(url, payload, null, 0);
    }
  }
コード例 #4
0
  private ReaderController() {
    bIsConnected = new NetworkUtil(mApp).hasConnectivity();
    ImgLruCacher.purgeDiskCache();

    trd.start();
    mDataHandler = new DataHandler(trd.getLooper());

    mInflator = (LayoutInflater) mApp.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mCs = new CookieStore(mApp);

    mConfig = new Config();
    mConfig.loadConfig();

    mSettings = new Settings();
    mShareHelper = new ShareHelper();

    mNewsHandler = new QueryNewsHandler();
    mapDrawNewsItem = new HashMap<>();

    newsSize =
        Integer.valueOf(
            Util.loadConfigAssets(mApp, "news_config.properties")
                .getProperty("CONFIG_NUM_ARTICLES"));
  }
コード例 #5
0
 public ArrayList applyFilter(ArrayList list, boolean clone) {
   synchronized (list) {
     if (clone) {
       list = Util.cloneList(list);
     }
     if (filters != null && list != null && !filters.isEmpty() && !list.isEmpty()) {
       Iterator<NewsArticle> it = list.iterator();
       elements:
       while (it.hasNext()) {
         NewsArticle item = it.next();
         for (FilterVO filter : filters) {
           if (filter.getAttribute().equals(Constants.ARTICLE_SCORE)
               || filter.getAttribute().equals(Constants.ARTICLE_RAW_SCORE_MAP)) {
             double value = Double.valueOf(filter.getValue());
             double attribute = (Double) convertAttribute(filter.getAttribute(), item);
             if (filter.getOperator().equals(Constants.FILTER_EQUALS_TO) && attribute != value) {
               it.remove();
               continue elements;
             } else if (filter.getOperator().equals(Constants.FILTER_HIGHER_THAN)
                 && attribute <= value) {
               it.remove();
               continue elements;
             } else if (filter.getOperator().equals(Constants.FILTER_LOWER_THAN)
                 && attribute >= value) {
               it.remove();
               continue elements;
             }
           } else if (filter.getAttribute().equals(Constants.ARTICLE_INDEX)) {
             int value = Integer.valueOf(filter.getValue());
             int attribute = (Integer) convertAttribute(filter.getAttribute(), item);
             if (filter.getOperator().equals(Constants.FILTER_EQUALS_TO) && attribute != value) {
               it.remove();
               continue elements;
             } else if (filter.getOperator().equals(Constants.FILTER_HIGHER_THAN)
                 && attribute <= value) {
               it.remove();
               continue elements;
             } else if (filter.getOperator().equals(Constants.FILTER_LOWER_THAN)
                 && attribute >= value) {
               it.remove();
               continue elements;
             }
           } else {
             String attribute = (String) convertAttribute(filter.getAttribute(), item);
             if (filter.getOperator().equals(Constants.FILTER_EQUALS_TO)
                 && attribute.equalsIgnoreCase(filter.getValue()) == false) {
               it.remove();
               continue elements;
             } else if (filter.getOperator().equals(Constants.FILTER_CONTAINS_STRING)
                 && attribute.contains(filter.getValue()) == false) {
               it.remove();
               continue elements;
             }
           }
         }
       }
     }
     isApplyFilter = false;
     return list;
   }
 }