Example #1
0
  private static void assignTypes(
      Collection<MemoryQuestion> questions, Map<String, NameInfo> nameMap) throws IOException {
    // assign categories. we have to assemble all the terms we want to look up together for
    // efficient lookup..
    // we'll put them in map
    Map<String, NameInfo> map = new LinkedHashMap<String, NameInfo>();
    for (MemoryQuestion mq : questions) {
      String name = mq.correctAnswer;
      String cname = name.toLowerCase().trim();
      map.put(cname, nameMap.get(cname));
    }

    // now we do a bulk type lookup...
    NameTypes.readTypes(map);

    // ... and copy the types back into the mq's
    for (MemoryQuestion mq : questions)
      try {
        if (mq != null && mq.correctAnswer != null) {
          NameInfo ni = nameMap.get(mq.correctAnswer.toLowerCase().trim().replaceAll(" ", "_"));
          if (ni != null) mq.clue.clueStats.answerCategory = ni.type;
        }
      } catch (Exception e) {
        Util.print_exception("Error reading types for question: " + mq, e, log);
      }
  }
Example #2
0
 public static synchronized boolean anyCodesAvailable()
     throws IOException, GeneralSecurityException, ClassNotFoundException {
   try {
     List<UserStats> users = readUsersFile();
     return (users.size() < codes.size());
   } catch (Exception e) {
     Util.print_exception(e, log);
   }
   return false;
 }
Example #3
0
  static {
    // read all the codes at bootup -- the codes file is not encrypted and never changes
    CODES_FILE =
        System.getProperty("user.home")
            + java.io.File.separator
            + "results"
            + java.io.File.separator
            + "codes.txt";
    USERS_FILE =
        System.getProperty("user.home")
            + File.separator
            + "results"
            + File.separator
            + "users"; // remember to change cryptoutils if you change this

    try {
      // read the codes statically at startup
      codes = Util.getLinesFromFile(CODES_FILE, true);
    } catch (Exception e) {
      Util.print_exception("\n\n\n\nSEVERE WARNING IN BOOTUP\n\n\n, codes file not read", e, log);
      codes = new ArrayList<String>(); // dummy list of codes (empty)
    }
  }
Example #4
0
 /** writes out csv stats as an encrypted file in RESULTS_DIR/<userid>/filename */
 public void logStats(String filename, boolean nullClues) {
   Indexer.IndexStats stats = archive.getIndexStats();
   StringBuilder statsLog = new StringBuilder();
   Pair<String, String> indexStats = Util.fieldsToCSV(stats, true);
   Pair<String, String> addressBookStats = Util.fieldsToCSV(archive.addressBook.getStats(), true);
   Pair<String, String> studyStats = Util.fieldsToCSV(stats, true);
   Pair<String, String> archiveStats = Util.fieldsToCSV(archive.stats, true);
   statsLog.append(
       "STUDYSTATS-1: "
           + studyStats.getFirst()
           + indexStats.getFirst()
           + addressBookStats.getFirst()
           + archiveStats.getFirst()
           + "\n");
   statsLog.append(
       "STUDYSTATS-2: "
           + studyStats.getSecond()
           + indexStats.getSecond()
           + addressBookStats.getSecond()
           + archiveStats.getSecond()
           + "\n");
   int idx = 1;
   for (MemoryQuestion mq : this.getQuestions()) {
     if (nullClues) mq.clue.clue = null;
     Pair<String, String> p = Util.fieldsToCSV(mq.clue.clueStats, true);
     Pair<String, String> p1 = Util.fieldsToCSV(mq.stats, true);
     if (idx == 1)
       statsLog.append(
           "QUESTIONSTATS-header: "
               + p.getFirst()
               + ','
               + p1.getFirst()
               + "correct answer, user answer, user answer before hint, clue"
               + "\n");
     //			statsLog.append("QUESTIONSTATS-2: " + p.getSecond()  + ',' + p1.getSecond() +
     // mq.correctAnswer + "," + mq.userAnswer + "," + mq.userAnswerBeforeHint + "," +
     // mq.clue.clue.replaceAll(",", " ") + "\n");
     statsLog.append(
         "QUESTIONSTATS-2: "
             + p.getSecond()
             + ','
             + p1.getSecond()
             + mq.correctAnswer
             + ","
             + mq.userAnswer
             + ","
             + mq.userAnswerBeforeHint
             + "\n");
     idx = idx + 1;
   }
   String RESULTS_DIR =
       System.getProperty("user.home")
           + File.separator
           + "results"
           + File.separator
           + this.stats.userid;
   new File(RESULTS_DIR).mkdirs();
   String file = RESULTS_DIR + File.separator + filename;
   try {
     CryptoUtils.writeEncryptedBytes(statsLog.toString().getBytes("UTF-8"), file);
   } catch (UnsupportedEncodingException e) {
     Util.print_exception(e, log);
   } catch (Exception e) {
     Util.print_exception("NOC ERROR: encryption failed!", e, log);
   }
   log.info(statsLog);
 }