def populate_attribute(self, summary_attribute, update=True): """Populate all instances of summary_attribute in table. Arguments: summary_attribute - either an instance of h1ds.models.SummaryAttribute or its slug """ try: attr_slug = summary_attribute.slug except AttributeError: attr_slug = summary_attribute shot_queryset = Shot.objects.filter(device=self.device, number__lte=self.device.latest_shot.number) if update: task_name = update_single_table_attribute else: task_name = insert_single_table_attribute shot_manager = get_backend_shot_manager_for_device(self.device) shot_timestamp = shot_manager().get_timestamp_for_shot group( (task_name.s(self.device.slug, shot.number, shot_timestamp(shot.number), attr_slug) for shot in shot_queryset), ).apply_async()
def add_shot(self, shot, update=False): """Add shot to summary database. Arguments: shot (h1ds.models.Shot or shot number) Keyword arguments: force_overwrite - if False: If the shot already exists then this will do nothing. - if True - overwrite any existing entries for shot """ if not isinstance(shot, Shot): shot = Shot(number=shot, device=self.device) new_shot = not self.shot_exists(shot) if not update and not new_shot: return table_attributes = self.get_attributes_from_table(filter_initial_attributes=True) if new_shot or not update: task_name = insert_table_attributes else: task_name = update_table_attributes # Hack workaround - see notes at top of file shot_manager = get_backend_shot_manager_for_device(self.device) shot_timestamp = shot_manager().get_timestamp_for_shot(shot.number) chord( (get_summary_attribute_data.s(self.device.slug, shot.number, a) for a in table_attributes), task_name.s(table_name=self.table_name, shot_number=shot.number, shot_timestamp=str(shot_timestamp)) ).apply_async()
def save(self, set_as_latest=False, populate_tree=True, *args, **kwargs): if not self.is_fallback: # TODO: don't set timestamp if it's already there. shot_manager = get_backend_shot_manager_for_device(self.device) self.timestamp = shot_manager().get_timestamp_for_shot(self.number) super(Shot, self).save(*args, **kwargs) if set_as_latest: self.set_as_latest_shot() if populate_tree: # need to set backend_module to None, as the model is not pickleable self.device.backend_module = None self.populate_tree() if not self.device.latest_shot: self.device.latest_shot = self self.device.save()