Skip to content

Commit

Permalink
Merge ab352b7 into bbd65b7
Browse files Browse the repository at this point in the history
  • Loading branch information
ethn committed Apr 17, 2024
2 parents bbd65b7 + ab352b7 commit ce3070d
Show file tree
Hide file tree
Showing 29 changed files with 92,764 additions and 450,156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,18 @@ def restrict_years_in_query?
end

def answer_query
query = { metric_id: input_card.id }
query[:company_id] = search_space.company_ids if search_space.company_ids?
{ metric_id: input_card.id }.tap do |query|
restrict_companies query
restrict_years query
end
end

def restrict_years query
query[:year] = search_space.years if restrict_years_in_query?
query
end

def restrict_companies query
query[:company_id] = search_space.company_ids if search_space.company_ids?
end

# overwritten in other places to move input items with no restriction on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ def answer_lists
end

def answer_relation
query = {
metric_id: input_card.id,
company_group: company_group.id,
published: :all
}
query = { metric_id: input_card.id,
company_group: company_group.id,
published: :all }
restrict_years query
Card::AnswerQuery.new(query).lookup_relation
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def input_answers_by_company_and_year
end

# must be overwritten, because "answers" does not filter by company
# (see #answer_query)
def answers_for company_id, year
@search_space = SearchSpace.new company_id, year
Answer.where answer_query.merge(company_id: relationship_hash[company_id])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ module SingleCompany
include CompanyIndependentInput

def year_answer_pairs
each_input_answer answer_query_relation, {} do |input_answer, hash|
each_input_answer answers, {} do |input_answer, hash|
hash[input_answer.year] = input_answer
end
end

def answer_query_relation
Answer.where metric_id: input_card.id, company_id: requested_company_id
def restrict_companies query
query[:company_id] = requested_company_id
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ def answer_value_hash *args
end

example "company group" do
expect(answer_value_hash(samsung, nil, company: "Deadliest"))
.to eq(1977 => %w[100 40 50])
expect(answer_value_hash(samsung, nil, company: "Deadliest")[1977].sort)
.to eq(%w[100 40 50])
end

example "metric with related company option" do
Expand Down

0 comments on commit ce3070d

Please sign in to comment.