From 3c5563c7a0981d8cc43c772a199d3353216cea8d Mon Sep 17 00:00:00 2001 From: Chris C Cerami Date: Thu, 16 Aug 2018 11:35:20 -0400 Subject: [PATCH] Add earth_date to manifests --- README.md | 1 + app/models/photo_manifest.rb | 6 +++--- spec/controllers/api/v1/manifests_controller_spec.rb | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 3b07ed1..1c6b8c1 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,7 @@ An example entry from `/manifests/Curiosity` might look like: ``` { sol: 0, + earth_date: "2012-08-06" total_photos: 3702, cameras: [ "CHEMCAM", diff --git a/app/models/photo_manifest.rb b/app/models/photo_manifest.rb index 449e631..62bf89d 100644 --- a/app/models/photo_manifest.rb +++ b/app/models/photo_manifest.rb @@ -10,9 +10,9 @@ def initialize(rover) end def to_a - rover.photos.joins(:camera).group(:sol) - .select('sol, count(photos.id) AS cnt, ARRAY_AGG(DISTINCT cameras.name) AS cameras') - .map { |photos| {sol: photos.sol, total_photos: photos.cnt, cameras: photos.cameras} } + rover.photos.joins(:camera).group(:sol, :earth_date) + .select('sol, earth_date, count(photos.id) AS cnt, ARRAY_AGG(DISTINCT cameras.name) AS cameras') + .map { |photos| {sol: photos.sol, earth_date: photos.earth_date, total_photos: photos.cnt, cameras: photos.cameras} } end def photos diff --git a/spec/controllers/api/v1/manifests_controller_spec.rb b/spec/controllers/api/v1/manifests_controller_spec.rb index 517ff83..035486e 100644 --- a/spec/controllers/api/v1/manifests_controller_spec.rb +++ b/spec/controllers/api/v1/manifests_controller_spec.rb @@ -39,9 +39,9 @@ it "contains a record for each sol for which there are photos" do expect(json["photo_manifest"]["photos"]).to contain_exactly( - {"sol" => 1, "total_photos" => 1, "cameras" => ["FHAZ"]}, - {"sol" => 30, "total_photos" => 1, "cameras" => ["FHAZ"]}, - {"sol" => 100, "total_photos" => 2, "cameras" => ["FHAZ"]} + {"sol" => 1, "earth_date"=>"2012-08-07", "total_photos" => 1, "cameras" => ["FHAZ"]}, + {"sol" => 30, "earth_date"=>"2012-09-05", "total_photos" => 1, "cameras" => ["FHAZ"]}, + {"sol" => 100, "earth_date"=>"2012-11-16", "total_photos" => 2, "cameras" => ["FHAZ"]} ) end end