-
-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Project dataset export missing headers #8141
Comments
As a quick hack we could pick the hash with the most keys as the header: def to_csv
CSV.generate do |csv|
- header = data.first
+ header = data.sort_by { |h| h.keys.size }.last
csv << header.keys.map(&:to_s) if header
data.each { |row| csv << row.values }
end Not exactly quick though: e = Project::Export.new(project)
puts Benchmark.measure { e.data.sort_by { |h| h.keys.size }.last }
# => 3.009553 0.175640 3.185193 ( 4.889427) |
Ideally we'd get the keys from the dataset associated with the project. That's available to us given we instantiate I think what we should really do is always use the dataset keys associated with the project to then go and get the associated values from each submission. A better intermediate solution might be to change def extracted_values_as_hash
return {} unless extracted_values
extracted_values.joins(:key).pluck('dataset_keys.title', :value).to_h
end |
Project::Export uses the first request in the project to generate the CSV headers. However, if the request hasn't had data extracted, the headers for the dataset columns will be blank, even though other requests in the project may have had a dataset extraction. This commit ensures that headers are always present by looking up the project's key set, and iterating through that to fetch the relevant submission value for that key, or otherwise assigning a nil value. This has the benefit of ensuring that the keys/values exported are always in sync with the current project key set. Fixes #8141.
Project::Export uses the first request in the project to generate the CSV headers. However, if the request hasn't had data extracted, the headers for the dataset columns will be blank, even though other requests in the project may have had a dataset extraction. This commit ensures that headers are always present by looking up the project's key set, and iterating through that to fetch the relevant submission value for that key, or otherwise assigning a nil value. This has the benefit of ensuring that the keys/values exported are always in sync with the current project key set. Fixes #8141.
Project::Export uses the first request in the project to generate the CSV headers. However, if the request hasn't had data extracted, the headers for the dataset columns will be blank, even though other requests in the project may have had a dataset extraction. This commit ensures that headers are always present by looking up the project's key set, and iterating through that to fetch the relevant submission value for that key, or otherwise assigning a nil value. This has the benefit of ensuring that the keys/values exported are always in sync with the current project key set. Fixes #8141.
See user query.
Project::Export
uses the first request in the project to generate the CSV headers. However, if the request hasn't had data extracted, the headers for the dataset columns will be blank, even though other requests in the project may have had a dataset extraction.The text was updated successfully, but these errors were encountered: