Skip to content

Commit

Permalink
Add nested messaging. Improve output messaging.
Browse files Browse the repository at this point in the history
  • Loading branch information
timronan committed Apr 22, 2020
1 parent 93638a5 commit 8dfb99f
Show file tree
Hide file tree
Showing 28 changed files with 251 additions and 785 deletions.
72 changes: 36 additions & 36 deletions src/main/java/edu/iris/dmc/station/RuleEngineRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,22 @@ private void defaultNetworkRules(Set<Integer> set) {
if (!set.contains(101)) {
add(101, new CodeCondition(true, codeRegex,
"Network:Code must be assigned a string consisting of 1-2 uppercase A-Z and numeric 0-9 characters."),
Network.class);
Network.class); //
}
if (!set.contains(110)) {
add(110, new StartTimeCondition(true,
"If Network:startDate is included then it must occur before Network:endDate if included."),
Network.class);
Network.class); //
}
if (!set.contains(111)) {
add(111, new EpochOverlapCondition(true,
"Station:Epoch cannot be partly concurrent with any other Station:Epoch encompassed in parent Network:Epoch."),
Network.class);
Network.class); //
}
if (!set.contains(112)) {
add(112, new EpochRangeCondition(true,
"Network:Epoch must encompass all subordinate Station:Epoch"),
Network.class);
Network.class); //
}
}

Expand All @@ -105,32 +105,32 @@ private void defaultStationRules(Set<Integer> set) {
if (!set.contains(201)) {
add(201, new CodeCondition(true, codeRegex,
"Station:Code must be assigned a string consisting of 1-5 uppercase A-Z and numeric 0-9 characters."),
Station.class);
Station.class); //
}

if (!set.contains(210)) {
add(210, new StartTimeCondition(true,
"Station:startDate must be included and must occur before Station:endDate if included."),
Station.class);
Station.class); //
}
if (!set.contains(211)) {
add(211, new EpochOverlapCondition(true,
"Channel:Epoch cannot be partly concurrent with any other Channel:Epoch encompassed in parent Station:Epoch."),
Station.class);
Station.class); //
}
if (!set.contains(221)) {
add(212, new EpochRangeCondition(true,
"Station:Epoch must encompass all subordinate Channel:Epoch."),
Station.class);
Station.class); //
}

if (!set.contains(222)) {
add(222, new DistanceCondition(true,
"Station:Position must be within 1 km of all subordinate Channel:Position.", 1), Station.class);
"Station:Position must be within 1 km of all subordinate Channel:Position.", 1), Station.class); //
}
if (!set.contains(223)) {
add(223, new StationElevationCondition(true,
"Station:Elevation must be within 1 km of all subordinate Channel:Elevation."), Station.class);
"Station:Elevation must be within 1 km of all subordinate Channel:Elevation."), Station.class); //
}

}
Expand All @@ -141,56 +141,56 @@ private void defaultChannelRules(Set<Integer> set) {
if (!set.contains(301)) {
add(301, new CodeCondition(true, codeRegex,
"Channel:Code must be assigned a string consisting of 3 uppercase A-Z and numeric 0-9 characters."),
Channel.class);
Channel.class); //
}
if (!set.contains(302)) {
add(302, new LocationCodeCondition(true, "([A-Z0-9\\*\\ ]{0,2})?",
"Channel:locationCode must be assigned a string consisting of 0-2 uppercase A-Z and numeric 0-9 characters OR 2 whitespace characters OR --."),
Channel.class);
Channel.class); //
}
if (!set.contains(303)) {
add(303, new CalibrationUnitCondition(false, "If CalibrationUnits are included then CalibrationUnits:Name must be assigned a value from the IRIS StationXML Unit dictionary, case inconsistencies trigger warnings."), Channel.class);
}
}//
if (!set.contains(304)) {
add(304, new SensorCondition(true, "Channel:Sensor:Description must be included and assigned a string consisting of 1 <= case insensitive A-Z and numeric 0-9 characters."), Channel.class);
}
}//
if (!set.contains(305)) {
add(305, new SampleRateCondition(false,
"If Channel:SampleRate equals 0 or is not included then Response must not be included.",
restrictions), Channel.class);
}
}//
if (!set.contains(310)) {
add(310, new StartTimeCondition(true,
"Channel:startDate must be included and must occur before Channel:endDate if included."),
Channel.class);
}
}//
if (!set.contains(320)) {
add(320, new AzimuthDipCondition(true,
"IF Channel:Code[2]==(H | L | M | N) THEN Channel:Azimuth and Channel:Dip must be included."),
Channel.class);
}
}//
if (!set.contains(321)) {
add(321, new InstrumentCodeUnitsCondition(true,
" IF Channel:Code[2] == (H | L | M | N) then Stage[1]:InputUnit must equal *m/s* AND Stage[Last]:OutputUnits must equal count*"),
Channel.class);
}
}//
if (!set.contains(332)) {
add(332, new OrientationCondition(true,
"If Channel:Code[LAST]==N then Channel:Azimuth must be assigned (>=355.0 or <=5.0) or (>=175.0 and <=185.0) and Channel:Dip must be assigned (>=-5 AND <=5.0).",
new Restriction[] { new ChannelCodeRestriction(), new ChannelTypeRestriction() }), Channel.class);
}
}//

if (!set.contains(333)) {
add(333, new OrientationConditionE(true,
"If Channel:Code[LAST]==E then Channel:Azimuth must be assigned (>=85.0 and <=95.0) or (>=265.0 and <=275.0) and Channel:Dip must be assigned (>=-5 and <=5.0).",
new Restriction[] { new ChannelCodeRestriction(), new ChannelTypeRestriction() }), Channel.class);
}
}//

if (!set.contains(334)) {
add(334, new OrientationConditionZ(true,
"If Channel:Code[LAST]==Z then Channel:Azimuth must be assigned (>=355.0 or <=5.0) and Channel:Dip must be assigned (>=-85.0 and <=-90.0) or (>=85.0 and <=90.0).",
new Restriction[] { new ChannelCodeRestriction(), new ChannelTypeRestriction() }), Channel.class);
}
}//
}

private void defaultResponseRules(Set<Integer> s) {
Expand All @@ -200,83 +200,83 @@ private void defaultResponseRules(Set<Integer> s) {
if (!s.contains(401)) {
add(401, new StageSequenceCondition(true,
"Stage:number must start at 1 and be sequential.",
restrictions), Response.class);
restrictions), Response.class); //
}
if (!s.contains(402)) {
add(402, new UnitCondition(true,
"Stage[N]:InputUnits:Name and Stage[N]:OutputUnits:Name must be assigned a value from the IRIS StationXML Unit dictionary, case inconsistencies trigger warnings.",
restrictions), Response.class);
restrictions), Response.class); //
}
if (!s.contains(403)) {
add(403, new StageUnitCondition(true, "If length(Stage) > 1 then Stage[N]:InputUnits:Name must equal the previously assigned Stage[M]:OutputUnits:Name.",
restrictions), Response.class);
restrictions), Response.class); //
}
if (!s.contains(404)) {
add(404, new DigitalFilterCondition(true,
"If Stage[N]:PolesZeros:PzTransferFunctionType:Digital or Stage[N]:FIR or Stage[N]:Coefficients:CfTransferFunctionType:DIGITAL are included then Stage[N] must include Stage[N]:Decimation and Stage[N]:StageGain elements.",
restrictions), Response.class);
restrictions), Response.class); //
}
if (!s.contains(405)) {
add(405, new ResponseListCondition(true,
"Stage:ResponseList cannot be the only stage included in a response.",
new ChannelCodeRestriction(), new ChannelTypeRestriction()), Response.class);
new ChannelCodeRestriction(), new ChannelTypeRestriction()), Response.class); //
}
if (!s.contains(410)) {
add(410, new EmptySensitivityCondition(true, "If InstrumentSensitivity is included then InstrumentSensitivity:Value must be assigned a double > 0.0 ",
new ChannelCodeRestriction(), new ChannelTypeRestriction(), new ResponsePolynomialRestriction()),
Response.class);
Response.class); //
}
if (!s.contains(411)) {
add(411, new FrequencyCondition(true,
"If InstrumentSensitivity is included then InstrumentSensitivity:Frequency must be less than Channel:SampleRate/2 [Nyquist Frequency]. ",
new ChannelCodeRestriction(), new ChannelTypeRestriction(), new ResponsePolynomialRestriction()),
Response.class);
Response.class); //
}
if (!s.contains(412)) {
add(412, new StageGainProductCondition(true,
"InstrumentSensitivity:Value must equal the product of all StageGain:Value if all StageGain:Frequency are equal to InstrumentSensitivity:Frequency [Normalization Frequency].",
new ChannelCodeRestriction(), new ChannelTypeRestriction(), new ResponsePolynomialRestriction()),
Response.class);
Response.class); //
}
if (!s.contains(413)) {
add(413, new StageGainNonZeroCondition(true, "Stage[1:N]:StageGain must be included and Stage[1:N]:StageGain:Value must be assigned a double > 0.0 and Stage[1:N]:StageGain:Frequency must be assigned a double.",
new ChannelCodeRestriction(), new ResponsePolynomialRestriction(), new ChannelTypeRestriction()),
Response.class);
Response.class); //
}
if (!s.contains(414)) {
add(414, new PolesZerosCondition(false,
"If Stage[N]:PolesZeros contains Zero:Real==0 and Zero:Imaginary==0 then InstrumentSensitivity:Frequency cannot equal 0 and Stage[N]:StageGain:Frequency cannot equal 0.",
new ChannelCodeRestriction(), new ChannelTypeRestriction(), new ResponsePolynomialRestriction()),
Response.class);
Response.class); //
}
if (!s.contains(415)) {
add(415, new PolynomialCondition(false,
"Response must include InstrumentPolynomial if a Polynomial stage is included.",
new ChannelCodeRestriction(), new ChannelTypeRestriction()), Response.class);
}
}//
if (!s.contains(416)) {
add(416, new InstrumentSensitivityCondition(false,
"Response must include InstrumentSensitivity if no Polynomial stages are included.",
new ChannelCodeRestriction(), new ChannelTypeRestriction()), Response.class);
}
} //
if (!s.contains(417)) {
add(417, new PolesZerosSequenceCondition(false,
"If Stage[N]:PolesZeros contains Zeros and Poles then Zero:Number and Pole:Number must start at 0 and be sequential.",
new ChannelCodeRestriction(), new ChannelTypeRestriction()), Response.class);
}
} //

if (!s.contains(420)) {
add(420, new MissingDecimationCondition(true,
"A Response must contain at least one instance of Response:Stage:Decimation.",
new ChannelCodeRestriction(), new ChannelTypeRestriction(), new ResponsePolynomialRestriction()),
Response.class);
}
}//
if (!s.contains(421)) {
add(421, new DecimationSampleRateCondition(true,
"Stage[LAST]:Decimation:InputSampleRate divided by Stage[LAST]:Decimation:Factor must equal Channel:SampleRate.",
new ChannelCodeRestriction(), new ChannelTypeRestriction(), new ResponsePolynomialRestriction()),
Response.class);
}
}//
if (!s.contains(422)) {
add(422, new DecimationCondition(true,
"Stage[N]:Decimation:InputSampleRate must equal the previously assigned Stage[M]:Decimation:InputSampleRate divided by Stage[M]:Decimation:Factor.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import edu.iris.dmc.fdsn.station.model.Station;
import edu.iris.dmc.station.restrictions.Restriction;
import edu.iris.dmc.station.rules.Message;
import edu.iris.dmc.station.rules.NestedMessage;
import edu.iris.dmc.station.rules.Result;

public class DecimationCondition extends ChannelRestrictedCondition {
Expand Down Expand Up @@ -43,6 +44,8 @@ public Message evaluate(Channel channel) {

@Override
public Message evaluate(Channel channel, Response response) {
NestedMessage nestedMessage = new NestedMessage();
boolean returnmessage = false;
if (isRestricted(channel)) {
return Result.success();
}
Expand All @@ -57,21 +60,42 @@ public Message evaluate(Channel channel, Response response) {
if (stage.getDecimation() != null) {
Frequency sampleRate = decimation.getInputSampleRate();
if(sampleRate==null) {
return Result.error("expected samplerate but was null");
if (stage.getNumber().intValue() < 10 ) {
nestedMessage.add(Result.error("[stage " + String.format("%02d", stage.getNumber().intValue())
+ "] must include Decimation:Samplerate"));
returnmessage =true;
}else {
nestedMessage.add(Result.error("[stage " + stage.getNumber().intValue()
+ "] must include Decimation:Samplerate"));
returnmessage =true;
}
}
double inputSampleRate = sampleRate.getValue();

if (inputSampleRateByFactor != null) {
if (Math.abs(inputSampleRate - inputSampleRateByFactor.doubleValue()) > 0.001) {
return Result.error("stage number: " + i+" inputSampleRate="+inputSampleRate+" : inputSampleRateByFactor="+inputSampleRateByFactor.doubleValue());
if (stage.getNumber().intValue() < 10 ) {
nestedMessage.add(Result.error("[stage " + String.format("%02d", stage.getNumber().intValue())
+ "] Decimation:InputSampleRate "+ inputSampleRate +" != [stage "+ String.format("%02d", (stage.getNumber().intValue()-1))
+ "] Decimation:InputSampleRate/Decimation:Factor "+inputSampleRateByFactor.doubleValue()));
returnmessage =true;
}else {
nestedMessage.add(Result.error("[stage " + stage.getNumber().intValue()
+ "] Decimation:InputSampleRate "+ inputSampleRate +" != [stage "+ (stage.getNumber().intValue()-1)
+ "] Decimation:InputSampleRate/Decimation:Factor "+inputSampleRateByFactor.doubleValue()));
returnmessage =true;
}
}
}
inputSampleRateByFactor = inputSampleRate / decimation.getFactor().doubleValue();
}
i++;
}

return Result.success();
if(returnmessage==true) {
return nestedMessage;
}else {
return Result.success();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ public Message evaluate(Channel channel, Response response) {
}

Decimation decimation = null;
int stageindex = 0;
for (ResponseStage stage : response.getStage()) {
if (stage.getDecimation() != null) {
decimation = stage.getDecimation();
}
stageindex = stageindex+1;
}
if (decimation == null) {
return Result.warning("Decimation cannot be null");
Expand All @@ -63,10 +65,27 @@ public Message evaluate(Channel channel, Response response) {
BigInteger factor = decimation.getFactor();

if (frequence == null) {
return Result.error("frequency is null");
if (stageindex < 10 ) {
return Result.error("[stage " + String.format("%02d", stageindex) +
"] Decimation:Frequency must not be null");
}else {
return Result.error("[stage " + stageindex +
"] Decimation:Frequency must not be null");
}


}
if (Math.abs(sampleRate.getValue() - (frequence.getValue() / factor.doubleValue())) > 0.0001) {
return Result.error("samplerate: "+sampleRate.getValue() + "!= frequency/factor " + (frequence.getValue() / factor.doubleValue()));
if (stageindex < 10 ) {
return Result.error("Chan:Samplerate "+sampleRate.getValue() + " != [stage "
+ String.format("%02d", stageindex) + "] Decimation:Frequency/Decimation:Factor "
+ (frequence.getValue() / factor.doubleValue()));
}else {
return Result.error("Channel:Samplerate: "+sampleRate.getValue() + " != [stage "
+ stageindex + "] Decimation:Frequency/Decimation:Factor "
+ (frequence.getValue() / factor.doubleValue()));
}

}

return Result.success();
Expand Down
Loading

0 comments on commit 8dfb99f

Please sign in to comment.