Browse Source

Alpha Version 3.1 - Ohne DB Schreibkonflikte

master
Raz492 3 years ago
parent
commit
a4cb71a8f3

+ 1
- 1
app/src/main/java/de/edotzlaff/schockwelle/Datenbank.java View File

@@ -35,7 +35,7 @@ public class Datenbank {
private long h_timestamp;
private int i_amplitude;
private int w_wellengeschwindigkeit;
private DatabaseReference mDatenbank = FirebaseDatabase.getInstance().getReference().child("aron");
private DatabaseReference mDatenbank = FirebaseDatabase.getInstance().getReference().child("overviewnodes");
private String TAG = "Datenbank";
DataSnapshot DatenBankInhalt;


+ 17
- 17
app/src/main/java/de/edotzlaff/schockwelle/MainActivity.java View File

@@ -149,18 +149,18 @@ public class MainActivity extends FragmentActivity {
Devices d3 = new Devices("","","",48.16958655466396,11.617418429524394,false,false,0,1000,10); //München 48.16958655466396, 11.617418429524394
Devices d4 = new Devices("","","",45.55620112204013,12.342516140205387,false,false,0,1000,10); //Venedig 45.55620112204013, 12.342516140205387
Devices d5 = new Devices("","","",41.9204784730154,12.651055829215638,false,false,0,1000,10); //Rom 41.9204784730154, 12.651055829215638
mDatenbank.child("aron").child("IDG1").setValue(d1);
mDatenbank.child("aron").child("IDG2").setValue(d2);
mDatenbank.child("aron").child("IDG3").setValue(d3);
mDatenbank.child("aron").child("IDG4").setValue(d4);
mDatenbank.child("aron").child("IDG5").setValue(d4);
mDatenbank.child("aron").child("IDG5").setValue(d5);
mDatenbank.child("overviewnodes").child("IDG1").setValue(d1);
mDatenbank.child("overviewnodes").child("IDG2").setValue(d2);
mDatenbank.child("overviewnodes").child("IDG3").setValue(d3);
mDatenbank.child("overviewnodes").child("IDG4").setValue(d4);
mDatenbank.child("overviewnodes").child("IDG5").setValue(d4);
mDatenbank.child("overviewnodes").child("IDG5").setValue(d5);
}
public void getDataBaseValuesNoListener()
{
mDatenbank = FirebaseDatabase.getInstance().getReference();
mDatenbank.child("aron").get().addOnCompleteListener(new OnCompleteListener<DataSnapshot>() {
mDatenbank.child("overviewnodes").get().addOnCompleteListener(new OnCompleteListener<DataSnapshot>() {
@Override
public void onComplete(@NonNull Task<DataSnapshot> task) {
if (!task.isSuccessful()) {
@@ -178,20 +178,20 @@ public class MainActivity extends FragmentActivity {
mDatenbank = FirebaseDatabase.getInstance().getReference();
for (int i = 1; i<=5; i++)
{
mDatenbank.child("aron").child("IDG" + i).child("a_androidid").setValue("");
mDatenbank.child("aron").child("IDG" + i).child("b_localdatetime").setValue("");
mDatenbank.child("aron").child("IDG" + i).child("c_ip").setValue("");
mDatenbank.child("aron").child("IDG" + i).child("d_breitengrad").setValue("");
mDatenbank.child("aron").child("IDG" + i).child("e_laengengrad").setValue("");
mDatenbank.child("aron").child("IDG" + i).child("f_nativegps").setValue(true);
mDatenbank.child("aron").child("IDG" + i).child("g_vibration").setValue(false);
mDatenbank.child("aron").child("IDG" + i).child("h_timestamp").setValue("");
mDatenbank.child("aron").child("IDG" + i).child("i_amplitude").setValue("");
mDatenbank.child("overviewnodes").child("IDG" + i).child("a_androidid").setValue("");
mDatenbank.child("overviewnodes").child("IDG" + i).child("b_localdatetime").setValue("");
mDatenbank.child("overviewnodes").child("IDG" + i).child("c_ip").setValue("");
mDatenbank.child("overviewnodes").child("IDG" + i).child("d_breitengrad").setValue("");
mDatenbank.child("overviewnodes").child("IDG" + i).child("e_laengengrad").setValue("");
mDatenbank.child("overviewnodes").child("IDG" + i).child("f_nativegps").setValue(true);
mDatenbank.child("overviewnodes").child("IDG" + i).child("g_vibration").setValue(false);
mDatenbank.child("overviewnodes").child("IDG" + i).child("h_timestamp").setValue("");
mDatenbank.child("overviewnodes").child("IDG" + i).child("i_amplitude").setValue("");
}
}
public void testProcess(DataSnapshot data)
{
mDatenbank = FirebaseDatabase.getInstance().getReference().child("aron");
mDatenbank = FirebaseDatabase.getInstance().getReference().child("overviewnodes");
}
}

+ 37
- 37
app/src/main/java/de/edotzlaff/schockwelle/SensorMapsActivity.java View File

@@ -316,7 +316,7 @@ public class SensorMapsActivity extends FragmentActivity implements OnMapReadyCa
public void processDataBaseUpdate (DataSnapshot data)
{
int indexMax = (int) data.child("aron").getChildrenCount();
int indexMax = (int) data.child("overviewnodes").getChildrenCount();
//Festellen ob DB oder eigene GPS-Daten verwendet werden sollen
if(analyzeForUseOfOwnGPS(data))
{
@@ -335,8 +335,8 @@ public class SensorMapsActivity extends FragmentActivity implements OnMapReadyCa
{
if(analyzeIfAnroidIdIsEmpty(data,f))
{
String breitengradString = data.child("aron").child("IDG" + f).child("d_breitengrad").getValue().toString();
String laengengradString = data.child("aron").child("IDG" + f).child("e_laengengrad").getValue().toString();
String breitengradString = data.child("overviewnodes").child("IDG" + f).child("d_breitengrad").getValue().toString();
String laengengradString = data.child("overviewnodes").child("IDG" + f).child("e_laengengrad").getValue().toString();
breitengrad = Double.parseDouble(breitengradString);
laengengrad = Double.parseDouble(laengengradString);
allocateIDtoDatabaseSlot(f);
@@ -354,8 +354,8 @@ public class SensorMapsActivity extends FragmentActivity implements OnMapReadyCa
{
System.out.println("Index: " + f + ": Eintrittskriterien erfüllt.");
//Nehme Quelle GPS Daten
String breitengradString = data.child("aron").child("IDG" + f).child("d_breitengrad").getValue().toString();
String laengengradString = data.child("aron").child("IDG" + f).child("e_laengengrad").getValue().toString();
String breitengradString = data.child("overviewnodes").child("IDG" + f).child("d_breitengrad").getValue().toString();
String laengengradString = data.child("overviewnodes").child("IDG" + f).child("e_laengengrad").getValue().toString();
breitengradQuellVibration = breitengradString;
laengengradQuellVibration = laengengradString;
@@ -371,7 +371,7 @@ public class SensorMapsActivity extends FragmentActivity implements OnMapReadyCa
//System.out.println("Index: " + f + ": Beide GPS Daten vorhanden. Ich reserviere mir diesen Platz und schreibe hier demnächst rein.");
//hier sofort ID eintragen
//mDatenbank = FirebaseDatabase.getInstance().getReference();
//mDatenbank.child("aron").child("IDG" + f).child("a_androidid").setValue(getandroidid());
//mDatenbank.child("overviewnodes").child("IDG" + f).child("a_androidid").setValue(getandroidid());
float distanceToEarthquake;
distanceToEarthquake = distance(currentLocation.getLatitude(), currentLocation.getLongitude(), Double.parseDouble(breitengradQuellVibration), Double.parseDouble(laengengradQuellVibration));
long wellenAusbreitungsGeschwindigkeit = (long) db.getMyWaveSpeed(); //Meter die Sekunde
@@ -398,7 +398,7 @@ public class SensorMapsActivity extends FragmentActivity implements OnMapReadyCa
{
//System.out.println("Index: " + f + ": Diese Slot war leer oder es ist meine eigene ID. Ich schreibe hier rein");
//mDatenbank = FirebaseDatabase.getInstance().getReference();
//mDatenbank.child("aron").child("IDG" + f).child("a_androidid").setValue(getandroidid());
//mDatenbank.child("overviewnodes").child("IDG" + f).child("a_androidid").setValue(getandroidid());
float distanceToEarthquake;
distanceToEarthquake = distance(currentLocation.getLatitude(), currentLocation.getLongitude(), Double.parseDouble(breitengradQuellVibration), Double.parseDouble(laengengradQuellVibration));
long wellenAusbreitungsGeschwindigkeit = (long) db.getMyWaveSpeed(); //Meter die Sekunde
@@ -424,10 +424,10 @@ public class SensorMapsActivity extends FragmentActivity implements OnMapReadyCa
String nativeGPSString;
boolean nativeGPS;
int amountNativeGPSisTrue = 0;
int indexMax = (int) data.child("aron").getChildrenCount();
int indexMax = (int) data.child("overviewnodes").getChildrenCount();
for (int i = 1; i <= indexMax; i++)
{
nativeGPSString = data.child("aron").child("IDG" + i).child("f_nativegps").getValue().toString();
nativeGPSString = data.child("overviewnodes").child("IDG" + i).child("f_nativegps").getValue().toString();
if(nativeGPSString.equals("true"))
{
amountNativeGPSisTrue++;
@@ -448,11 +448,11 @@ public class SensorMapsActivity extends FragmentActivity implements OnMapReadyCa
public boolean analyzeIfAnroidIdIsEmpty(DataSnapshot data, int k)
{
String androidid;
int indexMax = (int) data.child("aron").getChildrenCount();
int indexMax = (int) data.child("overviewnodes").getChildrenCount();
boolean androididempty = false;
for (int i = k; i <= k; i++)
{
androidid = data.child("aron").child("IDG" + i).child("a_androidid").getValue().toString();
androidid = data.child("overviewnodes").child("IDG" + i).child("a_androidid").getValue().toString();
if(androidid.isEmpty())
{
androididempty = true;
@@ -468,10 +468,10 @@ public class SensorMapsActivity extends FragmentActivity implements OnMapReadyCa
{
String androididString;
boolean ownAndroidID = false;
int indexMax = (int) data.child("aron").getChildrenCount();
int indexMax = (int) data.child("overviewnodes").getChildrenCount();
for (int i = k; i <= k; i++)
{
androididString = data.child("aron").child("IDG" + i).child("a_androidid").getValue().toString();
androididString = data.child("overviewnodes").child("IDG" + i).child("a_androidid").getValue().toString();
if(androididString.equals(getandroidid()))
{
ownAndroidID = true;
@@ -487,10 +487,10 @@ public class SensorMapsActivity extends FragmentActivity implements OnMapReadyCa
{
String vibrationString;
boolean stateOfVibration = false;
int indexMax = (int) data.child("aron").getChildrenCount();
int indexMax = (int) data.child("overviewnodes").getChildrenCount();
for (int i = k; i <= k; i++)
{
vibrationString = data.child("aron").child("IDG" + i).child("g_vibration").getValue().toString();
vibrationString = data.child("overviewnodes").child("IDG" + i).child("g_vibration").getValue().toString();
if(vibrationString.equals("true"))
{
stateOfVibration = true;
@@ -507,11 +507,11 @@ public class SensorMapsActivity extends FragmentActivity implements OnMapReadyCa
String breitengradString;
String laengengradString;
boolean bothGPSvaluesExist = false;
int indexMax = (int) data.child("aron").getChildrenCount();
int indexMax = (int) data.child("overviewnodes").getChildrenCount();
for (int i = k; i <= k; i++)
{
breitengradString = data.child("aron").child("IDG" + i).child("d_breitengrad").getValue().toString();
laengengradString = data.child("aron").child("IDG" + i).child("e_laengengrad").getValue().toString();
breitengradString = data.child("overviewnodes").child("IDG" + i).child("d_breitengrad").getValue().toString();
laengengradString = data.child("overviewnodes").child("IDG" + i).child("e_laengengrad").getValue().toString();
if(!breitengradString.isEmpty() && !laengengradString.isEmpty())
{
bothGPSvaluesExist = true;
@@ -526,7 +526,7 @@ public class SensorMapsActivity extends FragmentActivity implements OnMapReadyCa
public void allocateIDtoDatabaseSlot(int k)
{
mDatenbank = FirebaseDatabase.getInstance().getReference();
mDatenbank.child("aron").child("IDG" + k).child("a_androidid").setValue(getandroidid());
mDatenbank.child("overviewnodes").child("IDG" + k).child("a_androidid").setValue(getandroidid());
}
@@ -534,7 +534,7 @@ public class SensorMapsActivity extends FragmentActivity implements OnMapReadyCa
public void setVibrationInDataBase(int k)
{
System.out.println("Es wird versucht in DB zu schreiben....");
for(k =k; k<=datenBankSnapShot.child("aron").getChildrenCount();k++)
for(k =k; k<=datenBankSnapShot.child("overviewnodes").getChildrenCount();k++)
{
System.out.println("Index...." + k);
System.out.println("analyzeIfAnroidIdIsEmpty(datenBankSnapShot,k)" + k + "___" + analyzeIfAnroidIdIsEmpty(datenBankSnapShot,k));
@@ -547,35 +547,35 @@ public class SensorMapsActivity extends FragmentActivity implements OnMapReadyCa
System.out.println("Android ID war leer oder es war eigene ID mit Vibration = false. SChreibe in DB...... " + k);
//Reinschreieben
mDatenbank = FirebaseDatabase.getInstance().getReference();
mDatenbank.child("aron").child("IDG" + k).child("a_androidid").setValue(getandroidid());
mDatenbank.child("overviewnodes").child("IDG" + k).child("a_androidid").setValue(getandroidid());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
//mDatenbank.child("aron").child("IDG" + k).child("b_localdatetime").setValue(LocalDateTime.now().toString());
mDatenbank.child("aron").child("IDG" + k).child("b_localdatetime").setValue(LocalDateTime.now(ZoneOffset.UTC).toString());
//mDatenbank.child("overviewnodes").child("IDG" + k).child("b_localdatetime").setValue(LocalDateTime.now().toString());
mDatenbank.child("overviewnodes").child("IDG" + k).child("b_localdatetime").setValue(LocalDateTime.now(ZoneOffset.UTC).toString());
}
mDatenbank.child("aron").child("IDG" + k).child("c_ip").setValue(getDeviceIpAdress());
mDatenbank.child("overviewnodes").child("IDG" + k).child("c_ip").setValue(getDeviceIpAdress());
if (useOwnGPS)
{
mDatenbank.child("aron").child("IDG" + k).child("f_nativegps").setValue(true);
mDatenbank.child("aron").child("IDG" + k).child("d_breitengrad").setValue(currentLocation.getLatitude()); //aktueller Breitengrad
mDatenbank.child("aron").child("IDG" + k).child("e_laengengrad").setValue(currentLocation.getLongitude()); //aktueller Längergrad
mDatenbank.child("overviewnodes").child("IDG" + k).child("f_nativegps").setValue(true);
mDatenbank.child("overviewnodes").child("IDG" + k).child("d_breitengrad").setValue(currentLocation.getLatitude()); //aktueller Breitengrad
mDatenbank.child("overviewnodes").child("IDG" + k).child("e_laengengrad").setValue(currentLocation.getLongitude()); //aktueller Längergrad
}else{
mDatenbank.child("aron").child("IDG" + k).child("d_breitengrad").setValue(breitengrad); //aktueller Breitengrad
mDatenbank.child("aron").child("IDG" + k).child("e_laengengrad").setValue(laengengrad); //aktueller Längergrad
mDatenbank.child("aron").child("IDG" + k).child("f_nativegps").setValue(false);
mDatenbank.child("overviewnodes").child("IDG" + k).child("d_breitengrad").setValue(breitengrad); //aktueller Breitengrad
mDatenbank.child("overviewnodes").child("IDG" + k).child("e_laengengrad").setValue(laengengrad); //aktueller Längergrad
mDatenbank.child("overviewnodes").child("IDG" + k).child("f_nativegps").setValue(false);
}
mDatenbank.child("aron").child("IDG" + k).child("g_vibration").setValue(true);
mDatenbank.child("aron").child("IDG" + k).child("h_timestamp").setValue(Calendar.getInstance().getTimeInMillis()); //aktueller Zeitstempel wird in Datenbank eingetragen
mDatenbank.child("aron").child("IDG" + k).child("i_amplitude").setValue(1000);
mDatenbank.child("aron").child("IDG" + k).child("w_wellengeschwindigkeit").setValue(db.getMyWaveSpeed());
mDatenbank.child("overviewnodes").child("IDG" + k).child("g_vibration").setValue(true);
mDatenbank.child("overviewnodes").child("IDG" + k).child("h_timestamp").setValue(Calendar.getInstance().getTimeInMillis()); //aktueller Zeitstempel wird in Datenbank eingetragen
mDatenbank.child("overviewnodes").child("IDG" + k).child("i_amplitude").setValue(1000);
mDatenbank.child("overviewnodes").child("IDG" + k).child("w_wellengeschwindigkeit").setValue(db.getMyWaveSpeed());
break;
}else
{
System.out.println("Erhöhe Index weil nicht durchgekommen" + k);
//k erhöhen solange leerer Slot ist oder abbruch weil zu voll
if(k ==(int) datenBankSnapShot.child("aron").getChildrenCount())
if(k ==(int) datenBankSnapShot.child("overviewnodes").getChildrenCount())
{
System.out.println("Kein freier Slot mehr vorhanden");
break;
@@ -621,8 +621,8 @@ public class SensorMapsActivity extends FragmentActivity implements OnMapReadyCa
/*
//####### Auslesen für boolean-Werte #######:
int i = 1;
String vibrationString = data.child("aron").child("IDG").child("vibration").getValue().toString();
String amplitudeString = data.child("aron").child("IDG").child("amplitude").getValue().toString();
String vibrationString = data.child("overviewnodes").child("IDG").child("vibration").getValue().toString();
String amplitudeString = data.child("overviewnodes").child("IDG").child("amplitude").getValue().toString();
boolean vibration;
if(vibrationString.equals("true")){
vibration = true;

Loading…
Cancel
Save