Add new stat
This commit is contained in:
@@ -27,7 +27,11 @@
|
|||||||
{
|
{
|
||||||
"park_count": 474,
|
"park_count": 474,
|
||||||
"alert_count": 708,
|
"alert_count": 708,
|
||||||
"most_alerts": {
|
"state_with_most_parks": {
|
||||||
|
"state": "WY",
|
||||||
|
"park_count": 10
|
||||||
|
},
|
||||||
|
"park_with_most_alerts": {
|
||||||
"park_code": "zion",
|
"park_code": "zion",
|
||||||
"alert_count": 6
|
"alert_count": 6
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ module Api::V1
|
|||||||
def index
|
def index
|
||||||
@park_count = Park.count
|
@park_count = Park.count
|
||||||
@alert_count = Alert.count
|
@alert_count = Alert.count
|
||||||
|
@state_with_most_parks = ParksByState.group(:state).count.max
|
||||||
@park_with_most_alerts = Alert.group(:park_code).count.max
|
@park_with_most_alerts = Alert.group(:park_code).count.max
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
json.park_count @park_count
|
json.park_count @park_count
|
||||||
json.alert_count @alert_count
|
json.alert_count @alert_count
|
||||||
json.most_alerts do
|
json.state_with_most_parks do
|
||||||
|
json.state @state_with_most_parks[0]
|
||||||
|
json.park_count @state_with_most_parks[1]
|
||||||
|
end
|
||||||
|
json.park_with_most_alerts do
|
||||||
json.park_code @park_with_most_alerts[0]
|
json.park_code @park_with_most_alerts[0]
|
||||||
json.alert_count @park_with_most_alerts[1]
|
json.alert_count @park_with_most_alerts[1]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ RSpec.describe "Api::V1::Stats", type: :request do
|
|||||||
describe "GET /stats" do
|
describe "GET /stats" do
|
||||||
it "returns summary stats" do
|
it "returns summary stats" do
|
||||||
alerts(:two).update!(park_code: parks(:one).code)
|
alerts(:two).update!(park_code: parks(:one).code)
|
||||||
|
parks_by_states(:two).update!(state: "OR")
|
||||||
|
|
||||||
get api_v1_stats_url
|
get api_v1_stats_url
|
||||||
|
|
||||||
@@ -11,7 +12,11 @@ RSpec.describe "Api::V1::Stats", type: :request do
|
|||||||
expect(response.parsed_body).to match(
|
expect(response.parsed_body).to match(
|
||||||
park_count: 2,
|
park_count: 2,
|
||||||
alert_count: 2,
|
alert_count: 2,
|
||||||
most_alerts: {
|
state_with_most_parks: {
|
||||||
|
state: "OR",
|
||||||
|
park_count: 2
|
||||||
|
},
|
||||||
|
park_with_most_alerts: {
|
||||||
park_code: "crla",
|
park_code: "crla",
|
||||||
alert_count: 2
|
alert_count: 2
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user