<commit_before>from astropy import units as u
import time


def on_enter(event_data):
    """ The unit is tracking the target. Proceed to observations. """
    pan = event_data.model
    pan.say("Checking our tracking")

    target = pan.observatory.current_target

    # Make sure we have a target
    if target.current_visit is not None:

        # Get the delay for the RA and Dec and adjust mount accordingly.
        for direction in ['ra', 'dec']:

            # Adjust the rate
            # Adjust RA rate. NOTE: Dec not implemented for iOptron yet
            if direction == 'ra':
                delta_ra_rate = target._offset_info.get('delta_ra_rate', 0.0)
                if delta_ra_rate != 0.0:
                    pan.logger.debug("Delta RA Rate: {}".format(delta_ra_rate))
                    pan.say("I'm adjusting the tracking rate")
                    pan.observatory.mount.set_tracking_rate(delta=delta_ra_rate)
                    time.sleep(0.5)  # Make sure command goes through

            # delta_dec_rate = target._offset_info.get('delta_dec_rate', 0.0)
            # pan.logger.debug("Delta Dec Rate: {}".format(delta_dec_rate))

            # Now adjust for existing offset
            key = '{}_ms_offset'.format(direction)
            pan.logger.debug("{}".format(key))

            if key in target._offset_info:
                pan.logger.debug("Check offset values for {} {}".format(direction, target._offset_info))

                # Add some offset to the offset
                ms_offset = target._offset_info.get(key, 0)
                if isinstance(ms_offset, u.Quantity):
                    ms_offset = ms_offset.value

                ms_offset = int(ms_offset)
                pan.logger.debug("Checking {} {}".format(key, ms_offset))

                # Only adjust a reasonable offset
                if abs(ms_offset) > 20.0 and abs(ms_offset) <= 5000.0:

                    # One-fourth of time. FIXME
                    processing_time_delay = int(ms_offset / 4)
                    pan.logger.debug("Processing time delay: {}".format(processing_time_delay))

                    ms_offset = ms_offset + processing_time_delay
                    pan.logger.debug("Total offset: {}".format(ms_offset))

                    if direction == 'ra':
                        if ms_offset > 0:
                            direction_cardinal = 'west'
                        else:
                            direction_cardinal = 'east'
                    elif direction == 'dec':
                        if ms_offset > 0:
                            direction_cardinal = 'north'
                        else:
                            direction_cardinal = 'south'

                    pan.say("I'm adjusting the tracking by just a bit to the {}.".format(direction_cardinal))
                    # Now that we have direction, all ms are positive
                    ms_offset = abs(ms_offset)

                    move_dir = 'move_ms_{}'.format(direction_cardinal)
                    move_ms = "{:05.0f}".format(ms_offset)
                    pan.logger.debug("Adjusting tracking by {} to direction {}".format(move_ms, move_dir))

                    pan.observatory.mount.serial_query(move_dir, move_ms)

                    # The above is a non-blocking command but if we issue the next command (via the for loop)
                    # then it will override the above, so we manually block for one second
                    time.sleep(abs(ms_offset) / 1000)
                else:
                    pan.logger.debug("Offset not in range")<commit_msg>Fix dec adjustment<commit_after>from astropy import units as u
import time


def on_enter(event_data):
    """ The unit is tracking the target. Proceed to observations. """
    pan = event_data.model
    pan.say("Checking our tracking")

    target = pan.observatory.current_target

    # Make sure we have a target
    if target.current_visit is not None:

        # Get the delay for the RA and Dec and adjust mount accordingly.
        for direction in ['ra', 'dec']:

            # Adjust the rate
            # Adjust RA rate. NOTE: Dec not implemented for iOptron yet
            if direction == 'ra':
                delta_ra_rate = target._offset_info.get('delta_ra_rate', 0.0)
                if delta_ra_rate != 0.0:
                    pan.logger.debug("Delta RA Rate: {}".format(delta_ra_rate))
                    pan.say("I'm adjusting the tracking rate")
                    pan.observatory.mount.set_tracking_rate(delta=delta_ra_rate)
                    time.sleep(0.5)  # Make sure command goes through

            # delta_dec_rate = target._offset_info.get('delta_dec_rate', 0.0)
            # pan.logger.debug("Delta Dec Rate: {}".format(delta_dec_rate))

            # Now adjust for existing offset
            key = '{}_ms_offset'.format(direction)
            pan.logger.debug("{}".format(key))

            if key in target._offset_info:
                pan.logger.debug("Check offset values for {} {}".format(direction, target._offset_info))

                # Add some offset to the offset
                ms_offset = target._offset_info.get(key, 0)
                if isinstance(ms_offset, u.Quantity):
                    ms_offset = ms_offset.value

                ms_offset = int(ms_offset)
                pan.logger.debug("Checking {} {}".format(key, ms_offset))

                # Only adjust a reasonable offset
                if abs(ms_offset) > 20.0 and abs(ms_offset) <= 5000.0:

                    # One-fourth of time. FIXME
                    processing_time_delay = int(ms_offset / 4)
                    pan.logger.debug("Processing time delay: {}".format(processing_time_delay))

                    ms_offset = ms_offset + processing_time_delay
                    pan.logger.debug("Total offset: {}".format(ms_offset))

                    if direction == 'ra':
                        if ms_offset > 0:
                            direction_cardinal = 'west'
                        else:
                            direction_cardinal = 'east'
                    elif direction == 'dec':
                        if ms_offset > 0:
                            direction_cardinal = 'south'
                        else:
                            direction_cardinal = 'north'

                    pan.say("I'm adjusting the tracking by just a bit to the {}.".format(direction_cardinal))
                    # Now that we have direction, all ms are positive
                    ms_offset = abs(ms_offset)

                    move_dir = 'move_ms_{}'.format(direction_cardinal)
                    move_ms = "{:05.0f}".format(ms_offset)
                    pan.logger.debug("Adjusting tracking by {} to direction {}".format(move_ms, move_dir))

                    pan.observatory.mount.serial_query(move_dir, move_ms)

                    # The above is a non-blocking command but if we issue the next command (via the for loop)
                    # then it will override the above, so we manually block for one second
                    time.sleep(abs(ms_offset) / 1000)
                else:
                    pan.logger.debug("Offset not in range")
{'fraction_non_alphanumeric': 0.09019009296517275, 'fraction_numerical': 0.0074927154155681975, 'mean_word_length': 1.593738754947823, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3094022', 'n_tokens_mistral': 1966, 'n_tokens_neox': 1786, 'n_words': 517}