Browse Source

percentage of whole nettwork ist now working

Kevin Trometer 7 years ago
parent
commit
a007c166b5

+ 7 - 1
src/classes/HolonObject.java

@@ -31,8 +31,14 @@ public class HolonObject extends AbstractCpsObject {
 	/* Array for tracking Consumption */
 	private float[] trackingCons;
 	/*
-	 * 0 = no energy, 1 = not supplied, 2 = supplied, 3 producer
+	 * 0 = no energy, 1 = not supplied, 2 = supplied, 3 producer, 4 Partially Supplied
 	 */
+	public final static int NO_ENERGY = 0;
+	public final static int NOT_SUPPLIED = 1;
+	public final static int SUPPLIED = 2;
+	public final static int PRODUCER = 3;
+	public final static int PARTIALLY_SUPPLIED = 4;
+	
 	private int state = 0;
 
 	/**

+ 24 - 5
src/ui/controller/Control.java

@@ -110,7 +110,7 @@ public class Control {
 	public AbstractCpsObject searchByID(int id) {
 		return multiPurposeController.searchByID(id);
 	}
-	
+
 	/**
 	 * Search for Object by ID in upperNode
 	 * 
@@ -722,8 +722,8 @@ public class Control {
 		}
 	}
 
-	//========================= MANAGING TRACKED OBJECTS ====================
-	
+	// ========================= MANAGING TRACKED OBJECTS ====================
+
 	public void setTrackingObj(ArrayList<AbstractCpsObject> objArr) {
 		statsController.setTrackingObj(objArr);
 	}
@@ -739,8 +739,8 @@ public class Control {
 	public void removeTrackingObj(AbstractCpsObject obj) {
 		statsController.removeTrackingObj(obj);
 	}
-	
-	//========================== MANAGING TRACKED OBJECTS END ================
+
+	// ========================== MANAGING TRACKED OBJECTS END ================
 
 	/**
 	 * Controlling Nodes of Nodes
@@ -777,4 +777,23 @@ public class Control {
 	public void disconnectNodes(CpsEdge edge, CpsUpperNode upperNode) {
 		nodeController.disconnectNodes(edge, upperNode);
 	}
+
+	/**
+	 * Get the number of HolonObjects in the given List
+	 * 
+	 * @param list
+	 */
+	public int getNumberHolonObjects(ArrayList<AbstractCpsObject> list) {
+		return objectController.getNumberHolonObjects(list);
+	}
+	
+	/**
+	 * Get the number of HolonObjects with the given state in the given List
+	 * 
+	 * @param list
+	 * @param state
+	 */
+	public int getNumberStateObjects(ArrayList<AbstractCpsObject> list, int state) {
+		return objectController.getNumberStateObjects(list, state);
+	}
 }

+ 41 - 0
src/ui/controller/ObjectController.java

@@ -3,6 +3,7 @@ package ui.controller;
 import java.util.ArrayList;
 
 import classes.Category;
+import classes.CpsUpperNode;
 import classes.AbstractCpsObject;
 import classes.HolonElement;
 import classes.HolonObject;
@@ -221,4 +222,44 @@ public class ObjectController {
 	public void setClipboardObjects(ArrayList<AbstractCpsObject> list) {
 		model.setClipboradObjects(list);
 	}
+
+	/**
+	 * Get the number of HolonObjects in the given List
+	 * 
+	 * @param list
+	 */
+	public int getNumberHolonObjects(ArrayList<AbstractCpsObject> list) {
+		int val = 0;
+
+		for (AbstractCpsObject obj : list) {
+			if (obj instanceof HolonObject) {
+				val++;
+			} else if (obj instanceof CpsUpperNode) {
+				val += getNumberHolonObjects(((CpsUpperNode) obj).getNodes());
+			}
+		}
+		return val;
+	}
+
+	/**
+	 * Get the number of HolonObjects with the given state in the given List
+	 * 
+	 * @param list
+	 * @param state
+	 */
+	public int getNumberStateObjects(ArrayList<AbstractCpsObject> list, int state) {
+		int val = 0;
+
+		for (AbstractCpsObject obj : list) {
+			System.out.println(((HolonObject) obj).getState()+", "+((HolonObject) obj).getColor()+", "+((HolonObject) obj).getID());
+			if (obj instanceof HolonObject) {
+				if (((HolonObject) obj).getState() == state || (state == 2 && ((HolonObject) obj).getState() == 3)) {
+					val++;
+				}
+			} else if (obj instanceof CpsUpperNode) {
+				val += getNumberStateObjects(((CpsUpperNode) obj).getNodes(), state);
+			}
+		}
+		return val;
+	}
 }

+ 43 - 5
src/ui/view/StatisticGraph.java

@@ -32,7 +32,7 @@ public class StatisticGraph extends JPanel {
 	private static final long serialVersionUID = 1L;
 
 	// Maximum y Value
-	double maximum = 0;
+	float maximum = 0;
 
 	// is the Simulation running?
 	private boolean isSimRunning;
@@ -117,7 +117,7 @@ public class StatisticGraph extends JPanel {
 				case TrackedDataSet.PERCENT_SUPPLIED:
 				case TrackedDataSet.PERCENT_NOT_SUPPLIED:
 				case TrackedDataSet.PERCENT_PARTIAL_SUPPLIED:
-					//TODO Percentage Method
+					createPathPercent(set);
 					break;
 				default:
 					break;
@@ -285,13 +285,13 @@ public class StatisticGraph extends JPanel {
 				set.setValAt(-getTotalConsumptionAt(model.getObjectsOnCanvas(), model.getCurIteration()), model.getCurIteration());
 				break;
 			case TrackedDataSet.PERCENT_SUPPLIED:
-
+				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());
 				break;
 			case TrackedDataSet.PERCENT_PARTIAL_SUPPLIED:
-
+				set.setValAt(getPercentState(model.getObjectsOnCanvas(), HolonObject.PARTIALLY_SUPPLIED), model.getCurIteration());
 				break;
 			default:
 				break;
@@ -348,6 +348,31 @@ public class StatisticGraph extends JPanel {
 		}
 	}
 	
+	/**
+	 * create Path for percent values
+	 * 
+	 * @param set
+	 */
+	private void createPathPercent(TrackedDataSet set) {
+		boolean init = true;
+		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));
+				init = false;
+			}
+			if (!init) {
+				if (set.getValues()[i + 1] != -1) {
+					path.lineTo((i + 1) * this.getWidth() / model.getIterations(),
+							convertToCanvasY(set.getValues()[i + 1]*maximum));
+				} else {
+					break;
+				}
+			}
+
+		}
+	}
+	
 	/**
 	 * get the max total production of the given Objects
 	 *
@@ -437,5 +462,18 @@ public class StatisticGraph extends JPanel {
 		}
 		return val;
 	}
+	
+	/**
+	 * get the Percentage of how many objects with the given state are in the given List
+	 *
+	 *  @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;
+	}
 
 }