Merge "[TestPrep5] Parameterize MainLogBuffer"
commit
07050549b1
|
@ -64,15 +64,6 @@ public abstract class MainLogBuffer extends FixedLogBuffer {
|
||||||
// The size of the n-grams logged. E.g. N_GRAM_SIZE = 2 means to sample bigrams.
|
// The size of the n-grams logged. E.g. N_GRAM_SIZE = 2 means to sample bigrams.
|
||||||
public static final int N_GRAM_SIZE = 2;
|
public static final int N_GRAM_SIZE = 2;
|
||||||
|
|
||||||
// Whether all words should be recorded, leaving unsampled word between bigrams. Useful for
|
|
||||||
// testing.
|
|
||||||
/* package for test */ static final boolean IS_LOGGING_EVERYTHING = false
|
|
||||||
&& ProductionFlag.IS_EXPERIMENTAL_DEBUG;
|
|
||||||
|
|
||||||
// The number of words between n-grams to omit from the log.
|
|
||||||
private static final int DEFAULT_NUMBER_OF_WORDS_BETWEEN_SAMPLES =
|
|
||||||
IS_LOGGING_EVERYTHING ? 0 : (DEBUG ? 2 : 18);
|
|
||||||
|
|
||||||
private Suggest mSuggest;
|
private Suggest mSuggest;
|
||||||
private boolean mIsStopping = false;
|
private boolean mIsStopping = false;
|
||||||
|
|
||||||
|
@ -82,11 +73,10 @@ public abstract class MainLogBuffer extends FixedLogBuffer {
|
||||||
// after a sample is taken.
|
// after a sample is taken.
|
||||||
/* package for test */ int mNumWordsUntilSafeToSample;
|
/* package for test */ int mNumWordsUntilSafeToSample;
|
||||||
|
|
||||||
public MainLogBuffer() {
|
public MainLogBuffer(final int wordsBetweenSamples, final int numInitialWordsToIgnore) {
|
||||||
super(N_GRAM_SIZE + DEFAULT_NUMBER_OF_WORDS_BETWEEN_SAMPLES);
|
super(N_GRAM_SIZE + wordsBetweenSamples);
|
||||||
mNumWordsBetweenNGrams = DEFAULT_NUMBER_OF_WORDS_BETWEEN_SAMPLES;
|
mNumWordsBetweenNGrams = wordsBetweenSamples;
|
||||||
final Random random = new Random();
|
mNumWordsUntilSafeToSample = DEBUG ? 0 : numInitialWordsToIgnore;
|
||||||
mNumWordsUntilSafeToSample = DEBUG ? 0 : random.nextInt(mNumWordsBetweenNGrams + 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSuggest(final Suggest suggest) {
|
public void setSuggest(final Suggest suggest) {
|
||||||
|
@ -119,7 +109,7 @@ public abstract class MainLogBuffer extends FixedLogBuffer {
|
||||||
*/
|
*/
|
||||||
private boolean isSafeNGram(final ArrayList<LogUnit> logUnits, final int minNGramSize) {
|
private boolean isSafeNGram(final ArrayList<LogUnit> logUnits, final int minNGramSize) {
|
||||||
// Bypass privacy checks when debugging.
|
// Bypass privacy checks when debugging.
|
||||||
if (IS_LOGGING_EVERYTHING) {
|
if (ResearchLogger.IS_LOGGING_EVERYTHING) {
|
||||||
if (mIsStopping) {
|
if (mIsStopping) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,6 +88,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Random;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -132,13 +133,21 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
|
||||||
private static final String USER_RECORDING_FILENAME_SUFFIX = ".txt";
|
private static final String USER_RECORDING_FILENAME_SUFFIX = ".txt";
|
||||||
private static final SimpleDateFormat TIMESTAMP_DATEFORMAT =
|
private static final SimpleDateFormat TIMESTAMP_DATEFORMAT =
|
||||||
new SimpleDateFormat("yyyyMMddHHmmssS", Locale.US);
|
new SimpleDateFormat("yyyyMMddHHmmssS", Locale.US);
|
||||||
|
// Whether all words should be recorded, leaving unsampled word between bigrams. Useful for
|
||||||
|
// testing.
|
||||||
|
/* package for test */ static final boolean IS_LOGGING_EVERYTHING = false
|
||||||
|
&& ProductionFlag.IS_EXPERIMENTAL_DEBUG;
|
||||||
|
// The number of words between n-grams to omit from the log.
|
||||||
|
private static final int NUMBER_OF_WORDS_BETWEEN_SAMPLES =
|
||||||
|
IS_LOGGING_EVERYTHING ? 0 : (DEBUG ? 2 : 18);
|
||||||
|
|
||||||
// Whether to show an indicator on the screen that logging is on. Currently a very small red
|
// Whether to show an indicator on the screen that logging is on. Currently a very small red
|
||||||
// dot in the lower right hand corner. Most users should not notice it.
|
// dot in the lower right hand corner. Most users should not notice it.
|
||||||
private static final boolean IS_SHOWING_INDICATOR = true;
|
private static final boolean IS_SHOWING_INDICATOR = true;
|
||||||
// Change the default indicator to something very visible. Currently two red vertical bars on
|
// Change the default indicator to something very visible. Currently two red vertical bars on
|
||||||
// either side of they keyboard.
|
// either side of they keyboard.
|
||||||
private static final boolean IS_SHOWING_INDICATOR_CLEARLY = false ||
|
private static final boolean IS_SHOWING_INDICATOR_CLEARLY = false ||
|
||||||
(MainLogBuffer.IS_LOGGING_EVERYTHING && ProductionFlag.IS_EXPERIMENTAL_DEBUG);
|
(IS_LOGGING_EVERYTHING && ProductionFlag.IS_EXPERIMENTAL_DEBUG);
|
||||||
// FEEDBACK_WORD_BUFFER_SIZE should add 1 because it must also hold the feedback LogUnit itself.
|
// FEEDBACK_WORD_BUFFER_SIZE should add 1 because it must also hold the feedback LogUnit itself.
|
||||||
public static final int FEEDBACK_WORD_BUFFER_SIZE = (Integer.MAX_VALUE - 1) + 1;
|
public static final int FEEDBACK_WORD_BUFFER_SIZE = (Integer.MAX_VALUE - 1) + 1;
|
||||||
|
|
||||||
|
@ -464,11 +473,12 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
|
||||||
}
|
}
|
||||||
if (mMainLogBuffer == null) {
|
if (mMainLogBuffer == null) {
|
||||||
mMainResearchLog = new ResearchLog(createLogFile(mFilesDir), mLatinIME);
|
mMainResearchLog = new ResearchLog(createLogFile(mFilesDir), mLatinIME);
|
||||||
mMainLogBuffer = new MainLogBuffer() {
|
final int numWordsToIgnore = new Random().nextInt(NUMBER_OF_WORDS_BETWEEN_SAMPLES + 1);
|
||||||
|
mMainLogBuffer = new MainLogBuffer(NUMBER_OF_WORDS_BETWEEN_SAMPLES, numWordsToIgnore) {
|
||||||
@Override
|
@Override
|
||||||
protected void publish(final ArrayList<LogUnit> logUnits,
|
protected void publish(final ArrayList<LogUnit> logUnits,
|
||||||
boolean canIncludePrivateData) {
|
boolean canIncludePrivateData) {
|
||||||
canIncludePrivateData |= MainLogBuffer.IS_LOGGING_EVERYTHING;
|
canIncludePrivateData |= IS_LOGGING_EVERYTHING;
|
||||||
final int length = logUnits.size();
|
final int length = logUnits.size();
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
final LogUnit logUnit = logUnits.get(i);
|
final LogUnit logUnit = logUnits.get(i);
|
||||||
|
@ -1190,7 +1200,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
|
||||||
Integer.toHexString(editorInfo.inputType),
|
Integer.toHexString(editorInfo.inputType),
|
||||||
Integer.toHexString(editorInfo.imeOptions), editorInfo.fieldId,
|
Integer.toHexString(editorInfo.imeOptions), editorInfo.fieldId,
|
||||||
Build.DISPLAY, Build.MODEL, prefs, versionCode, versionName,
|
Build.DISPLAY, Build.MODEL, prefs, versionCode, versionName,
|
||||||
OUTPUT_FORMAT_VERSION, MainLogBuffer.IS_LOGGING_EVERYTHING,
|
OUTPUT_FORMAT_VERSION, IS_LOGGING_EVERYTHING,
|
||||||
ProductionFlag.IS_EXPERIMENTAL_DEBUG);
|
ProductionFlag.IS_EXPERIMENTAL_DEBUG);
|
||||||
} catch (NameNotFoundException e) {
|
} catch (NameNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
Loading…
Reference in New Issue