Commit e3ed3f15 authored by j.hoerdt's avatar j.hoerdt
Browse files

fix string compare bug, that did not manifest until now due to interning i think

also more refactors using sonarlint
parent f5b90e38
......@@ -213,7 +213,9 @@ public class Main {
private static Properties load_user_defined_properties_with_defaults(String fname, Properties defaults) throws Exception {
var config = new Properties(defaults);
config.load(new FileInputStream(fname));
try (var file = new FileInputStream(fname)) {
config.load(file);
}
return config;
}
......@@ -256,14 +258,14 @@ public class Main {
Map<String, Object> parameters = new Gson().fromJson(new FileReader(Main.config.getProperty("sensor_type_info")), new TypeToken <Map<String, Object>>() {}.getType());
try (var session = Main.driver.session(SessionConfig.forDatabase(Main.config.getProperty("database_name")))) {
session.writeTransaction(tx -> {
tx.run(
"unwind $sensor_type_info as sensor_type_info\n" +
"merge (n:SensorType {sensor_type: sensor_type_info.props.sensor_type})\n" +
"set n = sensor_type_info.props\n" +
"with n, sensor_type_info\n" +
"unwind sensor_type_info.measured_variables as measured_variable\n" +
"merge (m:MeasuredVariable {variable: measured_variable})\n" +
"merge (n)-[:MEASURES]->(m)\n",
tx.run("""
unwind $sensor_type_info as sensor_type_info
merge (n:SensorType {sensor_type: sensor_type_info.props.sensor_type})
set n = sensor_type_info.props
with n, sensor_type_info
unwind sensor_type_info.measured_variables as measured_variable
merge (m:MeasuredVariable {variable: measured_variable})
merge (n)-[:MEASURES]->(m)""",
parameters
);
return 42;
......
......@@ -19,13 +19,14 @@ import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.function.BiFunction;
import java.util.function.BinaryOperator;
import java.util.function.Predicate;
import java.util.logging.Level;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
class Sensor {
public Map<String, Object> properties = new HashMap<String, Object>();
public Map<String, Object> properties = new HashMap<>();
public void process(Session session, TransactionConfig transaction_config) throws Exception {
var rec = session.writeTransaction(tx -> {
......@@ -36,7 +37,7 @@ class Sensor {
String pid = rec.get("s.pid").asString();
properties.put("node_id", rec.get("id(s)").asObject());
if (pid == "null") {
if (pid.equals("null")) {
//no pid exists for this sensor
properties.put("pid", register_new_pid(rec));
put_pid_in_graphdb(session, transaction_config);
......@@ -193,7 +194,7 @@ class Sensor {
}
private Query get_creation_query() {
BiFunction<String, String, String> string_if_exists = (dependency, merge_string) -> (properties.get(dependency) != null ? merge_string : "");
BinaryOperator<String> string_if_exists = (dependency, merge_string) -> (properties.get(dependency) != null ? merge_string : "");
return new Query(
string_if_exists.apply("country",
......@@ -229,8 +230,8 @@ class Sensor {
string_if_exists.apply("city", "merge (measurement)-[:IN]->(city)") +
"set" +
" measurement.first_msg = case when $date > measurement.first_msg then measurement.first_msg else $date end," +
" measurement.last_msg = case when $date < measurement.last_msg then measurement.last_msg else $date end " +
"\tmeasurement.first_msg = case when $date > measurement.first_msg then measurement.first_msg else $date end," +
"\tmeasurement.last_msg = case when $date < measurement.last_msg then measurement.last_msg else $date end " +
"with s, type\n" +
"match (s)--(all_measurements:MeasurementLocation)" +
......@@ -281,11 +282,4 @@ class Sensor {
Main.glogger.log(Level.WARNING, "country_code is the key of the Country nodes and can't be null, which is what I got from reverse_geocode(" + latitude + ", " + longitude + ") what could not determine the country_code apparently. Not attaching a city consequently.");
}
}
/*
public static void main(String[] args) {
System.out.println(contains_indoor_string.test("2020-04-23_dht22_sensor_42841.csv"));
System.out.println(contains_indoor_string.test("2020-04-13_bme280_sensor_39365_indoor.csv"));
}
*/
}
\ No newline at end of file
......@@ -28,7 +28,7 @@ public class ReverseGeocoder {
private long request_timeout_millis;
private String nominatim_provider_uri;
private ConcurrentMap<Coordinates, Geodata> ram_cache = new ConcurrentHashMap<Coordinates, Geodata>();
private ConcurrentMap<Coordinates, Geodata> ram_cache = new ConcurrentHashMap<>();
private long last_request_milli_time_point = 0;
private ReverseGeocoder(String nominatim_provider_uri, long request_timeout_millis) {
......@@ -98,14 +98,13 @@ public class ReverseGeocoder {
}
private synchronized void uncached_request(String query_params, OutputStream response_output) throws Exception {
//throw new Exception("requesting from nominatim server is temporarily unavailable");
Util.sleep_until(last_request_milli_time_point + request_timeout_millis);
last_request_milli_time_point = System.currentTimeMillis();
Main.glogger.log(Level.INFO, "Requesting query " + query_params + " from osm server at time " + last_request_milli_time_point + "ms");
uncached_unlimited_request(query_params, response_output);
}
private void uncached_unlimited_request(String query_params, OutputStream response_output) throws MalformedURLException, IOException {
private void uncached_unlimited_request(String query_params, OutputStream response_output) throws IOException {
URLConnection connection = Util.create_timed_connection(nominatim_provider_uri + "reverse?email=j.hoerdt@stud.uni-goettingen.de&" + query_params);
Main.glogger.fine("opening uncached request stream to nominatim server for query " + query_params);
......@@ -116,13 +115,4 @@ public class ReverseGeocoder {
private static String make_query_string(double latitude, double longitude, int zoom) {
return "accept-language=en&zoom=" + zoom + "&lat=" + latitude + "&lon=" + longitude;
}
/*
public static void main(String[] args) throws Exception {
System.setProperty("http.agent", "Please/0.5");
ReverseGeocoder.osm_instance().reverse_geocode(13.52, 14.94);
ReverseGeocoder.osm_instance().reverse_geocode(37.21, 14.54);
ReverseGeocoder.osm_instance().reverse_geocode(13.37, 13.37);
}
*/
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment