소스 검색

Merge branch 'master' of https://git.tk.informatik.tu-darmstadt.de/carlos.garcia/praktikum-holons

jess 7 년 전
부모
커밋
78b782f908
3개의 변경된 파일87개의 추가작업 그리고 41개의 파일을 삭제
  1. 1 1
      src/classes/TrackedDataSet.java
  2. 80 40
      src/ui/view/StatisticGraph.java
  3. 6 0
      src/ui/view/StatisticGraphPanel.java

+ 1 - 1
src/classes/TrackedDataSet.java

@@ -5,7 +5,7 @@ import java.awt.Color;
 public class TrackedDataSet {
 
 	//Property Integers
-	public static  final int CONSUMPTION = 0;
+	public static final int CONSUMPTION = 0;
 	public static final int PRODUCTION = 1;
 	public static final int ACTIVATED_ELEMENTS = 2;
 	public static final int ON_OFF = 3;

+ 80 - 40
src/ui/view/StatisticGraph.java

@@ -109,6 +109,9 @@ public class StatisticGraph extends JPanel {
 				case TrackedDataSet.ACTIVATED_ELEMENTS:
 				case TrackedDataSet.TOTAL_PRODUCTION:
 				case TrackedDataSet.TOTAL_CONSUMPTION:
+				case TrackedDataSet.AMOUNT_SUBNETS:
+				case TrackedDataSet.GROUP_CONSUMPTION:
+				case TrackedDataSet.GROUP_PRODUCTION:
 					createPathFloats(set);
 					break;
 				case TrackedDataSet.ON_OFF:
@@ -124,7 +127,6 @@ public class StatisticGraph extends JPanel {
 				}
 				g2.setColor(set.getColor());
 				g2.draw(path);
-
 			}
 		}
 
@@ -199,7 +201,6 @@ public class StatisticGraph extends JPanel {
 						val += h.getEnergy() * h.getAmount();
 					}
 				}
-
 				break;
 			case TrackedDataSet.ACTIVATED_ELEMENTS:
 				for (HolonElement h : ((HolonObject) set.getCpsObject()).getElements()) {
@@ -221,7 +222,23 @@ public class StatisticGraph extends JPanel {
 			case TrackedDataSet.PERCENT_PARTIAL_SUPPLIED:
 				val = 1;
 				break;
+			case TrackedDataSet.GROUP_PRODUCTION:
+				val = getMaxTotalProduction(((CpsUpperNode) set.getCpsObject()).getNodes());
+				break;
+			case TrackedDataSet.GROUP_CONSUMPTION:
+				val = getMaxTotalConsumption(((CpsUpperNode) set.getCpsObject()).getNodes());
+				val *= -1;
+				break;
+			case TrackedDataSet.AMOUNT_SUBNETS:
+				val = controller.getSimManager().getSubNets().size();
+				for (int i = 0; i < model.getCurIteration(); i++) {
+					if (val < set.getValues()[i]) {
+						val = set.getValues()[i];
+					}
+				}
+				break;
 			default:
+				maximum = 0;
 				break;
 			}
 			if (val > maximum) {
@@ -236,7 +253,7 @@ public class StatisticGraph extends JPanel {
 	 */
 	private void addValues() {
 		for (TrackedDataSet set : objects) {
-			int val = 0;
+			float val = 0;
 			switch (set.getProperty()) {
 			case TrackedDataSet.CONSUMPTION:
 				for (HolonElement h : ((HolonObject) set.getCpsObject()).getElements()) {
@@ -279,20 +296,37 @@ public class StatisticGraph extends JPanel {
 				}
 				break;
 			case TrackedDataSet.TOTAL_PRODUCTION:
-				set.setValAt(getTotalProductionAt(model.getObjectsOnCanvas(), model.getCurIteration()), model.getCurIteration());
+				set.setValAt(getTotalProductionAt(model.getObjectsOnCanvas(), model.getCurIteration()),
+						model.getCurIteration());
 				break;
 			case TrackedDataSet.TOTAL_CONSUMPTION:
-				set.setValAt(-getTotalConsumptionAt(model.getObjectsOnCanvas(), model.getCurIteration()), model.getCurIteration());
+				set.setValAt(-getTotalConsumptionAt(model.getObjectsOnCanvas(), model.getCurIteration()),
+						model.getCurIteration());
 				break;
 			case TrackedDataSet.PERCENT_SUPPLIED:
-				set.setValAt(getPercentState(model.getObjectsOnCanvas(), HolonObject.SUPPLIED), model.getCurIteration());
+				set.setValAt(getPercentState(model.getObjectsOnCanvas(), HolonObject.SUPPLIED),
+						model.getCurIteration());
 				break;
 			case TrackedDataSet.PERCENT_NOT_SUPPLIED:
-				set.setValAt(getPercentState(model.getObjectsOnCanvas(), HolonObject.NOT_SUPPLIED), model.getCurIteration());
+				set.setValAt(getPercentState(model.getObjectsOnCanvas(), HolonObject.NOT_SUPPLIED),
+						model.getCurIteration());
 				break;
 			case TrackedDataSet.PERCENT_PARTIAL_SUPPLIED:
-				set.setValAt(getPercentState(model.getObjectsOnCanvas(), HolonObject.PARTIALLY_SUPPLIED), model.getCurIteration());
+				set.setValAt(getPercentState(model.getObjectsOnCanvas(), HolonObject.PARTIALLY_SUPPLIED),
+						model.getCurIteration());
+				break;
+			case TrackedDataSet.GROUP_PRODUCTION:
+				val = getTotalProductionAt(((CpsUpperNode) set.getCpsObject()).getNodes(),model.getCurIteration());
+				break;
+			case TrackedDataSet.GROUP_CONSUMPTION:
+				val = getTotalConsumptionAt(((CpsUpperNode) set.getCpsObject()).getNodes(),model.getCurIteration());
+				controller.addTextToConsole(val+"");
+				val *= -1;
+				break;
+			case TrackedDataSet.AMOUNT_SUBNETS:
+				set.setValAt(controller.getSimManager().getSubNets().size(), model.getCurIteration());
 				break;
+
 			default:
 				break;
 			}
@@ -347,7 +381,7 @@ public class StatisticGraph extends JPanel {
 			}
 		}
 	}
-	
+
 	/**
 	 * create Path for percent values
 	 * 
@@ -358,13 +392,14 @@ public class StatisticGraph extends JPanel {
 		path.moveTo(0, 0);
 		for (int i = 0; i < model.getCurIteration(); i++) {
 			if (init && set.getValues()[i] != -1) {
-				path.moveTo(i * this.getWidth() / model.getIterations() - 1, convertToCanvasY(set.getValues()[i]*maximum));
+				path.moveTo(i * this.getWidth() / model.getIterations() - 1,
+						convertToCanvasY(set.getValues()[i] * maximum));
 				init = false;
 			}
 			if (!init) {
 				if (set.getValues()[i + 1] != -1) {
 					path.lineTo((i + 1) * this.getWidth() / model.getIterations(),
-							convertToCanvasY(set.getValues()[i + 1]*maximum));
+							convertToCanvasY(set.getValues()[i + 1] * maximum));
 				} else {
 					break;
 				}
@@ -372,18 +407,19 @@ public class StatisticGraph extends JPanel {
 
 		}
 	}
-	
+
 	/**
 	 * get the max total production of the given Objects
 	 *
-	 *  @param objects List of Objects
+	 * @param objects
+	 *            List of Objects
 	 */
 	private float getMaxTotalProduction(ArrayList<AbstractCpsObject> objects) {
 		float val = 0;
-		
-		for (AbstractCpsObject obj: objects) {
+
+		for (AbstractCpsObject obj : objects) {
 			if (obj instanceof HolonObject) {
-				for (HolonElement ele: ((HolonObject) obj).getElements()) {
+				for (HolonElement ele : ((HolonObject) obj).getElements()) {
 					if (ele.getEnergy() > 0) {
 						val += ele.getEnergy() * ele.getAmount();
 					}
@@ -394,18 +430,19 @@ public class StatisticGraph extends JPanel {
 		}
 		return val;
 	}
-	
+
 	/**
 	 * get the max total consumption of the given Objects
 	 *
-	 *  @param objects List of Objects
+	 * @param objects
+	 *            List of Objects
 	 */
 	private float getMaxTotalConsumption(ArrayList<AbstractCpsObject> objects) {
 		float val = 0;
-		
-		for (AbstractCpsObject obj: objects) {
+
+		for (AbstractCpsObject obj : objects) {
 			if (obj instanceof HolonObject) {
-				for (HolonElement ele: ((HolonObject) obj).getElements()) {
+				for (HolonElement ele : ((HolonObject) obj).getElements()) {
 					if (ele.getEnergy() < 0) {
 						val += ele.getEnergy() * ele.getAmount();
 					}
@@ -416,19 +453,20 @@ public class StatisticGraph extends JPanel {
 		}
 		return val;
 	}
-	
+
 	/**
 	 * get the max total production of the given Objects
 	 *
-	 *  @param objects List of Objects
-	 *  @param tStep
+	 * @param objects
+	 *            List of Objects
+	 * @param tStep
 	 */
 	private float getTotalProductionAt(ArrayList<AbstractCpsObject> objects, int tStep) {
 		float val = 0;
-		
-		for (AbstractCpsObject obj: objects) {
+
+		for (AbstractCpsObject obj : objects) {
 			if (obj instanceof HolonObject) {
-				for (HolonElement ele: ((HolonObject) obj).getElements()) {
+				for (HolonElement ele : ((HolonObject) obj).getElements()) {
 					if (ele.getEnergyAt()[tStep] > 0 && ele.getActive()) {
 						val += ele.getEnergyAt()[tStep] * ele.getAmount();
 					}
@@ -439,19 +477,20 @@ public class StatisticGraph extends JPanel {
 		}
 		return val;
 	}
-	
+
 	/**
 	 * get the total consumption of the given Objects at the given timestep
 	 *
-	 *  @param objects List of Objects
-	 *  @param tStep
+	 * @param objects
+	 *            List of Objects
+	 * @param tStep
 	 */
 	private float getTotalConsumptionAt(ArrayList<AbstractCpsObject> objects, int tStep) {
 		float val = 0;
-		
-		for (AbstractCpsObject obj: objects) {
+
+		for (AbstractCpsObject obj : objects) {
 			if (obj instanceof HolonObject) {
-				for (HolonElement ele: ((HolonObject) obj).getElements()) {
+				for (HolonElement ele : ((HolonObject) obj).getElements()) {
 					if (ele.getEnergyAt()[tStep] < 0 && ele.getActive()) {
 						val += ele.getEnergyAt()[tStep] * ele.getAmount();
 					}
@@ -462,18 +501,19 @@ public class StatisticGraph extends JPanel {
 		}
 		return val;
 	}
-	
+
 	/**
-	 * get the Percentage of how many objects with the given state are in the given List
+	 * get the Percentage of how many objects with the given state are in the
+	 * given List
 	 *
-	 *  @param objects List of Objects
+	 * @param objects
+	 *            List of Objects
 	 */
 	private float getPercentState(ArrayList<AbstractCpsObject> objects, int state) {
 		float count = controller.getNumberHolonObjects(objects);
-		float stateObjectss= controller.getNumberStateObjects(objects, state);
-		
-		
-		return stateObjectss/count;
+		float stateObjectss = controller.getNumberStateObjects(objects, state);
+
+		return stateObjectss / count;
 	}
 
 }

+ 6 - 0
src/ui/view/StatisticGraphPanel.java

@@ -157,9 +157,11 @@ public class StatisticGraphPanel extends JPanel {
 		String property = "";
 		switch (set.getProperty()) {
 		case TrackedDataSet.CONSUMPTION:
+		case TrackedDataSet.GROUP_CONSUMPTION:
 			property = "consumption";
 			break;
 		case TrackedDataSet.PRODUCTION:
+		case TrackedDataSet.GROUP_PRODUCTION:
 			property = "production";
 			break;
 		case TrackedDataSet.ACTIVATED_ELEMENTS:
@@ -183,7 +185,11 @@ public class StatisticGraphPanel extends JPanel {
 		case TrackedDataSet.PERCENT_PARTIAL_SUPPLIED:
 			property = "Percentage of partial supplied";
 			break;
+		case TrackedDataSet.AMOUNT_SUBNETS:
+			property = "Amount of Subnets";
+			break;
 		default:
+			property = "null";
 			break;
 		}
 		JLabel b;