use of org.eyeseetea.malariacare.data.database.model.Tab in project pictureapp by EyeSeeTea.
the class RelationsIdCsvDB method getTabsIdRelationsCsvDB.
static HashMap<Long, Tab> getTabsIdRelationsCsvDB(Context context) throws IOException {
HashMap<Long, Tab> tabFK = new HashMap<>();
List<Tab> tabs = Tab.getAllTabs();
List<Long> csvIds = new ArrayList<>();
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.TABS_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
String[] idToAdd;
while ((idToAdd = reader.readNext()) != null) {
csvIds.add(Long.parseLong(idToAdd[0]));
}
for (int i = 0; i < tabs.size() && i < csvIds.size(); i++) {
tabFK.put(csvIds.get(i), tabs.get(i));
}
return tabFK;
}
use of org.eyeseetea.malariacare.data.database.model.Tab in project pictureapp by EyeSeeTea.
the class UpdateDB method updateHeaders.
/**
* Method to update the old headers and add new ones from the csv. Use before inserting all
* tabs.
*
* @param context Needed to open the csv with the headers.
* @throws IOException If there is a problem opening the csv.
*/
public static void updateHeaders(Context context) throws IOException {
FileCsvs fileCsvs = new FileCsvs();
fileCsvs.saveCsvFromAssetsToFile(PopulateDB.HEADERS_CSV);
List<Header> headers = Header.getAllHeaders();
HashMap<Long, Tab> tabIds = RelationsIdCsvDB.getTabsIdRelationsCsvDB(context);
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.HEADERS_CSV)), SEPARATOR, QUOTECHAR);
String[] line;
int i = 0;
while ((line = reader.readNext()) != null) {
if (i < headers.size()) {
PopulateRow.populateHeader(line, tabIds, headers.get(i)).save();
} else {
PopulateRow.populateHeader(line, tabIds, null).insert();
}
i++;
}
}
use of org.eyeseetea.malariacare.data.database.model.Tab in project pictureapp by EyeSeeTea.
the class UpdateDB method updateTabs.
/**
* Method to update the old tabs and add new ones from the csv. Use before insert all programs.
*
* @param context Needed to open the csv with the tabs.
* @throws IOException If there is a problem opening the csv.
*/
public static void updateTabs(Context context) throws IOException {
FileCsvs fileCsvs = new FileCsvs();
fileCsvs.saveCsvFromAssetsToFile(PopulateDB.TABS_CSV);
List<Tab> tabs = Tab.getAllTabs();
HashMap<Long, Program> programIds = RelationsIdCsvDB.getProgramIdRelationCsvDB(context);
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.TABS_CSV)), SEPARATOR, QUOTECHAR);
String[] line;
int i = 0;
while ((line = reader.readNext()) != null) {
if (i < tabs.size()) {
PopulateRow.populateTab(line, programIds, tabs.get(i)).save();
} else {
PopulateRow.populateTab(line, programIds, null).insert();
}
i++;
}
}
use of org.eyeseetea.malariacare.data.database.model.Tab in project pictureapp by EyeSeeTea.
the class SurveyService method prepareSurveyInfo.
/**
* Prepares required data to show a survey completely (tabs and composite scores).
*/
private void prepareSurveyInfo() {
Log.d(TAG, "prepareSurveyInfo (Thread:" + Thread.currentThread().getId() + ")");
// Get composite scores for current program & register them (scores)
List<CompositeScore> compositeScores = new Select().from(CompositeScore.class).queryList();
ScoreRegister.registerCompositeScores(compositeScores);
// Get tabs for current program & register them (scores)
List<Tab> tabs = new Select().from(Tab.class).queryList();
ScoreRegister.registerTabScores(tabs);
// Since intents does NOT admit NON serializable as values we use Session instead
Session.putServiceValue(PREPARE_SURVEY_ACTION_COMPOSITE_SCORES, compositeScores);
Session.putServiceValue(PREPARE_SURVEY_ACTION_TABS, tabs);
// Returning result to anyone listening
Intent resultIntent = new Intent(PREPARE_SURVEY_ACTION);
LocalBroadcastManager.getInstance(this).sendBroadcast(resultIntent);
}
Aggregations