* @brief End-to-end dry-run: parser + all dataset transforms applied to a sample frame. */
| 6440 | * @brief End-to-end dry-run: parser + all dataset transforms applied to a sample frame. |
| 6441 | */ |
| 6442 | API::CommandResponse API::Handlers::ProjectHandler::endToEndDryRun(const QString& id, |
| 6443 | const QJsonObject& params) |
| 6444 | { |
| 6445 | auto& pm = DataModel::ProjectModel::instance(); |
| 6446 | const auto sources = pm.sources(); |
| 6447 | const int sourceId = params.value(Keys::SourceId).toInt(0); |
| 6448 | if (sources.empty()) |
| 6449 | return CommandResponse::makeError( |
| 6450 | id, ErrorCode::InvalidParam, QStringLiteral("Project has no sources to dry-run against")); |
| 6451 | |
| 6452 | if (sourceId < 0 || sourceId >= static_cast<int>(sources.size())) |
| 6453 | return CommandResponse::makeError( |
| 6454 | id, ErrorCode::InvalidParam, QStringLiteral("Source id out of range: %1").arg(sourceId)); |
| 6455 | |
| 6456 | const auto& source = sources[sourceId]; |
| 6457 | |
| 6458 | const bool hasFrame = params.contains(QStringLiteral("sampleFrame")); |
| 6459 | const bool hasFrames = params.contains(QStringLiteral("sampleFrames")); |
| 6460 | if (!hasFrame && !hasFrames) |
| 6461 | return CommandResponse::makeError( |
| 6462 | id, |
| 6463 | ErrorCode::MissingParam, |
| 6464 | QStringLiteral("Missing required parameter: sampleFrame (string) or sampleFrames (array)")); |
| 6465 | |
| 6466 | QStringList frames; |
| 6467 | if (hasFrames) |
| 6468 | for (const auto& v : params.value(QStringLiteral("sampleFrames")).toArray()) |
| 6469 | frames.append(v.toString()); |
| 6470 | else |
| 6471 | frames.append(params.value(QStringLiteral("sampleFrame")).toString()); |
| 6472 | |
| 6473 | const bool verbose = params.value(QStringLiteral("verbose")).toBool(false); |
| 6474 | const QString code = params.contains(QStringLiteral("code")) |
| 6475 | ? params.value(QStringLiteral("code")).toString() |
| 6476 | : source.frameParserCode; |
| 6477 | const int language = params.contains(QStringLiteral("language")) |
| 6478 | ? params.value(QStringLiteral("language")).toInt() |
| 6479 | : source.frameParserLanguage; |
| 6480 | |
| 6481 | auto parser = makeScriptEngine(language); |
| 6482 | if (!parser->loadScript(code, sourceId, false)) |
| 6483 | return CommandResponse::makeError( |
| 6484 | id, |
| 6485 | ErrorCode::ExecutionError, |
| 6486 | QStringLiteral("Frame parser failed to compile or define parse(frame).") |
| 6487 | + frameParserCompileHint(code, language)); |
| 6488 | |
| 6489 | std::map<int, std::unique_ptr<DataModel::IScriptEngine>> transformEngines; |
| 6490 | std::map<int, bool> transformEngineOk; |
| 6491 | const auto& groups = pm.groups(); |
| 6492 | |
| 6493 | QJsonArray frameResults; |
| 6494 | for (const auto& sample : frames) { |
| 6495 | const auto parsed = parser->parseString(sample); |
| 6496 | |
| 6497 | QJsonArray rowResults; |
| 6498 | for (const auto& row : parsed) |
| 6499 | rowResults.append(buildDryRunRow( |
nothing calls this directly
no test coverage detected