Exemple #1
0
def load_thing_classes(dr: DataRiver, thing_class_dir: str):
    tcr = JSonThingClassRegistry()
    for entry in os.scandir(thing_class_dir):
        if entry.is_file() and entry.path.endswith('.json'):
            log.info(f'Loading thing class: {entry.path}')
            try:
                tcr.register_thing_classes_from_uri(f'file://{entry.path}')
            except Exception as e:
                log.error(f'Unable to load thing class: {entry.path} : {e}')
                pass
    dr.add_thing_class_registry(tcr)
Exemple #2
0
def load_tag_groups(dr: DataRiver, tag_group_dir: str):
    tgr = JSonTagGroupRegistry()

    for entry in os.scandir(tag_group_dir):
        if entry.is_file() and entry.path.endswith('.json'):
            log.info(f'Loading tag group: {entry.path}')
            try:
                tgr.register_tag_groups_from_uri(f'file://{entry.path}')
            except Exception as e:
                log.error(f'Unable to load tag group: {entry.path} : {e}')
                pass
    dr.add_tag_group_registry(tgr)
 def __enter__(self):
     self._datariver = DataRiver.get_instance()
     self._dispatcher = Dispatcher()
     self._new_thing_discovered_listener = NewThingDiscoveredListener(self._datariver)
     self._thing = self.create_thing()
     
     return self
Exemple #4
0
 def __enter__(self):
     self._datariver = DataRiver.get_instance()
     self._thing = self.create_thing()
     
     print('Rotational Speed Sensor started')
     
     return self
    def __enter__(self):
        self._datariver = DataRiver.get_instance()
        self._thing = self.create_thing()

        print('Distance Service started')

        return self
Exemple #6
0
    def __enter__(self):
        self._datariver = DataRiver.get_instance()
        self._thing = self.create_thing()

        print('Fuel Level Sensor started')

        return self
Exemple #7
0
    def __enter__(self):
        self._dr = DataRiver.get_instance()
        self._thing = self.create_thing()

        print('Temperature Sensor started')

        return self
Exemple #8
0
    def __enter__(self):
        self._datariver = DataRiver.get_instance()
        self._thing = self.create_thing()

        print('Throughput writer started')

        return self
Exemple #9
0
    def __init__(self,
                 config_uri: str = '',
                 properties_str: str = '',
                 tag_group_dir: str = './definitions/TagGroup',
                 thing_class_dir: str = './definitions/ThingClass',
                 tag_groups: List = [],
                 thing_cls: List = []):
        assert len(properties_str) > 0, f"Config properties must be defined"
        for f in map(lambda tg: path.join(tag_group_dir, f'{tg}.json'),
                     tag_groups):
            assert path.exists(f), f"Can't find Tag Group: {f}"
        for f in map(lambda tc: path.join(thing_class_dir, f'{tc}.json'),
                     thing_cls):
            assert path.exists(f), f"Can't find Thing Class: {f}"

        self.__config_uri = config_uri if config_uri and len(
            config_uri) > 0 else get_river_config_uri()
        self.__properties_str = properties_str
        self.__tag_group_dir = tag_group_dir
        self.__thing_class_dir = thing_class_dir
        self.__tags_groups = tag_groups
        self.__thing_cls = thing_cls
        self.__dr = DataRiver.get_instance(self.__config_uri)
        self.__thing = self.__create_thing()
        self.__terminate = False
    def __enter__(self):
        self._dr = DataRiver.get_instance()
        self._thing = self.create_thing()

        print('Video Stream receiver started')

        return self
Exemple #11
0
def register_thing_classes(dr: DataRiver, thing_class_dir: str,
                           thing_classes: List[str]):
    '''
    For each of the Thing Classes listed in thing_classes and whose definition is in thing_class_dir register them
    with the provided instance of the Data River; dr.

    The thing_classes list shoudl be the name of the file without the .json extension
    '''
    tcr = JSonThingClassRegistry()

    for tc in thing_classes:
        logging.info(f'Loading Thing Class: {tc}.json from {thing_class_dir}')
        tcr.register_thing_classes_from_uri(
            get_abs_file_uri(str(os.path.join(thing_class_dir, f'{tc}.json'))))

    dr.add_thing_class_registry(tcr)
Exemple #12
0
def register_tag_groups(dr: DataRiver, tag_group_dir: str,
                        tag_groups: List[str]):
    '''
    For each of the Tag Groups listed in tag_groups and whose definition is in tag_groups_dir register them with
    the provided instance of the Data River; dr.

    The tag_groups list should be the name of the file without the .json extension
    '''
    tgr = JSonTagGroupRegistry()

    for tg in tag_groups:
        logging.info(f'Loading Tag Group: {tg}.json from {tag_group_dir}')
        tgr.register_tag_groups_from_uri(
            get_abs_file_uri(str(os.path.join(tag_group_dir, f'{tg}.json'))))

    dr.add_tag_group_registry(tgr)
Exemple #13
0
 def __enter__(self):
     self._datariver = DataRiver.get_instance()
     self._thing = self.create_thing()
     
     print('Camera started')
     self.set_state('on')
     
     return self
Exemple #14
0
def create_thing(dr: DataRiver, properties_str: str):
    '''
    Given a string for a Thing, instantiate it in the provided DataRiver and return it.
    '''
    tp = JSonThingProperties()
    tp.read_properties_from_string(properties_str)

    return dr.create_thing(tp)
Exemple #15
0
def main():
    params = vars(create_argparser())

    data_river = DataRiver.get_instance(get_river_config_uri())

    if params['tag_groups'] is not None:
        load_tag_groups(data_river, params['tag_groups'])

    if params['thing_classes'] is not None:
        load_thing_classes(data_river, params['thing_classes'])

    tgr = data_river.discovered_tag_group_registry

    tcr = data_river.discovered_thing_class_registry
    print('Thing Classes')
    print('_____________')
    for tc in tcr.thing_classes:
        print(f'    {tc.name}')
        model = map_thing_class(tc, tgr)
        Path(tc.context).mkdir(parents=True, exist_ok=True)
        with open(os.path.join(tc.context, f'{tc.name}.json'), 'w') as outfile:
            json.dump(model.to_dict(), outfile)