Пример #1
0
 public int getHighestLevel(long threshold) {
   List<Status> filteredList =
       filterStatusListByTimeThreshold(sm.getCopyOfStatusList(), threshold);
   int maxLevel = Status.INFO;
   for (Status s : filteredList) {
     if (s.getLevel() > maxLevel) maxLevel = s.getLevel();
   }
   return maxLevel;
 }
Пример #2
0
  /**
   * Returns the difference between current battery level and ideal battery level. The return value
   * currentLevel - idealLevel
   *
   * @return percentage points of difference between current and ideal
   */
  public int levelGap() {
    int currentLevel = (int) Status.getLevel();
    int ideal = getIdealLevel();

    if (ideal < 0) {
      Log.i(TAG, "There seems to be no battery goal");
      return Integer.MAX_VALUE;
    }

    int gap = currentLevel - ideal;

    Log.i(TAG, "current (" + currentLevel + ") - ideal (" + ideal + ") = " + gap);

    return gap;
  }
Пример #3
0
  public boolean containsMatch(long threshold, int level, String regex) {
    List<Status> filteredList =
        filterStatusListByTimeThreshold(sm.getCopyOfStatusList(), threshold);
    Pattern p = Pattern.compile(regex);

    for (Status status : filteredList) {
      if (level != status.getLevel()) {
        continue;
      }
      String msg = status.getMessage();
      Matcher matcher = p.matcher(msg);
      if (matcher.lookingAt()) {
        return true;
      }
    }
    return false;
  }
Пример #4
0
  /**
   * Returns the allowed total units of work for the next horizon for the given unitName.
   *
   * @param unitName Name of the unit to calculate rate for
   * @param the number of allowed units for the next horizon.
   */
  public double suggestWorkLimit(String unitName) {
    if (mPlugged) return Double.NaN;

    if (!mDeadlineSet) return Double.NaN;

    if ((mModel == null) || (mStats == null)) return Double.NaN;

    if (!mModel.containsKey(unitName)) return Double.NaN;

    long curTime = Calendar.getInstance().getTimeInMillis();

    Calendar deadline = Calendar.getInstance();
    deadline.add(Calendar.MINUTE, mDeadline);
    long deadlineTime = deadline.getTimeInMillis();

    long left = ((deadlineTime - curTime) / ONE_MINUTE) / 1400;

    if (left < 0) {
      Log.i(TAG, "Deadline already missed.");
      return Double.NaN;
    }

    double curResource, interactive = 0.0;
    double mean, coef;

    for (String resource : mModel.keySet()) {
      if ((!mAdaptiveApps.contains(resource)) && (mStats.containsKey(resource))) {
        mean = mStats.get(resource);
        coef = mModel.get(resource);

        curResource = (mean * coef) / left;
        interactive += curResource;
      }
    }

    double available = Status.getLevel() - interactive;

    if (available < 0.0) available = 0.0;

    double workLoad = available / mModel.get(unitName);

    return workLoad;
  }