public void setupDisplay() { if (characters != null) return; characters = new ArrayList<PlayerCharacter>(); CloseableIterator<PlayerCharacter> pcs = charactersFC.closeableIterator(); while (pcs.hasNext()) { characters.add(pcs.next()); } try { pcs.close(); } catch (SQLException e) { } }
public double getCurrentNoise(TitaniumDb helper) throws SQLException, AngryJulienException { Dao<NoiseEntry, Long> dao = helper.dao(NoiseEntry.class, Long.class); QueryBuilder<NoiseEntry, Long> qb = dao.queryBuilder(); long curTime = System.currentTimeMillis(); double weekAgo = 0.0, dayAgo = 0.0, hourAgo = 0.0; //// WEEK AGO int count = 0; qb.where() .eq(NoiseEntry.COLUMN_NAME_PARENT_ID, this.id) .and() .between( NoiseEntry.COLUMN_NAME_TIMESTAMP, curTime - TimeUtils.WEEK - TimeUtils.HOUR, curTime - TimeUtils.WEEK + TimeUtils.HOUR); CloseableIterator<NoiseEntry> it = qb.iterator(); while (it.hasNext()) { weekAgo += it.next().getNoise(); count++; } it.close(); if (count == 0) { weekAgo = -1.1; } else { weekAgo /= count; } /// DAY AGO count = 0; qb = dao.queryBuilder(); qb.where() .eq(NoiseEntry.COLUMN_NAME_PARENT_ID, this.id) .and() .between( NoiseEntry.COLUMN_NAME_TIMESTAMP, curTime - TimeUtils.DAY - TimeUtils.HOUR, curTime - TimeUtils.DAY + TimeUtils.HOUR); it = qb.iterator(); while (it.hasNext()) { dayAgo += it.next().getNoise(); count++; } it.close(); if (count == 0) { dayAgo = -1.1; } else { dayAgo /= count; } //// HOUR AGO count = 0; qb = dao.queryBuilder(); qb.where() .eq(NoiseEntry.COLUMN_NAME_PARENT_ID, this.id) .and() .between( NoiseEntry.COLUMN_NAME_TIMESTAMP, curTime - TimeUtils.HOUR - (5 * TimeUtils.MINUTE), curTime - TimeUtils.HOUR + (5 * TimeUtils.MINUTE)); it = qb.iterator(); while (it.hasNext()) { hourAgo += it.next().getNoise(); count++; } it.close(); if (count == 0) { hourAgo = -1.1; } else { hourAgo /= count; } double time = 0; count = 0; if (dayAgo != -1.1) { count++; time += dayAgo; } if (weekAgo != -1.1) { count++; time += weekAgo; } if (hourAgo != -1.1) { count++; time += hourAgo; } if (count > 0) { return time / count; } time = 0.0; count = 0; it = noiseEntries.closeableIterator(); while (it.hasNext()) { time += it.next().getNoise(); count++; } if (count > 0) return time / count; throw new AngryJulienException("I am so mad at this point b/c you ain't got anything"); }