@Override public String classify(User user, Sample sample) { Instances trainingSet = new TrainingSetBuilder() .setAttributes(user.getBssids()) .setClassAttribute( "Location", user.getLocations().stream().map(Location::getName).collect(Collectors.toList())) .build("TrainingSet", 1); // Create instance Map<String, Integer> BSSIDLevelMap = getBSSIDLevelMap(sample); Instance instance = new Instance(trainingSet.numAttributes()); for (Enumeration e = trainingSet.enumerateAttributes(); e.hasMoreElements(); ) { Attribute attribute = (Attribute) e.nextElement(); String bssid = attribute.name(); int level = (BSSIDLevelMap.containsKey(bssid)) ? BSSIDLevelMap.get(bssid) : 0; instance.setValue(attribute, level); } if (sample.getLocation() != null) instance.setValue(trainingSet.classAttribute(), sample.getLocation()); instance.setDataset(trainingSet); trainingSet.add(instance); int predictedClass = classify(fromBase64(user.getClassifiers()), instance); return trainingSet.classAttribute().value(predictedClass); }
@Test public void save() { Sample sample = new Sample(); sample = sampleRepository.save(sample); assertNotNull(sample); assertNotNull(sample.getId()); }
private Map<String, Integer> getBSSIDLevelMap(Sample sample) { return sample .getScanResults() .stream() .collect( Collectors.toMap( wifiScanResult -> wifiScanResult.BSSID, wifiScanResult -> wifiScanResult.level)); }