How to get analysis results?

Once all analysis steps are finished, the scenario player gives access to analysis results. To know when the results are available you can listen on the ScenarioPlayer status. When it is .finished, .terminated or .closed you can ask the player to return analysis results outside of it using getResults().

player.getResults(key: String) -> [String: Any]

How to know the available result keys?

Depending of your scenario, you can have different results keys available. For example, if your scenario perform a variety analysis and a protein analysis, it won't have the same keys as a scenario performing only the variety analysis.

You can use the method below:

player.getResultsKeys() -> String[] // -> ["measured_variety", "measured_protein", ...]

Let assume that you have a variety analysis and a protein analysis in your scenario. You can retrieve the variety results as follows:

// variety
try player.getResults("measured_variety")
// protein
try player.getResults("measured_protein")

And then you can explore the different keys from this measure by using:

try player.getResults("measured_variety").keys // -> String[]

Finally, you can retrieve the value by accessing the dictionary as below:

// variety
try player.getResults("measured_variety")["main_variety_name"]
// protein
try player.getResults("measured_protein")["protein_percent"]
❗️

If you try to get the results when the player isn't in the proper status, it'll throw an exception.

Exceptions

Two types of exceptions can be thrown by the ScenarioPlayer when you're requesting the analysis results:

do {
  try player.getResults("measured_variety")
} catch InarixSDK.ScenarioPlayer.ResultError.InvalidPlayerState {
  // Thrown when the player isn't finished/terminated/closed.
} catch InarixSDK.ScenarioPlayer.ResultError.ResultKeyNotFound {
  // Thrown when the result key doesn't exist.
}