Skip to content

Commit

Permalink
Add C1 and C2 restrictions to rules 320 and 321.
Browse files Browse the repository at this point in the history
  • Loading branch information
timronan committed Jun 17, 2020
1 parent 79490af commit 441b45f
Show file tree
Hide file tree
Showing 6 changed files with 301 additions and 12 deletions.
6 changes: 4 additions & 2 deletions src/main/java/edu/iris/dmc/station/RuleEngineRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,14 @@ private void defaultChannelRules(Set<Integer> set) {
}
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."),
"If Channel:Code[2]==(H | L | M | N) THEN Channel:Azimuth and Channel:Dip must be included.",
new Restriction[] { new ChannelCodeRestriction(), new ChannelTypeRestriction() }),
Channel.class);
}
if (!set.contains(321)) {
add(321, new InstrumentCodeUnitsCondition(true,
"If Channel:Code[2] == (H | L | N) then Stage[1]:InputUnit must equal *m/s* AND Stage[Last]:OutputUnits must equal count*"),
"If Channel:Code[2] == (H | L | N) then Stage[1]:InputUnit must equal *m/s* AND Stage[Last]:OutputUnits must equal count*",
new Restriction[] { new ChannelCodeRestriction(), new ChannelTypeRestriction() }),
Channel.class);
}
if (!set.contains(332)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
import edu.iris.dmc.fdsn.station.model.Dip;
import edu.iris.dmc.fdsn.station.model.Network;
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.Result;

public class AzimuthDipCondition extends AbstractCondition {

public AzimuthDipCondition(boolean required, String description) {
super(required, description);
private Restriction[] restrictions;

public AzimuthDipCondition(boolean required, String description, Restriction[] restrictions) {
super(required, description);
this.restrictions = restrictions;
}

@Override
Expand All @@ -30,6 +33,11 @@ public Message evaluate(Channel channel) {
Azimuth azimuth = channel.getAzimuth();
Dip dip = channel.getDip();
String code = channel.getCode();
for (Restriction r : this.restrictions) {
if (r.qualifies(channel)) {
return Result.success();
}
}
try {
if("HLMN".indexOf(code.charAt(1)) >=0 | "hlmn".indexOf(code.charAt(1)) >=0) {
if (azimuth == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
import edu.iris.dmc.fdsn.station.model.ResponseStage;
import edu.iris.dmc.fdsn.station.model.Station;
import edu.iris.dmc.station.exceptions.StationxmlException;
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 InstrumentCodeUnitsCondition extends AbstractCondition {
private Restriction[] restrictions;

public InstrumentCodeUnitsCondition(boolean required, String description) {
public InstrumentCodeUnitsCondition(boolean required, String description, Restriction[] restrictions) {
super(required, description);

this.restrictions = restrictions;
}

@Override
Expand Down Expand Up @@ -50,7 +52,11 @@ public Message evaluate(Channel channel) {
}else {
return Result.success();
}

for (Restriction r : this.restrictions) {
if (r.qualifies(channel)) {
return Result.success();
}
}
int lastindex = channel.getResponse().getStage().size()-1;
ResponseStage stagelast = channel.getResponse().getStage().get(lastindex);
String outputUnit ="";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import edu.iris.dmc.fdsn.station.model.Network;
import edu.iris.dmc.fdsn.station.model.Station;
import edu.iris.dmc.station.RuleEngineServiceTest;
import edu.iris.dmc.station.restrictions.ChannelCodeRestriction;
import edu.iris.dmc.station.restrictions.ChannelTypeRestriction;
import edu.iris.dmc.station.restrictions.Restriction;
import edu.iris.dmc.station.rules.Message;

public class Condition320Test {
Expand All @@ -32,8 +35,9 @@ public void azimuthfail() throws Exception {
Network n = theDocument.getNetwork().get(0);
Station s = n.getStations().get(0);
Channel c = s.getChannels().get(0);
Restriction[] restrictions = new Restriction[] { new ChannelCodeRestriction(), new ChannelTypeRestriction() };

AzimuthDipCondition condition = new AzimuthDipCondition(true, "");
AzimuthDipCondition condition = new AzimuthDipCondition(true, "", restrictions);
Message result = condition.evaluate(c);
assertTrue(result instanceof edu.iris.dmc.station.rules.Error);
}
Expand All @@ -48,13 +52,33 @@ public void dipfail() throws Exception {
Network n = theDocument.getNetwork().get(0);
Station s = n.getStations().get(0);
Channel c = s.getChannels().get(0);
Restriction[] restrictions = new Restriction[] { new ChannelCodeRestriction(), new ChannelTypeRestriction() };

AzimuthDipCondition condition = new AzimuthDipCondition(true, "");

AzimuthDipCondition condition = new AzimuthDipCondition(true, "", restrictions);
Message result = condition.evaluate(c);
assertTrue(result instanceof edu.iris.dmc.station.rules.Error);
}

}

@Test
public void dipPass2() throws Exception {
try (InputStream is = RuleEngineServiceTest.class.getClassLoader().getResourceAsStream("P3_3201.xml")) {
theDocument = DocumentMarshaller.unmarshal(is);

Network n = theDocument.getNetwork().get(0);
Station s = n.getStations().get(0);
Channel c = s.getChannels().get(0);
Restriction[] restrictions = new Restriction[] { new ChannelCodeRestriction(), new ChannelTypeRestriction() };


AzimuthDipCondition condition = new AzimuthDipCondition(true, "", restrictions);
Message result = condition.evaluate(c);
assertTrue(result instanceof edu.iris.dmc.station.rules.Success);
}

}

@Test
public void pass() throws Exception {
Expand All @@ -64,9 +88,10 @@ public void pass() throws Exception {
Network n = theDocument.getNetwork().get(0);
Station s = n.getStations().get(0);
Channel c = s.getChannels().get(0);
Restriction[] restrictions = new Restriction[] { new ChannelCodeRestriction(), new ChannelTypeRestriction() };


AzimuthDipCondition condition = new AzimuthDipCondition(true, "");
AzimuthDipCondition condition = new AzimuthDipCondition(true, "", restrictions);

Message result = condition.evaluate(c);
assertTrue(result instanceof edu.iris.dmc.station.rules.Success);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import edu.iris.dmc.fdsn.station.model.Network;
import edu.iris.dmc.fdsn.station.model.Station;
import edu.iris.dmc.station.RuleEngineServiceTest;
import edu.iris.dmc.station.restrictions.ChannelCodeRestriction;
import edu.iris.dmc.station.restrictions.ChannelTypeRestriction;
import edu.iris.dmc.station.restrictions.Restriction;
import edu.iris.dmc.station.rules.Message;
import edu.iris.dmc.station.rules.NestedMessage;

Expand All @@ -33,8 +36,9 @@ public void azimuthfail() throws Exception {
Network n = theDocument.getNetwork().get(0);
Station s = n.getStations().get(0);
Channel c = s.getChannels().get(0);
Restriction[] restrictions = new Restriction[] { new ChannelCodeRestriction(), new ChannelTypeRestriction() };

InstrumentCodeUnitsCondition condition = new InstrumentCodeUnitsCondition(true, "");
InstrumentCodeUnitsCondition condition = new InstrumentCodeUnitsCondition(true, "", restrictions);
Message result = condition.evaluate(c);
NestedMessage nestedMessage=(NestedMessage)result;
System.out.println(nestedMessage.getNestedMessages().get(0).getDescription());
Expand All @@ -56,9 +60,10 @@ public void pass() throws Exception {
Network n = theDocument.getNetwork().get(0);
Station s = n.getStations().get(0);
Channel c = s.getChannels().get(0);
Restriction[] restrictions = new Restriction[] { new ChannelCodeRestriction(), new ChannelTypeRestriction() };


InstrumentCodeUnitsCondition condition = new InstrumentCodeUnitsCondition(true, "");
InstrumentCodeUnitsCondition condition = new InstrumentCodeUnitsCondition(true, "", restrictions);

Message result = condition.evaluate(c);
assertTrue(result instanceof edu.iris.dmc.station.rules.Success);
Expand Down
Loading

0 comments on commit 441b45f

Please sign in to comment.