Exemple #1
0
 private int sum(HistoryItem lottery) {
   int result = 0;
   final List<Integer> normals = lottery.getNormals();
   for (int i = 0; i < normals.size(); i++) {
     result += normals.get(i);
   }
   final List<Integer> specials = lottery.getSpecials();
   for (int i = 0; i < specials.size(); i++) {
     result += specials.get(i);
   }
   return result;
 }
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
 protected List<HistoryItem> loadFromLocal() throws DataSource.DataLoadingException {
   final File cacheFile = getCacheFile(mType);
   try {
     final String content = SimpleIOUtils.loadContent(new FileInputStream(cacheFile));
     final JSONArray jsonArray = new JSONArray(content);
     final List<HistoryItem> records = new ArrayList<>();
     for (int i = 0; i < jsonArray.length(); i++) {
       final JSONObject json = jsonArray.getJSONObject(i);
       final HistoryItem record = HistoryItem.fromJson(json);
       if (record != null) {
         records.add(record);
       }
     }
     if (records.isEmpty()) {
       return records;
     } else {
       final HistoryItem firstCache = records.get(0);
       final Date date = firstCache.getDate();
       final long deltaTime = System.currentTimeMillis() - date.getTime();
       int dayOfWeek = 3;
       if (mType == Lottery.Type.SSQ) {
         dayOfWeek = 4;
       }
       if (deltaTime < 2 * ONE_DAY
           // 周3是3.
           || (date.getDay() == dayOfWeek && deltaTime < 3 * ONE_DAY)) {
         //                        mDLTs = lotteryRecords;
         mHistoryCache.put(mType, records);
         return mHistoryCache.get(mType);
       }
       final List<HistoryItem> newer = mDataSource.getNewSince(records.get(0));
       records.addAll(0, newer);
       mHistoryCache.put(mType, records);
       saveToLocal();
       return records;
     }
   } catch (IOException | JSONException ignored) {
   }
   return null;
 }