Search in sources :

Example 46 with CSVReader

use of com.opencsv.CSVReader in project pictureapp by EyeSeeTea.

the class UpdateDB method updateQuestionOption.

public static void updateQuestionOption(Context context, boolean updateCSV) throws IOException {
    if (updateCSV) {
        FileCsvs fileCsvs = new FileCsvs();
        fileCsvs.saveCsvFromAssetsToFile(PopulateDB.QUESTION_OPTIONS_CSV);
    }
    List<QuestionOption> questionOptions = QuestionOption.listAll();
    HashMap<Long, Match> matchIds = RelationsIdCsvDB.getMatchIdRelationCsvDB(context);
    HashMap<Long, Question> questionsIds = RelationsIdCsvDB.getQuestionIdRelationCsvDB(context);
    HashMap<Long, Option> optionsIds = RelationsIdCsvDB.getOptionIdRelationCsvDB(context);
    CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.QUESTION_OPTIONS_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
    String[] line;
    int i = 0;
    while ((line = reader.readNext()) != null) {
        if (i < questionOptions.size()) {
            PopulateRow.populateQuestionOption(line, questionsIds, optionsIds, matchIds, questionOptions.get(i)).save();
        } else {
            QuestionOption questionOption = PopulateRow.populateQuestionOption(line, questionsIds, optionsIds, matchIds, null);
            questionOption.insert();
        }
        i++;
    }
}
Also used : QuestionOption(org.eyeseetea.malariacare.data.database.model.QuestionOption) InputStreamReader(java.io.InputStreamReader) CSVReader(com.opencsv.CSVReader) PopulateRow.populateMatch(org.eyeseetea.malariacare.data.database.utils.populatedb.PopulateRow.populateMatch) Match(org.eyeseetea.malariacare.data.database.model.Match) TreatmentMatch(org.eyeseetea.malariacare.data.database.model.TreatmentMatch) Question(org.eyeseetea.malariacare.data.database.model.Question) QuestionOption(org.eyeseetea.malariacare.data.database.model.QuestionOption) Option(org.eyeseetea.malariacare.data.database.model.Option)

Example 47 with CSVReader

use of com.opencsv.CSVReader in project pictureapp by EyeSeeTea.

the class UpdateDB method updateQuestionRelation.

public static void updateQuestionRelation(Context context) throws IOException {
    FileCsvs fileCsvs = new FileCsvs();
    fileCsvs.saveCsvFromAssetsToFile(PopulateDB.QUESTION_RELATIONS_CSV);
    List<QuestionRelation> questionRelations = QuestionRelation.listAll();
    HashMap<Long, Question> questionIds = RelationsIdCsvDB.getQuestionIdRelationCsvDB(context);
    CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.QUESTION_RELATIONS_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
    String[] line;
    int i = 0;
    while ((line = reader.readNext()) != null) {
        boolean added = false;
        if (i < questionRelations.size()) {
            populateQuestionRelation(line, questionIds, questionRelations.get(i)).save();
        } else {
            QuestionRelation questionRelation = populateQuestionRelation(line, questionIds, null);
            questionRelation.insert();
        }
        i++;
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) CSVReader(com.opencsv.CSVReader) PopulateRow.populateQuestionRelation(org.eyeseetea.malariacare.data.database.utils.populatedb.PopulateRow.populateQuestionRelation) QuestionRelation(org.eyeseetea.malariacare.data.database.model.QuestionRelation) Question(org.eyeseetea.malariacare.data.database.model.Question)

Example 48 with CSVReader

use of com.opencsv.CSVReader in project pictureapp by EyeSeeTea.

the class RelationsIdCsvDB method getQuestionRelationIdRelationCsvDB.

static HashMap<Long, QuestionRelation> getQuestionRelationIdRelationCsvDB(Context context) throws IOException {
    HashMap<Long, QuestionRelation> questionRelationsFK = new HashMap<>();
    List<QuestionRelation> questionRelations = QuestionRelation.listAll();
    List<Long> csvIds = new ArrayList<>();
    CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.QUESTION_RELATIONS_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
    String[] idToAdd;
    while ((idToAdd = reader.readNext()) != null) {
        csvIds.add(Long.parseLong(idToAdd[0]));
    }
    for (int i = 0; i < questionRelations.size() && i < csvIds.size(); i++) {
        questionRelationsFK.put(csvIds.get(i), questionRelations.get(i));
    }
    return questionRelationsFK;
}
Also used : InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) CSVReader(com.opencsv.CSVReader) QuestionRelation(org.eyeseetea.malariacare.data.database.model.QuestionRelation) ArrayList(java.util.ArrayList)

Example 49 with CSVReader

use of com.opencsv.CSVReader in project pictureapp by EyeSeeTea.

the class RelationsIdCsvDB method getAnswerFKRelationCsvDB.

static HashMap<Long, Answer> getAnswerFKRelationCsvDB(Context context) throws IOException {
    HashMap<Long, Answer> answerFK = new HashMap<>();
    List<Answer> answers = Answer.getAllAnswers();
    List<Long> csvIds = new ArrayList<>();
    CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.ANSWERS_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
    String[] idToAdd;
    while ((idToAdd = reader.readNext()) != null) {
        csvIds.add(Long.parseLong(idToAdd[0]));
    }
    for (int i = 0; i < answers.size() && i < csvIds.size(); i++) {
        answerFK.put(csvIds.get(i), answers.get(i));
    }
    return answerFK;
}
Also used : Answer(org.eyeseetea.malariacare.data.database.model.Answer) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) CSVReader(com.opencsv.CSVReader) ArrayList(java.util.ArrayList)

Example 50 with CSVReader

use of com.opencsv.CSVReader in project pictureapp by EyeSeeTea.

the class RelationsIdCsvDB method getMatchIdRelationCsvDB.

static HashMap<Long, Match> getMatchIdRelationCsvDB(Context context) throws IOException {
    HashMap<Long, Match> matchesFK = new HashMap<>();
    List<Match> matches = Match.listAll();
    List<Long> csvIds = new ArrayList<>();
    CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.MATCHES)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
    String[] idToAdd;
    while ((idToAdd = reader.readNext()) != null) {
        csvIds.add(Long.parseLong(idToAdd[0]));
    }
    for (int i = 0; i < matches.size() && i < csvIds.size(); i++) {
        matchesFK.put(csvIds.get(i), matches.get(i));
    }
    return matchesFK;
}
Also used : InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) CSVReader(com.opencsv.CSVReader) ArrayList(java.util.ArrayList) Match(org.eyeseetea.malariacare.data.database.model.Match)

Aggregations

CSVReader (com.opencsv.CSVReader)57 InputStreamReader (java.io.InputStreamReader)50 ArrayList (java.util.ArrayList)23 HashMap (java.util.HashMap)18 Question (org.eyeseetea.malariacare.data.database.model.Question)11 QuestionOption (org.eyeseetea.malariacare.data.database.model.QuestionOption)9 Match (org.eyeseetea.malariacare.data.database.model.Match)8 Option (org.eyeseetea.malariacare.data.database.model.Option)8 Answer (org.eyeseetea.malariacare.data.database.model.Answer)6 OptionAttribute (org.eyeseetea.malariacare.data.database.model.OptionAttribute)6 TreatmentMatch (org.eyeseetea.malariacare.data.database.model.TreatmentMatch)6 FileReader (java.io.FileReader)5 IOException (java.io.IOException)5 QuestionRelation (org.eyeseetea.malariacare.data.database.model.QuestionRelation)5 Treatment (org.eyeseetea.malariacare.data.database.model.Treatment)5 Drug (org.eyeseetea.malariacare.data.database.model.Drug)4 Organisation (org.eyeseetea.malariacare.data.database.model.Organisation)4 StringKey (org.eyeseetea.malariacare.data.database.model.StringKey)4 PopulateRow.populateMatch (org.eyeseetea.malariacare.data.database.utils.populatedb.PopulateRow.populateMatch)4 File (java.io.File)3