Browse Source

print out and name evalutation files

David Heck 4 years ago
parent
commit
a648eebbf1

+ 47 - 22
src/blackstart/ControlAlgorithm.java

@@ -1,7 +1,13 @@
 package blackstart;
 
 import java.awt.*;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.LinkedList;
 import java.util.List;
 
@@ -31,7 +37,7 @@ public class ControlAlgorithm implements AddOn {
 	private TextField storageStartCharge;
 	private TextField carStartCharge;
 	private TextField waitBetweenIterations;
-	private TextField lowVolatageTextfield;
+	private TextField fileNameTextfield;
 	private TextField highVolatageTextfield;
 	private TextField renewableTextfield;
 
@@ -43,6 +49,9 @@ public class ControlAlgorithm implements AddOn {
 	private List<HolonObject> consumers;
 	private StorageProductionController SPC;
 
+	private Path file;
+	private ArrayList<String> lines;
+
 	public static void main(String[] args) {
 		JFrame newFrame = new JFrame("exampleWindow");
 		ControlAlgorithm instance = new ControlAlgorithm();
@@ -142,21 +151,21 @@ public class ControlAlgorithm implements AddOn {
 		parameterPanel.add(waitBetweenIterationsLabel);
 
 		////////collums
-		lowVolatageTextfield = new TextField("230");
-		lowVolatageTextfield.setBounds(425, 10, 95, 20);
-		parameterPanel.add(lowVolatageTextfield);
-
-		JLabel lowVolatageLabel = new JLabel("low voltage in volt");
-		lowVolatageLabel.setBounds(530, 10, 300, 20);
-		parameterPanel.add(lowVolatageLabel);
-
-		highVolatageTextfield = new TextField("20000");
-		highVolatageTextfield.setBounds(425, 35, 95, 20);
-		parameterPanel.add(highVolatageTextfield);
-
-		JLabel highVolatageLabel = new JLabel("high voltage in volt");
-		highVolatageLabel.setBounds(530, 35, 300, 20);
-		parameterPanel.add(highVolatageLabel);
+		fileNameTextfield = new TextField("Eval.txt");
+		fileNameTextfield.setBounds(425, 10, 95, 20);
+		parameterPanel.add(fileNameTextfield);
+
+		JLabel fileNameLabel = new JLabel("Filename");
+		fileNameLabel.setBounds(530, 10, 300, 20);
+		parameterPanel.add(fileNameLabel);
+
+//		highVolatageTextfield = new TextField("20000");
+//		highVolatageTextfield.setBounds(425, 35, 95, 20);
+//		parameterPanel.add(highVolatageTextfield);
+//
+//		JLabel highVolatageLabel = new JLabel("high voltage in volt");
+//		highVolatageLabel.setBounds(530, 35, 300, 20);
+//		parameterPanel.add(highVolatageLabel);
 
 		renewableTextfield = new TextField("300");
 		renewableTextfield.setBounds(425, 60, 95, 20);
@@ -209,6 +218,7 @@ public class ControlAlgorithm implements AddOn {
 	}
 
 	private void println(String message) {
+		lines.add(message);
 		textArea.append(message + "\n");
 	}
 
@@ -238,9 +248,9 @@ public class ControlAlgorithm implements AddOn {
 				return;
 			}
 			control.getModel().setResistanceCalculator(new ResistanceCalculator(
-					Integer.parseInt(lowVolatageTextfield.getText()),
-					Integer.parseInt(highVolatageTextfield.getText()),
-					10, 25,0.017, 0.017));
+					230,
+					10000,
+					35, 25,0.017, 0.017));
 			control.getModel().getResistanceCalculator().setDistancesToCalcResistance(powerplant);
 
 			blackstartRunningCounter = 0;
@@ -269,6 +279,9 @@ public class ControlAlgorithm implements AddOn {
 					se.setStateOfCharge(Float.parseFloat(storageStartCharge.getText()));
 				}
 			}
+			lines = new ArrayList<String>();
+			lines.add(fileNameTextfield.getText());
+			file = Paths.get(fileNameTextfield.getText());
 			updateVisual();
 			if (blackstartStartTime + blackstartSuccessTime > control.getModel().getIterations() - 1) {
 				println("No Time for the blackstart, use working numbers");
@@ -293,6 +306,7 @@ public class ControlAlgorithm implements AddOn {
 				deactivateBlackstart();
 				updateVisual();
 				println("Simulation of blackstart failed in Iteration: " + curIteration);
+				writeOutputTxt();
 			} else {
 				// blackstart for this iteration was successfull
 				blackstartRunningCounter++;
@@ -303,6 +317,7 @@ public class ControlAlgorithm implements AddOn {
 					enableAllConsumers();
 					updateVisual();
 					println("Simulation of blackstart Successfull in Iteration: " + curIteration);
+					writeOutputTxt();
 				} else {
 					// blackstart not finished yet
 					updateVisual();
@@ -323,9 +338,7 @@ public class ControlAlgorithm implements AddOn {
 	}
 
 	/**
-	 * TODO: HOLEG UNTERVERSORGUNG CHECKEN
 	 * TODO: global resistance calculator?
-	 * TODO: entladen besser verteilen
 	 *
 	 *
 	 * maybes:
@@ -353,7 +366,11 @@ public class ControlAlgorithm implements AddOn {
 				println("Not enough storage energy available");
 				return false;
 			}
-		} else {
+		} else {try {
+						Files.write(file, lines, StandardCharsets.UTF_8);
+					} catch (IOException e) {
+						e.printStackTrace();
+					}
 			//TODO: disable storage?
 			// renewable energy production is sufficient for the blackstart
 			rampUpPowerplant();
@@ -533,6 +550,14 @@ public class ControlAlgorithm implements AddOn {
 		return list;
 	}
 
+	private void writeOutputTxt(){
+		try {
+			Files.write(file, lines, StandardCharsets.UTF_8);
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+
 	private void printCurrentEnergyState(){
 		println("CURRENT ALGORITHM ITERATION: "+ control.getModel().getCurIteration());
 		println("blackstart resi: " + getEnergyRequiredForPowerplantBlackstart());

BIN
src/blackstart/simulationmodel10kV35mm100percent.holon