def configuration_time_used(summary, observation_type):
    """ Calculates the block bounded time completed for time accounting purposes """
    configuration_time = timedelta(seconds=0)
    configuration_time += summary.end - summary.start

    if observation_type == RequestGroup.RAPID_RESPONSE:
        base_duration = timedelta(
            seconds=get_configuration_duration(summary.configuration_status.configuration.as_dict())['duration']
        )
        request_overheads = configdb.get_request_overheads(summary.configuration_status.configuration.instrument_type)
        base_duration += timedelta(seconds=(request_overheads['front_padding'] / len(summary.configuration_status.observation.request.configurations.all())))
        configuration_time = min(configuration_time, base_duration)

    return configuration_time
    def get_remaining_duration(self,
                               configurations_after_priority,
                               include_current=False):
        request_dict = self.as_dict()
        start_time = (min([
            window['start'] for window in request_dict['windows']
        ]) if 'windows' in request_dict and request_dict['windows'] else
                      timezone.now())
        try:
            configurations = sorted(request_dict['configurations'],
                                    key=lambda x: x['priority'])
        except KeyError:
            configurations = request_dict['configurations']
        duration = get_total_complete_configurations_duration(
            configurations, start_time, configurations_after_priority)
        if include_current:
            previous_optical_elements = {}
            for configuration_dict in configurations:
                if configuration_dict[
                        'priority'] == configurations_after_priority:
                    request_overheads = configdb.get_request_overheads(
                        configuration_dict['instrument_type'])
                    # Add the exposure overhead for the current configuration (no front padding)
                    duration += get_configuration_duration(
                        configuration_dict,
                        request_overheads,
                        include_front_padding=False)['duration']
                    # Add in the optical element change overhead for any changes within this configuration
                    duration += get_optical_change_duration(
                        configuration_dict, request_overheads,
                        previous_optical_elements)
                    break
                else:
                    previous_optical_elements = configuration_dict[
                        'instrument_configs'][-1].get('optical_elements', {})

        return duration
 def duration(self):
     request_overheads = configdb.get_request_overheads(
         self.instrument_type)
     return get_configuration_duration(self.as_dict(),
                                       request_overheads)['duration']
示例#4
0
 def duration(self):
     return get_configuration_duration(self.as_dict())['duration']