Commit 239d97de authored by Luna Riegel's avatar Luna Riegel
Browse files

Style: Log total time needed for check execution

parent ed20282c
package de.hft.stuttgart.citydoctor2.utils;
import java.text.ChoiceFormat;
public final class TimeFormatter {
private TimeFormatter(){}
private static final String LESS_THAN_A_SECOND =
Localization.getText("TimeFormatter.lessThanASecond");
private static final ChoiceFormat SECONDS =
new ChoiceFormat(
new double[]{1, 2},
new String[]{Localization.getText("TimeFormatter.oneSecond"),
Localization.getText("TimeFormatter.seconds")}
);
private static final ChoiceFormat MINUTES =
new ChoiceFormat(
new double[]{1, 2},
new String[]{Localization.getText("TimeFormatter.oneMinute"),
Localization.getText("TimeFormatter.minutes")}
);
private static final ChoiceFormat HOURS =
new ChoiceFormat(
new double[] {1, 2},
new String[]{Localization.getText("TimeFormatter.oneHour"),
Localization.getText("TimeFormatter.hours")}
);
/**
* Formats a time measurement in milliseconds as a localized String representation.
*
* <p>
* The String representation will return the time as a rounded down integer of the biggest fitting TimeUnit
* (seconds, minutes or hours), returning "< 1 second" for times under a second.
* <p/>
* @param millis
* @return A localized String representation of the timespan
*/
public static String format(long millis) {
if (millis < 1000) {
return LESS_THAN_A_SECOND;
}else if (millis < 60_000) {
long seconds = millis / 1000;
String pattern = SECONDS.format(seconds);
return pattern.replace("{0}", Long.toString(seconds));
}else if (millis < 3_600_000){
long minutes = millis / 60_000;
String pattern = MINUTES.format(minutes);
return pattern.replace("{0}", Long.toString(minutes));
} else {
long hours = millis / 3_600_000;
String pattern = HOURS.format(hours);
return pattern.replace("{0}", Long.toString(hours));
}
}
}
\ No newline at end of file
...@@ -34,7 +34,7 @@ CheckDialog.title=Check Configuration ...@@ -34,7 +34,7 @@ CheckDialog.title=Check Configuration
CheckDialog.validationConfiguration=Validation Configuration CheckDialog.validationConfiguration=Validation Configuration
CheckDialog.xmlReportsOption=Create XML reports CheckDialog.xmlReportsOption=Create XML reports
Checker.checkFeature=Checking feature: {} Checker.checkFeature=Checking feature: {}
Checker.checksFinished=Finished executing checks Checker.checksFinished=Finished executing checks. Total time: {0}
Checker.dbStillUnresponsive=Checker still unable to load some CityObjects from database! Checker.dbStillUnresponsive=Checker still unable to load some CityObjects from database!
Checker.dbUnresponsive=Checker could not load some CityObjects from database! Checker.dbUnresponsive=Checker could not load some CityObjects from database!
Checker.executeCheck=Executing check: {} Checker.executeCheck=Executing check: {}
...@@ -180,6 +180,13 @@ OpenFileDialog.select=Select CityGML file ...@@ -180,6 +180,13 @@ OpenFileDialog.select=Select CityGML file
OpenFileDialog.selectBtn=Select OpenFileDialog.selectBtn=Select
OpenFileDialog.settingsPane=Parser Preferences OpenFileDialog.settingsPane=Parser Preferences
OpenFileDialog.xmlValidationLabel=Use XML Validation OpenFileDialog.xmlValidationLabel=Use XML Validation
TimeFormatter.hours={0} hours
TimeFormatter.lessThanASecond=< 1 second
TimeFormatter.minutes={0} minutes
TimeFormatter.oneHour=1 hour
TimeFormatter.oneMinute=1 minute
TimeFormatter.oneSecond=1 second
TimeFormatter.seconds={0} seconds
Unit.Degree=Degree Unit.Degree=Degree
Unit.Radian=Radian Unit.Radian=Radian
ValidationConfiguration.missingSchematron={} is not an existing file, disabling schematron check ValidationConfiguration.missingSchematron={} is not an existing file, disabling schematron check
......
...@@ -34,7 +34,7 @@ CheckDialog.title=Pr\u00fcfungskonfiguration ...@@ -34,7 +34,7 @@ CheckDialog.title=Pr\u00fcfungskonfiguration
CheckDialog.validationConfiguration=Validierungskonfiguration CheckDialog.validationConfiguration=Validierungskonfiguration
CheckDialog.xmlReportsOption=XML Berichte erstellen CheckDialog.xmlReportsOption=XML Berichte erstellen
Checker.checkFeature=Pr\u00fcfe Feature: {} Checker.checkFeature=Pr\u00fcfe Feature: {}
Checker.checksFinished=Pr\u00fcfungen beendet Checker.checksFinished=Durchf\u00fchrung der Pr\u00fcfungen abgeschlossen. Gesamtzeit: {0}
Checker.dbStillUnresponsive=Pr\u00fcfung konnte weiterhin einige CityObjects nicht aus der Datenbank laden! Checker.dbStillUnresponsive=Pr\u00fcfung konnte weiterhin einige CityObjects nicht aus der Datenbank laden!
Checker.dbUnresponsive=Pr\u00fcfung konnte einige CityObjects nicht aus der Datenbank laden! Checker.dbUnresponsive=Pr\u00fcfung konnte einige CityObjects nicht aus der Datenbank laden!
Checker.executeCheck=F\u00fchre Pr\u00fcfung aus: {} Checker.executeCheck=F\u00fchre Pr\u00fcfung aus: {}
...@@ -180,6 +180,13 @@ OpenFileDialog.select=W\u00e4hle CityGML Datei aus ...@@ -180,6 +180,13 @@ OpenFileDialog.select=W\u00e4hle CityGML Datei aus
OpenFileDialog.selectBtn=Ausw\u00e4hlen OpenFileDialog.selectBtn=Ausw\u00e4hlen
OpenFileDialog.settingsPane=Parser Einstellungen OpenFileDialog.settingsPane=Parser Einstellungen
OpenFileDialog.xmlValidationLabel=F\u00fchre XML-Validierung aus OpenFileDialog.xmlValidationLabel=F\u00fchre XML-Validierung aus
TimeFormatter.hours={0} Stunden
TimeFormatter.lessThanASecond=< 1 Sekunde
TimeFormatter.minutes={0} Minuten
TimeFormatter.oneHour=1 Stunde
TimeFormatter.oneMinute=1 Minute
TimeFormatter.oneSecond=1 Sekunde
TimeFormatter.seconds={0} Sekunden
Unit.Degree=Grad Unit.Degree=Grad
Unit.Radian=Radiant Unit.Radian=Radiant
ValidationConfiguration.missingSchematron={} existiert nicht, deaktiviere Schematron Pr\u00fcfung ValidationConfiguration.missingSchematron={} existiert nicht, deaktiviere Schematron Pr\u00fcfung
......
...@@ -30,6 +30,7 @@ import de.hft.stuttgart.citydoctor2.checks.SvrlContentHandler; ...@@ -30,6 +30,7 @@ import de.hft.stuttgart.citydoctor2.checks.SvrlContentHandler;
import de.hft.stuttgart.citydoctor2.checks.util.FeatureCheckedListener; import de.hft.stuttgart.citydoctor2.checks.util.FeatureCheckedListener;
import de.hft.stuttgart.citydoctor2.database.CacheManager; import de.hft.stuttgart.citydoctor2.database.CacheManager;
import de.hft.stuttgart.citydoctor2.database.CityObjectCache; import de.hft.stuttgart.citydoctor2.database.CityObjectCache;
import de.hft.stuttgart.citydoctor2.database.FeatureCache;
import de.hft.stuttgart.citydoctor2.datastructure.CityDoctorModel; import de.hft.stuttgart.citydoctor2.datastructure.CityDoctorModel;
import de.hft.stuttgart.citydoctor2.datastructure.CityObject; import de.hft.stuttgart.citydoctor2.datastructure.CityObject;
import de.hft.stuttgart.citydoctor2.datastructure.FeatureType; import de.hft.stuttgart.citydoctor2.datastructure.FeatureType;
...@@ -46,6 +47,7 @@ import de.hft.stuttgart.citydoctor2.reporting.XmlValidationReporter; ...@@ -46,6 +47,7 @@ import de.hft.stuttgart.citydoctor2.reporting.XmlValidationReporter;
import de.hft.stuttgart.citydoctor2.reporting.pdf.PdfReporter; import de.hft.stuttgart.citydoctor2.reporting.pdf.PdfReporter;
import de.hft.stuttgart.citydoctor2.reporting.pdf.PdfStreamReporter; import de.hft.stuttgart.citydoctor2.reporting.pdf.PdfStreamReporter;
import de.hft.stuttgart.citydoctor2.utils.Localization; import de.hft.stuttgart.citydoctor2.utils.Localization;
import de.hft.stuttgart.citydoctor2.utils.TimeFormatter;
import de.hft.stuttgart.quality.model.enums.RequirementId; import de.hft.stuttgart.quality.model.enums.RequirementId;
import de.hft.stuttgart.quality.model.enums.TopLevelFeatureType; import de.hft.stuttgart.quality.model.enums.TopLevelFeatureType;
import de.hft.stuttgart.quality.model.properties.CheckingProperty; import de.hft.stuttgart.quality.model.properties.CheckingProperty;
...@@ -79,6 +81,8 @@ import java.io.InputStream; ...@@ -79,6 +81,8 @@ import java.io.InputStream;
import java.io.UncheckedIOException; import java.io.UncheckedIOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.text.ChoiceFormat;
import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
...@@ -199,9 +203,6 @@ public class Checker { ...@@ -199,9 +203,6 @@ public class Checker {
}); });
schematronThread.start(); schematronThread.start();
checkCityModel(model, l); checkCityModel(model, l);
if (logger.isInfoEnabled()) {
logger.info(Localization.getText("Checker.checksFinished"));
}
if (schematronThread.isAlive()) { if (schematronThread.isAlive()) {
logger.info(Localization.getText("Checker.schematronStillRunning")); logger.info(Localization.getText("Checker.schematronStillRunning"));
if(l !=null){ if(l !=null){
...@@ -221,14 +222,13 @@ public class Checker { ...@@ -221,14 +222,13 @@ public class Checker {
private void handleSchematronResults(SvrlContentHandler handler) { private void handleSchematronResults(SvrlContentHandler handler) {
model.addGlobalErrors(handler.getGeneralErrors()); model.addGlobalErrors(handler.getGeneralErrors());
Map<String, CityObject> featureMap = new HashMap<>(); FeatureCache cache = CacheManager.getFeatureCache();
model.createFeatureStream().forEach(f -> featureMap.put(f.getGmlId().getGmlString(), f));
handler.getFeatureErrors().forEach((k, v) -> { handler.getFeatureErrors().forEach((k, v) -> {
if (k.trim().isEmpty()) { if (k.trim().isEmpty()) {
// missing gml id, ignore? // missing gml id, ignore?
return; return;
} }
CityObject co = featureMap.get(k); CityObject co = cache.get(new GmlId(k));
if (co == null) { if (co == null) {
// gml id reported by schematron was not found, add to general errors // gml id reported by schematron was not found, add to general errors
for (SchematronError se : v) { for (SchematronError se : v) {
...@@ -663,22 +663,20 @@ public class Checker { ...@@ -663,22 +663,20 @@ public class Checker {
List<Future<GmlId>> futures = runChecksOnFeatures(exec, cache, features, checkedCount, l); List<Future<GmlId>> futures = runChecksOnFeatures(exec, cache, features, checkedCount, l);
List<GmlId> missedFeatures = getMissedFeatures(futures); List<GmlId> missedFeatures = getMissedFeatures(futures);
if (!missedFeatures.isEmpty()){ if (!missedFeatures.isEmpty()){
logger.warn(Localization.getText("Checker.dbUnresponsive")); logger.error(Localization.getText("Checker.dbUnresponsive"));
logger.info(Localization.getText("Checker.waitAndRetry")); if (logger.isDebugEnabled()){
Thread.sleep(1000); logger.debug(missedFeatures.toString());
futures = runChecksOnFeatures(exec, cache, missedFeatures, checkedCount, l);
missedFeatures = getMissedFeatures(futures);
if (!missedFeatures.isEmpty()){
logger.error(Localization.getText("Checker.dbStillUnresponsive"));
if (logger.isDebugEnabled()){
logger.debug(missedFeatures.toString());
}
} }
} }
long endTime = System.nanoTime(); long endTime = System.nanoTime();
if (logger.isDebugEnabled()){ if (logger.isInfoEnabled()){
logger.debug("Checks finished in {} ms", (endTime - startTime) / 1_000_000); long totalTime = (endTime - startTime) / 1_000_000; // Convert ns to ms
String messageString = Localization.getText("Checker.checksFinished");
String timeString = TimeFormatter.format(totalTime);
messageString = messageString.replace("{0}", timeString);
logger.info(messageString);
} }
} catch (InterruptedException e){ } catch (InterruptedException e){
// No interrupts implemented, so this block should actually never be entered // No interrupts implemented, so this block should actually never be entered
......
Supports Markdown
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