Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
a = {
"annotations" => [
{
"x" => 19,
"y" => 20,
"w" => 50,
"h" => 50,
"predictions" => {
"green" => 0.2,
"red" => 0.95
}
}
]}
def hstorify_annotation(annotation)
annotation.inject({}) do |acc, (k,v)|
acc[k] = v if ["x", "y", "w", "h"].include?(k)
if k == "predictions"
v.each do |(pred_k, pred_v)|
acc[pred_k + "_prediction"] = pred_v
end
end
acc
end
end
annotations = a["annotations"].collect{|a| hstorify_annotation(a)}
pp annotations
# =>
[{"x"=>19,
"y"=>20,
"w"=>50,
"h"=>50,
"green_prediction"=>0.2,
"red_prediction"=>0.95}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.