Parcourir la source

Fixes Light Label Bug

Andreas T. Meyer-Berg il y a 3 ans
Parent
commit
afb26abaed

+ 32 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/protocols/packets/MQTTpublishPacket.java

@@ -18,6 +18,8 @@ public class MQTTpublishPacket extends MQTT_packet {
 	 */
 	private float value = 0;
 	private float sensorValue = 0;
+	private boolean valueBool = false;
+	private boolean sensorBool = false;
 	/**
 	 * True if boolean
 	 */
@@ -53,6 +55,8 @@ public class MQTTpublishPacket extends MQTT_packet {
 		this.setTopic(topic);
 		this.setValue(value ? 1 : 0);
 		setBoolean(true);
+		this.setValueBool(value);
+		this.setSensorBool(value);
 		this.sensorValue = sensorValue ? 1 : 0;
 		this.message = "Topic:"+topic + ":"+ value;
 	}
@@ -89,4 +93,32 @@ public class MQTTpublishPacket extends MQTT_packet {
 		this.sensorValue = sensorValue;
 	}
 
+	/**
+	 * @return the valueBool
+	 */
+	public boolean isValueBool() {
+		return valueBool;
+	}
+
+	/**
+	 * @param valueBool the valueBool to set
+	 */
+	public void setValueBool(boolean valueBool) {
+		this.valueBool = valueBool;
+	}
+
+	/**
+	 * @return the sensorBool
+	 */
+	public boolean isSensorBool() {
+		return sensorBool;
+	}
+
+	/**
+	 * @param sensorBool the sensorBool to set
+	 */
+	public void setSensorBool(boolean sensorBool) {
+		this.sensorBool = sensorBool;
+	}
+
 }

+ 7 - 1
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/evaluation/BasicPacketClassifier.java

@@ -193,9 +193,12 @@ public abstract class BasicPacketClassifier implements PacketSniffer {
 		if(packet instanceof MQTTpublishPacket) {
 			MQTTpublishPacket mqttPack = (MQTTpublishPacket)packet;
 			if(mqttPack.isBoolean()) {
+				//System.out.println("MQTT PACK: " + mqttPack.getValue());
 				if(mqttPack.getValue() == 0) {
+					//System.out.println("False");
 					instance.setValue(6,0);
 				} else {
+					//System.out.println("True");
 					instance.setValue(6, 1);
 				}
 			}else {				
@@ -377,7 +380,10 @@ public abstract class BasicPacketClassifier implements PacketSniffer {
 					MQTTpublishPacket mqttPac = (MQTTpublishPacket)packet;
 					sensorLabel = ""+mqttPac.getSensorValue();
 					if(mqttPac.isBoolean()) {
-						sensorLabel = "" + Boolean.parseBoolean(sensorLabel);
+						if(mqttPac.getSensorValue() == 0)
+							sensorLabel = "false";
+						else
+							sensorLabel = "true";
 					}
 					sensorLabel = ","+sensorLabel;
 				}

+ 13 - 3
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/evaluation/BasicPacketClassifierWitLabels.java

@@ -193,16 +193,21 @@ public abstract class BasicPacketClassifierWitLabels implements PacketSniffer {
 		if(packet instanceof MQTTpublishPacket) {
 			MQTTpublishPacket mqttPack = (MQTTpublishPacket)packet;
 			if(mqttPack.isBoolean()) {
+				//System.out.println("MQTT PACK: " + mqttPack.getValue() + "," +mqttPack.getSensorValue());
 				if(mqttPack.getValue() == 0) {
 					instance.setValue(6,0);
+					//System.out.println("False");
 				}
 				else {
 					instance.setValue(6, 1);
+					//System.out.println("True");
 				}
 				if(mqttPack.getSensorValue() == 0) {
 					instance.setValue(7,0);
+					//System.out.println("False");
 				} else {
-					instance.setValue(7, 1);					
+					instance.setValue(7, 1);	
+					//System.out.println("True");				
 				}
 			}else {				
 				instance.setValue(6, ((MQTTpublishPacket)packet).getValue());
@@ -385,13 +390,17 @@ public abstract class BasicPacketClassifierWitLabels implements PacketSniffer {
 					MQTTpublishPacket mqttPac = (MQTTpublishPacket)packet;
 					sensorLabel = ""+mqttPac.getSensorValue();
 					if(mqttPac.isBoolean()) {
-						sensorLabel = "" + Boolean.parseBoolean(sensorLabel);
+						if(mqttPac.getSensorValue() == 0)
+							sensorLabel = "false";
+						else
+							sensorLabel = "true";
 					}
 					sensorLabel = ","+sensorLabel;
 				}
 				
 				try {
-					double dist = classifyInstance(packet_instance, packet);	
+					double dist = classifyInstance(packet_instance, packet);
+					//System.out.println(packet.getTextualRepresentation()+": "+packet.getLabel() +":"+sensorLabel);	
 					if(dist<=Settings.DECISION_THRESHOLD) {
 						if(packet.getLabel()==0) {
 							tn++;
@@ -412,6 +421,7 @@ public abstract class BasicPacketClassifierWitLabels implements PacketSniffer {
 						}
 					}
 				} catch (Exception e) {
+					System.out.println(e);
 					if(packet.getLabel()==0) {
 						fp++;
 						try {

+ 4 - 3
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/menuBar/MenuBarNetworkExamples.java

@@ -1078,6 +1078,8 @@ public class MenuBarNetworkExamples extends JMenu{
 			System.out.println("Light Anomaly:");
 			eventTime = noAnomEnd;
 			on = true;
+			smartLight.setTrueStatus(false);
+			smartLight.setBSval(true);
 			while(eventTime < lightEnd) {
 				/**
 				 * At least 1 second between events
@@ -1096,13 +1098,12 @@ public class MenuBarNetworkExamples extends JMenu{
 				eventTime+=Math.max(1000, Math.round(lightDist.sample()));
 				
 			}
-			smartLight.setTrueStatus(!smartLight.getBSval());
 			smartLight.setLabel((short)-1);
 			sim.getSimulationManager().simulateTimeIntervall(currentSimTime, lightEnd-currentSimTime);
 			currentSimTime=lightEnd;
-			
-			smartLight.setLabel((short)0);
+
 			smartLight.setBSval(smartLight.isTrueStatus());
+			smartLight.setLabel((short)0);
 			
 			new_time = System.currentTimeMillis();
 			elapsed_time = new_time-currentTime;