Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cached data stats #838

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions opensrp-app/src/main/java/org/smartregister/AllConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -596,5 +596,9 @@ public interface SyncInfo {
String INVALID_CLIENTS = "INValidClients";
String TASK_UNPROCESSED_EVENTS = "taskUnprocessedEvents";
String NULL_EVENT_SYNC_STATUS = "nullEventSyncStatus";
String CACHED_VACCINES = "cachedVaccines";
String CACHED_RECURRING_SERVICE_RECORDS = "cachedRecurringServiceRecords";
String CACHED_HEIGHTS = "cachedHeights";
String CACHED_WEIGHTS = "cachedWeights";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@

import static org.smartregister.AllConstants.DatabaseKeys.SYNC_STATUS;
import static org.smartregister.AllConstants.DatabaseKeys.VALIDATION_STATUS;
import static org.smartregister.AllConstants.SyncInfo.CACHED_HEIGHTS;
import static org.smartregister.AllConstants.SyncInfo.CACHED_RECURRING_SERVICE_RECORDS;
import static org.smartregister.AllConstants.SyncInfo.CACHED_VACCINES;
import static org.smartregister.AllConstants.SyncInfo.CACHED_WEIGHTS;
import static org.smartregister.AllConstants.SyncInfo.INVALID_CLIENTS;
import static org.smartregister.AllConstants.SyncInfo.INVALID_EVENTS;
import static org.smartregister.AllConstants.SyncInfo.NULL_EVENT_SYNC_STATUS;
Expand Down Expand Up @@ -54,14 +58,22 @@ public void fetchECSyncInfo() {
syncInfoMap.put(VALID_CLIENTS, 0);
syncInfoMap.put(INVALID_CLIENTS, 0);
syncInfoMap.put(TASK_UNPROCESSED_EVENTS, 0);
syncInfoMap.put(NULL_EVENT_SYNC_STATUS, 0);
syncInfoMap.put(CACHED_VACCINES, 0);
syncInfoMap.put(CACHED_RECURRING_SERVICE_RECORDS, 0);
syncInfoMap.put(CACHED_HEIGHTS, 0);
syncInfoMap.put(CACHED_WEIGHTS, 0);

String eventSyncSql = "select count(*), syncStatus from event group by syncStatus";
String clientSyncSql = "select count(*), syncStatus from client group by syncStatus";

String validatedEventsSql = "select count(*), validationStatus from event group by validationStatus";
String validatedClientsSql = "select count(*), validationStatus from client group by validationStatus";

String cachedVaccinesSql = "select count(*) vaccines WHERE sync_status != 'Synced'";
String cachedRecurringServiceRecordsSql = "select count(*) from recurring_service_records where WHERE sync_status != 'Synced'";
String cachedHeightsSql = "select count(*) from heights WHERE sync_status != 'Synced'";
String cachedWeightsSql = "select count(*) from weights WHERE sync_status != 'Synced'";

Cursor cursor = null;

try {
Expand Down Expand Up @@ -90,6 +102,34 @@ public void fetchECSyncInfo() {

cursor.close();


cursor = database.rawQuery(cachedVaccinesSql, new String[]{});
while (cursor.moveToNext()) {

}
cursor.close();


cursor = database.rawQuery(cachedRecurringServiceRecordsSql, new String[]{});
while (cursor.moveToNext()) {

}
cursor.close();


cursor = database.rawQuery(cachedHeightsSql, new String[]{});
while (cursor.moveToNext()) {

}
cursor.close();


cursor = database.rawQuery(cachedWeightsSql, new String[]{});
while (cursor.moveToNext()) {

}
cursor.close();

appExecutors.mainThread().execute(new Runnable() {
@Override
public void run() {
Expand Down Expand Up @@ -144,4 +184,5 @@ private void populateValidatedClientsInfo(Cursor cursor) {
syncInfoMap.put(INVALID_CLIENTS, cursor.getInt(0));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ public void testOnFetchRequestError() {
Mockito.verify(view).setLoadingState(false);
}

@Test
public void testOnFetchRequestErrorWithException() {
listPresenter.with(view);
Exception e = new Exception();
listPresenter.onFetchRequestError(e);
Mockito.verify(view).setLoadingState(false);
Mockito.verify(view).onFetchError(e);
}

@Test
public void testWithAttachesView() {
listPresenter.with(view);
Expand Down