mirror of https://github.com/nymea/nymea.git
improve debug output for the ruleengine
parent
ec667f15d9
commit
b8c11cc850
|
|
@ -183,8 +183,6 @@ LogEngine::~LogEngine()
|
|||
*/
|
||||
QList<LogEntry> LogEngine::logEntries(const LogFilter &filter) const
|
||||
{
|
||||
qCDebug(dcLogEngine) << "Read logging database" << m_db.databaseName();
|
||||
|
||||
QList<LogEntry> results;
|
||||
QSqlQuery query;
|
||||
|
||||
|
|
|
|||
|
|
@ -333,8 +333,15 @@ RuleEngine::~RuleEngine()
|
|||
QList<Rule> RuleEngine::evaluateEvent(const Event &event)
|
||||
{
|
||||
Device *device = NymeaCore::instance()->deviceManager()->findConfiguredDevice(event.deviceId());
|
||||
DeviceClass deviceClass = NymeaCore::instance()->deviceManager()->findDeviceClass(device->deviceClassId());
|
||||
EventType eventType = deviceClass.eventTypes().findById(event.eventTypeId());
|
||||
|
||||
qCDebug(dcRuleEngineDebug) << "Evaluate event:" << event << device->name() << event.eventTypeId();
|
||||
|
||||
if (event.params().count() == 0) {
|
||||
qCDebug(dcRuleEngineDebug).nospace().noquote() << "Evaluate event: " << device->name() << " - " << eventType.name() << " (DeviceId:" << device->id().toString() << ", EventTypeId:" << eventType.id().toString() << ")";
|
||||
} else {
|
||||
qCDebug(dcRuleEngineDebug).nospace().noquote() << "Evaluate event: " << device->name() << " - " << eventType.name() << " (DeviceId:" << device->id().toString() << ", EventTypeId:" << eventType.id().toString() << ")" << endl << " " << event.params();
|
||||
}
|
||||
|
||||
QList<Rule> rules;
|
||||
foreach (const RuleId &id, ruleIds()) {
|
||||
|
|
|
|||
|
|
@ -99,52 +99,54 @@ void StateEvaluator::setOperatorType(Types::StateOperator operatorType)
|
|||
/*! Returns true, if all child evaluator conditions are true depending on the \l {Types::StateOperator}{StateOperator}.*/
|
||||
bool StateEvaluator::evaluate() const
|
||||
{
|
||||
qCDebug(dcRuleEngineDebug()) << "Evaluating StateEvaluator." << this << "Operator type" << m_operatorType << "Valid descriptor:" << m_stateDescriptor.isValid() << "Childs:" << m_childEvaluators.count();
|
||||
qCDebug(dcRuleEngineDebug()) << "StateEvaluator:" << this << "Evaluating: Operator type" << m_operatorType << "Valid descriptor:" << m_stateDescriptor.isValid() << "Childs:" << m_childEvaluators.count();
|
||||
bool descriptorMatching = true;
|
||||
if (m_stateDescriptor.isValid()) {
|
||||
Device *device = NymeaCore::instance()->deviceManager()->findConfiguredDevice(m_stateDescriptor.deviceId());
|
||||
if (!device) {
|
||||
qCWarning(dcRuleEngine) << "Device not existing!";
|
||||
qCWarning(dcRuleEngine) << "StateEvaluator:" << this << "Device not existing!";
|
||||
descriptorMatching = false;
|
||||
} else {
|
||||
DeviceClass deviceClass = NymeaCore::instance()->deviceManager()->findDeviceClass(device->deviceClassId());
|
||||
if (!device->hasState(m_stateDescriptor.stateTypeId())) {
|
||||
qCWarning(dcRuleEngine) << "Device found, but it does not appear to have such a state!";
|
||||
qCWarning(dcRuleEngine) << "StateEvaluator:" << this << "Device found, but it does not appear to have such a state!";
|
||||
descriptorMatching = false;
|
||||
}
|
||||
if (m_stateDescriptor != device->state(m_stateDescriptor.stateTypeId())) {
|
||||
// state not matching
|
||||
qCDebug(dcRuleEngineDebug()) << "State" << device->name() << deviceClass.stateTypes().findById(m_stateDescriptor.stateTypeId()).name() << "not matching:" << m_stateDescriptor.stateValue() << "!=" << device->stateValue(m_stateDescriptor.stateTypeId());
|
||||
descriptorMatching = false;
|
||||
}
|
||||
qCDebug(dcRuleEngineDebug()) << "StateEvaluator:" << this << "State" << device->name() << deviceClass.stateTypes().findById(m_stateDescriptor.stateTypeId()).name() << (descriptorMatching ? "is" : "not") << "matching:" << m_stateDescriptor.stateValue() << m_stateDescriptor.operatorType() << device->stateValue(m_stateDescriptor.stateTypeId());
|
||||
}
|
||||
}
|
||||
|
||||
if (m_operatorType == Types::StateOperatorOr) {
|
||||
if (m_stateDescriptor.isValid() && descriptorMatching) {
|
||||
qCDebug(dcRuleEngineDebug()) << "Descriptor is matching. Operator is OR => Evaluation result: true";
|
||||
qCDebug(dcRuleEngineDebug()) << "StateEvaluator:" << this << "Descriptor is matching. Operator is OR => Evaluation result: true";
|
||||
return true;
|
||||
}
|
||||
foreach (const StateEvaluator &stateEvaluator, m_childEvaluators) {
|
||||
if (stateEvaluator.evaluate()) {
|
||||
qCDebug(dcRuleEngineDebug()) << "Child evaluator evaluated to true. Operator is OR => Evaluation result: true";
|
||||
qCDebug(dcRuleEngineDebug()) << "StateEvaluator:" << this << "Child evaluator evaluated to true. Operator is OR => Evaluation result: true";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
qCDebug(dcRuleEngineDebug()) << "No child evaluator evaluated to true => Evaluation result: false";
|
||||
qCDebug(dcRuleEngineDebug()) << "StateEvaluator:" << this << "No child evaluator evaluated to true => Evaluation result: false";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!descriptorMatching) {
|
||||
qCDebug(dcRuleEngineDebug()) << "Operator is AND => Evaluation result: false";
|
||||
qCDebug(dcRuleEngineDebug()) << "StateEvaluator:" << this << "StateDescriptor not matching and operator is AND => Evaluation result: false";
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (const StateEvaluator &stateEvaluator, m_childEvaluators) {
|
||||
if (!stateEvaluator.evaluate()) {
|
||||
qCDebug(dcRuleEngineDebug()) << "StateEvaluator:" << this << "Child evaluator not matching => Evaluation result: false";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
qCDebug(dcRuleEngineDebug()) << "StateEvaluator:" << this << "StateDescriptor and all child evaluators matching => Evaluation result: true";
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -76,9 +76,12 @@ QDebug operator<<(QDebug dbg, const Param ¶m)
|
|||
/*! Writes the param of the given \a params to \a dbg. */
|
||||
QDebug operator<<(QDebug dbg, const ParamList ¶ms)
|
||||
{
|
||||
dbg.nospace() << "ParamList (count:" << params.count() << ")" << endl;
|
||||
dbg.nospace() << "ParamList (count:" << params.count() << ")";
|
||||
if (params.count() == 0) {
|
||||
dbg.nospace() << endl;
|
||||
}
|
||||
for (int i = 0; i < params.count(); i++ ) {
|
||||
dbg.nospace() << " " << i << ": " << params.at(i) << endl;
|
||||
dbg.nospace() << endl << " " << i << ": " << params.at(i);
|
||||
}
|
||||
|
||||
return dbg.space();
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ DeviceManager::DeviceSetupStatus DevicePluginMock::setupDevice(Device *device)
|
|||
m_daemons.insert(device, daemon);
|
||||
|
||||
if (!daemon->isListening()) {
|
||||
qCWarning(dcMockDevice) << "HTTP port opening failed.";
|
||||
qCWarning(dcMockDevice) << "HTTP port opening failed:" << device->paramValue(mockHttpportParamTypeId).toInt();
|
||||
return DeviceManager::DeviceSetupStatusFailure;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue