/** * 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; }
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; }
/** * 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; }