Browse Source

Battery Anzeige

tolatesry 6 years ago
parent
commit
e71b80bdaa

+ 61 - 13
src/classes/HolonBattery.java

@@ -6,8 +6,8 @@ public class HolonBattery extends AbstractCpsObject{
 	private float outRatio;
 	private float capasity;
 	private float stateOfCharge;
-	
-	
+	public enum State{STANDBY, COLLECT, EMIT};
+	private State state;
 	/** Constructor for a unique ID.
 	 * @param ObjName
 	 */
@@ -18,6 +18,7 @@ public class HolonBattery extends AbstractCpsObject{
 		outRatio = 0;
 		capasity = 0;
 		stateOfCharge = 0;
+		setState(State.STANDBY);
 	}
 	/** Constructor to Copy a Battery
 	 * @param obj Object to copy.
@@ -25,15 +26,12 @@ public class HolonBattery extends AbstractCpsObject{
 	public HolonBattery(AbstractCpsObject obj)
 	{
 		super(obj);
-		
-		
-	}
-	/**
-	 * TestFunction for functionality
-	 */
-	public void HelloWorld()
-	{
-		System.out.println("JO");
+		super.setName(obj.getName());
+		setInRatio(((HolonBattery) obj).getInRatio());
+		setOutRatio(((HolonBattery) obj).getOutRatio());
+		setCapasity(((HolonBattery) obj).getCapasity());
+		setStateOfCharge(((HolonBattery) obj).getStateOfCharge());
+		setState(State.STANDBY);
 	}
 	public float getStateOfCharge() {
 		return stateOfCharge;
@@ -43,12 +41,21 @@ public class HolonBattery extends AbstractCpsObject{
 		{
 			stateOfCharge = capasity;
 		}
+		else if(stateOfCharge < 0) // state of charge can not be a negativ value
+		{
+			stateOfCharge = 0;
+		}
 		this.stateOfCharge = stateOfCharge;
 	}
 	public float getCapasity() {
+	
 		return capasity;
 	}
-	public void setCapasity(float capasity) {
+	public void setCapasity(float capasity) {	
+		if(capasity < 0) //capasity can not be negative
+		{
+			capasity = 0;
+		}
 		this.capasity = capasity;
 	}
 	public float getOutRatio() {
@@ -62,7 +69,22 @@ public class HolonBattery extends AbstractCpsObject{
 		this.outRatio = outRatio;
 	}
 	public float getInRatio() {
-		return inRatio;
+			return inRatio;
+	}
+	//For Calculations
+	public float getIN()
+	{
+		if(getCapasity() - getStateOfCharge() < inRatio)
+			return getCapasity() - getStateOfCharge();
+		else
+			return inRatio;
+	}
+	public float getOUT()
+	{
+		if(getStateOfCharge() < outRatio)
+			return getStateOfCharge();
+		else
+			return outRatio;
 	}
 	public void setInRatio(float inRatio) {
 		if(inRatio < 0)
@@ -71,4 +93,30 @@ public class HolonBattery extends AbstractCpsObject{
 		}
 		this.inRatio = inRatio;
 	}
+	public State getState() {
+		return state;
+	}
+	public void setState(State state) {
+		this.state = state;
+	}
+
+	/**
+	 * @return The String that is over the Battery in the Canvas if COLLECT the
+	 *         input if EMIT the output of the Battery
+	 */
+	public String getCanvasBatteryString()
+	{
+		switch(getState())
+		{
+		case COLLECT:
+			return "-" + Float.toString(getIN());
+		case EMIT:
+			return "+" + Float.toString(getOUT());
+		case STANDBY:
+		default:
+			return "0";
+		}
+		
+	}
+	
 }

+ 6 - 2
src/classes/SubNet.java

@@ -12,6 +12,7 @@ public class SubNet {
 	private ArrayList<HolonObject> subNetObjects;
 	private ArrayList<CpsEdge> subNetEdges;
 	private ArrayList<HolonSwitch> subNetSwitches;
+	private ArrayList<HolonBattery> subNetBatteries;
 	/**
 	 * Constructor for a Subnet.
 	 * 
@@ -22,10 +23,11 @@ public class SubNet {
 	 * @param switches
 	 *            Switches in the Subnet
 	 */
-	public SubNet(ArrayList<HolonObject> objects, ArrayList<CpsEdge> edges, ArrayList<HolonSwitch> switches) {
+	public SubNet(ArrayList<HolonObject> objects, ArrayList<CpsEdge> edges, ArrayList<HolonSwitch> switches, ArrayList<HolonBattery> batteries) {
 		subNetObjects = objects;
 		subNetEdges = edges;
 		subNetSwitches = switches;
+		subNetBatteries = batteries;
 	}
 
 	/**
@@ -53,7 +55,9 @@ public class SubNet {
 	public ArrayList<HolonSwitch> getSwitches() {
 		return subNetSwitches;
 	}
-
+	public ArrayList<HolonBattery> getBatteries() {
+		return subNetBatteries;
+	}
 
     public String toString(int timeStep) {
         StringBuilder sb = new StringBuilder();

+ 6 - 6
src/tests/PraktikumHolonsTestClasses.java

@@ -14,7 +14,7 @@ import static org.junit.Assert.assertTrue;
  * @author Gruppe14
  */
 public class PraktikumHolonsTestClasses {
-
+	
 	/**
 	 * Test for the Categories.
 	 */
@@ -45,6 +45,7 @@ public class PraktikumHolonsTestClasses {
 	/**
 	 * Test for HolonObject.
 	 */
+	
 	@Test
 	public void testHolonObject() {
 
@@ -199,10 +200,9 @@ public class PraktikumHolonsTestClasses {
 //		ele3.setSav("CVS");
 //		assertTrue("SAV not correct", ele3.getSav().equals("CVS"));
 	}
-
 	/**
 	 * Test for Position.
-	 */
+	*/
 	@Test
 	public void testPosition() {
 		Position pos1 = new Position(100, 200);
@@ -212,7 +212,6 @@ public class PraktikumHolonsTestClasses {
 		assertTrue("Are the Same", pos1.x != pos2.x);
 		assertTrue("not (-1,-1)", pos2.x == -1 && pos2.y == -1);
 	}
-
 	/**
 	 * Test SubNet.
 	 */
@@ -223,6 +222,7 @@ public class PraktikumHolonsTestClasses {
 		ArrayList<HolonObject> obj = new ArrayList<>();
 		ArrayList<CpsEdge> edge = new ArrayList<>();
 		ArrayList<HolonSwitch> sw = new ArrayList<>();
+		ArrayList<HolonBattery> sb = new ArrayList<>();
 
 		assertTrue("Not Empty", obj.isEmpty());
 		assertTrue("Not Empty", sw.isEmpty());
@@ -238,7 +238,7 @@ public class PraktikumHolonsTestClasses {
 			edge.add(new CpsEdge(o, s));
 		}
 
-		SubNet sub = new SubNet(obj, edge, sw);
+		SubNet sub = new SubNet(obj, edge, sw, sb);
 
 		assertTrue("Empty", !sub.getObjects().isEmpty() && sub.getObjects().size() == 9);
 		assertTrue("Empty", !sub.getSwitches().isEmpty() && sub.getSwitches().size() == 9);
@@ -246,5 +246,5 @@ public class PraktikumHolonsTestClasses {
 		assertTrue("Wrong Obj", sub.getObjects().get(5).getObjName().equals("F"));
 
 	}
-
+	
 }

+ 1 - 1
src/tests/PraktikumHolonsTestSuite.java

@@ -22,7 +22,7 @@ public class PraktikumHolonsTestSuite {
 		suite.addTest(new JUnit4TestAdapter(PraktikumHolonsTestCategoryController.class));
 		suite.addTest(new JUnit4TestAdapter(PraktikumHolonsTestCanvasController.class));
 		suite.addTest(new JUnit4TestAdapter(PraktikumHolonsTestObjectController.class));
-		//suite.addTest(new JUnit4TestAdapter(PraktikumHolonsTestLoadAndStoreController.class));
+		suite.addTest(new JUnit4TestAdapter(PraktikumHolonsTestLoadAndStoreController.class));
 		suite.addTest(new JUnit4TestAdapter(PraktikumHolonsTestGlobalController.class));
 		suite.addTest(new JUnit4TestAdapter(PraktikumHolonsTestAutoSaveController.class));
 		suite.addTest(new JUnit4TestAdapter(PraktikumHolonsTestConsoleController.class));

+ 27 - 3
src/ui/controller/SimulationManager.java

@@ -11,6 +11,8 @@ import ui.view.MyCanvas;
 import java.util.ArrayList;
 import java.util.HashMap;
 
+import com.sun.xml.internal.ws.util.xml.XMLReaderComposite.State;
+
 /**
  * Controller for Simulation.
  *
@@ -77,7 +79,26 @@ public class SimulationManager {
 			// surplus of energy is computed by sum, since consumption is a
 			// negative value
 			float energySurplus = production + consumption;
-
+			
+			//-->TODO: OutSourcing later in method and just use whats needed
+			float getMaxInPut = 0;
+			float getMaxOutPut = 0;
+			for(HolonBattery hB : singleSubNet.getBatteries())
+			{
+				getMaxInPut += hB.getIN();
+				getMaxOutPut += hB.getOUT();
+				if(energySurplus < 0)
+					hB.setState(HolonBattery.State.EMIT);
+				else if (energySurplus > 0)
+					hB.setState(HolonBattery.State.COLLECT);
+					
+			}
+			if(energySurplus < 0)
+				energySurplus += getMaxOutPut;
+			else if (energySurplus > 0)
+				energySurplus -= getMaxInPut;
+			System.out.println(energySurplus);
+			//<--
 			//float minConsumption = calculateMinimumEnergy(singleSubNet, timeStep);
 
 			// --------------- use flexible devices ---------------
@@ -567,7 +588,7 @@ public class SimulationManager {
 			}
 			if (type.equals("cons")) {
 				if (currentEnergyWithoutFlexibles < 0) {
-					energy = energy + currentEnergyWithoutFlexibles;
+					energy += currentEnergyWithoutFlexibles;
 					hl.setState(HolonObject.NOT_SUPPLIED);
 				}
 			}
@@ -666,7 +687,7 @@ public class SimulationManager {
 			while (!end) {
 				cps = objectsToHandle.get(i);
 				SubNet singleSubNet = new SubNet(new ArrayList<>(),
-						new ArrayList<>(), new ArrayList<>());
+						new ArrayList<>(), new ArrayList<>(), new ArrayList<>());
 				singleSubNet = buildSubNet(cps, new ArrayList<>(), singleSubNet);
 				if (singleSubNet.getObjects().size() != 0) {
 					subNets.add(singleSubNet);
@@ -699,6 +720,9 @@ public class SimulationManager {
 		if (cps instanceof HolonSwitch) {
 			sN.getSwitches().add((HolonSwitch) cps);
 		}
+		if (cps instanceof HolonBattery) {
+			sN.getBatteries().add((HolonBattery) cps);
+		}
 		removeFromToHandle(cps.getId());
 		AbstractCpsObject a;
 		AbstractCpsObject b;

+ 14 - 1
src/ui/controller/UpdateController.java

@@ -334,7 +334,20 @@ public class UpdateController {
 				model.getPropertyTable().addRow(numObj);
 				model.getPropertyTable().addRow(numSwi);
 				model.getPropertyTable().addRow(numUpp);
-			} else {
+			} else if (obj instanceof HolonBattery) {
+				deleteRows(model.getSingleTable());
+				deleteRows(model.getMultiTable());
+				Object[] numInRatio = {"InRatio:", ((HolonBattery)obj).getInRatio() };
+				Object[] numOutRatio = {"OutRatio:", ((HolonBattery)obj).getOutRatio() };
+				Object[] numSOC_Capasity = {"State of charge:", Float.toString(((HolonBattery)obj).getStateOfCharge()) + "/" + Float.toString(((HolonBattery)obj).getCapasity()) };
+				model.getPropertyTable().addRow(numInRatio);
+				model.getPropertyTable().addRow(numOutRatio);
+				model.getPropertyTable().addRow(numSOC_Capasity);
+				
+				model.getPropertyTable().setCellEditable(0, 1, true);
+				model.getPropertyTable().setCellEditable(2, 1, true);
+				model.getPropertyTable().setCellEditable(3, 1, true);
+			}else {
 				deleteRows(model.getSingleTable());
 				deleteRows(model.getMultiTable());
 			}

+ 12 - 0
src/ui/view/AbstractCanvas.java

@@ -240,6 +240,11 @@ public abstract class AbstractCanvas extends JPanel {
                     float totalEnergy = ((HolonObject) cps).getCurrentEnergyAtTimeStep(model.getCurIteration());
                     g2.drawString(Float.toString(totalEnergy), cps.getPosition().x - controller.getScaleDiv2(),
                             cps.getPosition().y - controller.getScaleDiv2() - 10);
+                }else if (showedInformation[1] && cps instanceof HolonBattery)
+                {
+                	g2.setColor(Color.BLACK);
+                    g2.drawString(((HolonBattery) cps).getCanvasBatteryString(), cps.getPosition().x - controller.getScaleDiv2(),
+                            cps.getPosition().y - controller.getScaleDiv2() - 10);
                 }
             } else if (cps instanceof HolonObject) {
                 g2.setColor(((HolonObject) cps).getColor());
@@ -256,6 +261,13 @@ public abstract class AbstractCanvas extends JPanel {
                             cps.getPosition().y - controller.getScaleDiv2() - 10);
                 }
             }
+            else if (cps instanceof HolonBattery) {
+                if (showedInformation[1]) {
+                	g2.setColor(Color.BLACK);
+                    g2.drawString(((HolonBattery) cps).getCanvasBatteryString(), cps.getPosition().x - controller.getScaleDiv2(),
+                            cps.getPosition().y - controller.getScaleDiv2() - 10);
+                }
+            }
             // draw image
             File checkPath = new File(cps.getImage());
             if (checkPath.exists()) {

+ 8 - 2
src/ui/view/GUI.java

@@ -1606,7 +1606,10 @@ public class GUI implements CategoryListener {
 								if (tempCps instanceof HolonTransformer) {
 									h = new HolonTransformer(tempCps);
 								}
-
+								if (tempCps instanceof HolonBattery)
+								{
+									h = new HolonBattery(tempCps);
+								}
 								h.setPosition(x, y);
 
 								controller.addObjUpperNode(h, unc.upperNode);
@@ -1630,7 +1633,10 @@ public class GUI implements CategoryListener {
 							if (tempCps instanceof HolonTransformer) {
 								h = new HolonTransformer(tempCps);
 							}
-
+							if (tempCps instanceof HolonBattery)
+							{
+								h = new HolonBattery(tempCps);
+							}
 							h.setPosition(x, y);
 
 							controller.addObjectCanvas(h);