Skip to content

Commit

Permalink
feat: #105 Add logic for determining content mastery
Browse files Browse the repository at this point in the history
  • Loading branch information
nya-elimu committed Feb 2, 2021
1 parent f978e9e commit 0f7c311
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public interface WordAssessmentEventDao {
@Query("SELECT * FROM WordAssessmentEvent ORDER BY time ASC")
List<WordAssessmentEvent> loadAllOrderedByTimeAsc();

@Query("SELECT * FROM WordAssessmentEvent ORDER BY time ASC")
Cursor loadAllOrderedByTimeAscAsCursor();
@Query("SELECT * FROM WordAssessmentEvent ORDER BY time DESC")
Cursor loadAllOrderedByTimeDesc();

@Query("SELECT * FROM WordAssessmentEvent WHERE wordId = :wordId ORDER BY time DESC")
Cursor loadAllOrderedByTimeDesc(Long wordId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import android.net.Uri;
import android.util.Log;

import java.util.List;

import ai.elimu.analytics.BuildConfig;
import ai.elimu.analytics.dao.WordAssessmentEventDao;
import ai.elimu.analytics.db.RoomDb;
Expand All @@ -17,10 +19,12 @@ public class WordAssessmentEventProvider extends ContentProvider {
private static final String AUTHORITY = BuildConfig.APPLICATION_ID + ".provider.word_assessment_event_provider";
private static final String TABLE = "events";
private static final int CODE_EVENTS = 1;
private static final int CODE_EVENTS_BY_WORD_ID = 2;

private static final UriMatcher MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
static {
MATCHER.addURI(AUTHORITY, TABLE, CODE_EVENTS);
MATCHER.addURI(AUTHORITY, TABLE + "/by-word-id/#", CODE_EVENTS_BY_WORD_ID);
}

@Override
Expand Down Expand Up @@ -55,7 +59,22 @@ public Cursor query(Uri uri, String[] projection, String selection, String[] sel
// Get the Room Cursor
RoomDb roomDb = RoomDb.getDatabase(context);
WordAssessmentEventDao wordAssessmentEventDao = roomDb.wordAssessmentEventDao();
Cursor cursor = wordAssessmentEventDao.loadAllOrderedByTimeAscAsCursor();
Cursor cursor = wordAssessmentEventDao.loadAllOrderedByTimeDesc();
Log.i(getClass().getName(), "cursor: " + cursor);
cursor.setNotificationUri(context.getContentResolver(), uri);
return cursor;
} else if (code == CODE_EVENTS_BY_WORD_ID) {
// Extract the Word ID from the URI
List<String> pathSegments = uri.getPathSegments();
Log.i(getClass().getName(), "pathSegments: " + pathSegments);
String wordIdAsString = pathSegments.get(2);
Long wordId = Long.valueOf(wordIdAsString);
Log.i(getClass().getName(), "wordId: " + wordId);

// Get the Room Cursor
RoomDb roomDb = RoomDb.getDatabase(context);
WordAssessmentEventDao wordAssessmentEventDao = roomDb.wordAssessmentEventDao();
Cursor cursor = wordAssessmentEventDao.loadAllOrderedByTimeDesc(wordId);
Log.i(getClass().getName(), "cursor: " + cursor);
cursor.setNotificationUri(context.getContentResolver(), uri);
return cursor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import ai.elimu.model.v2.gson.analytics.WordAssessmentEventGson;
import ai.elimu.model.v2.gson.analytics.WordLearningEventGson;
import ai.elimu.model.v2.gson.content.LetterGson;
import ai.elimu.model.v2.gson.content.WordGson;

public class EventProviderUtil {

Expand Down Expand Up @@ -210,4 +211,42 @@ public static List<WordAssessmentEventGson> getWordAssessmentEventGsons(Context

return wordAssessmentEventGsons;
}

public static List<WordAssessmentEventGson> getWordAssessmentEventGsonsByWord(WordGson wordGson, Context context, String analyticsApplicationId) {
Log.i(EventProviderUtil.class.getName(), "getWordAssessmentEventGsonsByWord");

List<WordAssessmentEventGson> wordAssessmentEventGsons = new ArrayList<>();

Uri wordAssessmentEventsUri = Uri.parse("content://" + analyticsApplicationId + ".provider.word_assessment_event_provider/events/by-word-id/" + wordGson.getId());
Log.i(EventProviderUtil.class.getName(), "wordAssessmentEventsUri: " + wordAssessmentEventsUri);
Cursor wordAssessmentEventsCursor = context.getContentResolver().query(wordAssessmentEventsUri, null, null, null, null);
Log.i(EventProviderUtil.class.getName(), "wordAssessmentEventsCursor: " + wordAssessmentEventsCursor);
if (wordAssessmentEventsCursor == null) {
Log.e(EventProviderUtil.class.getName(), "wordAssessmentEventsCursor == null");
Toast.makeText(context, "wordAssessmentEventsCursor == null", Toast.LENGTH_LONG).show();
} else {
Log.i(EventProviderUtil.class.getName(), "wordAssessmentEventsCursor.getCount(): " + wordAssessmentEventsCursor.getCount());
if (wordAssessmentEventsCursor.getCount() == 0) {
Log.e(EventProviderUtil.class.getName(), "wordAssessmentEventsCursor.getCount() == 0");
} else {
boolean isLast = false;
while (!isLast) {
wordAssessmentEventsCursor.moveToNext();

// Convert from Room to Gson
WordAssessmentEventGson wordAssessmentEventGson = CursorToWordAssessmentEventGsonConverter.getWordAssessmentEventGson(wordAssessmentEventsCursor);

wordAssessmentEventGsons.add(wordAssessmentEventGson);

isLast = wordAssessmentEventsCursor.isLast();
}

wordAssessmentEventsCursor.close();
Log.i(EventProviderUtil.class.getName(), "wordAssessmentEventsCursor.isClosed(): " + wordAssessmentEventsCursor.isClosed());
}
}
Log.i(EventProviderUtil.class.getName(), "wordAssessmentEventGsons.size(): " + wordAssessmentEventGsons.size());

return wordAssessmentEventGsons;
}
}

0 comments on commit 0f7c311

Please sign in to comment.