From bdbe279cecea7a16ef2a5c3b62622eb19e4b18bf Mon Sep 17 00:00:00 2001 From: Kurt Partridge Date: Thu, 9 Aug 2012 15:58:25 -0700 Subject: ResearchLog. Track time of log statements Log statements are now recorded with a timestamp. This is important for filtering out statements not part of words that are sampled when spaces are inserted automatically. multi-project commit with Change-Id: I68221a2528045d25632aef4bb716f92a4f4a56a4 Change-Id: I9f49c36391e1e1773b6d4876d7387c893024f87b --- .../com/android/inputmethod/research/LogUnit.java | 57 +++++++++++++++++++--- 1 file changed, 51 insertions(+), 6 deletions(-) (limited to 'java/src/com/android/inputmethod/research/LogUnit.java') diff --git a/java/src/com/android/inputmethod/research/LogUnit.java b/java/src/com/android/inputmethod/research/LogUnit.java index d8b3a29ff..5ce2d4883 100644 --- a/java/src/com/android/inputmethod/research/LogUnit.java +++ b/java/src/com/android/inputmethod/research/LogUnit.java @@ -18,7 +18,7 @@ package com.android.inputmethod.research; import com.android.inputmethod.latin.CollectionUtils; -import java.util.ArrayList; +import java.util.List; /** * A group of log statements related to each other. @@ -35,16 +35,39 @@ import java.util.ArrayList; * been published recently, or whether the LogUnit contains numbers, etc. */ /* package */ class LogUnit { - private final ArrayList mKeysList = CollectionUtils.newArrayList(); - private final ArrayList mValuesList = CollectionUtils.newArrayList(); - private final ArrayList mIsPotentiallyPrivate = CollectionUtils.newArrayList(); + private final List mKeysList; + private final List mValuesList; + // Assume that mTimeList is sorted in increasing order. Do not insert null values into + // mTimeList. + private final List mTimeList; + private final List mIsPotentiallyPrivate; private String mWord; private boolean mContainsDigit; + public LogUnit() { + mKeysList = CollectionUtils.newArrayList(); + mValuesList = CollectionUtils.newArrayList(); + mTimeList = CollectionUtils.newArrayList(); + mIsPotentiallyPrivate = CollectionUtils.newArrayList(); + } + + private LogUnit(final List keysList, final List valuesList, + final List timeList, final List isPotentiallyPrivate) { + mKeysList = keysList; + mValuesList = valuesList; + mTimeList = timeList; + mIsPotentiallyPrivate = isPotentiallyPrivate; + } + + /** + * Adds a new log statement. The time parameter in successive calls to this method must be + * monotonically increasing, or splitByTime() will not work. + */ public void addLogStatement(final String[] keys, final Object[] values, - final Boolean isPotentiallyPrivate) { + final long time, final boolean isPotentiallyPrivate) { mKeysList.add(keys); mValuesList.add(values); + mTimeList.add(time); mIsPotentiallyPrivate.add(isPotentiallyPrivate); } @@ -52,7 +75,7 @@ import java.util.ArrayList; final int size = mKeysList.size(); for (int i = 0; i < size; i++) { if (!mIsPotentiallyPrivate.get(i) || isIncludingPrivateData) { - researchLog.outputEvent(mKeysList.get(i), mValuesList.get(i)); + researchLog.outputEvent(mKeysList.get(i), mValuesList.get(i), mTimeList.get(i)); } } } @@ -80,4 +103,26 @@ import java.util.ArrayList; public boolean isEmpty() { return mKeysList.isEmpty(); } + + /** + * Split this logUnit, with all events before maxTime staying in the current logUnit, and all + * events after maxTime going into a new LogUnit that is returned. + */ + public LogUnit splitByTime(final long maxTime) { + // Assume that mTimeList is in sorted order. + final int length = mTimeList.size(); + for (int index = 0; index < length; index++) { + if (mTimeList.get(index) >= maxTime) { + final LogUnit newLogUnit = new LogUnit( + mKeysList.subList(index, length), + mValuesList.subList(index, length), + mTimeList.subList(index, length), + mIsPotentiallyPrivate.subList(index, length)); + newLogUnit.mWord = null; + newLogUnit.mContainsDigit = mContainsDigit; + return newLogUnit; + } + } + return new LogUnit(); + } } -- cgit v1.2.3-83-g751a