use of de.opendiabetes.vault.plugin.importer.googlecrawler.models.Location in project BachelorPraktikum by lucasbuschlinger.
the class ConflictViewController method saveSelectedLocation.
/**
* Saves the selected locations to the resolved locations instance.
* @param event - event sent by the mouse click
*/
@FXML
public void saveSelectedLocation(final MouseEvent event) {
if (!conflictedLocationsListView.getSelectionModel().isEmpty()) {
Location loc = new Location();
PlacesSearchResult sr = places.get(conflictedLocationsListView.getSelectionModel().getSelectedIndex());
loc.setName(sr.name);
loc.setCoordinate(new LatLng(sr.geometry.location.lat, sr.geometry.location.lng));
ResolvedLocations.getInstance().addLocation(loc);
conflictedActivities.remove(selectedActivityKey);
conflictedLocationsListView.getItems().clear();
conflictedLocationWebView.getEngine().load("");
setConflictedActivitiesListView();
}
}
use of de.opendiabetes.vault.plugin.importer.googlecrawler.models.Location in project BachelorPraktikum by lucasbuschlinger.
the class ConflictViewController method saveCustomLabel.
/**
* Saves the entered location to the resolved locations instance.
* @param event - event sent by the mouse click
*/
@FXML
public void saveCustomLabel(final MouseEvent event) {
if (!conflictedLocationTextField.getText().isEmpty()) {
Location loc = new Location();
loc.setName(conflictedLocationTextField.getText());
loc.setCoordinate(((ConflictedLocationIdentifier) selectedActivityKey).getCoordinate());
ResolvedLocations.getInstance().addLocation(loc);
conflictedActivities.remove(selectedActivityKey);
conflictedLocationsListView.getItems().clear();
conflictedLocationWebView.getEngine().load("");
setConflictedActivitiesListView();
}
}
use of de.opendiabetes.vault.plugin.importer.googlecrawler.models.Location in project BachelorPraktikum by lucasbuschlinger.
the class LocationHistory method refineLocations.
/**
* Populates the activity history by fetching the location names of coordinates
* from the Google Places API.
*/
public void refineLocations() {
for (Map.Entry<Long, List<Activity>> entry : activityHistory.entrySet()) {
List<Coordinate> coords = getLocationsPerDay(entry.getKey());
for (Activity act : entry.getValue()) {
if (act.getActivityId() == ActivityTypes.STILL || act.getActivityId() == ActivityTypes.UNKNOWN || act.getActivityId() == ActivityTypes.SLEEPING || act.getActivityId() == ActivityTypes.LIGHT_SLEEP || act.getActivityId() == ActivityTypes.DEEP_SLEEP || act.getActivityId() == ActivityTypes.REM_SLEEP || act.getActivityId() == ActivityTypes.MEDITATION) {
List<Coordinate> activityCoords = new ArrayList<>();
long startTime = act.getStartTime();
long endTime = act.getEndTime();
for (Coordinate c : coords) {
if (c.getTimestamp() >= startTime && c.getTimestamp() <= endTime) {
activityCoords.add(c);
}
}
if (activityCoords.size() > 0) {
activityCoords.sort(Comparator.comparing(Coordinate::getAccuracy));
int threshold = activityCoords.get((int) (activityCoords.size() * 0.75)).getAccuracy();
activityCoords = activityCoords.stream().filter(c -> c.getAccuracy() <= threshold).collect(Collectors.toList());
double weightedLatitude = 0;
double weightedLongitude = 0;
double weight = 0;
for (Coordinate c : activityCoords) {
weightedLatitude += c.getLatitude() * c.getAccuracy();
weightedLongitude += c.getLongitude() * c.getAccuracy();
weight += c.getAccuracy();
}
final double lat = weightedLatitude / weight;
final double lng = weightedLongitude / weight;
int searchRadius = DEFAULT_RADIUS;
if (searchRadius < threshold) {
searchRadius = threshold;
}
String place = GooglePlaces.getInstance().atOwnPlaces(lat, lng, searchRadius);
if (place.equals("AWAY")) {
place = GooglePlaces.getInstance().isAtContact(lat, lng, searchRadius);
if (place.equals("AWAY")) {
PlacesSearchResult[] results = GooglePlaces.getInstance().getPlaces(lat, lng, searchRadius);
if (results != null) {
if (results.length == 1) {
place = results[0].name;
} else {
List<PlacesSearchResult> places = extractRealLocations(results);
places.sort((PlacesSearchResult o1, PlacesSearchResult o2) -> {
double o1Distance = GooglePlaces.getInstance().calculateDistance(o1.geometry.location.lat, o1.geometry.location.lng, lat, lng);
double o2Distance = GooglePlaces.getInstance().calculateDistance(o2.geometry.location.lat, o2.geometry.location.lng, lat, lng);
return Double.compare(o1Distance, o2Distance);
});
List<PlacesSearchResult> sportRelatedPlaces = getGymOrSportClub(places);
GoogleMapsPlot.getInstance().addLocation(new LatLng(lat, lng));
if (sportRelatedPlaces.size() == 1) {
place = sportRelatedPlaces.get(0).name;
} else {
Location location = checkForResolvedLocations(lat, lng, searchRadius * 2);
if (location != null) {
place = location.getName();
} else if (sportRelatedPlaces.size() > 1) {
conflictLocations.put(new ConflictedLocationIdentifier(act.getStartTime(), new LatLng(lat, lng)), sportRelatedPlaces);
place = "CONFLICT";
} else if (places.size() > 0) {
results = GooglePlaces.getInstance().getPlaces(lat, lng, searchRadius * 2);
places = extractRealLocations(results);
places.sort((PlacesSearchResult o1, PlacesSearchResult o2) -> {
double o1Distance = GooglePlaces.getInstance().calculateDistance(o1.geometry.location.lat, o1.geometry.location.lng, lat, lng);
double o2Distance = GooglePlaces.getInstance().calculateDistance(o2.geometry.location.lat, o2.geometry.location.lng, lat, lng);
return Double.compare(o1Distance, o2Distance);
});
conflictLocations.put(new ConflictedLocationIdentifier(act.getStartTime(), new LatLng(lat, lng)), places);
place = "CONFLICT";
} else {
place = "UNKNOWN";
}
}
}
} else {
place = "UNKNOWN";
}
}
}
act.setLocation(place);
}
GoogleMapsPlot.getInstance().addLocationNames(act.getLocation());
}
}
}
}
Aggregations