ThrustCurveMotor now includes both common name and designation

If both are not available (which is the case when loading from a file
rather than from thrustcurve.org) use motor code for designation,
and simplified designation for common name
This commit is contained in:
JoePfeiffer 2021-08-20 13:35:20 -06:00
parent 31f52cec18
commit 08f76683e9
5 changed files with 90 additions and 9 deletions

View File

@ -74,6 +74,28 @@ public interface Motor {
public Type getMotorType();
/**
* Return the motor code
*
* @return the code
*/
public String getCode();
/**
* Return the common name of the motor.
*
* @return the common name
*/
public String getCommonName();
/**
* Return the common name of the motor, including a delay.
*
* @param delay the delay of the motor.
* @return common name with delay.
*/
public String getCommonName(double delay);
/**
* Return the designation of the motor.
*

View File

@ -4,6 +4,8 @@ import java.io.Serializable;
import java.text.Collator;
import java.util.Arrays;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -33,7 +35,10 @@ public class ThrustCurveMotor implements Motor, Comparable<ThrustCurveMotor>, Se
private String digest = "";
private Manufacturer manufacturer = Manufacturer.getManufacturer("Unknown");
private String code = "";
private String commonName = "";
private String designation = "";
private String description = "";
private Motor.Type type = Motor.Type.UNKNOWN;
private double[] delays = {};
@ -75,6 +80,16 @@ public class ThrustCurveMotor implements Motor, Comparable<ThrustCurveMotor>, Se
return this;
}
public Builder setCode(String c) {
motor.code = c;
return this;
}
public Builder setCommonName(String n) {
motor.commonName = n;
return this;
}
public Builder setDesignation(String d) {
motor.designation = d;
return this;
@ -130,11 +145,29 @@ public class ThrustCurveMotor implements Motor, Comparable<ThrustCurveMotor>, Se
return this;
}
public Builder setAvailablity(boolean avail) {
public Builder setAvailability(boolean avail) {
motor.available = avail;
return this;
}
/**
* Simplify a motor designation, if possible. This attempts to reduce the designation
* into a simple letter + number notation for the impulse class and average thrust.
*
* @param str the designation to simplify
* @return the simplified designation, or the string itself if the format was not detected
*/
private static final Pattern SIMPLIFY_PATTERN = Pattern.compile("^[0-9]*[ -]*([A-Z][0-9]+).*");
static String simplifyDesignation(String str) {
str = str.trim();
Matcher m = SIMPLIFY_PATTERN.matcher(str);
if (m.matches()) {
return m.group(1);
} else {
return str.replaceAll("\\s", "");
}
}
public ThrustCurveMotor build() {
// Check argument validity
if ((motor.time.length != motor.thrust.length) || (motor.time.length != motor.cg.length)) {
@ -202,6 +235,19 @@ public class ThrustCurveMotor implements Motor, Comparable<ThrustCurveMotor>, Se
motor.unitRotationalInertia = Inertia.filledCylinderRotational( motor.diameter / 2);
motor.unitLongitudinalInertia = Inertia.filledCylinderLongitudinal( motor.diameter / 2, motor.length);
// If I don't have a motor designation (will be the case if I read the thrustcurve from a file)
// use the motor code
if (motor.designation.equals("")) {
motor.designation = motor.code;
}
// If I don't have a motor common name (will be the case if I read the thrustcurve from a flle)
// apply the motor code simplification heuristics to generate a common name
if (motor.commonName.equals("")) {
motor.commonName = motor.designation;
}
motor.computeStatistics();
return motor;
@ -441,6 +487,21 @@ public class ThrustCurveMotor implements Motor, Comparable<ThrustCurveMotor>, Se
return this.unitLongitudinalInertia;
}
@Override
public String getCode() {
return code;
}
@Override
public String getCommonName() {
return commonName;
}
@Override
public String getCommonName(double delay) {
return commonName + "-" + getDelayString(delay);
}
@Override
public String getDesignation() {
return designation;

View File

@ -134,13 +134,11 @@ public class SerializeThrustcurveMotors {
builder.setLength(mi.getLength() / 1000.0);
builder.setMotorType(type);
if ("OOP".equals(mi.getAvailiability())) {
builder.setCommonName(mi.getCommon_name());
builder.setDesignation(mi.getDesignation());
builder.setAvailablity(false);
} else if (mi.getDesignation().startsWith("Micro")) {
builder.setDesignation(mi.getDesignation());
} else {
builder.setDesignation(mi.getCommon_name());
if ("OOP".equals(mi.getAvailability())) {
builder.setAvailability(false);
}
allMotors.add(builder.build());

View File

@ -270,7 +270,7 @@ public class TCMotor implements Cloneable {
this.updated_on = updated_on;
}
public String getAvailiability() {
public String getAvailability() {
return availability;
}