Skip to content

Commit

Permalink
Debug the locations & their image data more clearly
Browse files Browse the repository at this point in the history
  • Loading branch information
msp committed Jun 25, 2018
1 parent 23d0e2c commit c1214c9
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 31 deletions.
32 changes: 27 additions & 5 deletions apps/cyanometer/web/controllers/image_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,36 @@ defmodule Cyanometer.ImageController do

# HTML #######################################################################
def debug(conn, _params) do
images = Repo.all(from image in Image, limit: 300,
order_by: [desc: image.taken_at])
locations = Repo.all(from location in Location, order_by: [desc: location.id])

location_images =
Enum.map(locations, fn(location) ->
Repo.all(from image in Image,
join: l in assoc(image, :location),
where: image.location_id == ^location.id,
limit: 300,
order_by: [desc: image.taken_at],
preload: [location: l]
)
end)

location_environmental_datas =
Enum.map(locations, fn(location) ->
Repo.all(from ed in EnvironmentalData,
join: l in assoc(ed, :location),
where: ed.location_id == ^location.id,
limit: 24,
order_by: [desc: ed.taken_at],
preload: [location: l]
)
end)

environmental_datas = Repo.all(from ed in EnvironmentalData, limit: 24,
order_by: [desc: ed.taken_at])
conn
|> put_layout("vanilla.html")
|> render("debug.html", images: images, environmental_datas: environmental_datas)
|> render("debug.html",
locations: locations,
location_images: location_images,
location_environmental_datas: location_environmental_datas)

end

Expand Down
74 changes: 48 additions & 26 deletions apps/cyanometer/web/templates/image/debug.html.eex
Original file line number Diff line number Diff line change
@@ -1,41 +1,63 @@
<h4>Here's some images we know about:</h4>

<table class="table">
<tr>
<th>ID</th>
<th>S3 URL</th>
<th>Taken At</th>
<th>Blueness Index</th>

<%= for image <- @images do %>
<thead>
<tr>
<td><%= image.id %></td>
<td>
<a href="<%= image.s3_url %>">
<img src='<%= "http://res.cloudinary.com/mota/image/fetch/w_150,h_150/#{image.s3_url}" %>' />
</a>
</td>
<td><%= image.taken_at %></td>
<td><%= image.blueness_index %></td>
<th>ID</th>
<th>S3 URL</th>
<th>Taken At</th>
<th>Blueness Index</th>
<th>Location</th>
</tr>
</thead>
<%= for {location, i} <- Enum.with_index(@location_images) do %>
<tbody>
<tr><td style="font-size: larger;"><%= Enum.at(@locations, i).country %>, <%= Enum.at(@locations, i).city %>, <%= Enum.at(@locations, i).place %></td></tr>
<%= for image <- location do %>
<tr id="image-<%= image.id %>">
<td>
<a href="#image-<%= image.id %>"><%= image.id %></a>
</td>
<td>
<a href="<%= image.s3_url %>">
<img src='<%= "http://res.cloudinary.com/mota/image/fetch/w_150,h_150/#{image.s3_url}" %>' />
</a>
</td>
<td><%= image.taken_at %></td>
<td><%= image.blueness_index %></td>
<td><%= image.location_id %></td>
</tr>
<% end %>
</tbody>
<% end %>
</table>

<h4>Here's some environmental data we know about:</h4>

<table class="table">
<tr>
<th>ID</th>
<th>Taken At</th>
<th>Air Pollution Index</th>
<th>Icon</th>

<%= for environmental_data <- @environmental_datas do %>
<thead>
<tr>
<td><%= environmental_data.id %></td>
<td><%= environmental_data.taken_at %></td>
<td><%= environmental_data.air_pollution_index %></td>
<td><%= environmental_data.icon %></td>
<th>ID</th>
<th>Taken At</th>
<th>Air Pollution Index</th>
<th>Icon</th>
<th>Location</th>
</tr>
</thead>
<%= for {location, i} <- Enum.with_index(@location_environmental_datas) do %>
<tbody>
<tr><td><%= Enum.at(@locations, i).country %>, <%= Enum.at(@locations, i).city %>, <%= Enum.at(@locations, i).place %></td></tr>
<%= for environmental_data <- location do %>
<tr id="ed-<%= environmental_data.id %>">
<td>
<a href="#ed-<%= environmental_data.id %>"><%= environmental_data.id %></a>
</td>
<td><%= environmental_data.taken_at %></td>
<td><%= environmental_data.air_pollution_index %></td>
<td><%= environmental_data.icon %></td>
<td><%= environmental_data.location_id %></td>
</tr>
<% end %>
</tbody>
<% end %>
</table>

0 comments on commit c1214c9

Please sign in to comment.