summaryrefslogtreecommitdiffstats
path: root/DataStructure/GSMMapInterpolatorOld.java
diff options
context:
space:
mode:
Diffstat (limited to 'DataStructure/GSMMapInterpolatorOld.java')
-rw-r--r--DataStructure/GSMMapInterpolatorOld.java200
1 files changed, 200 insertions, 0 deletions
diff --git a/DataStructure/GSMMapInterpolatorOld.java b/DataStructure/GSMMapInterpolatorOld.java
new file mode 100644
index 0000000..eff8057
--- /dev/null
+++ b/DataStructure/GSMMapInterpolatorOld.java
@@ -0,0 +1,200 @@
+package DataStructure;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import Parse.sqlreader;
+
+@SuppressWarnings("serial")
+public class GSMMapInterpolatorOld extends GSMMap {
+
+ public GSMMapInterpolatorOld(sqlreader SQL, double accuracy) {
+ super(SQL, accuracy);
+ // TODO Auto-generated constructor stub
+ }
+
+ public void interpolate() {
+ for (SingleBTS currentBTS : this.btsnames) {
+ // go through every known BTS
+ interpolateBTS(currentBTS);
+
+ }
+ }
+
+ private void interpolateBTS(SingleBTS currentBTS) {
+ // add security bounds
+ for (int x = 2; x < this.Xcoords.length - 2; x++) {
+ for (int y = 2; y < this.Ycoords.length - 2; y++) {
+ // check if interpolation is needed
+ if (!InterpolateHelper.listContains(currentBTS, this.map[x][y])) {
+ // try to interpolate
+ SingleBTS interpolated = tryInterpolation(currentBTS, x, y);
+ if (interpolated != null)
+ // maybe the list is empty. then create list
+ if (map[x][y] == null) {
+ ArrayList<SingleBTS> list = new ArrayList<SingleBTS>();
+ list.add(interpolated);
+ map[x][y] = list;
+ } else {
+ map[x][y].add(interpolated);
+ }
+
+ }
+
+ }
+ }
+
+ }
+
+ private SingleBTS tryInterpolation(SingleBTS btsName, int x, int y) {
+ int interpolated = 0;
+ // do interpolation for left,right,up,down
+ SingleBTS left = interpolate1to2(btsName, x - 2, x - 1, y, y);
+ SingleBTS right = interpolate1to2(btsName, x + 2, x + 1, y, y);
+ SingleBTS down = interpolate1to2(btsName, x, x, y + 2, y + 1);
+ SingleBTS up = interpolate1to2(btsName, x, x, y - 2, y - 1);
+ SingleBTS between = interpolateInBetween(btsName, x, y);
+ if (left != null)
+ interpolated++;
+ if (right != null)
+ interpolated++;
+ if (down != null)
+ interpolated++;
+ if (up != null)
+ interpolated++;
+ if (between != null)
+ interpolated++;
+ if (interpolated > 1) {
+ // interpolation successfull!
+ SingleBTS element = new SingleBTS(btsName.ARFCN, 0, 0, true,
+ new Date(), btsName.name);
+ // prepare element for averaging
+ element.clear();
+ // nothing bad will happen if one of these BTSs are null!
+ element.addBTSMeasure(left);
+ element.addBTSMeasure(right);
+ element.addBTSMeasure(down);
+ element.addBTSMeasure(up);
+ element.addBTSMeasure(between);
+ if (element.getDldB() > -121 && element.getUldB() > -121)
+ if (element.getDldB() < -29 && element.getUldB() < -29)
+ return element;
+
+ }
+ return null;
+
+ }
+
+ private SingleBTS interpolate1to2(SingleBTS btsName, int x1, int x2,
+ int y1, int y2) {
+
+ SingleBTS first = InterpolateHelper.getFromList(btsName, map[x1][y1]);
+ SingleBTS second = InterpolateHelper.getFromList(btsName, map[x2][y2]);
+ // prepare returning BTS
+
+ if (first != null && second != null) {
+ // interpolation for these two elements possible
+ double deltaDL = second.getDldB() - first.getDldB();
+ double deltaUL = second.getUldB() - first.getUldB();
+ // add the value of log10(0.005). one Array cell is 5*5m big! See
+ // the
+ // Youngs Model!
+
+ // TODO: careful! double gets castet to int. Do correct
+ // interpolation here!
+
+ double DL = deltaDL + second.getDldB();
+ double UL = deltaUL + second.getUldB();
+ SingleBTS element = new SingleBTS(first.ARFCN, (int) UL, (int) DL,
+ true, new Date(), first.name);
+ // first.interpolated = true;
+ return element;
+ }
+
+ return null;
+ }
+
+ private SingleBTS interpolateInBetween(SingleBTS btsName, int x, int y) {
+ // take one from the left, one from the right
+ // one from the top, one from the bottom
+ // one from the diagonal and one from the other diagonal
+ // prepare interpolated element!
+ SingleBTS element = new SingleBTS(btsName.ARFCN, 0, 0, true,
+ new Date(), btsName.name);
+ element.clear();
+
+ // to check if a correct interpolation was done
+ boolean[] done = { false, false, false, false };
+
+ // diagonal leftAndRight
+ SingleBTS first = InterpolateHelper.getFromList(btsName,
+ map[x - 1][y + 1]);
+ SingleBTS third = InterpolateHelper.getFromList(btsName,
+ map[x + 1][y - 1]);
+ if (first != null && third != null) {
+ element.addBTSMeasure(first);
+ element.addBTSMeasure(third);
+ done[0] = true;
+ }
+
+ // diagonal rightAndLeft
+ first = InterpolateHelper.getFromList(btsName, map[x + 1][y + 1]);
+ third = InterpolateHelper.getFromList(btsName, map[x - 1][y - 1]);
+ if (first != null && third != null) {
+ element.addBTSMeasure(first);
+ element.addBTSMeasure(third);
+ done[1] = true;
+ }
+
+ // leftAndRight
+ first = InterpolateHelper.getFromList(btsName, map[x - 1][y]);
+ third = InterpolateHelper.getFromList(btsName, map[x + 1][y]);
+ if (first != null && third != null) {
+ element.addBTSMeasure(first);
+ element.addBTSMeasure(third);
+ done[2] = true;
+ }
+
+ // bottomAndTop
+ first = InterpolateHelper.getFromList(btsName, map[x][y + 1]);
+ third = InterpolateHelper.getFromList(btsName, map[x][y - 1]);
+ if (first != null && third != null) {
+ element.addBTSMeasure(first);
+ element.addBTSMeasure(third);
+ done[3] = true;
+ }
+
+ // return the BTS only if at least one Interpolation worked out
+ for (int i = 0; i < done.length; i++) {
+ if (done[i])
+ return element;
+ }
+ return null;
+
+ }
+}
+
+final class InterpolateHelper {
+
+ public static boolean listContains(SingleBTS bts, List<SingleBTS> btsList) {
+ for (SingleBTS listBTS : btsList) {
+ if (bts.ARFCN == listBTS.ARFCN)
+ return true;
+ }
+ return false;
+ }
+
+ // get the Element containing the ARFCN of btsName. Returns null, if no
+ // Element found!
+ public static SingleBTS getFromList(SingleBTS btsName,
+ List<SingleBTS> btslist) {
+ for (SingleBTS listBTS : btslist) {
+ if (listBTS.ARFCN == btsName.ARFCN)
+ return listBTS;
+
+ }
+ return null;
+ }
+
+}