Commit 53954f959568d516fdfd51ec4b2b448dfacf63b9

Authored by Notmoo
1 parent 5f24440c

Modification serveur pour effectuer les mesures avec RssiSample plutot qu'avec des gaussiennes

positioning_server.iml
... ... @@ -47,5 +47,21 @@
47 47 <orderEntry type="library" scope="RUNTIME" name="Maven: org.slf4j:slf4j-log4j12:1.5.8" level="project" />
48 48 <orderEntry type="library" scope="RUNTIME" name="Maven: log4j:log4j:1.2.14" level="project" />
49 49 <orderEntry type="library" scope="RUNTIME" name="Maven: javassist:javassist:3.9.0.GA" level="project" />
  50 + <orderEntry type="library" scope="TEST" name="Maven: junit:junit:3.8.1" level="project" />
  51 + <orderEntry type="library" scope="PROVIDED" name="Maven: javax:javaee-web-api:6.0" level="project" />
  52 + <orderEntry type="library" name="Maven: org.postgresql:postgresql:9.4.1212" level="project" />
  53 + <orderEntry type="library" name="Maven: org.hibernate:hibernate-core:3.5.6-Final" level="project" />
  54 + <orderEntry type="library" name="Maven: antlr:antlr:2.7.6" level="project" />
  55 + <orderEntry type="library" name="Maven: commons-collections:commons-collections:3.1" level="project" />
  56 + <orderEntry type="library" name="Maven: dom4j:dom4j:1.6.1" level="project" />
  57 + <orderEntry type="library" name="Maven: xml-apis:xml-apis:1.0.b2" level="project" />
  58 + <orderEntry type="library" name="Maven: javax.transaction:jta:1.1" level="project" />
  59 + <orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.5.8" level="project" />
  60 + <orderEntry type="library" name="Maven: org.hibernate:hibernate-annotations:3.5.6-Final" level="project" />
  61 + <orderEntry type="library" name="Maven: org.hibernate:hibernate-commons-annotations:3.2.0.Final" level="project" />
  62 + <orderEntry type="library" name="Maven: org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.0.Final" level="project" />
  63 + <orderEntry type="library" scope="RUNTIME" name="Maven: org.slf4j:slf4j-log4j12:1.5.8" level="project" />
  64 + <orderEntry type="library" scope="RUNTIME" name="Maven: log4j:log4j:1.2.14" level="project" />
  65 + <orderEntry type="library" scope="RUNTIME" name="Maven: javassist:javassist:3.9.0.GA" level="project" />
50 66 </component>
51 67 </module>
52 68 \ No newline at end of file
... ...
src/main/java/core/repository/RssiRecord.java
... ... @@ -11,8 +11,7 @@ import java.io.Serializable;
11 11 public class RssiRecord implements Serializable {
12 12 @Id @GeneratedValue
13 13 private int id;
14   -
15   -
  14 +
16 15 @OneToOne(fetch = FetchType.LAZY)
17 16 @JoinColumn(name = "id", nullable = false)
18 17 private Location loc;
... ... @@ -21,17 +20,15 @@ public class RssiRecord implements Serializable {
21 20 @JoinColumn(name = "id", nullable = false)
22 21 private AccessPoint ap;
23 22  
24   - private Double avg;
25   - private Double stdDev;
  23 + private Double val;
26 24  
27 25 public RssiRecord () {
28 26 }
29 27  
30   - public RssiRecord(Location loc, AccessPoint ap, Double avg, Double stdDev){
  28 + public RssiRecord(Location loc, AccessPoint ap, Double val){
31 29 this.loc = loc;
32 30 this.ap = ap;
33   - this.avg = avg;
34   - this.stdDev = stdDev;
  31 + this.val = val;
35 32 }
36 33  
37 34 public Location getLoc () {
... ... @@ -49,20 +46,20 @@ public class RssiRecord implements Serializable {
49 46 public void setAp (final AccessPoint ap) {
50 47 this.ap = ap;
51 48 }
52   -
53   - public Double getAvg () {
54   - return avg;
  49 +
  50 + public int getId() {
  51 + return id;
55 52 }
56   -
57   - public void setAvg (final Double avg) {
58   - this.avg = avg;
  53 +
  54 + public void setId(int id) {
  55 + this.id = id;
59 56 }
60   -
61   - public Double getStdDev () {
62   - return stdDev;
  57 +
  58 + public Double getVal() {
  59 + return val;
63 60 }
64   -
65   - public void setStdDev (final Double stdDev) {
66   - this.stdDev = stdDev;
  61 +
  62 + public void setVal(Double val) {
  63 + this.val = val;
67 64 }
68 65 }
... ...
src/main/java/core/repository/TempRssi.java
... ... @@ -16,18 +16,24 @@ public class TempRssi {
16 16 private AccessPoint ap;
17 17  
18 18 private String client_mac_addr;
19   - private Double avg, stdDev;
  19 + private Double val;
20 20  
21 21 public TempRssi () {}
22 22  
23   - public TempRssi (final AccessPoint accessPoint, final String clientMacAddr, final double avg,
24   - final double stdDev) {
  23 + public TempRssi (final AccessPoint accessPoint, final String clientMacAddr, final double val) {
25 24 ap = accessPoint;
26 25 client_mac_addr = clientMacAddr;
27   - this.avg = avg;
28   - this.stdDev = stdDev;
  26 + this.val = val;
29 27 }
30   -
  28 +
  29 + public int getId() {
  30 + return id;
  31 + }
  32 +
  33 + public void setId(int id) {
  34 + this.id = id;
  35 + }
  36 +
31 37 public AccessPoint getAp () {
32 38 return ap;
33 39 }
... ... @@ -43,20 +49,12 @@ public class TempRssi {
43 49 public void setClient_mac_addr (final String client_mac_addr) {
44 50 this.client_mac_addr = client_mac_addr;
45 51 }
46   -
47   - public Double getAvg () {
48   - return avg;
49   - }
50   -
51   - public void setAvg (final Double avg) {
52   - this.avg = avg;
53   - }
54   -
55   - public Double getStdDev () {
56   - return stdDev;
  52 +
  53 + public Double getVal() {
  54 + return val;
57 55 }
58   -
59   - public void setStdDev (final Double stdDev) {
60   - this.stdDev = stdDev;
  56 +
  57 + public void setVal(Double val) {
  58 + this.val = val;
61 59 }
62 60 }
... ...
src/main/java/core/service/PositioningService.java
... ... @@ -30,18 +30,19 @@ public class PositioningService {
30 30 List<TempRssi> clientRssi = hibDao.getTempRssi(debDao.getMacAddr(ipAddr));
31 31  
32 32 if(clientRssi.size()>=3) {
  33 +
33 34 Location bestLoc = null;
34   - double bestLocProbability = -1;
  35 + double bestLocDistance = -1;
  36 +
35 37 for (Location loc : hibDao.getLocations()) {
36 38 //Liste des RSSISample pour une position donnée, chaque RSSISample étant
37 39 //assossié à un AccessPoint
38 40 List<RssiRecord> rssis = hibDao.getRssiRecord(loc.getId());
39   -
40   -
41   - double currentLocProbability = probability(clientRssi, rssis, DEFAULT_POSITIONING_PRECISION);
42   - if (bestLocProbability == -1 || currentLocProbability > bestLocProbability) {
  41 +
  42 + double currentLocDistance = rssiDistance(clientRssi, rssis);
  43 + if (bestLocDistance == -1 || currentLocDistance < bestLocDistance) {
43 44 bestLoc = loc;
44   - bestLocProbability = currentLocProbability;
  45 + bestLocDistance = currentLocDistance;
45 46 }
46 47 }
47 48 return bestLoc;
... ... @@ -49,52 +50,51 @@ public class PositioningService {
49 50 return null;
50 51 }
51 52  
52   - private double probability(List<TempRssi> temps, List<RssiRecord> rssis, double precision){
  53 + private double rssiDistance(List<TempRssi> temps, List<RssiRecord> rssis){
53 54 try {
54   - double probability = 1;
  55 + double distance = 0;
55 56 for (TempRssi temp : temps) {
56 57 RssiRecord rssi = find(temp.getAp().getMac_addr(), rssis);
57   - probability*=gauss_probability(temp.getAvg(), temp.getStdDev(), rssi.getAvg(), rssi.getStdDev(), precision);
  58 + if(rssi!=null)
  59 + distance+=(temp.getVal()- rssi.getVal())*(temp.getVal()- rssi.getVal());
  60 + else
  61 + distance+=(temp.getVal()+95)*(temp.getVal()+95);
58 62 }
59   - return probability;
  63 +
  64 + for(RssiRecord rssi : rssis){
  65 + if(containsMacAddr(rssi.getAp().getMac_addr(), temps))
  66 + distance+=(rssi.getVal()+95)*(rssi.getVal()+95);
  67 + }
  68 +
  69 +
  70 + return Math.sqrt(distance);
60 71 }catch(IllegalArgumentException e){
61 72 e.printStackTrace();
62 73 return -1;
63 74 }
64 75 }
65   - private double gauss_probability(double avg1, double std1, double avg2, double std2, double precision){
66   - final double
67   - valDebut = Math.min(avg1-3*std1, avg2-3*std2),
68   - valFin = Math.max(avg1+3*std1, avg2+3*std2);
69   - double
70   - rectDebut = valDebut,
71   - rectFin = valDebut+precision,
72   - probabilite = 0;
73   -
74   - do{
75   - probabilite+=Math.min( gauss(avg1, std1, (rectDebut+rectFin)/2), gauss(avg2, std2, (rectDebut+rectFin)/2));
76   - rectDebut = rectFin;
77   - rectFin+=precision;
78   - }while(rectFin<valFin);
79   -
80   - return probabilite;
81   - }
82   - private double gauss (final double avg, final double std, final double x) {
83   - return (1/(std*Math.sqrt(2*Math.PI)))*Math.exp(-(Math.pow(x-avg, 2)/(2*Math.pow(std, 2))));
84   - }
  76 +
85 77 private RssiRecord find(String macAddr, List<RssiRecord> rrs){
86 78 final List<RssiRecord> results = new ArrayList<>();
87 79 rrs.stream().filter(rr->rr.getAp().getMac_addr().equals(macAddr)).forEach(rr->results.add(rr));
88 80  
89 81 switch(results.size()){
90 82 case 0:
91   - throw new IllegalArgumentException("No matching RssiRecord for mac address <"+macAddr+">");
  83 + return null;
92 84 case 1:
93 85 return results.get(0);
94 86 default :
95 87 throw new IllegalArgumentException("Several("+results.size()+") matching RssiRecord for mac address <"+macAddr+">");
96 88 }
97 89 }
  90 +
  91 + private boolean containsMacAddr(String macAddr, List<TempRssi> temps){
  92 + for(TempRssi temp : temps){
  93 + if(temp.getAp().getMac_addr().equals(macAddr))
  94 + return true;
  95 + }
  96 + return false;
  97 + }
98 98  
99 99 public String getMacAddr (final String clientIpAddr) {
100 100 return debDao.getMacAddr(clientIpAddr);
... ...