Exemple #1
0
 public void calculateHistoryDistribution(Lottery.Type type) {
   try {
     listUniverse(type);
     List<KeyValuePair> all =
         KeyValuePair.parseArray(
             new JSONArray(
                 SimpleIOUtils.loadContent(
                     new FileInputStream(new File(mRoot, type + "_all_sums")))));
     HistoryDetail detail = HistoryDetail.calculate(new History(mRoot).load(type));
     List<KeyValuePair> historyResult = new ArrayList<>();
     for (int i = 0; i < all.size(); i++) {
       KeyValuePair pair = all.get(i);
       historyResult.add(
           new KeyValuePair(
               pair.getKey(), detail.getTotalCounts()[Integer.parseInt(pair.getKey())] * 10000));
     }
     SimpleIOUtils.saveToFile(
         new File(mRoot, type + "_history_sum"), KeyValuePair.toArray(historyResult).toString());
   } catch (JSONException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   } catch (DataSource.DataLoadingException e) {
     e.printStackTrace();
   }
 }
Exemple #2
0
 public void historySumDistribution(Lottery.Type type) {
   try {
     List<KeyValuePair> sum = new ArrayList<>();
     List<KeyValuePair> av = new ArrayList<>();
     List<KeyValuePair> av5 = new ArrayList<>();
     List<KeyValuePair> av10 = new ArrayList<>();
     List<HistoryItem> items = new History(mRoot).load(type);
     Collections.reverse(items);
     double total = 0;
     StringBuilder x = new StringBuilder();
     StringBuilder y = new StringBuilder();
     x.append("[");
     y.append("[");
     for (int i = items.size() * 4 / 5; i < items.size(); i++) {
       final HistoryItem item = items.get(i);
       sum.add(new KeyValuePair(item.getDateDisplay(), sum(item)));
       x.append(i);
       y.append(sum(item));
       if (i < items.size() - 1) {
         x.append(",");
         y.append(",");
       }
       total += sum(item);
       av.add(new KeyValuePair(item.getDateDisplay(), (float) (total / sum.size())));
       double total5 = 0;
       for (int j = i; j > i - 5; j--) {
         total5 += sum(items.get(j));
       }
       av5.add(new KeyValuePair(item.getDateDisplay(), (float) (total5 / 5)));
       double total10 = 0;
       for (int j = i; j > i - 10; j--) {
         total10 += sum(items.get(j));
       }
       av10.add(new KeyValuePair(item.getDateDisplay(), (float) (total10 / 10)));
     }
     x.append("];");
     y.append("];");
     SimpleIOUtils.saveToFile(new File(mRoot, type + "disx"), x.toString());
     SimpleIOUtils.saveToFile(new File(mRoot, type + "disy"), y.toString());
     SimpleIOUtils.saveToFile(
         new File(mRoot, type + "_sum_line"), KeyValuePair.toArray(sum).toString());
     SimpleIOUtils.saveToFile(
         new File(mRoot, type + "_sum_line_av"), KeyValuePair.toArray(av).toString());
     SimpleIOUtils.saveToFile(
         new File(mRoot, type + "_sum_line_av5"), KeyValuePair.toArray(av5).toString());
     SimpleIOUtils.saveToFile(
         new File(mRoot, type + "_sum_line_av10"), KeyValuePair.toArray(av10).toString());
   } catch (DataSource.DataLoadingException | IOException e) {
     e.printStackTrace();
   }
 }
Exemple #3
0
  public void listUniverse(Lottery.Type type) {
    System.out.println("get all started");
    List<SimpleLottery> all = getAllLotteries(type, true);
    System.out.println("get all finished");
    HashMap<Integer, List<SimpleLottery>> sumDistribution = new HashMap<>();
    for (int i = 0; i < all.size(); i++) {
      SimpleLottery lottery = all.get(i);
      int sum = sum(lottery);
      List<SimpleLottery> value = sumDistribution.get(sum);
      if (value == null) {
        value = new ArrayList<>();
        sumDistribution.put(sum, value);
      }
      value.add(lottery);
    }
    System.out.println("map finished");

    Set<Map.Entry<Integer, List<SimpleLottery>>> entries = sumDistribution.entrySet();
    List<KeyValuePair> pairs = new ArrayList<>();
    for (Map.Entry<Integer, List<SimpleLottery>> entry : entries) {
      pairs.add(new KeyValuePair(String.valueOf(entry.getKey()), entry.getValue().size()));
    }
    Collections.sort(
        pairs,
        new Comparator<KeyValuePair>() {
          @Override
          public int compare(KeyValuePair o1, KeyValuePair o2) {
            return Integer.parseInt(o1.getKey()) - Integer.parseInt(o2.getKey());
          }
        });
    try {
      SimpleIOUtils.saveToFile(
          new File(mRoot, type + "_all_sums"), KeyValuePair.toArray(pairs).toString());
    } catch (IOException e) {
      e.printStackTrace();
    }
  }