1
0
mirror of https://github.com/christiaangoossens/Planetary-Orbit-Simulator synced 2024-11-22 03:04:10 +00:00

Improvements to the data writer

This commit is contained in:
Christiaan Goossens 2016-09-15 14:01:03 +02:00
parent e276abd3e4
commit 1d99586994
6 changed files with 95 additions and 65 deletions

View File

@ -7,10 +7,8 @@
</component>
<component name="ChangeListManager">
<list default="true" id="17f368cb-44f8-4101-9a29-49a0f4ff1f92" name="Default" comment="Update workspace">
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/com/verictas/pos/simulator/Main.java" afterPath="$PROJECT_DIR$/src/com/verictas/pos/simulator/Main.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/com/verictas/pos/simulator/Simulator.java" afterPath="$PROJECT_DIR$/src/com/verictas/pos/simulator/Simulator.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/com/verictas/pos/simulator/SimulatorConfig.java" afterPath="$PROJECT_DIR$/src/com/verictas/pos/simulator/SimulatorConfig.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/com/verictas/pos/simulator/dataWriter/DataWriter.java" afterPath="$PROJECT_DIR$/src/com/verictas/pos/simulator/dataWriter/DataWriter.java" />
</list>
<ignored path="simulator.iws" />
<ignored path=".idea/workspace.xml" />
@ -35,7 +33,7 @@
<file leaf-file-name="Main.java" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/com/verictas/pos/simulator/Main.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="510">
<state relative-caret-position="362">
<caret line="30" column="0" selection-start-line="30" selection-start-column="0" selection-end-line="30" selection-end-column="0" />
<folding>
<element signature="imports" expanded="true" />
@ -44,11 +42,11 @@
</provider>
</entry>
</file>
<file leaf-file-name="Simulator.java" pinned="false" current-in-tab="false">
<file leaf-file-name="Simulator.java" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/com/verictas/pos/simulator/Simulator.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="136">
<caret line="8" column="46" selection-start-line="8" selection-start-column="46" selection-end-line="8" selection-end-column="46" />
<state relative-caret-position="153">
<caret line="45" column="0" selection-start-line="45" selection-start-column="0" selection-end-line="45" selection-end-column="0" />
<folding>
<element signature="imports" expanded="true" />
</folding>
@ -56,16 +54,49 @@
</provider>
</entry>
</file>
<file leaf-file-name="SimulatorConfig.java" pinned="false" current-in-tab="true">
<file leaf-file-name="SimulatorConfig.java" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/com/verictas/pos/simulator/SimulatorConfig.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="34">
<caret line="2" column="13" selection-start-line="2" selection-start-column="13" selection-end-line="2" selection-end-column="13" />
<state relative-caret-position="153">
<caret line="9" column="1" selection-start-line="9" selection-start-column="1" selection-end-line="9" selection-end-column="1" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="DataWriter.java" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/com/verictas/pos/simulator/dataWriter/DataWriter.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1479">
<caret line="87" column="5" selection-start-line="87" selection-start-column="5" selection-end-line="87" selection-end-column="5" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#3621#3622#0" expanded="true" />
<element signature="e#3656#3657#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file leaf-file-name="Object.java" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/com/verictas/pos/simulator/Object.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="665">
<caret line="42" column="16" selection-start-line="42" selection-start-column="16" selection-end-line="42" selection-end-column="16" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#1090#1091#0" expanded="true" />
<element signature="e#1161#1162#0" expanded="true" />
<element signature="method#getSpeed#0;class#Object#0" expanded="false" />
<element signature="method#getPosition#0;class#Object#0" expanded="false" />
<element signature="method#setAcceleration#1;class#Object#0" expanded="false" />
<element signature="method#getAcceleration#0;class#Object#0" expanded="false" />
<element signature="method#setOldAcceleration#1;class#Object#0" expanded="false" />
</folding>
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="FileTemplateManagerImpl">
@ -104,8 +135,8 @@
<option value="$PROJECT_DIR$/src/com/verictas/pos/simulator/dataWriter/WritingException.java" />
<option value="$PROJECT_DIR$/src/com/verictas/pos/simulator/Object.java" />
<option value="$PROJECT_DIR$/src/com/verictas/pos/simulator/mathUtils/AU.java" />
<option value="$PROJECT_DIR$/src/com/verictas/pos/simulator/dataWriter/DataWriter.java" />
<option value="$PROJECT_DIR$/src/com/verictas/pos/simulator/Main.java" />
<option value="$PROJECT_DIR$/src/com/verictas/pos/simulator/dataWriter/DataWriter.java" />
<option value="$PROJECT_DIR$/src/com/verictas/pos/simulator/SimulatorConfig.java" />
<option value="$PROJECT_DIR$/src/com/verictas/pos/simulator/Simulator.java" />
</list>
@ -211,28 +242,6 @@
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
</PATH>
<PATH>
<PATH_ELEMENT>
<option name="myItemId" value="simulator" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="simulator" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="src" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="simulator" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="mathUtils" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
</PATH>
<PATH>
<PATH_ELEMENT>
<option name="myItemId" value="simulator" />
@ -569,7 +578,7 @@
<window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="true" content_ui="tabs" />
<window_info id="Maven Projects" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="8" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.3266385" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.23890063" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="9" side_tool="false" content_ui="tabs" />
<window_info id="Capture Tool" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
<window_info id="Designer" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
@ -998,16 +1007,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/verictas/pos/simulator/dataWriter/DataWriter.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="612">
<caret line="36" column="73" selection-start-line="36" selection-start-column="73" selection-end-line="36" selection-end-column="73" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/verictas/pos/simulator/dataWriter/WritingException.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="102">
@ -1016,19 +1015,9 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/verictas/pos/simulator/Simulator.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="136">
<caret line="8" column="46" selection-start-line="8" selection-start-column="46" selection-end-line="8" selection-end-column="46" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/verictas/pos/simulator/Main.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="510">
<state relative-caret-position="362">
<caret line="30" column="0" selection-start-line="30" selection-start-column="0" selection-end-line="30" selection-end-column="0" />
<folding>
<element signature="imports" expanded="true" />
@ -1038,7 +1027,7 @@
</entry>
<entry file="file://$PROJECT_DIR$/src/com/verictas/pos/simulator/Object.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="680">
<state relative-caret-position="665">
<caret line="42" column="16" selection-start-line="42" selection-start-column="16" selection-end-line="42" selection-end-column="16" />
<folding>
<element signature="imports" expanded="true" />
@ -1053,14 +1042,36 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/verictas/pos/simulator/dataWriter/DataWriter.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1479">
<caret line="87" column="5" selection-start-line="87" selection-start-column="5" selection-end-line="87" selection-end-column="5" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#3621#3622#0" expanded="true" />
<element signature="e#3656#3657#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/verictas/pos/simulator/SimulatorConfig.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="34">
<caret line="2" column="13" selection-start-line="2" selection-start-column="13" selection-end-line="2" selection-end-column="13" />
<state relative-caret-position="153">
<caret line="9" column="1" selection-start-line="9" selection-start-column="1" selection-end-line="9" selection-end-column="1" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/verictas/pos/simulator/Simulator.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="153">
<caret line="45" column="0" selection-start-line="45" selection-start-column="0" selection-end-line="45" selection-end-column="0" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
</component>
<component name="masterDetails">
<states>

View File

@ -1,6 +1,10 @@
package com.verictas.pos.simulator;
public class SimulatorConfig {
// The amount of rounds and the time step
public static int rounds = 525960;
public static double time = 60; // in seconds
// Set the skipLines integer to skip lines (for example: every 5th line is written) in the output file (for smaller files), if this is set to 1, it has no effect and all lines will be written.
public static int skipLines = 5;
}

View File

@ -1,5 +1,6 @@
package com.verictas.pos.simulator.dataWriter;
import com.verictas.pos.simulator.SimulatorConfig;
import com.verictas.pos.simulator.mathUtils.AU;
import javax.vecmath.Vector3d;
@ -16,6 +17,8 @@ public class DataWriter {
private static final String DELIMITER = "\t";
private static final String NEW_LINE = "\n";
private int counter = 0;
public DataWriter() throws WritingException {
try {
// Define the save path
@ -30,11 +33,12 @@ public class DataWriter {
}
this.writer = new FileWriter(path);
this.writer.write("Object" + DELIMITER + "Position (m)" + DELIMITER + "Position (AU)" + DELIMITER + "Speed (m)" + DELIMITER + "Speed (AU)" + DELIMITER + "Old Acceleration" + DELIMITER + "Acceleration" + DELIMITER + "Mass" + NEW_LINE);
this.writer.write("Object" + DELIMITER + "Position (m)" + DELIMITER + "Position (AU)" + DELIMITER + "Speed (m/s)" + DELIMITER + "Speed (AU/day)" + DELIMITER + "Old Acceleration" + DELIMITER + "Acceleration" + DELIMITER + "Mass" + NEW_LINE);
this.counter++;
} catch(IOException e) {
throw new WritingException("Whoop! Creation error!");
throw new WritingException("The destination file couldn't be created.");
} catch(Exception e) {
throw new WritingException("Whoop! Unknown creation error!");
throw new WritingException("Some unknown error occurred while writing to the file!");
}
}
@ -43,9 +47,13 @@ public class DataWriter {
throw new WritingException("The writer isn't defined yet");
} else {
try {
this.writer.append(string);
if (this.counter % SimulatorConfig.skipLines == 0) {
this.writer.append(string);
}
this.counter++;
} catch (Exception e) {
throw new WritingException("Whoop! Write error!");
e.printStackTrace();
throw new WritingException("An error occurred while writing to the file!");
}
}
}
@ -55,10 +63,13 @@ public class DataWriter {
throw new WritingException("The writer isn't defined yet");
} else {
try {
this.writer.append(id + DELIMITER + position.toString() + DELIMITER + AU.convertFromMeter(position).toString() + DELIMITER + speed.toString() + DELIMITER + AU.convertFromMetersPerSecond(speed).toString() + DELIMITER + oldAcceleration.toString() + DELIMITER + acceleration.toString() + DELIMITER + String.valueOf(mass) + NEW_LINE);
if (this.counter % SimulatorConfig.skipLines == 0) {
this.writer.append(id + DELIMITER + position.toString() + DELIMITER + AU.convertFromMeter(position).toString() + DELIMITER + speed.toString() + DELIMITER + AU.convertFromMetersPerSecond(speed).toString() + DELIMITER + oldAcceleration.toString() + DELIMITER + acceleration.toString() + DELIMITER + String.valueOf(mass) + NEW_LINE);
}
this.counter++;
} catch (Exception e) {
e.printStackTrace();
throw new WritingException("Whoop! Write error!");
throw new WritingException("An error occurred while writing to the file!");
}
}
}
@ -76,6 +87,10 @@ public class DataWriter {
}
}
public int getLines() {
return this.counter;
}
public String getCurrentTimeStamp() {
return new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(new Date());
}