Andreas T. Meyer-Berg 3 лет назад
Родитель
Сommit
e4b469c7c4

+ 1 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/devices/SmartLight.java

@@ -33,6 +33,7 @@ public class SmartLight extends BoolSensorDevice implements SensorLabel {
 	public void setTrueStatus(boolean trueStatus) {
 		this.trueStatus = trueStatus;
 		roomStatus.setLightOn(trueStatus);
+		sensor.setBSval(trueStatus);
 	}
 
 	@Override

+ 1 - 1
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/devices/SmartLightSensor.java

@@ -7,7 +7,7 @@ import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.scheduler.Schedulable;
 public class SmartLightSensor extends BoolSensorDevice implements Schedulable, SensorLabel {
 
 	long eventTime = 0;
-	long updateInterval = 10000;
+	long updateInterval = 1000;
 	RoomStatus roomStatus;
 	
 	public SmartLightSensor(String name, RoomStatus roomStatus, long updateInterval) {

+ 3 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/devices/SmartTemperatureSensor.java

@@ -1,6 +1,7 @@
 package de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices;
 
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.RoomStatus;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SimulationManager;
 
 public class SmartTemperatureSensor extends FloatSensorDevice implements SensorLabel {
 	
@@ -11,6 +12,7 @@ public class SmartTemperatureSensor extends FloatSensorDevice implements SensorL
 	public SmartTemperatureSensor(String name, RoomStatus room) {
 		super(name, 1000);
 		roomStatus = room;
+		SimulationManager.scheduleEvent(this);
 	}
 	
 	@Override
@@ -19,6 +21,7 @@ public class SmartTemperatureSensor extends FloatSensorDevice implements SensorL
 		 * Update Temperature to Room Temperature
 		 */
 		super.setFSval(roomStatus.getTemperature());
+		SimulationManager.scheduleEvent(this);
 	}
 
 	@Override

+ 18 - 4
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/evaluation/BasicPacketClassifier.java

@@ -382,22 +382,36 @@ public abstract class BasicPacketClassifier implements PacketSniffer {
 							tn++;
 						else {
 							fn++;
+							writer.write(packet.getTextualRepresentation()+",FN"+sensorLabel+"\n");
 							//System.out.println(packet.getTextualRepresentation()+",AnomalyNotFound"+sensorLabel);
 						}
 					}else {
 						if(packet.getLabel()==0) {
 							fp++;
-							writer.write(packet.getTextualRepresentation()+",FP,"+sensorLabel+"\n");
+							writer.write(packet.getTextualRepresentation()+",FP"+sensorLabel+"\n");
 						} else {
 							tp++;
-							writer.write(packet.getTextualRepresentation()+",TP,"+sensorLabel+"\n");
+							writer.write(packet.getTextualRepresentation()+",TP"+sensorLabel+"\n");
 						}
 					}
 				} catch (Exception e) {
-					if(packet.getLabel()==0)
+					if(packet.getLabel()==0) {
 						fp++;
-					else
+						try {
+							writer.write(packet.getTextualRepresentation()+",FP"+sensorLabel+"\n");
+						} catch (IOException e1) {
+							// TODO Auto-generated catch block
+							e1.printStackTrace();
+						}
+					} else {
 						tp++;
+						try {
+							writer.write(packet.getTextualRepresentation()+",TP"+sensorLabel+"\n");
+						} catch (IOException e1) {
+							// TODO Auto-generated catch block
+							e1.printStackTrace();
+						}
+					}
 				}
 			}	
 		}

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

@@ -23,7 +23,7 @@ public class SWCKMeansClustering extends BasicPacketClassifier {
 	 */ 
 	//17 works fine
 	//34 found value anomalies
-	protected int NUMBER_OF_CLUSTERS = 25;
+	protected int NUMBER_OF_CLUSTERS = 40;
 	protected double[] stdv = new double[NUMBER_OF_CLUSTERS];
 	/**
 	 * Initializes the k means clusterer

+ 9 - 8
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/menuBar/MenuBarNetworkExamples.java

@@ -864,7 +864,7 @@ public class MenuBarNetworkExamples extends JMenu{
 		/*
 		 * Add Heater (every second update)
 		 */
-		SmartTemperatureProducer heaterDevice = new SmartTemperatureProducer(roomName + " Heater", room, 1000, heatSensor);
+		SmartTemperatureProducer heaterDevice = new SmartTemperatureProducer(roomName + " Heater", room, 500, heatSensor);
 		heaterDevice.setFSinfoName("home/" + roomName + "/heaterTemp");
 		networkController.addLinkToDevice(zigbee, heaterDevice);
 		networkController.moveSmartDevice(heaterDevice, 300, 500, 50);
@@ -883,7 +883,7 @@ public class MenuBarNetworkExamples extends JMenu{
 		/*
 		 * Add light Sensor
 		 */
-		SmartLightSensor lightSensor = new SmartLightSensor(roomName + " LightSensor", room, 10000);
+		SmartLightSensor lightSensor = new SmartLightSensor(roomName + " LightSensor", room, 1000);
 		lightSensor.setBSinfoName("home/" + roomName + "/light");
 		networkController.addLinkToDevice(zigbee, lightSensor);
 		networkController.moveSmartDevice(lightSensor, 500, 300, 50);
@@ -1001,20 +1001,20 @@ public class MenuBarNetworkExamples extends JMenu{
 			 */
 			NormalDistribution tempDist = new NormalDistribution(2*hour, hour/2);
 			eventTime = 0;
-			while(eventTime < endTime + 1 * hour) {
+			while(eventTime < 27 * hour) {
 				/**
 				 * At least 1 second between events
 				 */
-				eventTime+=Math.max(1000, Math.round(tempDist.sample()));
 				SimulationManager.scheduleEvent(new AbstractEvent(eventTime) {
 					
 					@Override
 					public void simulateEvent(long time) {
-						float newTemp = (float)(heaterDevice.getFSmax() + Math.random() * (heaterDevice.getFSmax()-heaterDevice.getFSmin()));
-						heaterDevice.setFSval(newTemp);
+						float newTemp = (float)(heaterDevice.getFSmin() + Math.random() * (heaterDevice.getFSmax()-heaterDevice.getFSmin()));
 						heaterDevice.setFSval(newTemp);
+						heaterDevice.setTrueTemperature(newTemp);
 					}
 				});
+				eventTime+=Math.max(1000, Math.round(tempDist.sample()));
 				
 			}
 			
@@ -1041,7 +1041,7 @@ public class MenuBarNetworkExamples extends JMenu{
 			
 			
 			/*
-			 * Simulate/Test 1 hour without anomalies
+			 * Simulate/Test 2 hour without anomalies
 			 */
 			snifferKNN.setCurrentScenario("NoAnomalies");
 			System.out.println("Test w/0 anomalies:");//TODO
@@ -1059,11 +1059,12 @@ public class MenuBarNetworkExamples extends JMenu{
 			 */
 			snifferKNN.setCurrentScenario("LightAnomalies");
 			System.out.println("Light Anomaly:");
-			smartLight.setTrueStatus(smartLight.getBSval());
+			smartLight.setTrueStatus(!smartLight.getBSval());
 			smartLight.setLabel((short)-1);
 			for(int i=26; i<27; i++)
 				sim.getSimulationManager().simulateTimeIntervall(hour*i, hour);
 			smartLight.setLabel((short)0);
+			smartLight.setBSval(smartLight.isTrueStatus());
 			
 			new_time = System.currentTimeMillis();
 			elapsed_time = new_time-currentTime;