Пример #1
0
        def gen_icon_id():
            """generate a random icon id
            """

            icon_id = (self.icon_prefix +
                       get_rnd(n_digits=10, out_type=str, is_unique_seed=True))
            return icon_id
Пример #2
0
    def __init__(self, parent):
        self.parent = parent
        self.log = self.parent.log
        self.base_config = self.parent.base_config
        self.redis = self.parent.redis
        self.lock_namespace = self.parent.lock_namespace
        self.lock_prefix = self.parent.lock_prefix

        # expiration time for locks
        self.lock_timeout_sec = self.parent.lock_timeout_sec
        if self.lock_timeout_sec is None:
            self.lock_timeout_sec = 10
        self.lock_timeout_sec = int(ceil(self.lock_timeout_sec))

        # maximal nominal delay time for locking
        self.slow_lock_msec = self.parent.slow_lock_msec
        if self.slow_lock_msec is None:
            self.slow_lock_msec = 2500

        # lock counter for debugging
        self.n_locks = 0
        self.lock_id_prefix = 'lock_' + get_rnd(
            n_digits=6, out_type=str, is_unique_seed=True)

        return
Пример #3
0
 async def get_data_widget_type(self):
     data = {
         'rnd': get_rnd(),
         'time': get_time('msec'),
         'n_circ': 1,
         'anim_speed': 500,
     }
     return data
Пример #4
0
    def set_server_id(self):
        """derive a server id

           it is mandatory to have unique ids across servers, and so
           a randome number generator is used. for deployment,
           a larger a date/time msec prefix can be used
        """

        WebsocketBase.serv_id = (
            'serv_' + str(self.base_config.app_port) + '_' + get_rnd(
                n_digits=self.n_id_digits, out_type=str, is_unique_seed=True))

        return
Пример #5
0
def external_generate_events(self):
    time_now_sec = self.clock_sim.get_time_now_sec()

    if self.rnd_gen.random() < 0.001:
        new_event = {
            'id': get_rnd(n_digits=7, out_type=str),
            'start_time_sec': time_now_sec,
        }
        new_event['priority'] = random.randint(1, 3)

        if self.rnd_gen.random() < 0.1:
            new_event['name'] = 'alarm'
            new_event['icon'] = 'alarm.svg'
        elif self.rnd_gen.random() < 0.3:
            new_event['name'] = 'grb'
            new_event['icon'] = 'grb.svg'
        elif self.rnd_gen.random() < 0.5:
            new_event['name'] = 'hardware'
            new_event['icon'] = 'hardwareBreak.svg'
        elif self.rnd_gen.random() < 0.7:
            new_event['name'] = 'moon'
            new_event['icon'] = 'moon.svg'
        elif self.rnd_gen.random() < 1:
            new_event['name'] = 'sun'
            new_event['icon'] = 'sun.svg'

        # elif self.rnd_gen.random() < 0.6:
        #     new_event['name'] = 'dolphin'
        #     new_event['icon'] = 'dolphin.svg'
        # elif self.rnd_gen.random() < 0.8:
        #     new_event['name'] = 'eagle'
        #     new_event['icon'] = 'eagle.svg'
        # elif self.rnd_gen.random() < 1:
        #     new_event['name'] = 'chicken'
        #     new_event['icon'] = 'chicken.svg'

        self.external_events.append(new_event)

    self.redis.set(name='external_events', data=self.external_events)

    return
Пример #6
0
    def __init__(self, base_config, service_name, interrupt_sig):
        self.class_name = self.__class__.__name__
        service_name = (service_name if service_name is not None else self.class_name)
        super().__init__(service_name=service_name)

        self.log = LogParser(base_config=base_config, title=__name__)
        self.log.info([['g', ' - starting SchedulerStandalone ...']])

        self.base_config = base_config
        self.site_type = self.base_config.site_type
        self.clock_sim = self.base_config.clock_sim
        self.inst_data = self.base_config.inst_data

        self.service_name = service_name
        self.interrupt_sig = interrupt_sig

        self.tel_ids = self.inst_data.get_inst_ids(inst_types=['LST', 'MST', 'SST'])
        self.sub_array_insts = self.inst_data.get_sub_array_insts()

        self.no_sub_arr_name = self.base_config.no_sub_arr_name

        self.redis = RedisManager(
            name=self.class_name, base_config=self.base_config, log=self.log
        )

        self.debug = not True
        self.expire_sec = 86400 * 2  # two days
        # self.expire_sec = 5

        # self.max_n_obs_block = 4 if self.site_type == 'N' else 7
        # self.max_n_obs_block = min(self.max_n_obs_block, floor(len(self.tel_ids) / 4))

        # sleep duration for thread loops
        self.loop_sleep_sec = 1
        # minimal real-time delay between randomisations (once every self.loop_act_rate sec)
        self.loop_act_rate = max(int(2 / self.loop_sleep_sec), 1)

        self.max_n_cycles = 100
        self.min_n_sched_block = 2  # 2
        self.max_n_sched_block = 5  # 5
        self.min_n_obs_block = 1
        self.max_n_obs_block = 5
        self.min_n_tel_block = 4
        self.max_n_free_tels = 5

        self.name_prefix = get_rnd(n_digits=5, out_type=str)

        self.az_min_max = [-180, 180]
        self.zen_min_max_tel = [0, 70]
        self.zen_min_max_pnt = [0, 20]

        self.phases_exe = {
            'start': [
                'run_config_mount', 'run_config_camera', 'run_config_DAQ',
                'run_config_mirror'
            ],
            'during': ['run_take_data'],
            'finish': ['run_finish_mount', 'run_finish_camera', 'run_finish_cleanup'],
        }

        self.error_rnd_frac = {
            'E1': 0.3,
            'E2': 0.4,
            'E3': 0.5,
            'E4': 0.6,
            'E5': 0.7,
            'E6': 0.8,
            'E7': 0.9,
            'E8': 1,
        }

        self.phase_rnd_frac = {
            'start': 0.29,
            'finish': 0.1,
            'cancel': 0.06,
            'fail': 0.1,
        }

        # 1800 = 30 minutes
        self.obs_block_sec = 1800

        self.n_init_cycle = -1
        self.n_nights = -1

        self.update_name = 'obs_block_update'
        self.sched_block_prefix = 'sched_block_'
        self.obs_block_prefix = 'obs_block_'

        rnd_seed = get_rnd_seed()
        self.rnd_gen = Random(rnd_seed)

        self.external_clock_events = []
        external_generate_clock_events(self)

        self.redis.delete(self.update_name)

        self.init()

        # make sure this is the only active instance
        self.init_active_instance()

        self.setup_threads()

        return