We cannot use the designation directly in the search. For some manufacturers (CTI), the designation provided in the burn file is not at all consistent with the designation stored in the thrustcurve.org main database. Instead we pull out what looks like the common name using a regular expression and use that.

This commit is contained in:
Kevin Ruland 2012-02-16 19:25:28 +00:00
parent 178755ca90
commit 8e845590a8

View File

@ -1,12 +1,16 @@
package net.sf.openrocket.android.thrustcurve; package net.sf.openrocket.android.thrustcurve;
import java.util.Set; import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.sf.openrocket.android.util.AndroidLogWrapper; import net.sf.openrocket.android.util.AndroidLogWrapper;
import net.sf.openrocket.motor.ThrustCurveMotorPlaceholder; import net.sf.openrocket.motor.ThrustCurveMotorPlaceholder;
public class TCMissingMotorDownloadAction extends TCQueryAction { public class TCMissingMotorDownloadAction extends TCQueryAction {
private final static String DESIGNATION_REGEX_STRING = "(Micro Maxx|Micro Maxx II|1/4A|1/2A|[A-O][0-9]*)";
public static TCMissingMotorDownloadAction newInstance( Set<ThrustCurveMotorPlaceholder> missingMotors ) { public static TCMissingMotorDownloadAction newInstance( Set<ThrustCurveMotorPlaceholder> missingMotors ) {
TCMissingMotorDownloadAction frag = new TCMissingMotorDownloadAction(); TCMissingMotorDownloadAction frag = new TCMissingMotorDownloadAction();
frag.task = frag.new Downloader(missingMotors); frag.task = frag.new Downloader(missingMotors);
@ -16,16 +20,31 @@ public class TCMissingMotorDownloadAction extends TCQueryAction {
private class Downloader extends TCQueryAction.TCQueryTask { private class Downloader extends TCQueryAction.TCQueryTask {
private Set<ThrustCurveMotorPlaceholder> missingMotors; private Set<ThrustCurveMotorPlaceholder> missingMotors;
private Pattern designation_pattern = null;
private Downloader( Set<ThrustCurveMotorPlaceholder> missingMotors ) { private Downloader( Set<ThrustCurveMotorPlaceholder> missingMotors ) {
this.missingMotors = missingMotors; this.missingMotors = missingMotors;
try {
designation_pattern = Pattern.compile(DESIGNATION_REGEX_STRING);
} catch ( Exception ex ) {
AndroidLogWrapper.e(TCMissingMotorDownloadAction.class, "Exception in pattern compile {}", ex);
}
} }
private void downloadMissingMotor( ThrustCurveMotorPlaceholder motor ) { private void downloadMissingMotor( ThrustCurveMotorPlaceholder motor ) {
try { try {
SearchRequest request = new SearchRequest(); SearchRequest request = new SearchRequest();
request.setManufacturer(motor.getManufacturer()); request.setManufacturer(motor.getManufacturer());
request.setDesignation(motor.getDesignation()); String designation = motor.getDesignation();
if ( designation_pattern != null ) {
Matcher m = designation_pattern.matcher(designation);
if ( m.find() ) {
designation = m.group();
}
}
AndroidLogWrapper.d(TCMissingMotorDownloadAction.class, "using designation {}", designation);
request.setCommon_name(designation);
handler.post( new UpdateMessage("Looking for " + motor.getManufacturer() + " " + motor.getDesignation())); handler.post( new UpdateMessage("Looking for " + motor.getManufacturer() + " " + motor.getDesignation()));
@ -69,11 +88,11 @@ public class TCMissingMotorDownloadAction extends TCQueryAction {
@Override @Override
protected String doInBackground(Void... arg0) { protected String doInBackground(Void... arg0) {
for ( ThrustCurveMotorPlaceholder motor : missingMotors ) { for ( ThrustCurveMotorPlaceholder motor : missingMotors ) {
AndroidLogWrapper.d(TCMissingMotorDownloadAction.class, "Motor: {}", motor); AndroidLogWrapper.d(TCMissingMotorDownloadAction.class, "Motor: {}", motor);
downloadMissingMotor(motor); downloadMissingMotor(motor);
} }
dismiss();
return null; return null;
} }