Back to project page pinpoint-android.
The source code is released under:
MIT License
If you think the Android project pinpoint-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package co.islovely.pinpoint; /* w ww. j av a 2 s . c om*/ import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; public class TaskLog { private List<TaskLogEntry> taskLogEntries; private int homescreenId; public TaskLog(int homescreenId) { this.homescreenId = homescreenId; this.taskLogEntries = new ArrayList<TaskLogEntry>(); } public void addEntry(TaskLogEntry entry) { this.taskLogEntries.add(entry); } public long getAverageDuration() { if (!this.taskLogEntries.isEmpty()) { long sum = 0; for (TaskLogEntry entry : this.taskLogEntries) { sum += entry.getDuration(); } return sum / this.getTaskLogEntriesCount(); } return -1; } public int getCorrectTaskLogEntriesCount() { int count = 0; for (TaskLogEntry entry : this.taskLogEntries) { if (entry.wasCorrect()) { count++; } } return count; } public List<TaskLogEntry> getTaskLogEntries() { return new ArrayList<TaskLogEntry>(this.taskLogEntries); } public int getTaskLogEntriesCount() { return this.taskLogEntries.size(); } public double getSuccessQuota() { return 1.0 * this.getCorrectTaskLogEntriesCount() / this.getTaskLogEntriesCount(); } public JSONObject toJSONObject() { JSONObject jsonObject = new JSONObject(); JSONArray tasks = new JSONArray(); try { jsonObject.put("homescreen", this.homescreenId); for (TaskLogEntry taskLogEntry : this.taskLogEntries) { tasks.put(taskLogEntry.toJSON()); } jsonObject.put("tasks", tasks); } catch (JSONException exception) { Pinpoint.log("Could not create JSONObject from TaskLog."); } return jsonObject; } }