From 36ade586cf857c091a8276d63057d7bba22df902 Mon Sep 17 00:00:00 2001 From: Jo Grimstad Date: Sat, 27 May 2017 22:42:19 +0200 Subject: [PATCH] #48 Add VideoLearningEvent --- app/build.gradle | 6 +- app/src/main/AndroidManifest.xml | 4 +- .../analytics/dao/CustomDaoMaster.java | 12 +- .../literacyapp/analytics/dao/DaoMaster.java | 10 +- .../literacyapp/analytics/dao/DaoSession.java | 22 +- .../analytics/dao/UsageEventDao.java | 227 ------------------ .../analytics/dao/VideoLearningEventDao.java | 165 +++++++++++++ .../analytics/model/UsageEvent.java | 153 ------------ .../analytics/model/VideoLearningEvent.java | 99 ++++++++ .../receiver/LetterLearningEventReceiver.java | 5 - .../receiver/UsageEventReceiver.java | 132 ---------- .../receiver/VideoLearningEventReceiver.java | 84 +++++++ eventtracker/README.md | 6 +- eventtracker/build.gradle | 6 +- .../analytics/eventtracker/EventTracker.java | 23 +- 15 files changed, 383 insertions(+), 571 deletions(-) delete mode 100644 app/src/main/java/org/literacyapp/analytics/dao/UsageEventDao.java create mode 100644 app/src/main/java/org/literacyapp/analytics/dao/VideoLearningEventDao.java delete mode 100644 app/src/main/java/org/literacyapp/analytics/model/UsageEvent.java create mode 100644 app/src/main/java/org/literacyapp/analytics/model/VideoLearningEvent.java delete mode 100644 app/src/main/java/org/literacyapp/analytics/receiver/UsageEventReceiver.java create mode 100644 app/src/main/java/org/literacyapp/analytics/receiver/VideoLearningEventReceiver.java diff --git a/app/build.gradle b/app/build.gradle index d7f02a4..cf099bd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -15,8 +15,8 @@ android { applicationId "org.literacyapp.analytics" minSdkVersion 21 targetSdkVersion 23 - versionCode 1000007 - versionName "1.0.7" + versionCode 1000008 + versionName "1.0.8" } buildTypes { @@ -50,7 +50,7 @@ dependencies { testCompile 'junit:junit:4.12' - compile 'org.literacyapp:literacyapp-model:1.1.44' + compile 'org.literacyapp:literacyapp-model:1.1.45' compile 'com.android.support:appcompat-v7:23.4.0' compile 'commons-io:commons-io:2.5' compile 'org.greenrobot:greendao:3.2.0' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0c1e313..42bbd81 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -61,12 +61,12 @@ - + diff --git a/app/src/main/java/org/literacyapp/analytics/dao/CustomDaoMaster.java b/app/src/main/java/org/literacyapp/analytics/dao/CustomDaoMaster.java index c77673c..07de96b 100644 --- a/app/src/main/java/org/literacyapp/analytics/dao/CustomDaoMaster.java +++ b/app/src/main/java/org/literacyapp/analytics/dao/CustomDaoMaster.java @@ -26,15 +26,11 @@ public DevOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory public void onUpgrade(Database db, int oldVersion, int newVersion) { Log.i(getClass().getName(), "Upgrading schema from version " + oldVersion + " to " + newVersion); - if (oldVersion < 1000003) { + if (oldVersion < 1000008) { DbMigrationHelper.migrate(db, - UsageEventDao.class - ); - } - - if (oldVersion < 1000004) { - DbMigrationHelper.migrate(db, - UsageEventDao.class + LetterLearningEventDao.class, + NumberLearningEventDao.class, + VideoLearningEventDao.class ); } } diff --git a/app/src/main/java/org/literacyapp/analytics/dao/DaoMaster.java b/app/src/main/java/org/literacyapp/analytics/dao/DaoMaster.java index 2c8941c..6ed64e3 100644 --- a/app/src/main/java/org/literacyapp/analytics/dao/DaoMaster.java +++ b/app/src/main/java/org/literacyapp/analytics/dao/DaoMaster.java @@ -14,17 +14,17 @@ // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. /** - * Master of DAO (schema version 1000007): knows all DAOs. + * Master of DAO (schema version 1000008): knows all DAOs. */ public class DaoMaster extends AbstractDaoMaster { - public static final int SCHEMA_VERSION = 1000007; + public static final int SCHEMA_VERSION = 1000008; /** Creates underlying database table using DAOs. */ public static void createAllTables(Database db, boolean ifNotExists) { ApplicationOpenedEventDao.createTable(db, ifNotExists); LetterLearningEventDao.createTable(db, ifNotExists); NumberLearningEventDao.createTable(db, ifNotExists); - UsageEventDao.createTable(db, ifNotExists); + VideoLearningEventDao.createTable(db, ifNotExists); } /** Drops underlying database table using DAOs. */ @@ -32,7 +32,7 @@ public static void dropAllTables(Database db, boolean ifExists) { ApplicationOpenedEventDao.dropTable(db, ifExists); LetterLearningEventDao.dropTable(db, ifExists); NumberLearningEventDao.dropTable(db, ifExists); - UsageEventDao.dropTable(db, ifExists); + VideoLearningEventDao.dropTable(db, ifExists); } /** @@ -54,7 +54,7 @@ public DaoMaster(Database db) { registerDaoClass(ApplicationOpenedEventDao.class); registerDaoClass(LetterLearningEventDao.class); registerDaoClass(NumberLearningEventDao.class); - registerDaoClass(UsageEventDao.class); + registerDaoClass(VideoLearningEventDao.class); } public DaoSession newSession() { diff --git a/app/src/main/java/org/literacyapp/analytics/dao/DaoSession.java b/app/src/main/java/org/literacyapp/analytics/dao/DaoSession.java index ec0be02..8f0b887 100644 --- a/app/src/main/java/org/literacyapp/analytics/dao/DaoSession.java +++ b/app/src/main/java/org/literacyapp/analytics/dao/DaoSession.java @@ -11,12 +11,12 @@ import org.literacyapp.analytics.model.ApplicationOpenedEvent; import org.literacyapp.analytics.model.LetterLearningEvent; import org.literacyapp.analytics.model.NumberLearningEvent; -import org.literacyapp.analytics.model.UsageEvent; +import org.literacyapp.analytics.model.VideoLearningEvent; import org.literacyapp.analytics.dao.ApplicationOpenedEventDao; import org.literacyapp.analytics.dao.LetterLearningEventDao; import org.literacyapp.analytics.dao.NumberLearningEventDao; -import org.literacyapp.analytics.dao.UsageEventDao; +import org.literacyapp.analytics.dao.VideoLearningEventDao; // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. @@ -30,12 +30,12 @@ public class DaoSession extends AbstractDaoSession { private final DaoConfig applicationOpenedEventDaoConfig; private final DaoConfig letterLearningEventDaoConfig; private final DaoConfig numberLearningEventDaoConfig; - private final DaoConfig usageEventDaoConfig; + private final DaoConfig videoLearningEventDaoConfig; private final ApplicationOpenedEventDao applicationOpenedEventDao; private final LetterLearningEventDao letterLearningEventDao; private final NumberLearningEventDao numberLearningEventDao; - private final UsageEventDao usageEventDao; + private final VideoLearningEventDao videoLearningEventDao; public DaoSession(Database db, IdentityScopeType type, Map>, DaoConfig> daoConfigMap) { @@ -50,25 +50,25 @@ public DaoSession(Database db, IdentityScopeType type, Map { - - public static final String TABLENAME = "USAGE_EVENT"; - - /** - * Properties of entity UsageEvent.
- * Can be used for QueryBuilder and for referencing column names. - */ - public static class Properties { - public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property DeviceId = new Property(1, String.class, "deviceId", false, "DEVICE_ID"); - public final static Property Time = new Property(2, long.class, "time", false, "TIME"); - public final static Property PackageName = new Property(3, String.class, "packageName", false, "PACKAGE_NAME"); - public final static Property StudentId = new Property(4, String.class, "studentId", false, "STUDENT_ID"); - public final static Property LiteracySkill = new Property(5, String.class, "literacySkill", false, "LITERACY_SKILL"); - public final static Property NumeracySkill = new Property(6, String.class, "numeracySkill", false, "NUMERACY_SKILL"); - public final static Property Letter = new Property(7, String.class, "letter", false, "LETTER"); - public final static Property Number = new Property(8, Integer.class, "number", false, "NUMBER"); - public final static Property Word = new Property(9, String.class, "word", false, "WORD"); - } - - private final CalendarConverter timeConverter = new CalendarConverter(); - private final LiteracySkillConverter literacySkillConverter = new LiteracySkillConverter(); - private final NumeracySkillConverter numeracySkillConverter = new NumeracySkillConverter(); - - public UsageEventDao(DaoConfig config) { - super(config); - } - - public UsageEventDao(DaoConfig config, DaoSession daoSession) { - super(config, daoSession); - } - - /** Creates the underlying database table. */ - public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; - db.execSQL("CREATE TABLE " + constraint + "\"USAGE_EVENT\" (" + // - "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"DEVICE_ID\" TEXT NOT NULL ," + // 1: deviceId - "\"TIME\" INTEGER NOT NULL ," + // 2: time - "\"PACKAGE_NAME\" TEXT NOT NULL ," + // 3: packageName - "\"STUDENT_ID\" TEXT," + // 4: studentId - "\"LITERACY_SKILL\" TEXT," + // 5: literacySkill - "\"NUMERACY_SKILL\" TEXT," + // 6: numeracySkill - "\"LETTER\" TEXT," + // 7: letter - "\"NUMBER\" INTEGER," + // 8: number - "\"WORD\" TEXT);"); // 9: word - } - - /** Drops the underlying database table. */ - public static void dropTable(Database db, boolean ifExists) { - String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"USAGE_EVENT\""; - db.execSQL(sql); - } - - @Override - protected final void bindValues(DatabaseStatement stmt, UsageEvent entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - stmt.bindString(2, entity.getDeviceId()); - stmt.bindLong(3, timeConverter.convertToDatabaseValue(entity.getTime())); - stmt.bindString(4, entity.getPackageName()); - - String studentId = entity.getStudentId(); - if (studentId != null) { - stmt.bindString(5, studentId); - } - - LiteracySkill literacySkill = entity.getLiteracySkill(); - if (literacySkill != null) { - stmt.bindString(6, literacySkillConverter.convertToDatabaseValue(literacySkill)); - } - - NumeracySkill numeracySkill = entity.getNumeracySkill(); - if (numeracySkill != null) { - stmt.bindString(7, numeracySkillConverter.convertToDatabaseValue(numeracySkill)); - } - - String letter = entity.getLetter(); - if (letter != null) { - stmt.bindString(8, letter); - } - - Integer number = entity.getNumber(); - if (number != null) { - stmt.bindLong(9, number); - } - - String word = entity.getWord(); - if (word != null) { - stmt.bindString(10, word); - } - } - - @Override - protected final void bindValues(SQLiteStatement stmt, UsageEvent entity) { - stmt.clearBindings(); - - Long id = entity.getId(); - if (id != null) { - stmt.bindLong(1, id); - } - stmt.bindString(2, entity.getDeviceId()); - stmt.bindLong(3, timeConverter.convertToDatabaseValue(entity.getTime())); - stmt.bindString(4, entity.getPackageName()); - - String studentId = entity.getStudentId(); - if (studentId != null) { - stmt.bindString(5, studentId); - } - - LiteracySkill literacySkill = entity.getLiteracySkill(); - if (literacySkill != null) { - stmt.bindString(6, literacySkillConverter.convertToDatabaseValue(literacySkill)); - } - - NumeracySkill numeracySkill = entity.getNumeracySkill(); - if (numeracySkill != null) { - stmt.bindString(7, numeracySkillConverter.convertToDatabaseValue(numeracySkill)); - } - - String letter = entity.getLetter(); - if (letter != null) { - stmt.bindString(8, letter); - } - - Integer number = entity.getNumber(); - if (number != null) { - stmt.bindLong(9, number); - } - - String word = entity.getWord(); - if (word != null) { - stmt.bindString(10, word); - } - } - - @Override - public Long readKey(Cursor cursor, int offset) { - return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } - - @Override - public UsageEvent readEntity(Cursor cursor, int offset) { - UsageEvent entity = new UsageEvent( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.getString(offset + 1), // deviceId - timeConverter.convertToEntityProperty(cursor.getLong(offset + 2)), // time - cursor.getString(offset + 3), // packageName - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // studentId - cursor.isNull(offset + 5) ? null : literacySkillConverter.convertToEntityProperty(cursor.getString(offset + 5)), // literacySkill - cursor.isNull(offset + 6) ? null : numeracySkillConverter.convertToEntityProperty(cursor.getString(offset + 6)), // numeracySkill - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // letter - cursor.isNull(offset + 8) ? null : cursor.getInt(offset + 8), // number - cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9) // word - ); - return entity; - } - - @Override - public void readEntity(Cursor cursor, UsageEvent entity, int offset) { - entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setDeviceId(cursor.getString(offset + 1)); - entity.setTime(timeConverter.convertToEntityProperty(cursor.getLong(offset + 2))); - entity.setPackageName(cursor.getString(offset + 3)); - entity.setStudentId(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setLiteracySkill(cursor.isNull(offset + 5) ? null : literacySkillConverter.convertToEntityProperty(cursor.getString(offset + 5))); - entity.setNumeracySkill(cursor.isNull(offset + 6) ? null : numeracySkillConverter.convertToEntityProperty(cursor.getString(offset + 6))); - entity.setLetter(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); - entity.setNumber(cursor.isNull(offset + 8) ? null : cursor.getInt(offset + 8)); - entity.setWord(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); - } - - @Override - protected final Long updateKeyAfterInsert(UsageEvent entity, long rowId) { - entity.setId(rowId); - return rowId; - } - - @Override - public Long getKey(UsageEvent entity) { - if(entity != null) { - return entity.getId(); - } else { - return null; - } - } - - @Override - public boolean hasKey(UsageEvent entity) { - return entity.getId() != null; - } - - @Override - protected final boolean isEntityUpdateable() { - return true; - } - -} diff --git a/app/src/main/java/org/literacyapp/analytics/dao/VideoLearningEventDao.java b/app/src/main/java/org/literacyapp/analytics/dao/VideoLearningEventDao.java new file mode 100644 index 0000000..52dbc5c --- /dev/null +++ b/app/src/main/java/org/literacyapp/analytics/dao/VideoLearningEventDao.java @@ -0,0 +1,165 @@ +package org.literacyapp.analytics.dao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.internal.DaoConfig; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; + +import java.util.Calendar; +import org.literacyapp.analytics.dao.converter.CalendarConverter; + +import org.literacyapp.analytics.model.VideoLearningEvent; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. +/** + * DAO for table "VIDEO_LEARNING_EVENT". +*/ +public class VideoLearningEventDao extends AbstractDao { + + public static final String TABLENAME = "VIDEO_LEARNING_EVENT"; + + /** + * Properties of entity VideoLearningEvent.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property DeviceId = new Property(1, String.class, "deviceId", false, "DEVICE_ID"); + public final static Property Time = new Property(2, long.class, "time", false, "TIME"); + public final static Property PackageName = new Property(3, String.class, "packageName", false, "PACKAGE_NAME"); + public final static Property StudentId = new Property(4, String.class, "studentId", false, "STUDENT_ID"); + public final static Property VideoId = new Property(5, Long.class, "videoId", false, "VIDEO_ID"); + } + + private final CalendarConverter timeConverter = new CalendarConverter(); + + public VideoLearningEventDao(DaoConfig config) { + super(config); + } + + public VideoLearningEventDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** Creates the underlying database table. */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists? "IF NOT EXISTS ": ""; + db.execSQL("CREATE TABLE " + constraint + "\"VIDEO_LEARNING_EVENT\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"DEVICE_ID\" TEXT NOT NULL ," + // 1: deviceId + "\"TIME\" INTEGER NOT NULL ," + // 2: time + "\"PACKAGE_NAME\" TEXT NOT NULL ," + // 3: packageName + "\"STUDENT_ID\" TEXT," + // 4: studentId + "\"VIDEO_ID\" INTEGER);"); // 5: videoId + } + + /** Drops the underlying database table. */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"VIDEO_LEARNING_EVENT\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, VideoLearningEvent entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + stmt.bindString(2, entity.getDeviceId()); + stmt.bindLong(3, timeConverter.convertToDatabaseValue(entity.getTime())); + stmt.bindString(4, entity.getPackageName()); + + String studentId = entity.getStudentId(); + if (studentId != null) { + stmt.bindString(5, studentId); + } + + Long videoId = entity.getVideoId(); + if (videoId != null) { + stmt.bindLong(6, videoId); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, VideoLearningEvent entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + stmt.bindString(2, entity.getDeviceId()); + stmt.bindLong(3, timeConverter.convertToDatabaseValue(entity.getTime())); + stmt.bindString(4, entity.getPackageName()); + + String studentId = entity.getStudentId(); + if (studentId != null) { + stmt.bindString(5, studentId); + } + + Long videoId = entity.getVideoId(); + if (videoId != null) { + stmt.bindLong(6, videoId); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public VideoLearningEvent readEntity(Cursor cursor, int offset) { + VideoLearningEvent entity = new VideoLearningEvent( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.getString(offset + 1), // deviceId + timeConverter.convertToEntityProperty(cursor.getLong(offset + 2)), // time + cursor.getString(offset + 3), // packageName + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // studentId + cursor.isNull(offset + 5) ? null : cursor.getLong(offset + 5) // videoId + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, VideoLearningEvent entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setDeviceId(cursor.getString(offset + 1)); + entity.setTime(timeConverter.convertToEntityProperty(cursor.getLong(offset + 2))); + entity.setPackageName(cursor.getString(offset + 3)); + entity.setStudentId(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setVideoId(cursor.isNull(offset + 5) ? null : cursor.getLong(offset + 5)); + } + + @Override + protected final Long updateKeyAfterInsert(VideoLearningEvent entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(VideoLearningEvent entity) { + if(entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(VideoLearningEvent entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/org/literacyapp/analytics/model/UsageEvent.java b/app/src/main/java/org/literacyapp/analytics/model/UsageEvent.java deleted file mode 100644 index a97be04..0000000 --- a/app/src/main/java/org/literacyapp/analytics/model/UsageEvent.java +++ /dev/null @@ -1,153 +0,0 @@ -package org.literacyapp.analytics.model; - -import org.greenrobot.greendao.annotation.Convert; -import org.greenrobot.greendao.annotation.Entity; -import org.greenrobot.greendao.annotation.Id; -import org.greenrobot.greendao.annotation.NotNull; -import org.greenrobot.greendao.annotation.Generated; -import org.literacyapp.analytics.dao.converter.CalendarConverter; -import org.literacyapp.analytics.dao.converter.LiteracySkillConverter; -import org.literacyapp.analytics.dao.converter.NumeracySkillConverter; -import org.literacyapp.model.enums.content.LiteracySkill; -import org.literacyapp.model.enums.content.NumeracySkill; - -import java.util.Calendar; - -@Deprecated -@Entity -public class UsageEvent { - - @Id(autoincrement = true) - private Long id; - - // TODO: replace with Device? - @NotNull - private String deviceId; - - @NotNull - @Convert(converter = CalendarConverter.class, columnType = Long.class) - private Calendar time; - - // TODO: replace with Application? - @NotNull - private String packageName; - - // TODO: replace with Student? - private String studentId; - - @Convert(converter = LiteracySkillConverter.class, columnType = String.class) - private LiteracySkill literacySkill; - - @Convert(converter = NumeracySkillConverter.class, columnType = String.class) - private NumeracySkill numeracySkill; - - // TODO: replace with Letter? - private String letter; - - // TODO: replace with Number? - private Integer number; - - // TODO: replace with Word? - private String word; - - @Generated(hash = 1208691141) - public UsageEvent(Long id, @NotNull String deviceId, @NotNull Calendar time, - @NotNull String packageName, String studentId, - LiteracySkill literacySkill, NumeracySkill numeracySkill, String letter, - Integer number, String word) { - this.id = id; - this.deviceId = deviceId; - this.time = time; - this.packageName = packageName; - this.studentId = studentId; - this.literacySkill = literacySkill; - this.numeracySkill = numeracySkill; - this.letter = letter; - this.number = number; - this.word = word; - } - - @Generated(hash = 2057329387) - public UsageEvent() { - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getDeviceId() { - return deviceId; - } - - public void setDeviceId(String deviceId) { - this.deviceId = deviceId; - } - - public Calendar getTime() { - return time; - } - - public void setTime(Calendar time) { - this.time = time; - } - - public String getPackageName() { - return packageName; - } - - public void setPackageName(String packageName) { - this.packageName = packageName; - } - - public LiteracySkill getLiteracySkill() { - return literacySkill; - } - - public void setLiteracySkill(LiteracySkill literacySkill) { - this.literacySkill = literacySkill; - } - - public NumeracySkill getNumeracySkill() { - return numeracySkill; - } - - public void setNumeracySkill(NumeracySkill numeracySkill) { - this.numeracySkill = numeracySkill; - } - - public String getStudentId() { - return this.studentId; - } - - public void setStudentId(String studentId) { - this.studentId = studentId; - } - - public String getLetter() { - return this.letter; - } - - public void setLetter(String letter) { - this.letter = letter; - } - - public Integer getNumber() { - return this.number; - } - - public void setNumber(Integer number) { - this.number = number; - } - - public String getWord() { - return this.word; - } - - public void setWord(String word) { - this.word = word; - } -} diff --git a/app/src/main/java/org/literacyapp/analytics/model/VideoLearningEvent.java b/app/src/main/java/org/literacyapp/analytics/model/VideoLearningEvent.java new file mode 100644 index 0000000..4239706 --- /dev/null +++ b/app/src/main/java/org/literacyapp/analytics/model/VideoLearningEvent.java @@ -0,0 +1,99 @@ +package org.literacyapp.analytics.model; + +import org.greenrobot.greendao.annotation.Convert; +import org.greenrobot.greendao.annotation.Entity; +import org.greenrobot.greendao.annotation.Generated; +import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.NotNull; +import org.literacyapp.analytics.dao.converter.CalendarConverter; + +import java.util.Calendar; + +@Entity +public class VideoLearningEvent { + + @Id(autoincrement = true) + private Long id; + + // TODO: replace with Device? + @NotNull + private String deviceId; + + @NotNull + @Convert(converter = CalendarConverter.class, columnType = Long.class) + private Calendar time; + + // TODO: replace with Application? + @NotNull + private String packageName; + + // TODO: replace with Student? + private String studentId; + + // TODO: replace with Video? + private Long videoId; + + @Generated(hash = 1150493777) + public VideoLearningEvent(Long id, @NotNull String deviceId, + @NotNull Calendar time, @NotNull String packageName, String studentId, + Long videoId) { + this.id = id; + this.deviceId = deviceId; + this.time = time; + this.packageName = packageName; + this.studentId = studentId; + this.videoId = videoId; + } + + @Generated(hash = 934937089) + public VideoLearningEvent() { + } + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getDeviceId() { + return this.deviceId; + } + + public void setDeviceId(String deviceId) { + this.deviceId = deviceId; + } + + public Calendar getTime() { + return this.time; + } + + public void setTime(Calendar time) { + this.time = time; + } + + public String getPackageName() { + return this.packageName; + } + + public void setPackageName(String packageName) { + this.packageName = packageName; + } + + public String getStudentId() { + return this.studentId; + } + + public void setStudentId(String studentId) { + this.studentId = studentId; + } + + public Long getVideoId() { + return this.videoId; + } + + public void setVideoId(Long videoId) { + this.videoId = videoId; + } +} diff --git a/app/src/main/java/org/literacyapp/analytics/receiver/LetterLearningEventReceiver.java b/app/src/main/java/org/literacyapp/analytics/receiver/LetterLearningEventReceiver.java index 06a0fda..5016b74 100644 --- a/app/src/main/java/org/literacyapp/analytics/receiver/LetterLearningEventReceiver.java +++ b/app/src/main/java/org/literacyapp/analytics/receiver/LetterLearningEventReceiver.java @@ -13,13 +13,8 @@ import org.apache.commons.io.FileUtils; import org.literacyapp.analytics.AnalyticsApplication; import org.literacyapp.analytics.dao.LetterLearningEventDao; -import org.literacyapp.analytics.dao.UsageEventDao; import org.literacyapp.analytics.model.LetterLearningEvent; -import org.literacyapp.analytics.model.UsageEvent; import org.literacyapp.analytics.util.DeviceInfoHelper; -import org.literacyapp.analytics.util.VersionHelper; -import org.literacyapp.model.enums.content.LiteracySkill; -import org.literacyapp.model.enums.content.NumeracySkill; import java.io.File; import java.io.IOException; diff --git a/app/src/main/java/org/literacyapp/analytics/receiver/UsageEventReceiver.java b/app/src/main/java/org/literacyapp/analytics/receiver/UsageEventReceiver.java deleted file mode 100644 index ddc161f..0000000 --- a/app/src/main/java/org/literacyapp/analytics/receiver/UsageEventReceiver.java +++ /dev/null @@ -1,132 +0,0 @@ -package org.literacyapp.analytics.receiver; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.os.Environment; -import android.preference.PreferenceManager; -import android.text.TextUtils; -import android.text.format.DateFormat; -import android.util.Log; - -import org.apache.commons.io.FileUtils; -import org.literacyapp.analytics.AnalyticsApplication; -import org.literacyapp.analytics.dao.UsageEventDao; -import org.literacyapp.analytics.model.UsageEvent; -import org.literacyapp.analytics.util.DeviceInfoHelper; -import org.literacyapp.analytics.util.VersionHelper; -import org.literacyapp.model.enums.content.LiteracySkill; -import org.literacyapp.model.enums.content.NumeracySkill; - -import java.io.File; -import java.io.IOException; -import java.util.Calendar; - -@Deprecated -public class UsageEventReceiver extends BroadcastReceiver { - - @Override - public void onReceive(Context context, Intent intent) { - Log.i(getClass().getName(), "onReceive"); - - String packageName = intent.getStringExtra("packageName"); - Log.i(getClass().getName(), "packageName: " + packageName); - - LiteracySkill literacySkill = null; - String literacySkillExtra = intent.getStringExtra("literacySkill"); - Log.i(getClass().getName(), "literacySkillExtra: " + literacySkillExtra); - if (!TextUtils.isEmpty(literacySkillExtra)) { - literacySkill = LiteracySkill.valueOf(literacySkillExtra); - Log.i(getClass().getName(), "literacySkill: " + literacySkill); - } - - NumeracySkill numeracySkill = null; - String numeracySkillExtra = intent.getStringExtra("numeracySkill"); - Log.i(getClass().getName(), "numeracySkillExtra: " + numeracySkillExtra); - if (!TextUtils.isEmpty(numeracySkillExtra)) { - numeracySkill = NumeracySkill.valueOf(numeracySkillExtra); - Log.i(getClass().getName(), "numeracySkill: " + numeracySkill); - } - - String letter = null; - String letterExtra = intent.getStringExtra("letter"); - Log.i(getClass().getName(), "letterExtra: " + letterExtra); - if (!TextUtils.isEmpty(letterExtra)) { - letter = letterExtra; - Log.i(getClass().getName(), "letter: " + letter); - } - - Integer number = null; - Integer numberIntExtra = intent.getIntExtra("number", Integer.MIN_VALUE); - Log.i(getClass().getName(), "numberIntExtra: " + numberIntExtra); - if (numberIntExtra > Integer.MIN_VALUE) { - number = numberIntExtra; - Log.i(getClass().getName(), "number: " + number); - } - - String word = null; - String wordExtra = intent.getStringExtra("word"); - Log.i(getClass().getName(), "wordExtra: " + wordExtra); - if (!TextUtils.isEmpty(wordExtra)) { - word = wordExtra; - Log.i(getClass().getName(), "word: " + word); - } - - // TODO: add task type, task result, duration, etc. - - - SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); - String studentId = sharedPreferences.getString(StudentUpdatedReceiver.PREF_STUDENT_ID, null); - Log.i(getClass().getName(), "studentId: " + studentId); - - // Store in database - UsageEvent usageEvent = new UsageEvent(); - usageEvent.setTime(Calendar.getInstance()); - usageEvent.setDeviceId(DeviceInfoHelper.getDeviceId(context)); - usageEvent.setStudentId(studentId); - usageEvent.setPackageName(packageName); - usageEvent.setLiteracySkill(literacySkill); - usageEvent.setNumeracySkill(numeracySkill); - usageEvent.setLetter(letter); - usageEvent.setNumber(number); - usageEvent.setWord(word); - - AnalyticsApplication analyticsApplication = (AnalyticsApplication) context.getApplicationContext(); - UsageEventDao usageEventDao = analyticsApplication.getDaoSession().getUsageEventDao(); - long id = usageEventDao.insert(usageEvent); - Log.i(getClass().getName(), "UsageEvent saved in database with id " + id); - - - // Store in log file - // Expected format: id:1|deviceId:4113947bec18b7ad|time:1481916197273|packageName:org.literacyapp|literacySkill:LETTER_IDENTIFICATION|numeracySkill:null|letter:a|number:null|word:null - String logLine = "id:" + id - + "|deviceId:" + usageEvent.getDeviceId() - + "|studentId:" + usageEvent.getStudentId() - + "|time:" + usageEvent.getTime().getTimeInMillis() - + "|packageName:" + usageEvent.getPackageName() - + "|literacySkill:" + usageEvent.getLiteracySkill() - + "|numeracySkill:" + usageEvent.getNumeracySkill() - + "|letter:" + usageEvent.getLetter() - + "|number:" + usageEvent.getNumber() - + "|word:" + usageEvent.getWord() - + "\n"; - Log.i(getClass().getName(), "logLine: " + logLine); - - String logsPath = Environment.getExternalStorageDirectory() + "/.literacyapp-analytics/logs/" + VersionHelper.getAppVersionCode(context); - File logsDir = new File(logsPath); - if (!logsDir.exists()) { - logsDir.mkdirs(); - } - - String dateFormatted = (String) DateFormat.format("yyyy-MM-dd", Calendar.getInstance()); - String fileName = "usage_events_" + dateFormatted + ".log"; - File logFile = new File(logsDir, fileName); - Log.i(getClass().getName(), "logFile: " + logFile); - try { - FileUtils.writeStringToFile(logFile, logLine, "UTF-8", true); - } catch (IOException e) { - Log.e(getClass().getName(), null, e); - } - } -} diff --git a/app/src/main/java/org/literacyapp/analytics/receiver/VideoLearningEventReceiver.java b/app/src/main/java/org/literacyapp/analytics/receiver/VideoLearningEventReceiver.java new file mode 100644 index 0000000..6bf83ae --- /dev/null +++ b/app/src/main/java/org/literacyapp/analytics/receiver/VideoLearningEventReceiver.java @@ -0,0 +1,84 @@ +package org.literacyapp.analytics.receiver; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Environment; +import android.preference.PreferenceManager; +import android.text.TextUtils; +import android.text.format.DateFormat; +import android.util.Log; + +import org.apache.commons.io.FileUtils; +import org.literacyapp.analytics.AnalyticsApplication; +import org.literacyapp.analytics.dao.VideoLearningEventDao; +import org.literacyapp.analytics.model.VideoLearningEvent; +import org.literacyapp.analytics.util.DeviceInfoHelper; + +import java.io.File; +import java.io.IOException; +import java.util.Calendar; + +public class VideoLearningEventReceiver extends BroadcastReceiver { + + @Override + public void onReceive(Context context, Intent intent) { + Log.i(getClass().getName(), "onReceive"); + + String packageName = intent.getStringExtra("packageName"); + Log.i(getClass().getName(), "packageName: " + packageName); + + Long videoId = intent.getLongExtra("videoId", -1); + Log.i(getClass().getName(), "videoId: " + videoId); + + SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); + String studentId = sharedPreferences.getString(StudentUpdatedReceiver.PREF_STUDENT_ID, null); + Log.i(getClass().getName(), "studentId: " + studentId); + + // Store in database + VideoLearningEvent videoLearningEvent = new VideoLearningEvent(); + videoLearningEvent.setDeviceId(DeviceInfoHelper.getDeviceId(context)); + videoLearningEvent.setTime(Calendar.getInstance()); + videoLearningEvent.setPackageName(packageName); + videoLearningEvent.setStudentId(studentId); + videoLearningEvent.setVideoId(videoId); + + AnalyticsApplication analyticsApplication = (AnalyticsApplication) context.getApplicationContext(); + VideoLearningEventDao videoLearningEventDao = analyticsApplication.getDaoSession().getVideoLearningEventDao(); + long id = videoLearningEventDao.insert(videoLearningEvent); + Log.i(getClass().getName(), "VideoLearningEvent saved in database with id " + id); + + // Store in log file + // Expected format: id:1|deviceId:4113947bec18b7ad|time:1481916197273|packageName:org.literacyapp|studentId:4113947bec18b7ad_1|videoId:25 + String logLine = "id:" + id + + "|deviceId:" + videoLearningEvent.getDeviceId() + + "|time:" + videoLearningEvent.getTime().getTimeInMillis() + + "|packageName:" + videoLearningEvent.getPackageName() + + "|studentId:" + videoLearningEvent.getStudentId() + + "|videoId:" + videoLearningEvent.getVideoId() + + "\n"; + Log.i(getClass().getName(), "logLine: " + logLine); + + String logsPath = Environment.getExternalStorageDirectory() + "/.literacyapp-analytics/events/device_" + videoLearningEvent.getDeviceId(); + File logsDir = new File(logsPath); + Log.i(getClass().getName(), "logsDir: " + logsDir); + if (!logsDir.exists()) { + logsDir.mkdirs(); + } + + if (!TextUtils.isEmpty(videoLearningEvent.getStudentId())) { + // TODO: create one subfolder per student id (if not null)? + } + + String dateFormatted = (String) DateFormat.format("yyyy-MM-dd", Calendar.getInstance()); + String fileName = "video_learning_events_" + dateFormatted + ".log"; + File logFile = new File(logsDir, fileName); + Log.i(getClass().getName(), "logFile: " + logFile); + try { + FileUtils.writeStringToFile(logFile, logLine, "UTF-8", true); + } catch (IOException e) { + Log.e(getClass().getName(), null, e); + } + } +} diff --git a/eventtracker/README.md b/eventtracker/README.md index 4e5a6b0..dc8bdf3 100644 --- a/eventtracker/README.md +++ b/eventtracker/README.md @@ -17,16 +17,16 @@ Then, add the following dependencies: dependencies { ... - compile 'org.literacyapp.analytics:eventtracker:1.0.0' + compile 'org.literacyapp.analytics:eventtracker:1.0.2' } ``` ## Report Learning Activity To report learning activity, use one of the static methods provided by the EventTracker class: -EventTracker.reportUsageEvent(getApplicationContext(), LiteracySkill.LETTER_IDENTIFICATION, “a”); +EventTracker.reportLetterLearningEvent(getApplicationContext(), “a”); -Note that for the analytics data to be stored on the SD card, the Analytics application must be installed on the tablet. The log files will then appear under /sdcard/.literacyapp-analytics/logs +Note that for the analytics data to be stored on the SD card, the Analytics application must be installed on the tablet. The log files will then appear under /sdcard/.literacyapp-analytics/events ### Sample Application diff --git a/eventtracker/build.gradle b/eventtracker/build.gradle index f691cbe..da41f5f 100644 --- a/eventtracker/build.gradle +++ b/eventtracker/build.gradle @@ -7,8 +7,8 @@ android { defaultConfig { minSdkVersion 21 targetSdkVersion 23 - versionCode 1000001 - versionName "1.0.1" + versionCode 1000002 + versionName "1.0.2" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -33,6 +33,6 @@ dependencies { }) testCompile 'junit:junit:4.12' - compile 'org.literacyapp:literacyapp-model:1.1.44' + compile 'org.literacyapp:literacyapp-model:1.1.45' compile 'com.android.support:appcompat-v7:23.4.0' } diff --git a/eventtracker/src/main/java/org/literacyapp/analytics/eventtracker/EventTracker.java b/eventtracker/src/main/java/org/literacyapp/analytics/eventtracker/EventTracker.java index 48995ba..bfcb245 100644 --- a/eventtracker/src/main/java/org/literacyapp/analytics/eventtracker/EventTracker.java +++ b/eventtracker/src/main/java/org/literacyapp/analytics/eventtracker/EventTracker.java @@ -41,29 +41,14 @@ public static void reportNumberLearningEvent(Context context, Integer number) { context.sendBroadcast(intent); } - @Deprecated - public static void reportUsageEvent(Context context, LiteracySkill literacySkill, String letter) { - Log.i(EventTracker.class.getName(), "reportUsageEvent"); - - Intent intent = new Intent(); - intent.setPackage("org.literacyapp.analytics"); - intent.setAction("literacyapp.intent.action.USAGE_EVENT"); - intent.putExtra("packageName", context.getPackageName()); - intent.putExtra("literacySkill", literacySkill); - intent.putExtra("letter", letter); - context.sendBroadcast(intent); - } - - @Deprecated - public static void reportUsageEvent(Context context, NumeracySkill numeracySkill, Integer number) { - Log.i(EventTracker.class.getName(), "reportUsageEvent"); + public static void reportVideoLearningEvent(Context context, Long videoId) { + Log.i(EventTracker.class.getName(), "reportNumberLearningEvent"); Intent intent = new Intent(); intent.setPackage("org.literacyapp.analytics"); - intent.setAction("literacyapp.intent.action.USAGE_EVENT"); + intent.setAction("literacyapp.intent.action.VIDEO_LEARNING_EVENT"); intent.putExtra("packageName", context.getPackageName()); - intent.putExtra("numeracySkill", numeracySkill); - intent.putExtra("number", number); + intent.putExtra("videoId", videoId); context.sendBroadcast(intent); } }