include intensity data in image api response

This commit is contained in:
byte[] 2019-12-30 09:18:38 -05:00
parent 330e4ffb26
commit dd5d553c0d
4 changed files with 10 additions and 6 deletions

View file

@ -4,9 +4,9 @@ defmodule PhilomenaWeb.Api.Json.ImageController do
alias PhilomenaWeb.ImageJson
alias Philomena.Images.Image
plug :load_and_authorize_resource, model: Image, only: [:show], preload: [:tags, :user]
plug :load_and_authorize_resource, model: Image, only: [:show], preload: [:tags, :user, :intensity]
def show(conn, _params) do
json(conn, %{image: ImageJson.as_json(conn, conn.assigns.image)})
end
end
end

View file

@ -9,7 +9,7 @@ defmodule PhilomenaWeb.Api.Json.Search.ImageController do
import Ecto.Query
def index(conn, params) do
queryable = Image |> preload([:tags, :user])
queryable = Image |> preload([:tags, :user, :intensity])
user = conn.assigns.current_user
sort = ImageSorter.parse_sort(params)
@ -31,4 +31,4 @@ defmodule PhilomenaWeb.Api.Json.Search.ImageController do
|> json(%{error: msg})
end
end
end
end

View file

@ -20,6 +20,7 @@ defmodule PhilomenaWeb.ImageJson do
uploader: if(!!image.user and !image.anonymous, do: image.user.name),
uploader_id: if(!!image.user and !image.anonymous, do: image.user.id),
wilson_score: Philomena.Images.ElasticsearchIndex.wilson_score(image),
intensities: intensities(image),
score: image.score,
upvotes: image.upvotes_count,
downvotes: image.downvotes_count,
@ -35,4 +36,7 @@ defmodule PhilomenaWeb.ImageJson do
processed: image.processed
}
end
defp intensities(%{intensity: %{nw: nw, ne: ne, sw: sw, se: se}}), do: %{nw: nw, ne: ne, sw: sw, se: se}
defp intensities(_), do: nil
end

View file

@ -20,7 +20,7 @@ defmodule PhilomenaWeb.ImageReverse do
dist = normalize_dist(image_params)
DuplicateReports.duplicates_of(intensities, aspect, dist, dist)
|> preload([:tags, :user])
|> preload([:tags, :user, :intensity])
|> Repo.all()
end
end
@ -45,4 +45,4 @@ defmodule PhilomenaWeb.ImageReverse do
|> min(1.0)
end
defp normalize_dist(_dist), do: 0.25
end
end