示例#1
0
  /**
   * Obtain top callers by minutes
   *
   * @param activity caller activity
   * @param startBillingDay starting billing day
   * @return ArrayList with all calls made
   */
  private static ArrayList<CallStat> getTopCallersByMinutes() {

    LinkedList<ContactValue> data = new LinkedList<ContactValue>();

    for (Chargeable chargeable : calls) {
      Call call = (Call) chargeable;
      Contact contact = call.getContact();
      if (data.contains(contact)) {
        ContactValue contactValue = data.get(data.indexOf(contact));
        contactValue.incValue(call.getDuration());
      } else {
        ContactValue contactValue = new ContactValue(contact, call.getDuration());
        data.add(contactValue);
      }
    }

    Collections.sort(data);

    ArrayList<CallStat> ret = new ArrayList<CallStat>();
    int i = 0;
    for (ContactValue cv : data) {
      ret.add(
          new CallStat(
              cv.getContact().getContactName(), Formatter.formatDurationAsString(cv.getValue())));
      i++;
      if (i > 20) {
        break;
      }
    }
    return ret;
  }
示例#2
0
  /**
   * Obtain call statistics
   *
   * @param activity caller activity
   * @param startBillingDay starting billing day
   * @return ArrayList with all calls made
   */
  private static ArrayList<CallStat> getSummary(Activity activity) {

    long totalMissed = 0;
    long totalAnswered = 0;
    long totalInbound = 0;
    long totalOutbound = 0;
    long totalCalls = 0;

    long totalInboundSeconds = 0;
    long totalOutboundSeconds = 0;

    long shortestCallSeconds = -1;
    long longestCallSeconds = -1;
    long averageCallSeconds = 0;

    long callsToCountAverage = 0;

    for (Chargeable chargeable : calls) {
      Call call = (Call) chargeable;
      long duration = call.getDuration();
      totalCalls++;
      if (longestCallSeconds == -1 || duration > longestCallSeconds) {
        longestCallSeconds = duration;
      }
      if (duration > 0 && (shortestCallSeconds == -1 || duration < shortestCallSeconds)) {
        shortestCallSeconds = duration;
      }
      switch (call.getType()) {
        case Call.CALL_TYPE_RECEIVED:
          totalInbound++;
          totalAnswered++;
          totalInboundSeconds += duration;
          averageCallSeconds += duration;
          callsToCountAverage++;
          break;
        case Call.CALL_TYPE_RECEIVED_MISSED:
          totalInbound++;
          totalMissed++;
          break;
        case Call.CALL_TYPE_SENT:
          totalOutbound++;
          totalAnswered++;
          totalOutboundSeconds += duration;
          averageCallSeconds += duration;
          callsToCountAverage++;
          break;
        case Call.CALL_TYPE_SENT_MISSED:
          totalOutbound++;
          totalMissed++;
          break;
      }
    }

    if (callsToCountAverage > 0) {
      averageCallSeconds = averageCallSeconds / callsToCountAverage;
    }

    ArrayList<CallStat> ret = new ArrayList<CallStat>();
    ret.add(new CallStat(activity.getString(R.string.stats_missed_calls), "" + totalMissed));
    ret.add(new CallStat(activity.getString(R.string.stats_answered_calls), "" + totalAnswered));
    ret.add(new CallStat(activity.getString(R.string.stats_inbound_calls), "" + totalInbound));
    ret.add(new CallStat(activity.getString(R.string.stats_outbound_calls), "" + totalOutbound));
    ret.add(new CallStat(activity.getString(R.string.stats_total_calls), "" + calls.size()));

    ret.add(
        new CallStat(
            activity.getString(R.string.stats_inbound_seconds),
            Formatter.formatDurationAsString(totalInboundSeconds)));
    ret.add(
        new CallStat(
            activity.getString(R.string.stats_outbound_seconds),
            Formatter.formatDurationAsString(totalOutboundSeconds)));

    ret.add(
        new CallStat(
            activity.getString(R.string.stats_shortest_call),
            Formatter.formatDurationAsString(shortestCallSeconds)));
    ret.add(
        new CallStat(
            activity.getString(R.string.stats_longest_call),
            Formatter.formatDurationAsString(longestCallSeconds)));
    ret.add(
        new CallStat(
            activity.getString(R.string.stats_average_call),
            Formatter.formatDurationAsString(averageCallSeconds)));
    return ret;
  }