def update_size(self, id=None): batch = self.__batch(id) if not batch: abort(404) batch_test = self.__batch_test(id) if not batch_test: batch_test = ConsumableBatchTest(consumable_batch_id=batch.id) Session.add(batch_test) batch_test.pixel_calibration = self.form_result["pixel_calibration"] garbage = [] # check for cleared entities first for chan in batch_test.size_channels: thechip = [chip for chip in self.form_result["chips"] if chip["chip_num"] == chan.chip_num] if not thechip: garbage.append(chan) continue thechan = [c for c in thechip[0]["channels"] if c["channel_num"] == chan.channel_num] if not thechan: garbage.append(chan) continue if thechan[0]["droplet_count"] is None and thechan[0]["mean"] is None and thechan[0]["stdev"] is None: garbage.append(chan) for g in garbage: batch_test.size_channels.remove(g) Session.delete(g) # This is the case for a GAE-like Entity or a Mongo object or storing # JSON in a text column or whatever for chip in self.form_result["chips"]: for channel in chip["channels"]: if channel["droplet_count"] is not None or channel["mean"] is not None or channel["stdev"] is not None: dbchan = batch_test.size_channel(chip["chip_num"], channel["channel_num"]) if not dbchan: dbchan = ConsumableBatchSizeChannel( chip_num=chip["chip_num"], channel_num=channel["channel_num"] ) batch_test.size_channels.append(dbchan) dbchan.size_mean = channel["mean"] dbchan.size_stdev = channel["stdev"] dbchan.droplet_count = channel["droplet_count"] Session.commit() session["flash"] = "Sizes updated." session.save() return redirect(url(controller="consumable", action="size", id=batch.id))
def batch_size_upload(self, id=None): batch = self.__batch(id) if not batch: abort(404) batch_test = self.__batch_test(id) if not batch_test: batch_test = ConsumableBatchTest(consumable_batch_id=batch.id) Session.add(batch_test) batch_test.pixel_calibration = self.form_result["pixel_calibration"] for i in range(len(batch_test.size_channels)): sc = batch_test.size_channels.pop() Session.delete(sc) # place files in order chip_num = 0 pc = batch_test.pixel_calibration for idx, channel in enumerate(sorted(self.form_result["sizes"], key=operator.itemgetter("file_num"))): if idx % 8 == 0: chip_num = chip_num + 1 dbchan = ConsumableBatchSizeChannel( chip_num=chip_num, channel_num=(idx % 8) + 1, size_mean=channel["mean"] * pc, size_stdev=channel["stdev"] * pc, droplet_count=channel["droplet_count"], ) batch_test.size_channels.append(dbchan) Session.commit() session["flash"] = "Sizes updated." session.save() return redirect(url(controller="consumable", action="size", id=batch.id))