Пример #1
0
	private Map<Integer, List<ApSet>> createApSetsByFingerprintId() {
		Map<Integer, List<ApSet>> fingerprintsMap = new TreeMap<Integer, List<ApSet>>();
		for (ApSet apSet : apSets) {
			if (fingerprintsMap.get(apSet.getFingerprintId()) == null) {
				fingerprintsMap.put(apSet.getFingerprintId(),
						new ArrayList<ApSet>());
			}
			fingerprintsMap.get(apSet.getFingerprintId()).add(apSet);
		}
		return fingerprintsMap;
	}
Пример #2
0
	private List<ApSet> createAllApSetsFromExternalFile() throws IOException {
		List<ApSet> result = new ArrayList<ApSet>();
		String fileName = "ap_set.csv";
		InputStream is = context.getAssets().open(fileName);
		InputStreamReader isr = new InputStreamReader(is);
		BufferedReader br = new BufferedReader(isr);
		String readStr;

		br.readLine(); // 첫 줄 버림.
		while ((readStr = br.readLine()) != null) {
			String[] tokens = readStr.split(delimiter);
			ApSet apSet = new ApSet();
			apSet.setFingerprintId(Integer.parseInt(tokens[0]));
			apSet.setApId(Integer.parseInt(tokens[1]));
			apSet.setSignalStrength(Integer.parseInt(tokens[2]));
			result.add(apSet);
		}
		return result;
	}
Пример #3
0
	private void createRepresentativeFingerprintAndApSet() throws IOException {
		Map<String, Fingerprint> newFingerprintByCoordinateMap = new HashMap<String, Fingerprint>();
		List<ApSet> newApSets = new ArrayList<ApSet>();
		Map<Integer, List<ApSet>> newApSetsByFingerprintIdMap = new TreeMap<Integer, List<ApSet>>();

		int fingerprintId = 1;
		Fingerprint f;
		Timestamp time;
		Double x;
		Double y;
		Double z;

		for (String coordinate : fingerprintsByCoordinateMap.keySet()) {
			f = fingerprintsByCoordinateMap.get(coordinate).get(0);
			time = f.getTime();
			x = f.getX();
			y = f.getY();
			z = f.getZ();

			Map<Integer, List<Integer>> signalsByApId = new TreeMap<Integer, List<Integer>>();
			for (Fingerprint fingerprint : fingerprintsByCoordinateMap
					.get(coordinate)) {

				List<ApSet> apSets = apSetsByFingerprintIdMap.get(fingerprint
						.getId());
				if (apSets == null) {
					continue;
				}
				for (ApSet apSet : apSets) {
					if (signalsByApId.get(apSet.getApId()) == null) {
						signalsByApId.put(apSet.getApId(),
								new ArrayList<Integer>());
					}
					signalsByApId.get(apSet.getApId()).add(
							apSet.getSignalStrength());
				}
			}

			List<ApSet> representiveApSet = new ArrayList<ApSet>();
			for (Integer apId : signalsByApId.keySet()) {
				Integer avgSignalStrength = 0;
				for (Integer signalStrength : signalsByApId.get(apId)) {
					avgSignalStrength = avgSignalStrength + signalStrength;
				}
				avgSignalStrength = (int) ((double) avgSignalStrength / (double) signalsByApId
						.get(apId).size());
				representiveApSet.add(new ApSet(fingerprintId, apId,
						avgSignalStrength));
			}
			newApSets.addAll(representiveApSet);
			Fingerprint representiveFingerprint = new Fingerprint(
					fingerprintId, time, x, y, z);
			this.fingerprints.add(representiveFingerprint);
			this.fingerprintByFingerprintIdMap.put(fingerprintId,
					representiveFingerprint);
			newFingerprintByCoordinateMap.put(coordinate,
					representiveFingerprint);
			newApSetsByFingerprintIdMap.put(fingerprintId, representiveApSet);
			fingerprintId++;
		}

		this.apSets = newApSets;
		this.representativeFingerprintByCoordinateMap = newFingerprintByCoordinateMap;
		this.apSetsByFingerprintIdMap = newApSetsByFingerprintIdMap;
	}