long queryId(String sql) throws SQLException { TLongDoubleHashMap vals = new TLongDoubleHashMap(); NativeSql.on(destDb).query(sql, r -> { vals.put(r.getLong(1), r.getDouble(2)); return true; }); long exchangeId = -1; double delta = 0; for (long id : vals.keys()) { double dist = Math.abs(amount - vals.get(id)); if (exchangeId == -1 || dist < delta) { exchangeId = id; delta = dist; } } return exchangeId; }
private double causal(LongPair provider, CalcExchange e) { if (exchangeFactors == null) return 1d; TLongDoubleHashMap map = exchangeFactors.get(provider); if (map == null) return 1d; return map.get(e.exchangeId); // default is 1.0 }
private void loadFactors(Connection con, String table, TLongDoubleHashMap map) throws Exception { Statement statement = con.createStatement(); String query = "select id, conversion_factor from " + table; ResultSet set = statement.executeQuery(query); while (set.next()) { long id = set.getLong("id"); double factor = set.getDouble("conversion_factor"); map.put(id, factor); } statement.close(); set.close(); }
/** * Constructs an empty ConceptVector. */ public ConceptVector() { vector = new TLongDoubleHashMap(); }