public EvaluationResult evaluate(Classifier classifier, Instances validationSet) { EvaluationResult evaluation = new EvaluationResult(); makeAndValidatePredictions(classifier, validationSet); evaluation.setMisclassifications(misclassifications); evaluation.setCorrectClassifications(correctClassifications); evaluation.setEvaluationStatistics(evaluationStatistics); return evaluation; }
@Override public void serialize( SimpleEvaluationObject value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { synchronized (value) { String id = getUpdateManager().register(value); jgen.writeStartObject(); jgen.writeObjectField("type", "SimpleEvaluationObject"); jgen.writeStringField("update_id", id); jgen.writeStringField("expression", value.getExpression()); jgen.writeObjectField("status", value.getStatus()); if (value.getMessage() != null) jgen.writeStringField("message", value.getMessage()); if (value.getProgressBar() > 0) jgen.writeNumberField("progressBar", value.getProgressBar()); if (value.getPayloadChanged()) { EvaluationResult o = value.getPayload(); if (o != null && o.getValue() != null) { jgen.writeFieldName("payload"); if (!getObjectSerializer().writeObject(o, jgen, true)) jgen.writeObject(o.toString()); } else if (value.getJsonRes() != null) { jgen.writeFieldName("payload"); if (ControlCharacterUtils.containsControlCharacters(value.getJsonRes())) { jgen.writeRawValue(ControlCharacterUtils.escapeControlCharacters(value.getJsonRes())); } else { jgen.writeRawValue(value.getJsonRes()); } } } if (value.getJsonRes() != null && value.getPayload() != null && value.getPayload().getValue() != null) { logger.trace("adding raw json data: '" + value.getJsonRes() + "'"); jgen.writeFieldName("jsonres"); if (ControlCharacterUtils.containsControlCharacters(value.getJsonRes())) { jgen.writeRawValue(ControlCharacterUtils.escapeControlCharacters(value.getJsonRes())); } else { jgen.writeRawValue(value.getJsonRes()); } } jgen.writeArrayFieldStart("outputdata"); for (Object o : value.getOutputdata()) { if (o instanceof EvaluationStdOutput) { jgen.writeStartObject(); jgen.writeStringField("type", "out"); jgen.writeStringField("value", ((EvaluationStdOutput) o).payload); jgen.writeEndObject(); } else if (o instanceof EvaluationStdError) { jgen.writeStartObject(); jgen.writeStringField("type", "err"); jgen.writeStringField("value", ((EvaluationStdError) o).payload); jgen.writeEndObject(); } } jgen.writeEndArray(); jgen.writeEndObject(); } }
/** * resolve the RuntimeVariable (e.g. $curtime). then see if some more work has to be done (e.g. * $curtime._repos_id) */ public EvaluationResult extractFromMessage( EvaluationResult evaluationResult, ComponentName componentName, RuntimeVariable runtimeVariable) throws EvaluationException { ETCLComponentName _componentName = (ETCLComponentName) componentName; if (_componentName.right() != null) { return extractFromAny( _componentName.right(), evaluationResult.getAny(), runtimeVariable.toString()); } return evaluationResult; }
public EvaluationResult unmarshall(StaxUnmarshallerContext context) throws Exception { EvaluationResult evaluationResult = new EvaluationResult(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 1; while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) return evaluationResult; if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) { if (context.testExpression("EvalActionName", targetDepth)) { evaluationResult.setEvalActionName( StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("EvalResourceName", targetDepth)) { evaluationResult.setEvalResourceName( StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("EvalDecision", targetDepth)) { evaluationResult.setEvalDecision( StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("MatchedStatements", targetDepth)) { evaluationResult.withMatchedStatements(new ArrayList<Statement>()); continue; } if (context.testExpression("MatchedStatements/member", targetDepth)) { evaluationResult.withMatchedStatements( StatementStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("MissingContextValues", targetDepth)) { evaluationResult.withMissingContextValues(new ArrayList<String>()); continue; } if (context.testExpression("MissingContextValues/member", targetDepth)) { evaluationResult.withMissingContextValues( StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("EvalDecisionDetails/entry", targetDepth)) { Entry<String, String> entry = EvalDecisionDetailsMapEntryUnmarshaller.getInstance().unmarshall(context); evaluationResult.addEvalDecisionDetailsEntry(entry.getKey(), entry.getValue()); continue; } if (context.testExpression("ResourceSpecificResults", targetDepth)) { evaluationResult.withResourceSpecificResults(new ArrayList<ResourceSpecificResult>()); continue; } if (context.testExpression("ResourceSpecificResults/member", targetDepth)) { evaluationResult.withResourceSpecificResults( ResourceSpecificResultStaxUnmarshaller.getInstance().unmarshall(context)); continue; } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return evaluationResult; } } } }
private double getFitnessScoreAux() { EvaluationResult er = getCorrespondingEvaluation(fitnessIndex); return (double) er.value(); }
private EvaluationResult extractFromAny(AbstractTCLNode expr, Any any, String rootName) throws EvaluationException { if (logger_.isDebugEnabled()) { logger_.debug("extractFromAny" + "\trootname=" + rootName + "\tvalue=" + any); } EvaluationResult _result = null; Any _any = null; AbstractTCLNode _currentOperator = expr; Any _currentAny = any; StringBuffer _currentPath = new StringBuffer(rootName); while (_currentOperator != null) { _currentPath.append(_currentOperator.toString()); if (logger_.isDebugEnabled()) { logger_.debug("current path=" + _currentPath.toString()); logger_.debug("current operator=" + _currentOperator.toString()); logger_.debug("current any=" + _currentAny); } // lookup result in cache _any = lookupAny(_currentPath.toString()); if (_any == null) { // cache MISS switch (_currentOperator.getType()) { case TCLParserTokenTypes.DOT: // dots are skipped break; case TCLParserTokenTypes.UNION_POS: logger_.debug("evaluate union by position"); UnionPositionOperator _upo = (UnionPositionOperator) _currentOperator; // default union if (_upo.isDefault()) { _any = getETCLEvaluator().evaluateUnion(_currentAny); } else { _any = getETCLEvaluator().evaluateUnion(_currentAny, _upo.getPosition()); } break; case TCLParserTokenTypes.IDENTIFIER: String _identifer = ((IdentValue) _currentOperator).getIdentifier(); _any = getETCLEvaluator().evaluateIdentifier(_currentAny, _identifer); break; case TCLParserTokenTypes.NUMBER: int _pos = ((NumberValue) _currentOperator).getNumber().intValue(); _any = getETCLEvaluator().evaluateIdentifier(_currentAny, _pos); break; case TCLParserTokenTypes.IMPLICIT: ImplicitOperator _op = ((ImplicitOperatorNode) _currentOperator).getOperator(); _any = _op.evaluateImplicit(getETCLEvaluator(), _currentAny); _result = EvaluationResult.fromAny(_any); _result.addAny(_currentAny); return _result; case TCLParserTokenTypes.ARRAY: int _arrayIndex = ((ArrayOperator) _currentOperator).getArrayIndex(); _any = getETCLEvaluator().evaluateArrayIndex(_currentAny, _arrayIndex); break; case TCLParserTokenTypes.ASSOC: String _assocName = ((AssocOperator) _currentOperator).getAssocName(); _any = getETCLEvaluator().evaluateNamedValueList(_currentAny, _assocName); break; default: throw new RuntimeException( "unexpected operator: " + AbstractTCLNode.getNameForType(_currentOperator.getType())); } } if (_any != null) { storeAny(_currentPath.toString(), _any); _currentAny = _any; } _currentOperator = (AbstractTCLNode) _currentOperator.getNextSibling(); } // Create the EvaluationResult _result = EvaluationResult.fromAny(_any); return _result; }
private void evaluateUpdater( final MutableStoreProvider storeProvider, final UpdateFactory.Update update, IJobUpdateSummary summary, Map<Integer, Optional<IScheduledTask>> changedInstance) throws UpdateStateException { JobUpdateStatus updaterStatus = summary.getState().getStatus(); final IJobUpdateKey key = summary.getKey(); JobUpdateStore.Mutable updateStore = storeProvider.getJobUpdateStore(); if (!updateStore.getLockToken(key).isPresent()) { recordAndChangeJobUpdateStatus( storeProvider, key, newEvent(ERROR).setMessage(LOST_LOCK_MESSAGE)); return; } IJobUpdateInstructions instructions = updateStore.fetchJobUpdateInstructions(key).get(); if (isCoordinatedAndPulseExpired(key, instructions)) { // Move coordinated update into awaiting pulse state. JobUpdateStatus blockedStatus = getBlockedState(summary.getState().getStatus()); changeUpdateStatus( storeProvider, summary, newEvent(blockedStatus).setMessage(PULSE_TIMEOUT_MESSAGE)); return; } InstanceStateProvider<Integer, Optional<IScheduledTask>> stateProvider = instanceId -> getActiveInstance(storeProvider.getTaskStore(), key.getJob(), instanceId); EvaluationResult<Integer> result = update.getUpdater().evaluate(changedInstance, stateProvider); LOG.info(key + " evaluation result: " + result); for (Map.Entry<Integer, SideEffect> entry : result.getSideEffects().entrySet()) { Iterable<InstanceUpdateStatus> statusChanges; int instanceId = entry.getKey(); List<IJobInstanceUpdateEvent> savedEvents = updateStore.fetchInstanceEvents(key, instanceId); Set<JobUpdateAction> savedActions = FluentIterable.from(savedEvents).transform(EVENT_TO_ACTION).toSet(); // Don't bother persisting a sequence of status changes that represents an instance that // was immediately recognized as being healthy and in the desired state. if (entry.getValue().getStatusChanges().equals(NOOP_INSTANCE_UPDATE) && savedEvents.isEmpty()) { LOG.info("Suppressing no-op update for instance " + instanceId); statusChanges = ImmutableSet.of(); } else { statusChanges = entry.getValue().getStatusChanges(); } for (InstanceUpdateStatus statusChange : statusChanges) { JobUpdateAction action = STATE_MAP.get(Pair.of(statusChange, updaterStatus)); requireNonNull(action); // A given instance update action may only be issued once during the update lifecycle. // Suppress duplicate events due to pause/resume operations. if (savedActions.contains(action)) { LOG.info( String.format( "Suppressing duplicate update %s for instance %s.", action, instanceId)); } else { IJobInstanceUpdateEvent event = IJobInstanceUpdateEvent.build( new JobInstanceUpdateEvent() .setInstanceId(instanceId) .setTimestampMs(clock.nowMillis()) .setAction(action)); updateStore.saveJobInstanceUpdateEvent(summary.getKey(), event); } } } OneWayStatus status = result.getStatus(); if (status == SUCCEEDED || status == OneWayStatus.FAILED) { if (SideEffect.hasActions(result.getSideEffects().values())) { throw new IllegalArgumentException( "A terminal state should not specify actions: " + result); } JobUpdateEvent event = new JobUpdateEvent(); if (status == SUCCEEDED) { event.setStatus(update.getSuccessStatus()); } else { event.setStatus(update.getFailureStatus()); // Generate a transition message based on one (arbitrary) instance in the group that pushed // the update over the failure threshold (in all likelihood this group is of size 1). // This is done as a rough cut to aid in diagnosing a failed update, as generating a // complete summary would likely be of dubious value. for (Map.Entry<Integer, SideEffect> entry : result.getSideEffects().entrySet()) { Optional<Failure> failure = entry.getValue().getFailure(); if (failure.isPresent()) { event.setMessage(failureMessage(entry.getKey(), failure.get())); break; } } } changeUpdateStatus(storeProvider, summary, event); } else { LOG.info("Executing side-effects for update of " + key + ": " + result.getSideEffects()); for (Map.Entry<Integer, SideEffect> entry : result.getSideEffects().entrySet()) { IInstanceKey instance = InstanceKeys.from(key.getJob(), entry.getKey()); Optional<InstanceAction> action = entry.getValue().getAction(); if (action.isPresent()) { Optional<InstanceActionHandler> handler = action.get().getHandler(); if (handler.isPresent()) { Optional<Amount<Long, Time>> reevaluateDelay = handler .get() .getReevaluationDelay( instance, instructions, storeProvider, stateManager, updaterStatus); if (reevaluateDelay.isPresent()) { executor.schedule( getDeferredEvaluator(instance, key), reevaluateDelay.get().getValue(), reevaluateDelay.get().getUnit().getTimeUnit()); } } } } } }