summaryrefslogtreecommitdiffstats
path: root/gui/Localization.java
diff options
context:
space:
mode:
Diffstat (limited to 'gui/Localization.java')
-rw-r--r--gui/Localization.java291
1 files changed, 291 insertions, 0 deletions
diff --git a/gui/Localization.java b/gui/Localization.java
new file mode 100644
index 0000000..8024c9e
--- /dev/null
+++ b/gui/Localization.java
@@ -0,0 +1,291 @@
+package gui;
+
+import helper.ListBTS;
+
+import java.awt.BorderLayout;
+import java.awt.Button;
+import java.awt.Graphics2D;
+import java.awt.TextField;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Date;
+
+import javax.swing.JCheckBox;
+import javax.swing.JFrame;
+
+import org.jdesktop.swingx.JXMapKit;
+import org.jdesktop.swingx.JXMapKit.DefaultProviders;
+import org.jdesktop.swingx.JXMapViewer;
+import org.jdesktop.swingx.mapviewer.DefaultTileFactory;
+import org.jdesktop.swingx.mapviewer.GeoPosition;
+import org.jdesktop.swingx.mapviewer.TileFactoryInfo;
+import org.jdesktop.swingx.painter.CompoundPainter;
+import org.jdesktop.swingx.painter.Painter;
+
+import DataStructure.BayesAll;
+import DataStructure.Interpolator;
+import DataStructure.MobilePhone;
+import DataStructure.PhoneContainer;
+import DataStructure.SingleBTS;
+import Parse.SqlPollerDate;
+import Parse.SqlPollerUnThreaded;
+
+public class Localization {
+ static Interpolator map;
+
+ private static ArrayList<SingleBTS> filterMR(ArrayList<SingleBTS> MR,
+ JCheckBox[] btsFilter) {
+ SingleBTS[] content = map.content();
+ ArrayList<SingleBTS> result = new ArrayList<SingleBTS>();
+ for (int i = 0; i < content.length; i++) {
+ if (btsFilter[i].isSelected()) {
+ // add this BTS
+ ArrayList<SingleBTS> elementsToAdd = ListBTS.getAllARFCN(MR,
+ content[i].ARFCN);
+ if (elementsToAdd != null)
+ result.addAll(elementsToAdd);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * @param args
+ */
+ @SuppressWarnings("unused")
+ public static void main(String[] args) {
+ JFrame frame = new JFrame();
+ JFrame control = new JFrame();
+ control.setSize(400, 300);
+ JFrame filter = new JFrame("filter BTS");
+ filter.setSize(200, 600);
+
+ frame.setSize(400, 400);
+ JXMapKit mapViewer = new JXMapKit();
+ // JXMapViewer
+ // Painter
+ // mapViewer.setDefaultProvider(DefaultProviders.OpenStreetMaps);
+ mapViewer.setDefaultProvider(DefaultProviders.Custom);
+
+ TileFactoryInfo ownTileFactory = new TileFactoryInfo(0, 18, 18, 256,
+ false, false, "http://c.tile.openstreetmap.org", "/", "/", "/") {
+ public String getTileUrl(int x, int y, int zoom) {
+ return this.baseURL + "/" + (18 - zoom) + "/" + x + "/" + y
+ + ".png";
+ }
+ };
+ mapViewer.setTileFactory(new DefaultTileFactory(ownTileFactory));
+
+ mapViewer.setDataProviderCreditShown(true);
+ frame.add(mapViewer);
+ System.out.println("da");
+
+ SqlPollerUnThreaded sql = new SqlPollerUnThreaded();
+ SqlPollerDate sqlDate;
+ sqlDate = new SqlPollerDate(sql);
+ TextField actionRefID = new TextField();
+ TextField confidenceField = new TextField();
+ control.add(actionRefID, BorderLayout.CENTER);
+ JCheckBox useActionRef = new JCheckBox("use RefID");
+ control.add(useActionRef, BorderLayout.SOUTH);
+ confidenceField.setText("0.75");
+ actionRefID.setText("146373");
+ control.add(confidenceField, BorderLayout.NORTH);
+ control.setVisible(true);
+ Button next = new Button("next");
+ control.add(next, BorderLayout.EAST);
+ frame.setVisible(true);
+ mapViewer.setZoom(18);
+ try {
+
+ map = readGSM("D:/parallel-strictdB-BER.obj");
+ // map = readGSM("parallel-strictdB.obj");
+ // map = readGSM("RichyUndKerstinInterpoliert.obj");
+ // map = readGSM("parallel.obj");
+ mapViewer.setAddressLocation(new GeoPosition(
+ (map.minY + map.maxY) / 2, (map.minX + map.maxX) / 2));
+ mapViewer.setAddressLocationShown(true);
+ mapViewer.setZoom(1);
+ mapViewer.setCenterPosition(new GeoPosition(
+ (map.minY + map.maxY) / 2, (map.minX + map.maxX) / 2));
+
+ // mapViewer.setTileFactory(new DefaultTileFactory(new
+ // ownTileFactory(minimumZoomLevel, maximumZoomLevel, totalMapZoom,
+ // tileSize, xr2l, yt2b, baseURL, xparam, yparam, zparam)))
+ // mapViewer.getMainMap().
+
+ } catch (FileNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (ClassNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ SingleBTS[] content = map.content();
+ JCheckBox[] btsFilter = new JCheckBox[content.length];
+ int y = 30;
+ filter.setLayout(null);
+ for (int i = 0; i < content.length; i++) {
+ btsFilter[i] = new JCheckBox(Integer.toString(content[i].ARFCN),
+ true);
+ btsFilter[i].setLocation(30, y);
+ btsFilter[i].setSize(70, 25);
+ y += 30;
+ filter.add(btsFilter[i]);
+ }
+ filter.validate();
+ filter.setVisible(true);
+
+ PhoneContainer container = new PhoneContainer();
+ CompoundPainter cp = new CompoundPainter();
+ BayesAll bayes = new BayesAll(map);
+
+ // hack: make while (true) again!
+ // long lastRefID = 0;
+
+ while (true) {
+
+ if (useActionRef.isSelected()) {
+
+ try {
+ double confidence = Double.parseDouble(confidenceField
+ .getText());
+ long refID = Long.parseLong(actionRefID.getText());
+
+ ArrayList<SingleBTS> report = sqlDate.getActionRefID(refID).MR;
+
+ // MobilePhone phone = sqlDate.getActionRefID(refID);
+ MobilePhone phone = new MobilePhone();
+ phone.bayes = bayes;
+ phone.MR = filterMR(report, btsFilter);
+ phone.correctCoordinate = sqlDate.getCoord(refID);
+ long time = phone.getMinTime();
+ // long timeMax = phone.getMaxTime();
+ confidence = Double.parseDouble(confidenceField.getText());
+ phone.locate(confidence);
+ // phone.locateTimeSensitiv(confidence, (time + timeMax) /
+ // 2);
+ // phone.locateTimeSensitiv(confidence, timeMax - 3000);
+ // Zeitschleife
+ System.out.println(phone.localizationAccuracy());
+
+ while (time <= phone.getMaxTime()) {
+ // go out of while loop
+ if (true)
+ break;
+ phone.MR = filterMR(report, btsFilter);
+ // phone.MR = ListBTS.generateAveragedList(phone.MR);
+
+ System.out.println("Zeit: " + new Date(time) + "("
+ + time + ")");
+ confidence = Double.parseDouble(confidenceField
+ .getText());
+ // phone.locateTimeSensitiv(map, confidence, time);
+ phone.locateTimeSensitiv(confidence, time);
+ System.out.println(phone.localizationAccuracy());
+ mapViewer.getMainMap().setOverlayPainter(phone);
+ time += 3000;
+ }
+ System.out.println("Ende Zeitschleife... Neuanfang");
+
+ // phone.locate(map, confidence, false);
+ System.out.println("confidence: " + confidence);
+ mapViewer.getMainMap().setOverlayPainter(phone);
+ } catch (NumberFormatException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (SQLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (Exception e) {
+ System.out.println("irgednwas anderes hat nicht geklappt");
+ e.printStackTrace();
+ }
+ } else {
+ container.removeAll();
+ ArrayList<MobilePhone> phones = sql.getMRs();
+ // MobilePhone hackPhone = new MobilePhone();
+
+ // insert MR reports from phone!
+
+ for (MobilePhone phone : phones) {
+ phone.locate(map, 0.75, false);
+ container.add(phone);
+ }
+
+ // make mappainter overlay
+
+ cp.setCacheable(false);
+
+ mapViewer.getMainMap().setOverlayPainter(container);
+ }
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ }
+
+ static private Interpolator readGSM(String filename)
+ throws FileNotFoundException, IOException, ClassNotFoundException {
+
+ ObjectInputStream ois = new ObjectInputStream(new FileInputStream(
+ filename));
+ Interpolator map = (Interpolator) ois.readObject();
+ System.out.println("GSMMap eingelesen");
+ return map;
+ }
+
+}
+
+class locationPainter implements Painter<JXMapViewer> {
+ private ArrayList<MobilePhone> phones = new ArrayList<MobilePhone>();
+
+ // private Interpolator map;
+
+ public locationPainter(ArrayList<MobilePhone> phones, Interpolator map) {
+ this.phones = phones;
+ // this.map = map;
+ for (int i = 0; i < phones.size(); i++) {
+ phones.get(i).locate(map, false);
+ }
+
+ }
+
+ @Override
+ public void paint(Graphics2D g, JXMapViewer map, int w, int h) {
+
+ for (int i = 0; i < phones.size(); i++) {
+
+ }
+
+ }
+
+}
+
+class ownTileFactory extends TileFactoryInfo {
+
+ public ownTileFactory(int minimumZoomLevel, int maximumZoomLevel,
+ int totalMapZoom, int tileSize, boolean xr2l, boolean yt2b,
+ String baseURL, String xparam, String yparam, String zparam) {
+ super(0, 18, 18, 256, true, true, "http://b.tile.openstreetmap.org",
+ xparam, yparam, zparam);
+ maximumZoomLevel = 18;
+ minimumZoomLevel = 0;
+ totalMapZoom = 18;
+
+ // TODO Auto-generated constructor stub
+ }
+
+}