Class AutomationDiagnostics
java.lang.Object
neqsim.process.automation.AutomationDiagnostics
- All Implemented Interfaces:
Serializable
Provides self-diagnosis, fuzzy matching, and error-recovery capabilities for the
ProcessAutomation API. When an agent uses an incorrect address, unit name, or property,
this class supplies structured remediation hints including closest-match suggestions and
auto-correction.
Also tracks operation history to learn from failures and provide accumulated insights.
Key Capabilities:
- Fuzzy name resolution — finds closest unit/property when exact match fails
- Auto-correction — fixes common mistakes (casing, whitespace, partial names)
- Structured diagnostics — returns JSON with error category, suggestions, and fix actions
- Operation history — tracks successes/failures to improve over time
- Physical validation — warns when values are outside reasonable bounds
- Version:
- 1.0
- Author:
- Even Solbraa
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA diagnostic result returned when an operation fails, containing the error analysis, closest suggestions, and auto-correction attempt.static enumClassification of automation errors for structured remediation.(package private) static classTracks a single automation operation for learning.private static classRepresents physical bounds for a property value.private static classHelper for sorting names by match score. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final com.google.gson.Gsonprivate final List<AutomationDiagnostics.OperationRecord> private intprivate static final long -
Constructor Summary
ConstructorsConstructorDescriptionCreates an AutomationDiagnostics instance with default history size (1000).AutomationDiagnostics(int maxHistorySize) Creates an AutomationDiagnostics instance with a specified history size. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidAdds an operation record to history, trimming if over capacity.autoCorrectName(String input, List<String> validNames) Attempts auto-correction of a unit name by trying common transformations.private doublecomputeMatchScore(String input, String valid) Computes a match score between two strings (higher is better).Diagnoses a port-not-found error.diagnosePropertyNotFound(String address, String unitName, String propertyName, List<SimulationVariable> validVariables) Diagnoses a property-not-found error and returns structured remediation.diagnoseUnitNotFound(String unitName, List<String> validUnits) Diagnoses a unit-not-found error and returns structured remediation.(package private) static inteditDistance(String a, String b) Computes the Levenshtein edit distance between two strings.findClosestNames(String input, List<String> validNames, int maxResults) Finds the closest matching unit name from a list of valid names using edit distance.Generates recommendations based on failure patterns.Gets the most common error categories from operation history.Gets the learned corrections that can be applied automatically in future calls.Generates a learning report summarizing patterns from operation history.intGets the total number of operations recorded.getPhysicalBound(String propertyName, String unit) Returns physical bounds for common properties.getRecentFailures(int count) Gets the most recent failures for diagnostics.doubleGets the success rate for recent operations.voidrecordFailure(String operationType, String address, AutomationDiagnostics.ErrorCategory category, String correction) Records a failed operation with its correction.voidrecordSuccess(String operationType, String address) Records a successful operation.voidreset()Clears the operation history and learned corrections.validatePhysicalBounds(String propertyName, double value, String unit) Validates a value against known physical bounds for a property.
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
GSON
private static final com.google.gson.Gson GSON -
history
-
learnedCorrections
-
maxHistorySize
private int maxHistorySize
-
-
Constructor Details
-
AutomationDiagnostics
public AutomationDiagnostics()Creates an AutomationDiagnostics instance with default history size (1000). -
AutomationDiagnostics
public AutomationDiagnostics(int maxHistorySize) Creates an AutomationDiagnostics instance with a specified history size.- Parameters:
maxHistorySize- maximum number of operation records to keep
-
-
Method Details
-
findClosestNames
Finds the closest matching unit name from a list of valid names using edit distance.- Parameters:
input- the input name that was not foundvalidNames- the list of valid names to searchmaxResults- maximum number of suggestions to return- Returns:
- ranked list of closest matches
-
autoCorrectName
Attempts auto-correction of a unit name by trying common transformations.Tries: case-insensitive match, trimmed whitespace, partial substring match, and previously learned corrections.
- Parameters:
input- the unit name to correctvalidNames- the list of valid names- Returns:
- the corrected name, or null if no confident correction found
-
diagnoseUnitNotFound
public AutomationDiagnostics.DiagnosticResult diagnoseUnitNotFound(String unitName, List<String> validUnits) Diagnoses a unit-not-found error and returns structured remediation.- Parameters:
unitName- the name that was not foundvalidUnits- list of valid unit names in the process- Returns:
- diagnostic result with suggestions and auto-correction
-
diagnosePropertyNotFound
public AutomationDiagnostics.DiagnosticResult diagnosePropertyNotFound(String address, String unitName, String propertyName, List<SimulationVariable> validVariables) Diagnoses a property-not-found error and returns structured remediation.- Parameters:
address- the full address that was not resolvedunitName- the unit namepropertyName- the property that was not foundvalidVariables- the valid variables for that unit- Returns:
- diagnostic result with suggestions and auto-correction
-
diagnosePortNotFound
public AutomationDiagnostics.DiagnosticResult diagnosePortNotFound(String address, String unitName, String portName, List<String> validPorts) Diagnoses a port-not-found error.- Parameters:
address- the full addressunitName- the unit nameportName- the port that was not foundvalidPorts- known valid port names for the equipment type- Returns:
- diagnostic result with suggestions
-
validatePhysicalBounds
public AutomationDiagnostics.DiagnosticResult validatePhysicalBounds(String propertyName, double value, String unit) Validates a value against known physical bounds for a property.- Parameters:
propertyName- the property being setvalue- the value to validateunit- the unit of the value- Returns:
- diagnostic result if out of bounds, null if valid
-
recordSuccess
-
recordFailure
public void recordFailure(String operationType, String address, AutomationDiagnostics.ErrorCategory category, String correction) Records a failed operation with its correction.- Parameters:
operationType- the type of operation (get, set, list)address- the address that failedcategory- the error categorycorrection- the correction that was applied, or null
-
getSuccessRate
public double getSuccessRate()Gets the success rate for recent operations.- Returns:
- success rate as fraction (0.0 to 1.0)
-
getErrorCategoryCounts
-
getLearnedCorrections
-
getOperationCount
public int getOperationCount()Gets the total number of operations recorded.- Returns:
- operation count
-
getLearningReport
Generates a learning report summarizing patterns from operation history.- Returns:
- JSON string with operation statistics and learned corrections
-
reset
public void reset()Clears the operation history and learned corrections. -
computeMatchScore
-
editDistance
-
addRecord
Adds an operation record to history, trimming if over capacity.- Parameters:
record- the record to add
-
getRecentFailures
-
generateRecommendations
-
getPhysicalBound
Returns physical bounds for common properties.- Parameters:
propertyName- the property nameunit- the unit of measurement- Returns:
- physical bounds, or null if unknown
-