Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.wiematic.www.sensor;
- import android.graphics.Color;
- import android.location.Location;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.TextView;
- import android.widget.Toast;
- import com.google.android.gms.maps.model.LatLng;
- import java.util.ArrayList;
- import java.util.List;
- import static android.R.attr.button;
- public class Auswertung extends AppCompatActivity {
- List<Location> listNetworkLocation = new ArrayList<Location>();
- List<Location> listGPSLocation = new ArrayList<Location>();
- List<Location> listInterpolationLocation = new ArrayList<Location>();
- Button bttnabweichung;
- private SensorDataSource dataSource;
- TextView tvStatus,tvfehler;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_auswertung);
- dataSource = new SensorDataSource(this);
- init();
- fillgps();
- fillNetwork();
- fillInterpol();
- //Toast.makeText(getApplicationContext(),sensorDataSource.getAllSensorDataObjects().get(1).getWifiBesch(), Toast.LENGTH_LONG).show();
- //getErrorvalues(listtestInterpol,listtestGPS);
- }
- public double getDistance(Location location0, Location location)
- {
- String str = "";
- double dDistance = 0.0;
- double earthRadius = 6371000; //meters
- double dLat = Math.toRadians(location0.getLatitude()-location.getLatitude());
- double dLng = Math.toRadians(location0.getLongitude()-location.getLongitude());
- double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
- Math.cos(Math.toRadians(location.getLatitude())) * Math.cos(Math.toRadians(location0.getLatitude())) *
- Math.sin(dLng/2) * Math.sin(dLng/2);
- double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
- dDistance= (earthRadius * c);
- return dDistance;
- }
- public void interpolation(Location location1, Location location2)
- {
- location1.setTime(0);
- location2.setTime(149261);
- long t1 = location1.getTime(); // in milliseconds;
- long t2 = location2.getTime();
- double last1,last2;
- double deltaLat = location2.getLatitude() - location1.getLatitude();
- double deltaLon = location2.getLongitude()- location1.getLongitude();
- long step = 1 * 1000; // 1 second in millis
- for (long t = t1; t < t2; t+= step)
- {
- double i1 = t - t1;
- double i2 = t2 - t1;
- double t0_1 = (i1) / (i2);
- double latInter = location1.getLatitude() + deltaLat * t0_1;
- double lonInter = location1.getLongitude() + deltaLon * t0_1;
- Location locInter = new Location("");
- locInter.setLatitude(latInter);
- locInter.setLongitude(lonInter);
- locInter.setTime(t);
- listInterpolationLocation.add(locInter);
- }
- }//
- public Location interpolation(Location location1, Location location2, Location location3)
- {
- long t1 = location1.getTime(); // in milliseconds;
- long t2 = location2.getTime();
- long t3 = location3.getTime();
- double deltaLat = location2.getLatitude() - location1.getLatitude();
- double deltaLon = location2.getLongitude()- location1.getLongitude();
- long step = t3 - t1;
- long t = t1 + step;
- double ts1 = t - t1;
- double ts2 = t2 - t1;
- double t0_1 = ts1 / ts2;
- double latInter = location1.getLatitude() + deltaLat * t0_1;
- double lonInter = location1.getLongitude() + deltaLon * t0_1;
- Location interPolLocation = new Location("");
- interPolLocation.setLongitude(lonInter);
- interPolLocation.setLatitude(latInter);
- return interPolLocation;
- }//
- public String getErrorvalues(List<Location> listInterpol, List<Location> listGPSNWLocation)
- {
- dataSource.open();
- double dStarttime = dataSource.getStartDataObjects().get(0).getTimeStamp();
- dataSource.close();
- String s = "Errorvalues";
- for(int i=0;i<listGPSNWLocation.size()-1;i++)
- {//For1-Start
- for (int j = 0;j<listInterpol.size()-1;j++)
- {//For2-Start
- if (listInterpol.get(j).getTime()==listGPSNWLocation.get(i).getTime()-dStarttime)
- {//If-Start
- s += "\n"+i+". "+ getDistance(listInterpol.get(j),listGPSNWLocation.get(i));
- }//If-End
- }//For2-End
- }//For1-End
- return s;
- }//Method-End
- public void fillgps()
- {
- tvStatus.setText("Status: Fülle GPSliste");
- dataSource.open();
- List<Location> listLocations= new ArrayList<Location>();
- for (int i = 0; i<dataSource.getGPSSensorDataObjects().size()-1;i++)
- {//For-Start
- dataSource.open();
- Location location = new Location("");
- location.setLatitude(dataSource.getGPSSensorDataObjects().get(i).getGPSlat());
- location.setLongitude(dataSource.getGPSSensorDataObjects().get(i).getGPSlong());
- location.setTime(dataSource.getGPSSensorDataObjects().get(i).getTimeStamp());
- listGPSLocation.add(location);
- }//For-End
- dataSource.close();
- }
- public void fillNetwork()
- {
- tvStatus.setText("Status: Fülle NWliste");
- dataSource.open();
- List<Location> listLocations= new ArrayList<Location>();
- for (int i = 0; i<dataSource.getNETWORKSensorDataObjects().size()-1;i++)
- {//For-Start
- dataSource.open();
- Location location = new Location("");
- location.setLatitude(dataSource.getNETWORKSensorDataObjects().get(i).getGPSlat());
- location.setLongitude(dataSource.getNETWORKSensorDataObjects().get(i).getGPSlong());
- location.setTime(dataSource.getNETWORKSensorDataObjects().get(i).getTimeStamp());
- listNetworkLocation.add(location);
- }//For-End
- dataSource.close();
- }
- public void fillInterpol()
- {
- tvStatus.setText("Status: Fülle Interpolationsliste");
- dataSource.open();
- Location location1 = new Location("");
- location1.setLatitude(dataSource.getStartDataObjects().get(0).getGPSlat());
- location1.setLongitude(dataSource.getStartDataObjects().get(0).getGPSlong());
- location1.setTime(dataSource.getStartDataObjects().get(0).getTimeStamp());
- Location location2 = new Location("");
- location2.setLatitude(dataSource.getEndSensorDataObjects().get(0).getGPSlat());
- location2.setLongitude(dataSource.getEndSensorDataObjects().get(0).getGPSlong());
- location2.setTime(dataSource.getEndSensorDataObjects().get(0).getTimeStamp());
- interpolation(location1,location2);
- dataSource.close();
- tvStatus.setText("Status: Betriebsbereit");
- tvStatus.setTextColor(Color.GREEN);
- }
- public void init()
- {
- tvStatus = (TextView) findViewById(R.id.tv_Status);
- tvfehler = (TextView) findViewById(R.id.tv_abweichung);
- //BUTTONS
- bttnabweichung = (Button) findViewById(R.id.bttn_abweichung);
- bttnabweichung.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- tvfehler.setText(getErrorvalues(listInterpolationLocation,listGPSLocation));
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement