Ejemplo n.º 1
0
  /**
   * Obtain top callers by calls.
   *
   * @param activity caller activity
   * @param startBillingDay starting billing day
   * @return ArrayList with all calls made
   */
  private static ArrayList<CallStat> getTopCallersByCalls() {

    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((long) 1);
      } else {
        ContactValue contactValue = new ContactValue(contact, (long) 1);
        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(), String.valueOf(cv.getValue())));
      i++;
      if (i > 20) {
        break;
      }
    }
    return ret;
  }
Ejemplo n.º 2
0
  public PlanSummary process(ArrayList<Chargeable> data) {
    PlanSummary ret = new PlanSummary(this);
    ret.addPlanCall(
        new PlanChargeable(
            new ChargeableMessage(ChargeableMessage.MESSAGE_MONTH_FEE),
            monthFee,
            this.getCurrency()));
    int smsSent = 0;
    int secondsTotal = 0;
    for (Chargeable chargeable : data) {
      if (chargeable.getChargeableType() == Chargeable.CHARGEABLE_TYPE_CALL) {
        Call call = (Call) chargeable;

        if (call.getType() != Call.CALL_TYPE_SENT) {
          continue;
        }

        double callPrice = 0;

        if (call.getContact().getMsisdnType() == MsisdnType.UK_SPECIAL_ZER0) {
          callPrice = 0;
        } else {
          secondsTotal += call.getDuration();
          boolean insidePlan = secondsTotal <= maxSecondsMonth;
          if (!insidePlan) {
            long duration =
                (secondsTotal > maxSecondsMonth)
                        && (secondsTotal - call.getDuration() <= maxSecondsMonth)
                    ? secondsTotal - maxSecondsMonth
                    : call.getDuration();
            callPrice += initialPrice + (duration * pricePerSecond);
          }
        }
        ret.addPlanCall(new PlanChargeable(call, callPrice, this.getCurrency()));
      } else if (chargeable.getChargeableType() == Chargeable.CHARGEABLE_TYPE_SMS) {
        Sms sms = (Sms) chargeable;
        if (sms.getType() == Sms.SMS_TYPE_RECEIVED) {
          continue;
        }
        smsSent++;
        ret.addPlanCall(
            new PlanChargeable(
                chargeable, (smsSent > maxFreeSMS) ? smsPrice : 0, this.getCurrency()));
      }
    }
    return ret;
  }