Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
vladsavelyev committed Feb 19, 2024
1 parent 63dc17d commit e4869c8
Showing 1 changed file with 26 additions and 32 deletions.
58 changes: 26 additions & 32 deletions megaqc/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,39 +319,33 @@ def handle_report_data(user, report_data):
existing_category.save()
category_id = existing_category.plot_category_id
for sa_idx, actual_data in enumerate(sub_dict["data"]):
try:
existing_sample = (
db.session.query(Sample)
.filter(
Sample.sample_name
== report_data["report_plot_data"][plot]["samples"][
dst_idx
][sa_idx]
)
.first()
)
if existing_sample:
sample_id = existing_sample.sample_id
else:
new_sample = Sample(
sample_name=sub_dict["name"], report_id=report_id
)
new_sample.save()
sample_id = new_sample.sample_id
new_dataset_row = PlotData(
report_id=report_id,
config_id=config_id,
sample_id=sample_id,
plot_category_id=existing_category.plot_category_id,
data=json.dumps(actual_data),
existing_sample = (
db.session.query(Sample)
.filter(
Sample.sample_name
== report_data["report_plot_data"][plot]["samples"][
dst_idx
][sa_idx]
)
new_dataset_row.save()
new_plotdata_cnt += 1
except Exception as e:
current_app.logger.error(
"Error saving plot data: {}".format(str(e))
.first()
)
if existing_sample:
sample_id = existing_sample.sample_id
else:
new_sample = Sample(
sample_name=sub_dict["name"], report_id=report_id
)
raise
new_sample.save()
sample_id = new_sample.sample_id
new_dataset_row = PlotData(
report_id=report_id,
config_id=config_id,
sample_id=sample_id,
plot_category_id=existing_category.plot_category_id,
data=json.dumps(actual_data),
)
new_dataset_row.save()
new_plotdata_cnt += 1

# Save line plot data
elif report_data["report_plot_data"][plot]["plot_type"] == "xy_line":
Expand Down Expand Up @@ -450,7 +444,7 @@ def handle_report_data(user, report_data):
config_id=config_id,
sample_id=sample_id,
plot_category_id=category_id,
data=json.dumps(actual_data),
data=json.dumps(sub_dict["data"]),
)
new_dataset_row.save()
new_plotdata_cnt += 1
Expand Down

0 comments on commit e4869c8

Please sign in to comment.