Skip to content

Commit

Permalink
fix DataPoint query to use Array of datapoint_ids
Browse files Browse the repository at this point in the history
  • Loading branch information
brianlball committed Apr 29, 2022
1 parent 22e7130 commit c8bb769
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions server/app/controllers/analyses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -934,21 +934,18 @@ def get_analysis_data(analysis, datapoint_id = nil, only_completed_normal = true
# Eventually use this where the timestamp is processed as part of the request to save time
plot_data = if datapoint_id
if only_completed_normal
DataPoint.where(
analysis_id: analysis, status: 'completed', id: datapoint_id, status_message: 'completed normal'
)
DataPoint.where(analysis_id: analysis, status: 'completed', :id.in => datapoint_id, status_message: 'completed normal')
else
DataPoint.where(analysis_id: analysis, id: datapoint_id)
DataPoint.where(analysis_id: analysis, :id.in => datapoint_id)
end
else
if only_completed_normal
DataPoint.where(analysis_id: analysis, status: 'completed', status_message: 'completed normal')
.order_by(:created_at.asc)
DataPoint.where(analysis_id: analysis, status: 'completed', status_message: 'completed normal').order_by(:created_at.asc)
else
DataPoint.where(analysis_id: analysis).order_by(:created_at.asc)
end
end

logger.info "PLOT_DATA.count: #{plot_data.count}"
logger.info "finished fixing up data: #{Time.now - start_time}"

start_time = Time.now
Expand Down Expand Up @@ -1030,7 +1027,6 @@ def write_and_send_csv(analysis, datapoint_ids = nil)
def write_and_send_rdata(analysis, datapoint_ids = nil)
# get variables from the variables object now instead of using the "superset_of_input_variables"
variables, data = get_analysis_data(analysis, datapoint_ids, false, export: true)

static_fields = ['name', '_id', 'run_start_time', 'run_end_time', 'status', 'status_message']
names_of_vars = static_fields + variables.map { |_k, v| v['output'] ? v['name'] : v['name'] }

Expand Down Expand Up @@ -1066,23 +1062,27 @@ def write_and_send_rdata(analysis, datapoint_ids = nil)

start_time = Time.now
logger.info 'starting creation of data frame'
# TODO: check these permissions and make them less open
r.command(data_frame_name.to_sym => out_hash.to_dataframe) do
%{
dir.create('/mnt/openstudio/tmp')
temp <- tempfile('rdata', tmpdir="/mnt/openstudio/tmp")
save('#{data_frame_name}', file = temp)
Sys.chmod(temp, mode = "0777", use_umask = TRUE)
}
end
tmp_filename = r.converse('temp')
logger.info "finished data frame: #{Time.now - start_time}"
if !out_hash.empty?
# TODO: check these permissions and make them less open
r.command(data_frame_name.to_sym => out_hash.to_dataframe) do
%{
dir.create('/mnt/openstudio/tmp')
temp <- tempfile('rdata', tmpdir="/mnt/openstudio/tmp")
save('#{data_frame_name}', file = temp)
Sys.chmod(temp, mode = "0777", use_umask = TRUE)
}
end
tmp_filename = r.converse('temp')
logger.info "finished data frame: #{Time.now - start_time}"

if File.exist?(tmp_filename)
send_data File.open(tmp_filename).read, filename: download_filename, type: 'application/rdata; header=present', disposition: 'attachment'
else
raise 'could not create R dataframe'
end
if File.exist?(tmp_filename)
send_data File.open(tmp_filename).read, filename: download_filename, type: 'application/rdata; header=present', disposition: 'attachment'
else
raise 'could not create R dataframe'
end
else
raise 'out_hash is empty'
end
end

private
Expand Down

0 comments on commit c8bb769

Please sign in to comment.