Android Open Source - SurgeTracker Aggregate






From Project

Back to project page SurgeTracker.

License

The source code is released under:

MIT License

If you think the Android project SurgeTracker listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.bklimt.surgetracker.model;
//from  ww  w  . ja v a  2 s. c o  m
import android.content.Context;
import android.text.format.DateFormat;

import com.bklimt.surgetracker.backbone.Model;

import java.util.Date;
import java.util.List;

/**
 * Created by klimt on 7/1/14.
 */
public class Aggregate extends Model {
    public Aggregate(List<Surge> surges, Date since) {
        if (surges.size() == 0) {
            throw new RuntimeException("Tried to aggregate 0 surges.");
        }

        int totalDuration = 0;
        int totalFrequency = 0;
        for (int i = 0; i < surges.size(); ++i) {
            totalDuration += surges.get(i).getDurationSeconds();
            totalFrequency += surges.get(i).getSecondsSincePrevious();
        }

        set("count", surges.size());
        set("since", since);
        set("averageDuration", (int)Math.round((double) totalDuration / surges.size()));
        set("averageTimeBetween", (int)Math.round((double) totalFrequency / surges.size()));
    }

    public int getCount() {
        return getInt("count");
    }

    public Date getSince() {
        return getDate("since");
    }

    public int getAverageDurationSeconds() {
        return getInt("averageDuration");
    }

    public int getAverageSecondsBetween() {
        return getInt("averageTimeBetween");
    }

    public String getAverageDurationString() {
        int durationSeconds = getAverageDurationSeconds();
        int durationMinutes = durationSeconds / 60;
        durationSeconds %= 60;
        return String.format("%02d:%02d", durationMinutes, durationSeconds);
    }

    public String getAverageTimeBetweenString() {
        int secondsBetween = getAverageSecondsBetween();
        int minutesBetween = secondsBetween / 60;
        secondsBetween %= 60;
        return String.format("%02d:%02d", minutesBetween, secondsBetween);
    }

    public String getSinceDay(Context context) {
        return DateFormat.getDateFormat(context).format(getSince());
    }

    public String getSinceTime(Context context) {
        return DateFormat.getTimeFormat(context).format(getSince());
    }
}




Java Source Code List

com.bklimt.surgetracker.ApplicationTest.java
com.bklimt.surgetracker.SurgeTrackerApplication.java
com.bklimt.surgetracker.TimerThread.java
com.bklimt.surgetracker.backbone.CollectionListener.java
com.bklimt.surgetracker.backbone.Collection.java
com.bklimt.surgetracker.backbone.ModelListener.java
com.bklimt.surgetracker.backbone.Model.java
com.bklimt.surgetracker.backbone.Visitor.java
com.bklimt.surgetracker.model.AggregateCollection.java
com.bklimt.surgetracker.model.Aggregate.java
com.bklimt.surgetracker.model.RootViewModel.java
com.bklimt.surgetracker.model.SurgeCollection.java
com.bklimt.surgetracker.model.SurgeParseObject.java
com.bklimt.surgetracker.model.Surge.java
com.bklimt.surgetracker.view.AggregateListAdapter.java
com.bklimt.surgetracker.view.AggregateListFragment.java
com.bklimt.surgetracker.view.MainActivity.java
com.bklimt.surgetracker.view.SurgeDeletionDialogFragment.java
com.bklimt.surgetracker.view.SurgeDurationDialogFragment.java
com.bklimt.surgetracker.view.SurgeGraphFragment.java
com.bklimt.surgetracker.view.SurgeListAdapter.java
com.bklimt.surgetracker.view.SurgeListFragment.java
com.bklimt.surgetracker.view.SurgeStartDialogFragment.java