Skip to content

Commit

Permalink
Sweeping changes all over the place
Browse files Browse the repository at this point in the history
  • Loading branch information
storrgie committed Aug 24, 2010
1 parent 5f00960 commit 4bdf0cd
Show file tree
Hide file tree
Showing 4 changed files with 288 additions and 180 deletions.
14 changes: 14 additions & 0 deletions pDA/da/gov/dod/army/rdecom/tardec/tcctda/ComponentError.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
package gov.dod.army.rdecom.tardec.tcctda;

import org.dxc.api.datatypes.*;

import java.util.Vector;
import java.util.Map;
import java.util.HashMap;

/**
*
* @author Jeremy Mange, Michael Duffy, Andrew Dunn
* @see License and contact information in project root
* @version 0.0.1
*
* Code adaptation from the supplied example during the PHM DXC'10 competition.
* Developed for participation in PHM DXC'10 while the authors were employed at
* US Army TARDEC (Tank Automotive Research Development Engineering Command)
*
* The code and comments contained in all files do not directly represent the
* intentions of the authors organization.
*/
public class ComponentError {
public static Map<String, Value> finalError(Vector<Map<String, Value>> errorSensors, Map<String, Sensor> allSensors) {
// returns the component error to report to the Oracle
Expand Down
72 changes: 40 additions & 32 deletions pDA/da/gov/dod/army/rdecom/tardec/tcctda/DiagnosticAlgorithm.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,56 +184,53 @@ private static void ErrorData(DxcCallback callback, DxcData daters) {
System.out.print(((ErrorData) daters).getError() + "\n");
}

/**
* Individually pass the Sensors to our Sensor and Component Searching algorithms, build out the errors vector and pass the final error to the
*/
private static void ProcessRecievedData() {
Vector<Map<String, Value>> errorSensors = new Vector<Map<String, Value>>();
Vector<Map<String, Value>> errors = new Vector<Map<String, Value>>();

for(Object keySet : allSensors.keySet()) {
Sensor individualSensor = (Sensor)allSensors.get(keySet);
individualSensor.removeOutliers();

//Send the individual sensor to our filters, if there is a detected error we will make sure to set the falutIndex.
Map<String, Value> filterSensor = SensorError.findError(individualSensor);
Map<String, Value> sensorError = SensorError.findError(individualSensor);

if(filterSensor.containsKey("faultIndex")) {
filterSensor.put("sensorId", Value.v(individualSensor.id));
errorSensors.add(filterSensor);
if(sensorError.containsKey("faultIndex")) {
sensorError.put("sensorId", Value.v(individualSensor.id));
if(printDebug)
printMap(sensorError);
errors.add(sensorError);
}
if(printDebug)
printMap(filterSensor);
}

// based on which sensors found faults, determine which component is problematic
Map<String, Value> finalError = ComponentError.finalError(errorSensors, allSensors);
Map<String, Value> finalError = ComponentError.finalError(errors, allSensors);
//printMap(finalError);
if(finalError.size() >0)
reportError(finalError);

// wait for the Oracle response ...
try {
Thread.sleep(threadSleep);
} catch (Exception e) {
System.out.append(e.toString() + " " + e.getMessage());
}
sendErrorToOracle(finalError);

// ... and then choose the lowest-cost action we have
if(recommendedAction != null) {
mainConnector.sendMessage(new CommandData(recommendedAction));
//System.out.println("DA recommendation: " + ((Command)(recommendedAction.toArray()[0])).getValue() + "\n" );
}
}

/**
* Just prints out the map of information
* @param map -- map to print out
*/
public static void printMap(Map<String, Value> map) {
for(String s:map.keySet()) {
System.out.println(" " + s + ": " + map.get(s));
if(!map.isEmpty()) {
for(String s : map.keySet()) {
System.out.println(" " + s + ": " + map.get(s));
}
System.out.println();
}
System.out.println();
}

private static void reportError(Map<String, Value> errorValues) {
/**
*
* @param errorValues
*/
private static void sendErrorToOracle(Map<String, Value> errorValues) {
CandidateSet candidateSet = new CandidateSet();
Candidate candidate = new Candidate();

Expand All @@ -242,9 +239,7 @@ private static void reportError(Map<String, Value> errorValues) {
if(Character.isUpperCase(s.charAt(0)))
faultValues.put(s, errorValues.get(s));

candidate.getFaultSet().add(new Fault( ((StringValue)(errorValues.get("sensorId"))).get() ,
((StringValue)(errorValues.get("faultType"))).get(),
faultValues));
candidate.getFaultSet().add(new Fault( ((StringValue)(errorValues.get("sensorId"))).get() , ((StringValue)(errorValues.get("faultType"))).get(), faultValues));

candidate.setWeight(1);
candidateSet.add(candidate);
Expand All @@ -255,17 +250,30 @@ private static void reportError(Map<String, Value> errorValues) {
// query Oracle for cost of both ABORT and NOP, choose lower-cost action
CommandSet commands = new CommandSet();
commands.add(new Command("systemAction", Value.v("NOP")));
RecoveryData rd = new RecoveryData(candidate.getFaultSet(), commands);
RecoveryData recoveryDataNOP = new RecoveryData(candidate.getFaultSet(), commands);

CommandSet commands2 = new CommandSet();
commands2.add(new Command("systemAction", Value.v("ABORT")));
RecoveryData rd2 = new RecoveryData(candidate.getFaultSet(), commands2);
RecoveryData recoveryDataAbort = new RecoveryData(candidate.getFaultSet(), commands2);

try {
mainConnector.sendMessage(rd);
mainConnector.sendMessage(rd2);
mainConnector.sendMessage(recoveryDataNOP);
mainConnector.sendMessage(recoveryDataAbort);
} catch(Exception ex) {
System.out.println(ex.toString() + " " + ex.getMessage());
}

makeReccomendation();
}

private static void makeReccomendation() {

// ... and then choose the lowest-cost action we have
if(recommendedAction != null) {
mainConnector.sendMessage(new CommandData(recommendedAction));
if(printDebug)
System.out.println("DA recommendation: " + ((Command)(recommendedAction.toArray()[0])).getValue() + "\n" );
}
}

}
11 changes: 9 additions & 2 deletions pDA/da/gov/dod/army/rdecom/tardec/tcctda/Sensor.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@
* @author Jeremy Mange, Michael Duffy, Andrew Dunn
* @see License and contact information in project root
* @version 0.0.1
*
*
* Code adaptation from the supplied example during the PHM DXC'10 competition.
* Developed for participation in PHM DXC'10 while the authors were employed at
* US Army TARDEC (Tank Automotive Research Development Engineering Command)
*
* The code and comments contained in all files do not directly represent the
* intentions of the authors organization.
*
* Used for storing sensor information and performing basic mathematics over selected internal data.
*
* @todo Currently the data and timestamps are stored in vectors, realistically they should be in a multidimensional structure to avoid issues with concurrency.
Expand Down Expand Up @@ -76,7 +83,7 @@ public double meanThrough(int start, int numSamples) {
* @param numSamples -- Number of samples to use when calculating the mean
* @return Standard Deviation throughout the Sensor Data from start through the number of required samples
*/
public double stdThrough(int start, int numSamples) {
public double sdThrough(int start, int numSamples) {
double mean = meanThrough(0, numSamples);
double std = 0;
for(int index = start; index < numSamples; index++) {
Expand Down
Loading

0 comments on commit 4bdf0cd

Please sign in to comment.