Compare commits

...
26 Commits
Author SHA1 Message Date
halbothpa61667 59d17304ad Threshold angepasst 2021-06-28 13:39:48 +02:00
kunzeja48885 906df05c6c Abänderung für Dreiecks Berechnung 2021-06-28 09:21:50 +02:00
halbothpa61667 a685f972bf Threshold angepasst 2021-06-27 22:31:30 +02:00
Raz492 53528a82e9 Per-AlphaV10 - Displayverbesserung 2021-06-27 11:28:28 +02:00
kunzeja48885 ba9e3d5aa7 Fehlerbehebung EpizentrumRechnung 2021-06-26 16:24:58 +02:00
kunzeja48885 9f1f243f50 Merge remote-tracking branch 'origin/master' 2021-06-26 11:46:39 +02:00
Raz492 2c9c2ef7c4 Pre-AlphaV9 - EpizentrumAnpassung 2021-06-26 11:46:19 +02:00
kunzeja48885 3ba534c285 Test 2021-06-26 11:06:26 +02:00
kunzeja48885 dfffc2c9f1 Ausgabe Auslösung Erdbeben 2021-06-26 11:00:54 +02:00
kunzeja48885 0d8e04f9e0 Anpassung Koordinatenberechnung 2021-06-26 10:58:26 +02:00
Raz492 2e0da83888 Pre-AlphaV8 - Epizentrum fehlt 2021-06-25 22:56:19 +02:00
Raz492 d3a1380658 Pre-AlphaV7 2021-06-25 21:40:20 +02:00
kunzeja48885 48d53ca1d9 Anspassung Zeitberechnung 2021-06-25 19:49:35 +02:00
kunzeja48885 8c780e9462 Anspassung Zeitberechnung 2021-06-25 19:48:55 +02:00
Raz492 8f2eb9b012 Pre-AlphaV6 2021-06-25 19:32:18 +02:00
Raz492 71b53e42e6 Pre-AlphaV5 2021-06-25 18:46:56 +02:00
Raz492 e9c0ddb711 Pre-AlphaV5 2021-06-25 18:43:13 +02:00
Raz492 00dbbc810d Pre-AlphaV5 2021-06-25 18:28:09 +02:00
Raz492 b88f45b728 Pre-AlphaV5 2021-06-25 18:23:44 +02:00
Raz492 59880392f6 Pre-AlphaV4 2021-06-25 17:30:46 +02:00
Raz492 022ecd94a6 Pre-AlphaV3 2021-06-25 16:54:17 +02:00
Raz492 ab02421307 Pre-AlphaV3 2021-06-25 16:51:52 +02:00
halbothpa61667 77900b3088 Button added 2021-06-25 12:31:20 +02:00
halbothpa61667 2b5b997192 vvv Detection Code vvv 2021-06-25 11:56:47 +02:00
halbothpa61667 5b78abe6ca vvv Detection Code vvv 2021-06-25 11:10:39 +02:00
halbothpa61667 cfb0b0c612 vvv Detection Code vvv 2021-06-25 11:00:13 +02:00
17 changed files with 932 additions and 114 deletions

No files matched your search

Generated
+1
View File
@@ -0,0 +1 @@
Detection
Generated
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
+5
View File
@@ -1,5 +1,7 @@
plugins { plugins {
id 'com.android.application' id 'com.android.application'
id 'com.google.gms.google-services'
} }
android { android {
@@ -34,10 +36,13 @@ dependencies {
implementation 'com.google.android.material:material:1.3.0' implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.google.android.gms:play-services-maps:17.0.1' implementation 'com.google.android.gms:play-services-maps:17.0.1'
implementation 'com.google.firebase:firebase-database:20.0.0'
testImplementation 'junit:junit:4.+' testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.ext:junit:1.1.2'
implementation "com.google.android.gms:play-services-location:15.0.1" //Important to find the location from the device implementation "com.google.android.gms:play-services-location:15.0.1" //Important to find the location from the device
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation("com.google.guava:guava:30.1.1-jre") implementation("com.google.guava:guava:30.1.1-jre")
implementation ('com.lemmingapex.trilateration:trilateration:1.0.2')
} }
+69
View File
@@ -0,0 +1,69 @@
{
"project_info": {
"project_number": "957720376634",
"firebase_url": "https://schockwelle-mdt5-g1-default-rtdb.europe-west1.firebasedatabase.app",
"project_id": "schockwelle-mdt5-g1",
"storage_bucket": "schockwelle-mdt5-g1.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:957720376634:android:7e4e3f644d052e6f70cc03",
"android_client_info": {
"package_name": "de.edotzlaff.detection"
}
},
"oauth_client": [
{
"client_id": "957720376634-gvj86hvfrnt5npvqfbsb8lnu77fgaumh.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyDNnG6F_VIzKbu4r7QBqsUZ3z6ELFbgyuc"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "957720376634-gvj86hvfrnt5npvqfbsb8lnu77fgaumh.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
},
{
"client_info": {
"mobilesdk_app_id": "1:957720376634:android:fdc03f689ff71b2f70cc03",
"android_client_info": {
"package_name": "de.edotzlaff.schockwelle"
}
},
"oauth_client": [
{
"client_id": "957720376634-gvj86hvfrnt5npvqfbsb8lnu77fgaumh.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyDNnG6F_VIzKbu4r7QBqsUZ3z6ELFbgyuc"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "957720376634-gvj86hvfrnt5npvqfbsb8lnu77fgaumh.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
}
],
"configuration_version": "1"
}
+3 -2
View File
@@ -10,12 +10,13 @@
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<application <application
android:allowBackup="true" android:allowBackup="true"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_trianglesign"
android:label="@string/app_name" android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_trianglesign"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.Detection"> android:theme="@style/Theme.Detection">
@@ -1,11 +1,20 @@
package de.edotzlaff.detection; package de.edotzlaff.detection;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Build; import android.os.Build;
import android.os.CountDownTimer;
import android.provider.ContactsContract;
import android.util.Log; import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import android.os.Bundle; import android.os.Bundle;
import android.widget.Toast;
import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.GoogleMap;
@@ -14,10 +23,21 @@ import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions; import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import de.edotzlaff.detection.detektion.Detektionssignal; import de.edotzlaff.detection.detektion.Detektionssignal;
import de.edotzlaff.detection.detektion.Epizentrum; import de.edotzlaff.detection.detektion.Epizentrum;
import de.edotzlaff.detection.detektion.Erdbeben; import de.edotzlaff.detection.detektion.Erdbeben;
import de.edotzlaff.detection.detektion.berechnung.mathObjekte.Deg2UTM;
import de.edotzlaff.detection.detektion.berechnung.mathObjekte.Koordinaten;
import de.edotzlaff.detection.detektion.berechnung.mathObjekte.UTM2Deg;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Objects; import java.util.Objects;
@@ -25,68 +45,150 @@ public class EarthquakeLocation extends FragmentActivity implements OnMapReadyCa
private GoogleMap mMap; private GoogleMap mMap;
private static final String TAGEPIZENTRUM = "Epizentrum"; private static final String TAGEPIZENTRUM = "Epizentrum";
private DatabaseReference mDatenbank;
private double latitudeD1, latitudeD2, latitudeD3, latitudeD4, latitudeEPI;
private double longitudeD1, longitudeD2, longitudeD3, longitudeD4, lonitudeEPI;
private String dev1, dev2, dev3, dev4;
Epizentrum epizentrum;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_earthquake_location); setContentView(R.layout.activity_earthquake_location);
getLocationInfo();
// Obtain the SupportMapFragment and get notified when the map is ready to be used. // Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this); mapFragment.getMapAsync(this);
} }
//########################################################################################################################################################################## //##########################################################################################################################################################################
//################################################################## vvv DB Code vvv ##################################################################################### //################################################################## vvv DB Code vvv #####################################################################################
//TODO Aron
public void getLocationInfo()
{
mDatenbank = FirebaseDatabase.getInstance().getReference().child("overviewdetection");
mDatenbank.get().addOnCompleteListener(new OnCompleteListener<DataSnapshot>() {
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public void onComplete(@NonNull Task<DataSnapshot> task) {
if (!task.isSuccessful()) {
System.out.println("Datenbank Fehler in getDataBaseValuesNoListener");
}
else{
defineGPSforMapping(task.getResult());
epizentrum = ermittleEpizentrum(task.getResult());
//ermittleEpizentrum(task.getResult());
//mapToDetektionssignale(task.getResult());
}
}
});
}
public void defineGPSforMapping(DataSnapshot data)
{
String breitengradString;
String laengengradString;
String androidID;
for(int i =1; i<=3; i++)
{
breitengradString = data.child("IDG" + i).child("d_breitengrad").getValue().toString();
laengengradString = data.child("IDG" + i).child("e_laengengrad").getValue().toString();
androidID = data.child("IDG" + i).child("a_androidid").getValue().toString();
double breitengrad = Double.parseDouble(breitengradString);
double laengengrad = Double.parseDouble(laengengradString);
switch (i){
case 1:
latitudeD1 = breitengrad;
longitudeD1 = laengengrad;
dev1 = androidID;
break;
case 2:
latitudeD2 = breitengrad;
longitudeD2 = laengengrad;
dev2 = androidID;
break;
case 3:
latitudeD3 = breitengrad;
longitudeD3 = laengengrad;
dev3 = androidID;
break;
default:
break;
}
}
}
//################################################################## ^^^^ DB Code ^^^^ ################################################################################### //################################################################## ^^^^ DB Code ^^^^ ###################################################################################
//########################################################################################################################################################################## //##########################################################################################################################################################################
//########################################################################################################################################################################## //##########################################################################################################################################################################
//################################################################## vvv Calculate Epicenter vvv ######################################################################### //################################################################## vvv Calculate Epicenter vvv #########################################################################
//TODO Jan
@RequiresApi(api = Build.VERSION_CODES.O) @RequiresApi(api = Build.VERSION_CODES.O)
public Epizentrum ermittleEpizentrum(DataSnapshot data) public Epizentrum ermittleEpizentrum(DataSnapshot data)
{ {
Log.i(TAGEPIZENTRUM, "Start Ermittle Epizentrum");
Erdbeben erdbeben = new Erdbeben(); Erdbeben erdbeben = new Erdbeben();
erdbeben.addDetektionssignalList(mapToDetektionssignale(data)); erdbeben.addDetektionssignalList(mapToDetektionssignale(data));
Epizentrum epizentrum = new Epizentrum(); Epizentrum epizentrum = erdbeben.ermittleEpizentrum();
epizentrum = erdbeben.ermittleEpizentrum();
if(Objects.isNull(epizentrum)) if(Objects.isNull(epizentrum))
{ {
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!Kein Epizentrum vorhanden!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
Log.i(TAGEPIZENTRUM, "Kein Epizentrum vorhanden"); Log.i(TAGEPIZENTRUM, "Kein Epizentrum vorhanden");
} }
else else
{ {
UTM2Deg utm2Deg = new UTM2Deg();
utm2Deg.convertToDeg(32,'U',epizentrum.getKoordinaten().getX(),epizentrum.getKoordinaten().getY());
epizentrum.getKoordinaten().setLocation(utm2Deg.getLatitude(), utm2Deg.getLongitude());
Log.i(TAGEPIZENTRUM, "Epizentrum konnte ermittelt werden, Koordinaten: " + epizentrum.getKoordinaten().getX() + " " + epizentrum.getKoordinaten().getY()); Log.i(TAGEPIZENTRUM, "Epizentrum konnte ermittelt werden, Koordinaten: " + epizentrum.getKoordinaten().getX() + " " + epizentrum.getKoordinaten().getY());
Log.i(TAGEPIZENTRUM, "Enstehungszeitpunkt: " + epizentrum.getEntstehungsZeitpunkt());
} }
return epizentrum;
return epizentrum;
} }
@RequiresApi(api = Build.VERSION_CODES.O)
public ArrayList<Detektionssignal> mapToDetektionssignale(DataSnapshot data) public ArrayList<Detektionssignal> mapToDetektionssignale(DataSnapshot data)
{ {
ArrayList<Detektionssignal> detektionssignale = new ArrayList<>(); ArrayList<Detektionssignal> detektionssignale = new ArrayList<>();
for(data.child("overviewnodes").getChildernKey) for(int i=1; i<=3; i++)
{ {
Detektionssignal detektionssignal = new Detektionssignal(); Detektionssignal detektionssignal = new Detektionssignal();
detektionssignal.setAnkunftsZeit();
detektionssignal.setDeviceId(); //LocalDateTime als LocalDateTime
detektionssignal.setKoordinaten(data.child("overviewnodes").child("IDG" + f).child("d_breitengrad").getValue().toString(), String localdatetimeString = data.child("IDG" + i).child("b_localdatetime").getValue().toString();
data.child("overviewnodes").child("IDG" + f).child("e_laengengrad").getValue().toString()); DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE_TIME;
detektionssignal.setGeschwErdbeben(); LocalDateTime localdatetime = LocalDateTime.parse(localdatetimeString, formatter);
detektionssignal.setAnkunftsZeit(localdatetime);
//ID als String
detektionssignal.setDeviceId(data.child("IDG" + i).child("a_androidid").getValue().toString());
//Koordinaten
String breitengradString = data.child("IDG" + i).child("d_breitengrad").getValue().toString();
String laengengradString = data.child("IDG" + i).child("e_laengengrad").getValue().toString();
double breitengrad = Double.parseDouble(breitengradString);
double laengengrad = Double.parseDouble(laengengradString);
Deg2UTM deg2UTM = new Deg2UTM(breitengrad, laengengrad);
Koordinaten koordinaten = new Koordinaten(deg2UTM.getEasting(), deg2UTM.getNorthing());
detektionssignal.setKoordinaten(koordinaten);
//Welle in m/s
String welle = data.child("IDG" + i).child("w_wellengeschwindigkeit").getValue().toString();
int wellengeschwindigkeit = Integer.parseInt(welle);
detektionssignal.setGeschwErdbeben(wellengeschwindigkeit);
detektionssignale.add(detektionssignal); detektionssignale.add(detektionssignal);
} }
return detektionssignale; return detektionssignale;
} }
@@ -95,33 +197,48 @@ public class EarthquakeLocation extends FragmentActivity implements OnMapReadyCa
//########################################################################################################################################################################## //##########################################################################################################################################################################
//########################################################################################################################################################################## //##########################################################################################################################################################################
//################################################################## vvv Maps Code vvv ################################################################################### //################################################################## vvv Maps Code vvv ###################################################################################
@RequiresApi(api = Build.VERSION_CODES.N)
@Override @Override
public void onMapReady(GoogleMap googleMap) { public void onMapReady(GoogleMap googleMap) {
mMap = googleMap; mMap = googleMap;
//TODO Aron: Daten aus DB in die jeweiligen Devices einsetzten if(Objects.isNull(epizentrum))
{
System.out.println("--------Keine Epizentrum Koordinaten verfügbar");
}else
{
System.out.println(">>>>>>>>Epizentrum Koordinaten");
latitudeEPI = epizentrum.getKoordinaten().getX();
lonitudeEPI = epizentrum.getKoordinaten().getY();
System.out.println("Breitengrad/Latitude: " + latitudeEPI);
System.out.println("Längengrad/Longitude: " + lonitudeEPI);
}
//aus DB für Device 1 long lat //aus DB für Device 1 long lat
LatLng divice1 = new LatLng(-34, 152); LatLng device1 = new LatLng(latitudeD1, longitudeD1);
mMap.addMarker(new MarkerOptions().position(divice1).title("Device 1").icon(BitmapDescriptorFactory mMap.addMarker(new MarkerOptions().position(device1).title("Device 1").icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_GREEN))); .defaultMarker(BitmapDescriptorFactory.HUE_GREEN)));
//aus DB für Device 2 long lat //aus DB für Device 2 long lat
LatLng divice2 = new LatLng(-33, 152); LatLng device2 = new LatLng(latitudeD2, longitudeD2);
mMap.addMarker(new MarkerOptions().position(divice2).title("Device 2").icon(BitmapDescriptorFactory mMap.addMarker(new MarkerOptions().position(device2).title("Device 2").icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_GREEN))); .defaultMarker(BitmapDescriptorFactory.HUE_GREEN)));
//aus DB für Device 3 long lat //aus DB für Device 3 long lat
LatLng divice3 = new LatLng(-34, 150); LatLng device3 = new LatLng(latitudeD3, longitudeD3);
mMap.addMarker(new MarkerOptions().position(divice3).title("Device 3").icon(BitmapDescriptorFactory mMap.addMarker(new MarkerOptions().position(device3).title("Device 3").icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_GREEN))); .defaultMarker(BitmapDescriptorFactory.HUE_GREEN)));
//man könnten noch eine IF Abfrage einbauen falls es 4 Devices gibt //man könnten noch eine IF Abfrage einbauen falls es 4 Devices gibt
// Add a marker in Epicenter // Add a marker in Epicenter
LatLng epicenter = new LatLng(-34, 151); LatLng epicenter = new LatLng(latitudeEPI, lonitudeEPI);
mMap.addMarker(new MarkerOptions().position(epicenter).title("Epicenter")); mMap.addMarker(new MarkerOptions().position(epicenter).title("Epicenter"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(epicenter)); mMap.moveCamera(CameraUpdateFactory.newLatLng(epicenter));
} }
@@ -1,16 +1,25 @@
package de.edotzlaff.detection; package de.edotzlaff.detection;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import android.Manifest; import android.Manifest;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.location.Location; import android.location.Location;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.CountDownTimer;
import android.provider.Settings;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
@@ -22,19 +31,23 @@ import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.location.FusedLocationProviderClient; import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices; import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.tasks.OnCompleteListener; import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task; import com.google.android.gms.tasks.Task;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import org.w3c.dom.Text; import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Calendar; import java.util.Calendar;
import java.util.Objects;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity"; private static final String TAG = "MainActivity";
private static final int ERROR_DIALOG_REQUEST = 9001; private static final int ERROR_DIALOG_REQUEST = 9001;
private static final String FINE_LOCATION = Manifest.permission.ACCESS_FINE_LOCATION; private static final String FINE_LOCATION = Manifest.permission.ACCESS_FINE_LOCATION;
@@ -45,38 +58,117 @@ public class MainActivity extends AppCompatActivity {
Long currentTime; Long currentTime;
Location currentLocation; Location currentLocation;
// private DatabaseReference mDatenbank; private DatabaseReference mDatenbank;
private double breitengrad; private double breitengrad;
private double laengengrad; private double laengengrad;
private boolean useOwnGPS = true; private boolean useOwnGPS = true;
private int indexID = 1; private int indexID = 1;
private int writtenDevices = 1;
private boolean allowCalculation = true;
private boolean enableDisplayReset = true;
//##########################################################################################################################################################################
//################################################################## vvv SensorParameter vvv ##############################################################################
private SensorManager mSensorManager;
private static final float mUpperThreshold = 0.075f; // für Emulator auf 1.5 setzen
private static final float mLowerThreshold = 0.5f; // für Emulator auf 0.5 setzen
private static final long mShakeDetectionLockTimeMicroSeconds = 3500;
private float mAccel;
private float mAccelCurrent;
private float mAccelLast;
private boolean mShakeDetectionIsActive = false;
private boolean mShakeDetected = false;
private boolean allowShakeEvent = true;
//################################################################## ^^^^ SensorParameter ^^^^ ############################################################################
//##########################################################################################################################################################################
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
if (isServiceOK()){ if (isServiceOK()){
init(); init();
} }
sensorManagementInit();
//Detection funktion here initDataBase();
getLocationPermission(); getLocationPermission();
getDataBaseValuesWithListener();
}
//DB function here //################################################################## vvv Detection Code vvv ###################################################################################
//##########################################################################################################################################################################
private void sensorManagementInit()
{
//TextView txtEarthquake = (TextView) findViewById(R.id.txtEarthquake);
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
Objects.requireNonNull(mSensorManager).registerListener(mSensorListener, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_FASTEST);
mAccel = 0.05f;
mAccelCurrent = SensorManager.GRAVITY_EARTH;
mAccelLast = SensorManager.GRAVITY_EARTH;
mShakeDetectionIsActive = false;
mShakeDetected = false;
} }
private final SensorEventListener mSensorListener = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
float x = event.values[0];
float y = event.values[1];
float z = event.values[2];
mAccelLast = mAccelCurrent;
mAccelCurrent = (float) Math.sqrt((double) (x * x + y * y + z * z));
float delta = mAccelCurrent - mAccelLast;
mAccel = mAccel * 0.9f + delta;
Log.d(TAG,"mAccel: "+ mAccel);
if (mShakeDetectionIsActive && !mShakeDetected) {
if(Math.abs(mAccel) > mUpperThreshold) {
new CountDownTimer(500, 10) {
public void onTick(long millisUntilFinished) {
mShakeDetectionIsActive = false;
/* if (Math.abs(mAccel) > mUpperThreshold) {
mShakeDetectionIsActive = false;
} else if (Math.abs(mAccel) < mLowerThreshold) {
mShakeDetectionIsActive = true;
this.cancel();
}
*/
}
public void onFinish() {
if (Math.abs(mAccel) > mUpperThreshold) {
mShakeDetectionIsActive = false;
mShakeDetected = true;
earthquakeDetected();
} else {
mShakeDetectionIsActive = true;
mShakeDetected = false;
}
}
}.start();
}
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
};
private void earthquakeDetected()
{
Toast.makeText(getApplicationContext(), "Earthquake detected", Toast.LENGTH_SHORT).show();
Log.d(TAG,"!Earthquake detected!");
//Hier wird bei Vibration in DB geschrieben
getDataBaseValuesNoListenerForVibration();
Button buttonReadyToDetect = (Button) findViewById(R.id.buttonReadyToDetect);
buttonReadyToDetect.setEnabled(true);
}
//################################################################## ^^^^ Detection Code ^^^^ ###################################################################################
//########################################################################################################################################################################## //##########################################################################################################################################################################
//################################################################## vvv Detect Vibration vvv ############################################################################
//TODO Böbbi
//################################################################## ^^^^ Detect Vibration ^^^^ ##########################################################################
//##########################################################################################################################################################################
//########################################################################################################################################################################## //##########################################################################################################################################################################
//################################################################## vvv Get Location from Device vvv #################################################################### //################################################################## vvv Get Location from Device vvv ####################################################################
@@ -111,7 +203,7 @@ public class MainActivity extends AppCompatActivity {
} }
currentLocation.setLatitude(breitengrad); currentLocation.setLatitude(breitengrad);
currentLocation.setLongitude(laengengrad); currentLocation.setLongitude(laengengrad);
setText(); //setText();
} }
else{ else{
Toast.makeText(MainActivity.this, "Current Location unavailable", Toast.LENGTH_SHORT).show(); Toast.makeText(MainActivity.this, "Current Location unavailable", Toast.LENGTH_SHORT).show();
@@ -130,38 +222,294 @@ public class MainActivity extends AppCompatActivity {
//########################################################################################################################################################################## //##########################################################################################################################################################################
//################################################################## vvv DB Code vvv ##################################################################################### //################################################################## vvv DB Code vvv #####################################################################################
//TODO Aron //###### Für Start der APP ####
public void initDataBase()
{
getDataBaseValuesNoListener();
}
public void getDataBaseValuesNoListener()
{
mDatenbank = FirebaseDatabase.getInstance().getReference().child("overviewdetection");
mDatenbank.get().addOnCompleteListener(new OnCompleteListener<DataSnapshot>() {
@Override
public void onComplete(@NonNull Task<DataSnapshot> task) {
if (!task.isSuccessful()) {
System.out.println("Datenbank Fehler in getDataBaseValuesNoListener");
}
else {
analyzeForEmptyDB(task.getResult());
}
}
});
}
//Methode bestimmt, ob DB mit leer IDGn Felder überhaupt vorhanden ist
public void analyzeForEmptyDB(DataSnapshot data)
{
String androidid;
String localedatetime;
String breitengrad;
String laengengrad;
String timestamp;
String ampltiude;
String welle;
int emptyIDG =0;
for (int i=1; i<=data.getChildrenCount(); i++)
{
androidid = data.child("IDG" + i).child("a_androidid").getValue().toString();
localedatetime = data.child("IDG" + i).child("b_localdatetime").getValue().toString();
breitengrad = data.child("IDG" + i).child("d_breitengrad").getValue().toString();
laengengrad = data.child("IDG" + i).child("e_laengengrad").getValue().toString();
timestamp = data.child("IDG" + i).child("h_timestamp").getValue().toString();
ampltiude = data.child("IDG" + i).child("i_amplitude").getValue().toString();
welle = data.child("IDG" + i).child("w_wellengeschwindigkeit").getValue().toString();
if(androidid.isEmpty() && localedatetime.isEmpty() && breitengrad.isEmpty() && laengengrad.isEmpty() && timestamp.isEmpty() && ampltiude.isEmpty() && welle.isEmpty())
{
emptyIDG++;
}else{
emptyIDG--;
}
}
//Wenn DB nicht vorhanden ODER leer ist, erstelle diese DB mit IDG 1-5
if(emptyIDG == data.getChildrenCount())
{
for (int i=1; i<=5; i++)
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
writeEmptyToSecondDataBase(i);
}
}
}
}
@RequiresApi(api = Build.VERSION_CODES.O)
public void writeEmptyToSecondDataBase(int k)
{
mDatenbank = FirebaseDatabase.getInstance().getReference().child("overviewdetection");
mDatenbank.child("IDG" + k).child("a_androidid").setValue("");
mDatenbank.child("IDG" + k).child("b_localdatetime").setValue("");
mDatenbank.child("IDG" + k).child("d_breitengrad").setValue("");
mDatenbank.child("IDG" + k).child("e_laengengrad").setValue("");
mDatenbank.child("IDG" + k).child("h_timestamp").setValue("");
mDatenbank.child("IDG" + k).child("i_amplitude").setValue("");
mDatenbank.child("IDG" + k).child("w_wellengeschwindigkeit").setValue("");
}
//###### Bei Vibration der APP ####
public void getDataBaseValuesNoListenerForVibration()
{
mDatenbank = FirebaseDatabase.getInstance().getReference().child("overviewdetection");
mDatenbank.get().addOnCompleteListener(new OnCompleteListener<DataSnapshot>() {
@Override
public void onComplete(@NonNull Task<DataSnapshot> task) {
if (!task.isSuccessful()) {
System.out.println("Datenbank Fehler in getDataBaseValuesNoListener");
}
else {
checkForEmptyIDG(task.getResult());
}
}
});
}
public void checkForEmptyIDG(DataSnapshot data)
{
for (int i=1; i<=data.getChildrenCount(); i++)
{
if(analyzeForEmptyIDG(data,i))
{
writeDeviceToDB(i);
break;
}
}
}
public boolean analyzeForEmptyIDG(DataSnapshot data, int i)
{
String androidid;
String localedatetime;
String breitengrad;
String laengengrad;
String timestamp;
String ampltiude;
String welle;
androidid = data.child("IDG" + i).child("a_androidid").getValue().toString();
localedatetime = data.child("IDG" + i).child("b_localdatetime").getValue().toString();
breitengrad = data.child("IDG" + i).child("d_breitengrad").getValue().toString();
laengengrad = data.child("IDG" + i).child("e_laengengrad").getValue().toString();
timestamp = data.child("IDG" + i).child("h_timestamp").getValue().toString();
ampltiude = data.child("IDG" + i).child("i_amplitude").getValue().toString();
welle = data.child("IDG" + i).child("w_wellengeschwindigkeit").getValue().toString();
if(androidid.isEmpty() && localedatetime.isEmpty() && breitengrad.isEmpty() && laengengrad.isEmpty() && timestamp.isEmpty() && ampltiude.isEmpty() && welle.isEmpty())
{
return true;
}else
{
return false;
}
}
public void writeDeviceToDB (int k)
{
mDatenbank = FirebaseDatabase.getInstance().getReference().child("overviewdetection");
mDatenbank.child("IDG" + k).child("a_androidid").setValue(getandroidid());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
mDatenbank.child("IDG" + k).child("b_localdatetime").setValue(LocalDateTime.now(ZoneOffset.UTC).toString());
}
mDatenbank.child("IDG" + k).child("d_breitengrad").setValue(currentLocation.getLatitude());
mDatenbank.child("IDG" + k).child("e_laengengrad").setValue(currentLocation.getLongitude());
mDatenbank.child("IDG" + k).child("h_timestamp").setValue(Calendar.getInstance().getTimeInMillis());
mDatenbank.child("IDG" + k).child("i_amplitude").setValue(1000);
mDatenbank.child("IDG" + k).child("w_wellengeschwindigkeit").setValue(10);
}
//###### Bei Eintragungen in der DB ####
public void getDataBaseValuesWithListener()
{
mDatenbank = FirebaseDatabase.getInstance().getReference().child("overviewdetection");
mDatenbank.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
analyzeDBchanges(snapshot);
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
getDataBaseFailure(error);
}
});
}
public void analyzeDBchanges(DataSnapshot data)
{
for (int i=1; i<=data.getChildrenCount(); i++)
{
if(analyzeForFullIDG(data,i) || analyzeForEmptyIDG(data,i))
{
TextView txtDevice1 = (TextView) findViewById(R.id.txtdevice1);
TextView txtDevice2 = (TextView) findViewById(R.id.txtdevice2);
TextView txtDevice3 = (TextView) findViewById(R.id.txtdevice3);
TextView txtDevice4 = (TextView) findViewById(R.id.txtdevice4);
String dbSlotStringContent = getSlotString(data,i);
String displayContent;
switch (i){
case 1:
displayContent = txtDevice1.getText().toString();
if(!displayContent.equals(dbSlotStringContent))
{
if(analyzeForEmptyIDG(data,i))
{
txtDevice1.setText("");
}else
{
txtDevice1.setText(dbSlotStringContent);
}
}
break;
case 2:
displayContent = txtDevice2.getText().toString();
if(!displayContent.equals(dbSlotStringContent))
{
if(analyzeForEmptyIDG(data,i))
{
txtDevice2.setText("");
}else
{
txtDevice2.setText(dbSlotStringContent);
}
}
break;
case 3:
displayContent = txtDevice3.getText().toString();
if(!displayContent.equals(dbSlotStringContent))
{
if(analyzeForEmptyIDG(data,i))
{
txtDevice3.setText("");
}else
{
txtDevice3.setText(dbSlotStringContent);
}
}
break;
case 4:
displayContent = txtDevice4.getText().toString();
if(!displayContent.equals(dbSlotStringContent))
{
if(analyzeForEmptyIDG(data,i))
{
txtDevice4.setText("");
}else
{
txtDevice4.setText(dbSlotStringContent);
}
}
break;
default:
break;
}
}
}
int takenIDG = 0;
for (int i=1; i<=data.getChildrenCount(); i++)
{
if(analyzeForFullIDG(data,i))
{
takenIDG++;
}
}
if(takenIDG >= 3 && allowCalculation)
{
Toast.makeText(MainActivity.this, "3 Geräte regisrtiert - Berechnung möglich!", Toast.LENGTH_SHORT).show();
allowCalculation = false;
Button btnEarthquake = (Button) findViewById(R.id.btnEarthquakeLocation);
btnEarthquake.setEnabled(true);
}
}
public String getSlotString(DataSnapshot data,int i)
{
String androidid = data.child("IDG" + i).child("a_androidid").getValue().toString();
String localedatetime = data.child("IDG" + i).child("b_localdatetime").getValue().toString();
String breitengrad = data.child("IDG" + i).child("d_breitengrad").getValue().toString();
String laengengrad = data.child("IDG" + i).child("e_laengengrad").getValue().toString();
String timestamp = data.child("IDG" + i).child("h_timestamp").getValue().toString();
String ampltiude = data.child("IDG" + i).child("i_amplitude").getValue().toString();
String databaseSlotString = "Device ID " + i + ": "+ androidid + "\n" + "Latitude: "+breitengrad+"\n"+ "Longitude: "+ laengengrad +"\n" + "Time Stamp: "+ timestamp + "\n" + "LocalDateTime: " + localedatetime +"\n"+ "Amplitude: "+ ampltiude+"\n";
return databaseSlotString;
}
public boolean analyzeForFullIDG(DataSnapshot data, int i)
{
String androidid = data.child("IDG" + i).child("a_androidid").getValue().toString();
String localedatetime = data.child("IDG" + i).child("b_localdatetime").getValue().toString();
String breitengrad = data.child("IDG" + i).child("d_breitengrad").getValue().toString();
String laengengrad = data.child("IDG" + i).child("e_laengengrad").getValue().toString();
String timestamp = data.child("IDG" + i).child("h_timestamp").getValue().toString();
String ampltiude = data.child("IDG" + i).child("i_amplitude").getValue().toString();
String welle = data.child("IDG" + i).child("w_wellengeschwindigkeit").getValue().toString();
if(!androidid.isEmpty() && !localedatetime.isEmpty() && !breitengrad.isEmpty() && !laengengrad.isEmpty() && !timestamp.isEmpty() && !ampltiude.isEmpty() && !welle.isEmpty())
{
return true;
}else
{
return false;
}
}
public String getandroidid ()
{
return Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID);
}
public void getDataBaseFailure (DatabaseError error)
{
System.out.println("Fehler");
Log.w("Datenbankfehler", error.toException());
}
//################################################################## ^^^^ DB Code ^^^^ ################################################################################### //################################################################## ^^^^ DB Code ^^^^ ###################################################################################
//########################################################################################################################################################################## //##########################################################################################################################################################################
//##########################################################################################################################################################################
//################################################################## vvv Set Text of Device 1/2/3 on MainActivity vvv ####################################################
private void setText(){
TextView txtDevice1 = (TextView) findViewById(R.id.txtdevice1);
TextView txtDevice2 = (TextView) findViewById(R.id.txtdevice2);
TextView txtDevice3 = (TextView) findViewById(R.id.txtdevice3);
TextView txtDevice4 = (TextView) findViewById(R.id.txtdevice4);
txtDevice1.setText("Device 1"+"\n"+"Time Stamp: "+ Calendar.getInstance().getTimeInMillis()+"\n"+"Latitude: "+breitengrad+"\n"+ "Longitude: "+ laengengrad+"\n");
txtDevice2.setText("Device 2"+"\n"+"Time Stamp: "+ Calendar.getInstance().getTimeInMillis()+"\n"+"Latitude: "+breitengrad+"\n"+ "Longitude: "+ laengengrad+"\n");
txtDevice3.setText("Device 3"+"\n"+"Time Stamp: "+ Calendar.getInstance().getTimeInMillis()+"\n"+"Latitude: "+breitengrad+"\n"+ "Longitude: "+ laengengrad+"\n");
txtDevice4.setText("Device 4"+"\n"+"Time Stamp: "+ Calendar.getInstance().getTimeInMillis()+"\n"+"Latitude: "+breitengrad+"\n"+ "Longitude: "+ laengengrad+"\n");
}
//################################################################## ^^^^ Set Text of Device 1/2/3 on MainActivity ^^^^ ##################################################
//##########################################################################################################################################################################
//########################################################################################################################################################################## //##########################################################################################################################################################################
//################################################################## vvv Maps Code vvv ################################################################################### //################################################################## vvv Maps Code vvv ###################################################################################
@@ -188,6 +536,7 @@ public class MainActivity extends AppCompatActivity {
private void init() { private void init() {
Button btnEarthquake = (Button) findViewById(R.id.btnEarthquakeLocation); Button btnEarthquake = (Button) findViewById(R.id.btnEarthquakeLocation);
btnEarthquake.setEnabled(false);
btnEarthquake.setOnClickListener(new View.OnClickListener() { btnEarthquake.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@@ -196,6 +545,28 @@ public class MainActivity extends AppCompatActivity {
} }
}); });
Button btnResetDB = (Button) findViewById(R.id.btnResetDB);
btnResetDB.setOnClickListener(new View.OnClickListener() {
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public void onClick(View v) {
for (int i=1; i<=5; i++)
{
writeEmptyToSecondDataBase(i);
}
}
});
Button btnReadyToDetect = (Button) findViewById(R.id.buttonReadyToDetect);
btnReadyToDetect.setOnClickListener(new View.OnClickListener() {
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public void onClick(View v) {
mShakeDetectionIsActive = true;
mShakeDetected = false;
btnReadyToDetect.setEnabled(false);
}
});
} }
@@ -27,7 +27,7 @@ public class Detektionssignal {
this.koordinaten = koordinaten; this.koordinaten = koordinaten;
} }
public int getGeschwErdbeben() { public double getGeschwErdbeben() {
return geschwErdbeben; return geschwErdbeben;
} }
@@ -44,6 +44,6 @@ public class Detektionssignal {
} }
public Koordinaten koordinaten; public Koordinaten koordinaten;
public int geschwErdbeben; public double geschwErdbeben;
public LocalDateTime ankunftsZeit; public LocalDateTime ankunftsZeit;
} }
@@ -2,7 +2,10 @@ package de.edotzlaff.detection.detektion;
import android.os.Build; import android.os.Build;
import android.util.Log;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import de.edotzlaff.detection.detektion.berechnung.Endpunkt; import de.edotzlaff.detection.detektion.berechnung.Endpunkt;
import de.edotzlaff.detection.detektion.berechnung.EndpunktVerbindung; import de.edotzlaff.detection.detektion.berechnung.EndpunktVerbindung;
import de.edotzlaff.detection.detektion.berechnung.EpizentrumRechnung; import de.edotzlaff.detection.detektion.berechnung.EpizentrumRechnung;
@@ -15,12 +18,13 @@ import java.util.Objects;
public class Erdbeben { public class Erdbeben {
//ToDO anpassen an Szenario umso mehr umso wahrscheinlich ein Ergebnis, oder Abbruchbedingung mit do while //ToDO anpassen an Szenario umso mehr umso wahrscheinlich ein Ergebnis, oder Abbruchbedingung mit do while
public static final Integer SCHLEIFENDURCHLAUFTE = 400; public static final Integer SCHLEIFENDURCHLAUFTE = 200;
private static final String TAG = "ERDBEBEN";
private Epizentrum epizentrum; private Epizentrum epizentrum;
private EpizentrumRechnung epizentrumRechnung; private EpizentrumRechnung epizentrumRechnung;
private HashMap<String, Detektionssignal> nutzerDaten; private HashMap<String, Detektionssignal> nutzerDaten;
private Detektionssignal erstesDetektionssignal;
public Erdbeben() { public Erdbeben() {
@@ -34,12 +38,11 @@ public class Erdbeben {
return nutzerDaten.size(); return nutzerDaten.size();
} }
public void addDetektionssignalList(ArrayList<Detektionssignal> detektionssignale) public void addDetektionssignalList(ArrayList<Detektionssignal> detektionssignale) {
{ for (int i = 0; i < detektionssignale.size(); i++) {
for (int i = 0; i< detektionssignale.size(); i++) nutzerDaten.put(detektionssignale.get(i).getDeviceId() + "i", detektionssignale.get(i));
{
nutzerDaten.put(detektionssignale.get(i).getDeviceId(),detektionssignale.get(i));
} }
Log.i(TAG, "addDetektionssignalList: " + nutzerDaten.size());
} }
@RequiresApi(api = Build.VERSION_CODES.O) @RequiresApi(api = Build.VERSION_CODES.O)
@@ -48,7 +51,9 @@ public class Erdbeben {
ArrayList<Detektionssignal> rechenListe = new ArrayList<>(); ArrayList<Detektionssignal> rechenListe = new ArrayList<>();
nutzerDaten.forEach((key, value) -> rechenListe.add(value)); nutzerDaten.forEach((key, value) -> rechenListe.add(value));
//Initialisierung der Rechung - First Element mit delta r + alle möglichen EndpunktKombinationen (einfach) //Initialisierung der Rechung - First Element mit delta r + alle möglichen EndpunktKombinationen (einfach)
ArrayList<Endpunkt> berechnungsEndpunkte = epizentrumRechnung.initEndpunkte(rechenListe); erstesDetektionssignal = epizentrumRechnung.ermittleErstesDetektionssignal(rechenListe);
ArrayList<Endpunkt> berechnungsEndpunkte = epizentrumRechnung.initEndpunkte(rechenListe, erstesDetektionssignal);
ArrayList<EndpunktVerbindung> endpunktKonbinationen = epizentrumRechnung.ermittleEndpunktKonbinationen(berechnungsEndpunkte); ArrayList<EndpunktVerbindung> endpunktKonbinationen = epizentrumRechnung.ermittleEndpunktKonbinationen(berechnungsEndpunkte);
//ToDo Vernünftiger Endpunkt überlegen bzw. bis wann abgebrochen wird -> Umzug in Berechnungs //ToDo Vernünftiger Endpunkt überlegen bzw. bis wann abgebrochen wird -> Umzug in Berechnungs
@@ -57,15 +62,22 @@ public class Erdbeben {
epizentrum = epizentrumRechnung.ueberpruefeObEpizentrum(endpunktKonbinationen); epizentrum = epizentrumRechnung.ueberpruefeObEpizentrum(endpunktKonbinationen);
//ToDo set EnstehungsZeitpunkt -> (Bezugszeit, Koord, Koord, v;) //ToDo set EnstehungsZeitpunkt -> (Bezugszeit, Koord, Koord, v;)
if (!Objects.isNull(epizentrum)) { if (!Objects.isNull(epizentrum)) {
System.out.println("Epizentrum ermittelt"); epizentrum.setEntstehungsZeitpunkt(epizentrumRechnung.berechneEntstehungsZeitpunktLongLatt(erstesDetektionssignal, epizentrum.getKoordinaten()));
epizentrum.setEntstehungsZeitpunkt(
epizentrumRechnung.berechneEntstehungsZeitpunkt(
nutzerDaten.get(berechnungsEndpunkte.get(0).getNutzer()), epizentrum.getKoordinaten()));
return epizentrum; return epizentrum;
} }
} }
epizentrumRechnung.erhoheRadius(berechnungsEndpunkte); epizentrumRechnung.erhoheRadius(berechnungsEndpunkte);
} }
if(!Objects.isNull(epizentrumRechnung.trilateration(berechnungsEndpunkte)))
{
epizentrum = epizentrumRechnung.trilateration(berechnungsEndpunkte);
Log.i(TAG, "Koordinaten: " +epizentrum.getKoordinaten().getX() + " " + epizentrum.getKoordinaten().getY());
epizentrum.setEntstehungsZeitpunkt(epizentrumRechnung.berechneEntstehungsZeitpunktLongLatt(erstesDetektionssignal, epizentrum.getKoordinaten()));
return epizentrum;
}
return null; return null;
} }
@@ -1,15 +1,26 @@
package de.edotzlaff.detection.detektion.berechnung; package de.edotzlaff.detection.detektion.berechnung;
import android.location.Location;
import android.nfc.Tag;
import android.os.Build; import android.os.Build;
import android.util.Log;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.lemmingapex.trilateration.NonLinearLeastSquaresSolver;
import com.lemmingapex.trilateration.TrilaterationFunction;
import org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer;
import org.apache.commons.math3.fitting.leastsquares.LevenbergMarquardtOptimizer;
import de.edotzlaff.detection.detektion.Detektionssignal; import de.edotzlaff.detection.detektion.Detektionssignal;
import de.edotzlaff.detection.detektion.Epizentrum; import de.edotzlaff.detection.detektion.Epizentrum;
import de.edotzlaff.detection.detektion.berechnung.mathObjekte.Koordinaten; import de.edotzlaff.detection.detektion.berechnung.mathObjekte.Koordinaten;
import de.edotzlaff.detection.detektion.berechnung.mathObjekte.Kreis; import de.edotzlaff.detection.detektion.berechnung.mathObjekte.Kreis;
import de.edotzlaff.detection.detektion.berechnung.mathObjekte.Schnittpunkt; import de.edotzlaff.detection.detektion.berechnung.mathObjekte.Schnittpunkt;
import de.edotzlaff.detection.detektion.berechnung.mathObjekte.UTM2Deg;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
@@ -21,32 +32,47 @@ import java.util.Set;
public class EpizentrumRechnung { public class EpizentrumRechnung {
//ToDo Schrittweite und Abstand auf Szenario anpassen //ToDo Schrittweite und Abstand auf Szenario anpassen
private static final double SCHRITTWEITE = 0.02; private static final double SCHRITTWEITE = 5;
private static final double MAX_ABSTAND = 0.009; private static final double MAX_ABSTAND = 5;
private static final int DOUBLESTELLEN = 8; private static final int DOUBLESTELLEN = 15;
private static final int SCHLEIFENDURCHLAUFTE = 5000;
private static final String TAG = "EPIZENTRUMRECHNUNG";
@RequiresApi(api = Build.VERSION_CODES.O) @RequiresApi(api = Build.VERSION_CODES.O)
public ArrayList<Endpunkt> initEndpunkte(ArrayList<Detektionssignal> detektionssignal) { public ArrayList<Endpunkt> initEndpunkte(ArrayList<Detektionssignal> detektionssignal, Detektionssignal ersteMessung) {
Detektionssignal nahegelegensteMessung = detektionssignal.get(0);
ArrayList<Endpunkt> arrBerechnungsObjekte = new ArrayList<>(); ArrayList<Endpunkt> arrBerechnungsObjekte = new ArrayList<>();
for (int i = 1; i < detektionssignal.size(); i++) {
if (detektionssignal.get(i).getAnkunftsZeit().isBefore(nahegelegensteMessung.getAnkunftsZeit())) {
nahegelegensteMessung = detektionssignal.get(i);
}
}
for (Detektionssignal aufzeichnung : detektionssignal) { for (Detektionssignal aufzeichnung : detektionssignal) {
int zeitunterschied = aufzeichnung.getAnkunftsZeit().getHour() * 3600 + aufzeichnung.getAnkunftsZeit().getMinute() * 60 + aufzeichnung.getAnkunftsZeit().getSecond() int zeitunterschied = aufzeichnung.getAnkunftsZeit().getHour() * 3600 + aufzeichnung.getAnkunftsZeit().getMinute() * 60 + aufzeichnung.getAnkunftsZeit().getSecond()
- nahegelegensteMessung.getAnkunftsZeit().getHour() * 3600 - nahegelegensteMessung.getAnkunftsZeit().getMinute() * 60 - nahegelegensteMessung.getAnkunftsZeit().getSecond(); - ersteMessung.getAnkunftsZeit().getHour() * 3600 - ersteMessung.getAnkunftsZeit().getMinute() * 60 - ersteMessung.getAnkunftsZeit().getSecond();
double startradius = zeitunterschied * aufzeichnung.getGeschwErdbeben(); double startradius = zeitunterschied * aufzeichnung.getGeschwErdbeben();
Log.i(TAG, "Init Daten: " + aufzeichnung.getDeviceId() + "Startradius: " + startradius);
Endpunkt tempEndpunkt = new Endpunkt(aufzeichnung.getDeviceId()); Endpunkt tempEndpunkt = new Endpunkt(aufzeichnung.getDeviceId());
Kreis k = new Kreis(aufzeichnung.getKoordinaten().getX(), aufzeichnung.getKoordinaten().getY(), startradius); Kreis k = new Kreis(aufzeichnung.getKoordinaten().getX(), aufzeichnung.getKoordinaten().getY(), startradius);
tempEndpunkt.setKreis(k); tempEndpunkt.setKreis(k);
arrBerechnungsObjekte.add(tempEndpunkt); arrBerechnungsObjekte.add(tempEndpunkt);
} }
Log.i(TAG, "Daten Erfolgreich initialisiert");
return arrBerechnungsObjekte; return arrBerechnungsObjekte;
} }
@RequiresApi(api = Build.VERSION_CODES.O)
public Detektionssignal ermittleErstesDetektionssignal(ArrayList<Detektionssignal> detektionssignale)
{
Detektionssignal erstesDetektionssignal = detektionssignale.get(0);
for (int i = 1; i < detektionssignale.size(); i++) {
if (detektionssignale.get(i).getAnkunftsZeit().isBefore(erstesDetektionssignal.getAnkunftsZeit())) {
erstesDetektionssignal = detektionssignale.get(i);
}
}
Log.i(TAG, "Test");
return erstesDetektionssignal;
}
public ArrayList<Schnittpunkt> berechneKreisSchnittpunkte(Kreis kreis1, Kreis kreis2) { public ArrayList<Schnittpunkt> berechneKreisSchnittpunkte(Kreis kreis1, Kreis kreis2) {
ArrayList<Schnittpunkt> schnittpunkte = new ArrayList<>(); ArrayList<Schnittpunkt> schnittpunkte = new ArrayList<>();
@@ -85,7 +111,8 @@ public class EpizentrumRechnung {
} }
public boolean genuegendSchnittpunktevorhanden(ArrayList<EndpunktVerbindung> endpunktVerbindungen) { public boolean genuegendSchnittpunktevorhanden(ArrayList<EndpunktVerbindung> endpunktVerbindungen) {
//Log.i(TAG,"Überprüfe ob genügend Schnittpunkte vorhanden sind");
//Log.i(TAG,"Radius: "+ Double.toString(endpunktVerbindungen.get(0).getEndpunkt1().getKreis().getRadius()));
for (EndpunktVerbindung endpunktVerbindung : endpunktVerbindungen) { for (EndpunktVerbindung endpunktVerbindung : endpunktVerbindungen) {
ArrayList<Schnittpunkt> templist; ArrayList<Schnittpunkt> templist;
templist = berechneKreisSchnittpunkte(endpunktVerbindung.getEndpunkt1().getKreis(), endpunktVerbindung.getEndpunkt2().getKreis()); templist = berechneKreisSchnittpunkte(endpunktVerbindung.getEndpunkt1().getKreis(), endpunktVerbindung.getEndpunkt2().getKreis());
@@ -98,7 +125,6 @@ public class EpizentrumRechnung {
} }
public Epizentrum ueberpruefeObEpizentrum(ArrayList<EndpunktVerbindung> endpunktVerbindungen) { public Epizentrum ueberpruefeObEpizentrum(ArrayList<EndpunktVerbindung> endpunktVerbindungen) {
int counter; int counter;
ArrayList<Schnittpunkt> schnittpunkte = new ArrayList<>(); ArrayList<Schnittpunkt> schnittpunkte = new ArrayList<>();
@@ -118,7 +144,9 @@ public class EpizentrumRechnung {
if (counter == endpunktVerbindungen.size() - 1) { if (counter == endpunktVerbindungen.size() - 1) {
schnittpunkte.add(s1); schnittpunkte.add(s1);
Epizentrum tempEpizentrum = new Epizentrum(); Epizentrum tempEpizentrum = new Epizentrum();
tempEpizentrum.setKoordinaten(berechneEpizentrumKoordinaten(schnittpunkte)); Koordinaten koordinaten = (berechneEpizentrumKoordinaten(schnittpunkte));
tempEpizentrum.setKoordinaten(koordinaten);
Log.i(TAG, "Epizentrumkoord: " + tempEpizentrum.getKoordinaten().getX() + " " + tempEpizentrum.getKoordinaten().getY());
return tempEpizentrum; return tempEpizentrum;
} }
} }
@@ -128,17 +156,21 @@ public class EpizentrumRechnung {
} }
public Koordinaten berechneEpizentrumKoordinaten(ArrayList<Schnittpunkt> schnittpunkte) { public Koordinaten berechneEpizentrumKoordinaten(ArrayList<Schnittpunkt> schnittpunkte) {
Log.i(TAG, "Berechne Epizentrum Koordinaten");
double x = 0; double x = 0;
double y = 0; double y = 0;
for (Schnittpunkt s : schnittpunkte) { for (Schnittpunkt s : schnittpunkte) {
Log.i(TAG, "Koordinaten der Schnittpunkte: "+ s.getKoordinaten().getX() + " " + s.getKoordinaten().getY());
x+= s.getKoordinaten().getX(); x+= s.getKoordinaten().getX();
y+= s.getKoordinaten().getY(); y+= s.getKoordinaten().getY();
} }
return new Koordinaten(new BigDecimal(x/schnittpunkte.size()).setScale(DOUBLESTELLEN, RoundingMode.HALF_UP).doubleValue(), x = new BigDecimal(x/schnittpunkte.size()).setScale(DOUBLESTELLEN, RoundingMode.HALF_UP).doubleValue();
new BigDecimal(y/schnittpunkte.size()).setScale(DOUBLESTELLEN, RoundingMode.HALF_UP).doubleValue()); y = new BigDecimal(y/schnittpunkte.size()).setScale(DOUBLESTELLEN, RoundingMode.HALF_UP).doubleValue();
return new Koordinaten(x,y);
} }
public ArrayList<EndpunktVerbindung> ermittleEndpunktKonbinationen(ArrayList<Endpunkt> tempBerechungsObjekte) { public ArrayList<EndpunktVerbindung> ermittleEndpunktKonbinationen(ArrayList<Endpunkt> tempBerechungsObjekte) {
ArrayList<EndpunktVerbindung> verbindungen = new ArrayList<>(); ArrayList<EndpunktVerbindung> verbindungen = new ArrayList<>();
Set<Set<Endpunkt>> combinations = Sets.combinations(ImmutableSet.copyOf(tempBerechungsObjekte), 2); Set<Set<Endpunkt>> combinations = Sets.combinations(ImmutableSet.copyOf(tempBerechungsObjekte), 2);
for (Set<Endpunkt> tempEndpunkt : combinations) { for (Set<Endpunkt> tempEndpunkt : combinations) {
@@ -146,6 +178,7 @@ public class EpizentrumRechnung {
EndpunktVerbindung endpunktVerbindung = new EndpunktVerbindung(helpArrayToGetValues.get(0), helpArrayToGetValues.get(1)); EndpunktVerbindung endpunktVerbindung = new EndpunktVerbindung(helpArrayToGetValues.get(0), helpArrayToGetValues.get(1));
verbindungen.add(endpunktVerbindung); verbindungen.add(endpunktVerbindung);
} }
Log.i(TAG, "Endpunkteverbindungen Erfolgreich festgelegt, Anzahl: " + verbindungen.size());
return verbindungen; return verbindungen;
} }
@@ -154,15 +187,54 @@ public class EpizentrumRechnung {
double abstand = Math.sqrt( double abstand = Math.sqrt(
Math.pow(detektionssignal.getKoordinaten().getX() - koordEpi.getX(), 2) + Math.pow(detektionssignal.getKoordinaten().getX() - koordEpi.getX(), 2) +
Math.pow(detektionssignal.getKoordinaten().getY() - koordEpi.getY(), 2)); Math.pow(detektionssignal.getKoordinaten().getY() - koordEpi.getY(), 2));
int sec = (int) abstand/ detektionssignal.geschwErdbeben; int sec = (int) (abstand / detektionssignal.geschwErdbeben);
return detektionssignal.getAnkunftsZeit().minusSeconds(sec); return detektionssignal.getAnkunftsZeit().minusSeconds(sec);
} }
@RequiresApi(api = Build.VERSION_CODES.O)
public LocalDateTime berechneEntstehungsZeitpunktLongLatt(Detektionssignal detektionssignal, Koordinaten koordEpi) {
float[] results = new float[1];
Location.distanceBetween(detektionssignal.getKoordinaten().getX(), detektionssignal.getKoordinaten().getY(), koordEpi.getX(), koordEpi.getY(), results);
float distanceInMeters = results[0];
int sec = (int) (distanceInMeters / detektionssignal.geschwErdbeben);
return detektionssignal.getAnkunftsZeit().minusSeconds(sec);
}
public void erhoheRadius(ArrayList<Endpunkt> tempEndpunktListe) { public void erhoheRadius(ArrayList<Endpunkt> tempEndpunktListe) {
for (Endpunkt b : tempEndpunktListe) { for (Endpunkt b : tempEndpunktListe) {
b.erhoeheRadius(SCHRITTWEITE); b.erhoeheRadius(SCHRITTWEITE);
} }
} }
public Epizentrum trilateration(ArrayList<Endpunkt> tempEndpunktListe) {
double[][] positions = new double[tempEndpunktListe.size()][2];
double[] distances = new double[tempEndpunktListe.size()];
for (int i = 0; i < tempEndpunktListe.size(); i++) {
positions[i][0] = tempEndpunktListe.get(i).getKreis().getMittelPunkt().getX();
positions[i][1] = tempEndpunktListe.get(i).getKreis().getMittelPunkt().getY();
distances[i] = tempEndpunktListe.get(i).getKreis().getRadius();
}
NonLinearLeastSquaresSolver solver = new NonLinearLeastSquaresSolver(new TrilaterationFunction(positions, distances), new LevenbergMarquardtOptimizer());
LeastSquaresOptimizer.Optimum optimum = solver.solve();
double[] centroid = optimum.getPoint().toArray();
if (centroid.length == 2) {
UTM2Deg utm2Deg = new UTM2Deg();
utm2Deg.convertToDeg(32, 'U', centroid[0], centroid[1]);
Log.i(TAG, "Center: " + utm2Deg.getLatitude() + " " + utm2Deg.getLongitude());
Epizentrum epizentrum = new Epizentrum();
Koordinaten koordinaten = new Koordinaten(centroid[0], centroid[1]);
epizentrum.setKoordinaten(koordinaten);
return epizentrum;
}
return null;
}
} }
@@ -0,0 +1,76 @@
package de.edotzlaff.detection.detektion.berechnung.mathObjekte;
public class Deg2UTM {
double Easting;
double Northing;
int Zone;
char Letter;
public Deg2UTM(double Lat, double Lon) {
Zone = (int) Math.floor(Lon / 6 + 31);
if (Lat < -72)
Letter = 'C';
else if (Lat < -64)
Letter = 'D';
else if (Lat < -56)
Letter = 'E';
else if (Lat < -48)
Letter = 'F';
else if (Lat < -40)
Letter = 'G';
else if (Lat < -32)
Letter = 'H';
else if (Lat < -24)
Letter = 'J';
else if (Lat < -16)
Letter = 'K';
else if (Lat < -8)
Letter = 'L';
else if (Lat < 0)
Letter = 'M';
else if (Lat < 8)
Letter = 'N';
else if (Lat < 16)
Letter = 'P';
else if (Lat < 24)
Letter = 'Q';
else if (Lat < 32)
Letter = 'R';
else if (Lat < 40)
Letter = 'S';
else if (Lat < 48)
Letter = 'T';
else if (Lat < 56)
Letter = 'U';
else if (Lat < 64)
Letter = 'V';
else if (Lat < 72)
Letter = 'W';
else
Letter = 'X';
Easting = 0.5 * Math.log((1 + Math.cos(Lat * Math.PI / 180) * Math.sin(Lon * Math.PI / 180 - (6 * Zone - 183) * Math.PI / 180)) / (1 - Math.cos(Lat * Math.PI / 180) * Math.sin(Lon * Math.PI / 180 - (6 * Zone - 183) * Math.PI / 180))) * 0.9996 * 6399593.62 / Math.pow((1 + Math.pow(0.0820944379, 2) * Math.pow(Math.cos(Lat * Math.PI / 180), 2)), 0.5) * (1 + Math.pow(0.0820944379, 2) / 2 * Math.pow((0.5 * Math.log((1 + Math.cos(Lat * Math.PI / 180) * Math.sin(Lon * Math.PI / 180 - (6 * Zone - 183) * Math.PI / 180)) / (1 - Math.cos(Lat * Math.PI / 180) * Math.sin(Lon * Math.PI / 180 - (6 * Zone - 183) * Math.PI / 180)))), 2) * Math.pow(Math.cos(Lat * Math.PI / 180), 2) / 3) + 500000;
Easting = Math.round(Easting * 100) * 0.01;
Northing = (Math.atan(Math.tan(Lat * Math.PI / 180) / Math.cos((Lon * Math.PI / 180 - (6 * Zone - 183) * Math.PI / 180))) - Lat * Math.PI / 180) * 0.9996 * 6399593.625 / Math.sqrt(1 + 0.006739496742 * Math.pow(Math.cos(Lat * Math.PI / 180), 2)) * (1 + 0.006739496742 / 2 * Math.pow(0.5 * Math.log((1 + Math.cos(Lat * Math.PI / 180) * Math.sin((Lon * Math.PI / 180 - (6 * Zone - 183) * Math.PI / 180))) / (1 - Math.cos(Lat * Math.PI / 180) * Math.sin((Lon * Math.PI / 180 - (6 * Zone - 183) * Math.PI / 180)))), 2) * Math.pow(Math.cos(Lat * Math.PI / 180), 2)) + 0.9996 * 6399593.625 * (Lat * Math.PI / 180 - 0.005054622556 * (Lat * Math.PI / 180 + Math.sin(2 * Lat * Math.PI / 180) / 2) + 4.258201531e-05 * (3 * (Lat * Math.PI / 180 + Math.sin(2 * Lat * Math.PI / 180) / 2) + Math.sin(2 * Lat * Math.PI / 180) * Math.pow(Math.cos(Lat * Math.PI / 180), 2)) / 4 - 1.674057895e-07 * (5 * (3 * (Lat * Math.PI / 180 + Math.sin(2 * Lat * Math.PI / 180) / 2) + Math.sin(2 * Lat * Math.PI / 180) * Math.pow(Math.cos(Lat * Math.PI / 180), 2)) / 4 + Math.sin(2 * Lat * Math.PI / 180) * Math.pow(Math.cos(Lat * Math.PI / 180), 2) * Math.pow(Math.cos(Lat * Math.PI / 180), 2)) / 3);
if (Letter < 'M')
Northing = Northing + 10000000;
Northing = Math.round(Northing * 100) * 0.01;
}
public double getEasting() {
return Easting;
}
public void setEasting(double easting) {
Easting = easting;
}
public double getNorthing() {
return Northing;
}
public void setNorthing(double northing) {
Northing = northing;
}
}
@@ -0,0 +1,50 @@
package de.edotzlaff.detection.detektion.berechnung.mathObjekte;
public class UTM2Deg {
double latitude;
double longitude;
public void convertToDeg(int zone, char letter, double easting, double northing)
{
int Zone=zone;
char Letter=letter;
double Easting=easting;
double Northing=northing;
double Hem;
if (Letter>'M')
Hem='N';
else
Hem='S';
double north;
if (Hem == 'S')
north = Northing - 10000000;
else
north = Northing;
latitude = (north/6366197.724/0.9996+(1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2)-0.006739496742*Math.sin(north/6366197.724/0.9996)*Math.cos(north/6366197.724/0.9996)*(Math.atan(Math.cos(Math.atan(( Math.exp((Easting - 500000) / (0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2))))*(1-0.006739496742*Math.pow((Easting - 500000) / (0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2)))),2)/2*Math.pow(Math.cos(north/6366197.724/0.9996),2)/3))-Math.exp(-(Easting-500000)/(0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2))))*( 1 - 0.006739496742*Math.pow((Easting - 500000) / (0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2)))),2)/2*Math.pow(Math.cos(north/6366197.724/0.9996),2)/3)))/2/Math.cos((north-0.9996*6399593.625*(north/6366197.724/0.9996-0.006739496742*3/4*(north/6366197.724/0.9996+Math.sin(2*north/6366197.724/0.9996)/2)+Math.pow(0.006739496742*3/4,2)*5/3*(3*(north/6366197.724/0.9996+Math.sin(2*north/6366197.724/0.9996 )/2)+Math.sin(2*north/6366197.724/0.9996)*Math.pow(Math.cos(north/6366197.724/0.9996),2))/4-Math.pow(0.006739496742*3/4,3)*35/27*(5*(3*(north/6366197.724/0.9996+Math.sin(2*north/6366197.724/0.9996)/2)+Math.sin(2*north/6366197.724/0.9996)*Math.pow(Math.cos(north/6366197.724/0.9996),2))/4+Math.sin(2*north/6366197.724/0.9996)*Math.pow(Math.cos(north/6366197.724/0.9996),2)*Math.pow(Math.cos(north/6366197.724/0.9996),2))/3))/(0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2))))*(1-0.006739496742*Math.pow((Easting-500000)/(0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2)))),2)/2*Math.pow(Math.cos(north/6366197.724/0.9996),2))+north/6366197.724/0.9996)))*Math.tan((north-0.9996*6399593.625*(north/6366197.724/0.9996 - 0.006739496742*3/4*(north/6366197.724/0.9996+Math.sin(2*north/6366197.724/0.9996)/2)+Math.pow(0.006739496742*3/4,2)*5/3*(3*(north/6366197.724/0.9996+Math.sin(2*north/6366197.724/0.9996)/2)+Math.sin(2*north/6366197.724/0.9996 )*Math.pow(Math.cos(north/6366197.724/0.9996),2))/4-Math.pow(0.006739496742*3/4,3)*35/27*(5*(3*(north/6366197.724/0.9996+Math.sin(2*north/6366197.724/0.9996)/2)+Math.sin(2*north/6366197.724/0.9996)*Math.pow(Math.cos(north/6366197.724/0.9996),2))/4+Math.sin(2*north/6366197.724/0.9996)*Math.pow(Math.cos(north/6366197.724/0.9996),2)*Math.pow(Math.cos(north/6366197.724/0.9996),2))/3))/(0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2))))*(1-0.006739496742*Math.pow((Easting-500000)/(0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2)))),2)/2*Math.pow(Math.cos(north/6366197.724/0.9996),2))+north/6366197.724/0.9996))-north/6366197.724/0.9996)*3/2)*(Math.atan(Math.cos(Math.atan((Math.exp((Easting-500000)/(0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2))))*(1-0.006739496742*Math.pow((Easting-500000)/(0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2)))),2)/2*Math.pow(Math.cos(north/6366197.724/0.9996),2)/3))-Math.exp(-(Easting-500000)/(0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2))))*(1-0.006739496742*Math.pow((Easting-500000)/(0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2)))),2)/2*Math.pow(Math.cos(north/6366197.724/0.9996),2)/3)))/2/Math.cos((north-0.9996*6399593.625*(north/6366197.724/0.9996-0.006739496742*3/4*(north/6366197.724/0.9996+Math.sin(2*north/6366197.724/0.9996)/2)+Math.pow(0.006739496742*3/4,2)*5/3*(3*(north/6366197.724/0.9996+Math.sin(2*north/6366197.724/0.9996)/2)+Math.sin(2*north/6366197.724/0.9996)*Math.pow(Math.cos(north/6366197.724/0.9996),2))/4-Math.pow(0.006739496742*3/4,3)*35/27*(5*(3*(north/6366197.724/0.9996+Math.sin(2*north/6366197.724/0.9996)/2)+Math.sin(2*north/6366197.724/0.9996)*Math.pow(Math.cos(north/6366197.724/0.9996),2))/4+Math.sin(2*north/6366197.724/0.9996)*Math.pow(Math.cos(north/6366197.724/0.9996),2)*Math.pow(Math.cos(north/6366197.724/0.9996),2))/3))/(0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2))))*(1-0.006739496742*Math.pow((Easting-500000)/(0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2)))),2)/2*Math.pow(Math.cos(north/6366197.724/0.9996),2))+north/6366197.724/0.9996)))*Math.tan((north-0.9996*6399593.625*(north/6366197.724/0.9996-0.006739496742*3/4*(north/6366197.724/0.9996+Math.sin(2*north/6366197.724/0.9996)/2)+Math.pow(0.006739496742*3/4,2)*5/3*(3*(north/6366197.724/0.9996+Math.sin(2*north/6366197.724/0.9996)/2)+Math.sin(2*north/6366197.724/0.9996)*Math.pow(Math.cos(north/6366197.724/0.9996),2))/4-Math.pow(0.006739496742*3/4,3)*35/27*(5*(3*(north/6366197.724/0.9996+Math.sin(2*north/63Line truncated
latitude=Math.round(latitude*10000000);
latitude=latitude/10000000;
longitude =Math.atan((Math.exp((Easting-500000)/(0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2))))*(1-0.006739496742*Math.pow((Easting-500000)/(0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2)))),2)/2*Math.pow(Math.cos(north/6366197.724/0.9996),2)/3))-Math.exp(-(Easting-500000)/(0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2))))*(1-0.006739496742*Math.pow((Easting-500000)/(0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2)))),2)/2*Math.pow(Math.cos(north/6366197.724/0.9996),2)/3)))/2/Math.cos((north-0.9996*6399593.625*( north/6366197.724/0.9996-0.006739496742*3/4*(north/6366197.724/0.9996+Math.sin(2*north/6366197.724/0.9996)/2)+Math.pow(0.006739496742*3/4,2)*5/3*(3*(north/6366197.724/0.9996+Math.sin(2*north/6366197.724/0.9996)/2)+Math.sin(2* north/6366197.724/0.9996)*Math.pow(Math.cos(north/6366197.724/0.9996),2))/4-Math.pow(0.006739496742*3/4,3)*35/27*(5*(3*(north/6366197.724/0.9996+Math.sin(2*north/6366197.724/0.9996)/2)+Math.sin(2*north/6366197.724/0.9996)*Math.pow(Math.cos(north/6366197.724/0.9996),2))/4+Math.sin(2*north/6366197.724/0.9996)*Math.pow(Math.cos(north/6366197.724/0.9996),2)*Math.pow(Math.cos(north/6366197.724/0.9996),2))/3)) / (0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2))))*(1-0.006739496742*Math.pow((Easting-500000)/(0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2)))),2)/2*Math.pow(Math.cos(north/6366197.724/0.9996),2))+north/6366197.724/0.9996))*180/Math.PI+Zone*6-183;
longitude=Math.round(longitude*10000000);
longitude=longitude/10000000;
}
public double getLatitude() {
return latitude;
}
public void setLatitude(double latitude) {
this.latitude = latitude;
}
public double getLongitude() {
return longitude;
}
public void setLongitude(double longitude) {
this.longitude = longitude;
}
}
+33 -5
View File
@@ -9,7 +9,7 @@
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Device 1" android:text="@string/device_1"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
@@ -20,7 +20,7 @@
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Device 2" android:text="@string/device_2"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
@@ -32,7 +32,7 @@
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Device 3" android:text="@string/device_3"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
@@ -44,7 +44,7 @@
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Device 4" android:text="@string/device_4"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
@@ -60,6 +60,34 @@
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:layout_marginBottom="0dp" android:layout_marginBottom="0dp"
android:text="Show Earthquake Location" /> android:text="@string/show_earthquake_location" />
<Button
android:id="@+id/buttonReadyToDetect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/btnEarthquakeLocation"
android:layout_alignParentStart="false"
android:layout_alignParentEnd="false"
android:layout_alignParentBottom="false"
android:layout_centerInParent="true"
android:text="@string/sensor_ready_to_detect" />
<Button
android:id="@+id/btnResetDB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_above="@id/buttonReadyToDetect"
android:layout_alignParentStart="false"
android:layout_alignParentEnd="false"
android:layout_alignParentBottom="false"
android:layout_centerInParent="true"
android:textColor="@color/black"
android:text="@string/db_zur_cksetzen" />
</RelativeLayout> </RelativeLayout>
Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

+8
View File
@@ -1,4 +1,12 @@
<resources> <resources>
<string name="app_name">Detection</string> <string name="app_name">Detection</string>
<string name="title_activity_earthquake_location">Map</string> <string name="title_activity_earthquake_location">Map</string>
<string name="testbutton">Testbutton</string>
<string name="sensor_ready_to_detect">Sensor Ready To Detect</string>
<string name="show_earthquake_location">Show Earthquake Location</string>
<string name="device_4">Device 4</string>
<string name="device_3">Device 3</string>
<string name="device_2">Device 2</string>
<string name="device_1">Device 1</string>
<string name="db_zur_cksetzen">DB zurücksetzen</string>
</resources> </resources>
+3 -1
View File
@@ -5,7 +5,9 @@ buildscript {
jcenter() jcenter()
} }
dependencies { dependencies {
classpath "com.android.tools.build:gradle:4.1.3" classpath 'com.android.tools.build:gradle:4.2.1'
classpath 'com.google.gms:google-services:4.3.8'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files
+1 -1
View File
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip