def __init__(self,
                 index,
                 actionFn=None,
                 numTraining=100,
                 alpha=0.5,
                 gamma=0.9,
                 partialObs=True,
                 epsilon=0.0,
                 exploration="True",
                 shareQ=True):
        """
        :param index: int, agent index
        :param actionFn: func, function to get list of legal actions
        :param numTraining: int, number of training episodes
        :param alpha: float, learning rate
        :param gamma: float, discount factor
        :param partialObs: bool, whether the agent takes partial observation
        """
        self.index = index
        if actionFn is None:
            actionFn = lambda state: state.getLegalActions(agentIndex=index)
        self.actionFn = actionFn
        self.accumTrainRewards = 0.0
        self.accumTestRewards = 0.0
        self.numTraining = int(numTraining)
        self.alpha = float(alpha)
        self.gamma = float(gamma)

        self.partialObs = string_to_bool(partialObs)
        self.shareQ = string_to_bool(shareQ)
        if self.shareQ:
            global shared_q
            shared_q = util.Counter()
            global shared_weights
            shared_weights = util.Counter()

        self.epsilon = float(epsilon)
        self.exploration = string_to_bool(exploration)
        if self.epsilon == 0 and not self.exploration:
            raise Exception(
                "Need either epsilon-greedy or exploration function for exploration"
            )
        if self.epsilon != 0 and self.exploration:
            raise Exception(
                "Cannot have both epsilon-greedy and exploration function for exploration"
            )
        self.N = util.Counter()

        self.q_values = util.Counter()  # Map (state, action) to value

        # Episode records
        self.lastState = None
        self.lastAction = None
        self.episodeRewards = 0.0
        self.episodesSoFar = 0
Example #2
0
    def get_content_by_location_identifier(self, request):
        db = CSVDataProvider()
        system = check_auth(self, request, db)

        language = request.language.split('-')[0]

        #initialize response
        response = EndUserScanResponseMessage()

        #get marker
        marker = db.get_marker(request.location_identifier)

        #get spot connected to marker
        spot = db.get_spot(marker.spot_id)

        #get content
        content = db.get_content_by_id(spot.content)
        content_message = content.to_enduser_message(language,
                                                     system,
                                                     full=True)

        #set status flags
        #on the CSV backend both always have to be true
        response.has_spot = bool_to_string(True)
        response.has_content = bool_to_string(True)

        #get system name
        system_name = system.name
        l_infos = system.localized_information
        for info in l_infos:  #try to find selected language
            if info.language == content_message.language:
                system_name = info.display_name

        #get settings
        settings = db.get_settings()
        response.app_id_google_play = settings[1]
        response.app_id_itunes = settings[0]

        #render message
        response.system_name = system_name
        response.system_url = system.base_url  #not needed in apps or wordpress
        response.system_id = 1  #always 1, because this is single tenant

        response.content = content_message

        #render message
        if string_to_bool(request.include_style):
            response.style = content.style.to_enduser_message()

        if string_to_bool(request.include_menu):
            response.menu = db.get_menu().to_enduser_message(
                content_message.language, system, db)

        return response
def create_parser():
    '''
    Defines script's arguments.
    '''
    parser = argparse.ArgumentParser(
        description=(
            'Edits the settings.json file ruling the heater behavior.'
        )
    )
    parser.add_argument(
        '-a', '--auto',
        help='Set auto to ON. Turns ON heater according to program.'
    )
    parser.add_argument(
        '-l', '--loglevel',
        help='Defines the log level for logger in scripts.',
        type=str
    )
    parser.add_argument(
        '-m', '--manual',
        help='Set manual to ON. Turns ON heater.'
    )
    parser.add_argument(
        '-p', '--program',
        help='Insert the program number you wish to load.',
    )
    parser.add_argument(
        '-t', '--temperature',
        help='Insert the desired temperature when in manual mode.',
        type=float
    )
    args = parser.parse_args()
    logger.debug(
        f'manual: {args.manual}; auto: {args.auto}; program: {args.program};'
    )
    args.manual = util.string_to_bool(args.manual, parser)
    args.auto = util.string_to_bool(args.auto, parser)
    logger.debug(
        f'manual: {args.manual}; auto: {args.auto}; program: {args.program};'
    )
    if (
        args.auto is None and
        args.loglevel is None and
        args.manual is None and
        args.program is None and
        args.temperature is None
    ):
        raise parser.error(
            'Please enter at least one argument.'
            " Type '--help' for more information."
        )

    return args
Example #4
0
    def get_content_by_location_identifier(self, request):
        db = CSVDataProvider()
        system = check_auth(self,request,db)
        
        language = request.language.split('-')[0]
        
        #initialize response
        response = EndUserScanResponseMessage()
        
        #get marker
        marker = db.get_marker(request.location_identifier)
        
        #get spot connected to marker
        spot = db.get_spot(marker.spot_id)
        
        #get content
        content = db.get_content_by_id(spot.content)
        content_message = content.to_enduser_message(language, system, full=True)
        
        #set status flags
        #on the CSV backend both always have to be true
        response.has_spot = bool_to_string(True)
        response.has_content = bool_to_string(True)
        
        #get system name
        system_name = system.name
        l_infos = system.localized_information
        for info in l_infos: #try to find selected language
            if info.language == content_message.language:
                system_name = info.display_name
        
        #get settings
        settings = db.get_settings()
        response.app_id_google_play = settings[1]
        response.app_id_itunes = settings[0]

        #render message
        response.system_name = system_name
        response.system_url = system.base_url #not needed in apps or wordpress
        response.system_id = 1 #always 1, because this is single tenant
        
        response.content = content_message
        
        #render message
        if string_to_bool(request.include_style):
            response.style = content.style.to_enduser_message()
        
        if string_to_bool(request.include_menu):
            response.menu = db.get_menu().to_enduser_message(content_message.language, system, db)

        return response
Example #5
0
    def get_content_by_content_id_full(self, request):
        db = CSVDataProvider()
        system = check_auth(self, request, db)

        request.language = request.language.split('-')[0]

        content_id = request.content_id

        response = EndUserSignleContentResponseMessage()

        #get Content
        content = db.get_content_by_id(content_id)

        #deliver full content?
        full = True if hasattr(
            request,
            "full") == True and request.full != None and string_to_bool(
                request.full) == True else False

        content_message = content.to_enduser_message(request.language,
                                                     system,
                                                     full=full)
        response.content = content_message

        #get system name
        system_name = system.name
        l_infos = system.localized_information
        for info in l_infos:  #try to find selected language
            if info.language == content_message.language:
                system_name = info.display_name

        #get settings
        settings = db.get_settings()
        response.app_id_google_play = settings[1]
        response.app_id_itunes = settings[0]

        #render message
        response.system_name = system_name
        response.system_url = system.base_url  #not needed in apps or wordpress
        response.system_id = 1  #always 1, because this is single tenant

        if string_to_bool(request.include_style):
            response.style = content.style.to_enduser_message()

        if string_to_bool(request.include_menu):
            response.menu = db.get_menu().to_enduser_message(
                content_message.language, system, db)

        return response
Example #6
0
    def get_content_by_content_id_full(self, request):
        db = CSVDataProvider()
        system = check_auth(self,request,db)

        request.language = request.language.split('-')[0]

        content_id = request.content_id
        
        response = EndUserSignleContentResponseMessage()

        #get Content
        content = db.get_content_by_id(content_id)

        #deliver full content?
        full = True if hasattr(request,"full") == True and request.full != None and string_to_bool(request.full) == True else False

        content_message = content.to_enduser_message(request.language, system, full=full)
        response.content = content_message
        
        #get system name
        system_name = system.name
        l_infos = system.localized_information
        for info in l_infos: #try to find selected language
            if info.language == content_message.language:
                system_name = info.display_name
                
        #get settings
        settings = db.get_settings()
        response.app_id_google_play = settings[1]
        response.app_id_itunes = settings[0]

        #render message
        response.system_name = system_name
        response.system_url = system.base_url #not needed in apps or wordpress
        response.system_id = 1 #always 1, because this is single tenant

        
        if string_to_bool(request.include_style):
            response.style = content.style.to_enduser_message()
        
        if string_to_bool(request.include_menu):
            response.menu = db.get_menu().to_enduser_message(content_message.language, system, db)

        return response
        
    def __store_args_or_set_to_defaults(self, args, defaults):

        LOGGER.debug('Setting the attributes:')

        # Useful for read and write:

        if args['handle_server_url']:
            self.__handle_server_url = args['handle_server_url']
            LOGGER.info(' - handle_server_url set to '+self.__handle_server_url)
        else:
            self.__handle_server_url = defaults['handle_server_url']
            LOGGER.info(' - handle_server_url set to default: '+self.__handle_server_url)


        if args['REST_API_url_extension']:
            self.__REST_API_url_extension = args['REST_API_url_extension']
            LOGGER.info(' - url_extension_REST_API set to: '+self.__REST_API_url_extension)
        else:
            self.__REST_API_url_extension = defaults['REST_API_url_extension']
            LOGGER.info(' - url_extension_REST_API set to default: '+self.__REST_API_url_extension)


        if args['HTTPS_verify'] is not None:
            self.__HTTPS_verify = util.string_to_bool(args['HTTPS_verify'])
            LOGGER.info(' - https_verify set to: '+str(self.__HTTPS_verify))
        else:
            self.__HTTPS_verify = defaults['HTTPS_verify']
            LOGGER.info(' - https_verify set to default: '+str(self.__HTTPS_verify))


        # Useful for write:

        if args['password']:
            self.__password = args['password']
            LOGGER.info(' - password set.')

        if args['username']:
            self.__username = args['username']
            LOGGER.info(' - username set to: '+self.__username)

        if args['certificate_only']:
            self.__certificate_only = args['certificate_only']
            LOGGER.info(' - certificate_only set to: '+str(self.__certificate_only))

        if args['private_key']:
            self.__private_key = args['private_key']
            LOGGER.info(' - private_key set to: '+str(self.__private_key))

        if args['certificate_and_key']:
            self.__certificate_and_key = args['certificate_and_key']
            LOGGER.info(' - certificate_and_key set to: '+str(self.__certificate_and_key))
Example #8
0
    def get_spot_map(self, request):
        db = CSVDataProvider()
        system = check_auth(self,request,db)
        
        language = request.language.split('-')[0]

        spots = db.get_spot_map(request.map_tag)
        
        #check if spots should also deliver content
        include_content = False
        if hasattr(request,'include_content') == True and request.include_content != None:
            include_content = string_to_bool(request.include_content)

        items = [s.to_enduser_message(language,system,include_content=include_content) for s in spots]
        
        return EnduserSpotMapResponseMessage(items=items,style=db.get_style().to_enduser_message())
Example #9
0
    def get_spot_map(self, request):
        db = CSVDataProvider()
        system = check_auth(self, request, db)

        language = request.language.split('-')[0]

        spots = db.get_spot_map(request.map_tag)

        #check if spots should also deliver content
        include_content = False
        if hasattr(
                request,
                'include_content') == True and request.include_content != None:
            include_content = string_to_bool(request.include_content)

        items = [
            s.to_enduser_message(language,
                                 system,
                                 include_content=include_content)
            for s in spots
        ]

        return EnduserSpotMapResponseMessage(
            items=items, style=db.get_style().to_enduser_message())
Example #10
0
    def load_content(self):
        content_data = self.__read_csv("content")
        localized_content_data = self.__read_csv("content_localized")
        contentblocks_data = self.__read_csv("content_blocks")
        style_sys_data = self.__read_csv("system_style")[0]

        #load style
        ## READ STYLE
        style = SystemStyle()
        self.__fill_members_with_csv_data(
            style, ('fg_color', 'bg_color', 'hl_color', 'ch_color', 'icon',
                    'custom_marker'), style_sys_data)

        #load content
        self.content = {}
        for item in content_data:
            c = Content()
            self.__fill_members_with_csv_data(
                c, ('content_id', 'name', 'image_name', 'tags', 'category'),
                item)
            c.tags = c.tags.split(',')  #split tags
            c.category = int(c.category)  #parse category to int
            c.style = style

            self.content[c.content_id] = c  #add to content items

        #load localized info
        for item in localized_content_data:
            lang = LocalizedContentInformation()
            self.__fill_members_with_csv_data(
                lang, ('content_id', 'language', 'title', 'description'), item)

            #add to right content
            if self.content.has_key(item[0]):
                self.content[item[0]].localized_content_information[
                    item[1]] = lang
            else:
                logging.warn(
                    "Localized Content Data with invalid content id: " +
                    item[0])

        #load content blocks
        for item in contentblocks_data:
            #they have to be parsed in a special way,because they vary in terms of fields
            b = ContentBlock()
            b.content_id = item[0]
            b.content_block_type = int(item[2])
            b.public = string_to_bool(item[3])

            if b.content_block_type == ContentBlockTypes.TEXT:
                b.title = item[4]
                b.text = item[5]
            elif b.content_block_type == ContentBlockTypes.AUDIO:
                b.title = item[4]
                b.artists = item[5]
                b.file_id = item[6]
            elif b.content_block_type == ContentBlockTypes.VIDEO:
                b.title = item[4]
                b.youtube_url = item[5]
            elif b.content_block_type == ContentBlockTypes.IMAGE:
                b.title = item[4]
                b.file_id = item[5]
                b.scale_x = float(item[6])
                b.alt_text = item[7]
            elif b.content_block_type == ContentBlockTypes.LINK:
                b.title = item[4]
                b.text = item[5]
                b.link_type = int(item[6])
                b.link_url = item[7]
            elif b.content_block_type == ContentBlockTypes.EBOOK:
                b.title = item[4]
                b.artists = item[5]
                b.file_id = item[6]
            elif b.content_block_type == ContentBlockTypes.CONTENT:
                b.title = item[4]
                b.content_id = item[5]
            elif b.content_block_type == ContentBlockTypes.SOUNDCLOUD:
                b.title = item[4]
                b.soundcloud_url = item[5]
            elif b.content_block_type == ContentBlockTypes.DOWNLOAD:
                b.title = item[4]
                b.text = item[5]
                b.download_type = int(item[6])
                b.file_id = item[7]
            elif b.content_block_type == ContentBlockTypes.SPOTMAP:
                b.title = item[4]
                b.spot_map_tag = item[5]
            else:
                raise Exception("Unknown Content Block Type: " +
                                str(b.content_block_type))

            #add to right content and lang
            if self.content.has_key(item[0]):
                if self.content[item[0]].localized_content_information.has_key(
                        item[1]):
                    self.content[item[0]].localized_content_information[
                        item[1]].content_blocks.append(b)
                else:
                    logging.warn("Content Block Data with invalid lang: " +
                                 item[0] + "/" + item[1])
            else:
                logging.warn("Content Block Data with invalid content id: " +
                             item[0])
Example #11
0
 def __init__(self, index, partialObs=False, **kwargs):
     self.index = index
     self.partialObs = string_to_bool(partialObs)
Example #12
0
    def __store_args_or_set_to_defaults(self, args, defaults):

        LOGGER.debug('Setting the attributes:')

        if args['HTTPS_verify'] is not None: # Without this check, a passed "False" is not found!
            self.__HTTPS_verify = util.string_to_bool(args['HTTPS_verify'])
            LOGGER.info(' - https_verify set to: '+str(self.__HTTPS_verify))
        else:
            self.__HTTPS_verify = defaults['HTTPS_verify']
            LOGGER.info(' - https_verify set to default: '+str(self.__HTTPS_verify))

        if args['allowed_search_keys'] is not None: # Without this check, empty lists are not found!
            self.__allowed_search_keys = args['allowed_search_keys']
            LOGGER.info(' - allowed_search_keys set to: '+str(self.__allowed_search_keys))
        else:
            self.__allowed_search_keys = defaults['allowed_search_keys']
            LOGGER.info(' - allowed_search_keys set to default: '+str(self.__allowed_search_keys))

        if args['reverselookup_baseuri']:
            self.__reverselookup_baseuri = args['reverselookup_baseuri']
            LOGGER.info(' - solrbaseurl set to: '+self.__reverselookup_baseuri)
        elif 'handle_server_url' in args.keys() and args['handle_server_url'] is not None:
            self.__reverselookup_baseuri = args['handle_server_url']
            LOGGER.info(' - solrbaseurl set to same as handle server: '+str(self.__reverselookup_baseuri))
        else:
            LOGGER.info(' - solrbaseurl: No default.')

        if args['reverselookup_url_extension']:
            self.__reverselookup_url_extension = args['reverselookup_url_extension']
            LOGGER.info(' - reverselookup_url_extension set to: '+self.__reverselookup_url_extension)
        else:
            self.__reverselookup_url_extension = defaults['reverselookup_url_extension']
            LOGGER.info(' - reverselookup_url_extension set to default: '+self.__reverselookup_url_extension)

        # Authentication reverse lookup:
        #   If specified, use it.
        #   Else: Try using handle system authentication
        #   Else: search_handle does not work and will raise an exception.

        if args['reverselookup_username']:
            self.__user = args['reverselookup_username']
            LOGGER.info('" - reverselookup_username set to: '+self.__user)
        elif args['username']:
            self.__user = args['username']
            self.__handle_system_username_used = True
            LOGGER.info(' - reverselookup_username set to handle server username: '******' - reverselookup_username: No default.')

        if args['reverselookup_password']:
            self.__password = args['reverselookup_password']
            LOGGER.info(' - reverselookup_password set.')
        elif args['password']:
            self.__password = args['password']
            self.__handle_system_password_used = True
            LOGGER.info(' - reverselookup_password set to handle server password.')
        else:
            LOGGER.info(' - reverselookup_password: No default.')

        if self.__user is not None and self.__password is not None:
            self.__has_search_access = True
Example #13
0
 def load_content(self):
     content_data = self.__read_csv("content")
     localized_content_data = self.__read_csv("content_localized")
     contentblocks_data = self.__read_csv("content_blocks")
     style_sys_data = self.__read_csv("system_style")[0]
     
     #load style
     ## READ STYLE
     style = SystemStyle()
     self.__fill_members_with_csv_data(style,('fg_color','bg_color','hl_color','ch_color','icon','custom_marker'),style_sys_data)
     
     #load content
     self.content = {}
     for item in content_data:
         c = Content()
         self.__fill_members_with_csv_data(c,('content_id','name','image_name','tags','category'),item)
         c.tags = c.tags.split(',') #split tags
         c.category = int(c.category) #parse category to int
         c.style = style
     
         self.content[c.content_id] = c #add to content items
     
     #load localized info
     for item in localized_content_data:
         lang = LocalizedContentInformation()
         self.__fill_members_with_csv_data(lang,('content_id','language','title','description'),item)
         
         #add to right content
         if self.content.has_key(item[0]):
             self.content[item[0]].localized_content_information[item[1]] = lang
         else:
             logging.warn("Localized Content Data with invalid content id: " + item[0])
             
     #load content blocks
     for item in contentblocks_data:
         #they have to be parsed in a special way,because they vary in terms of fields
         b = ContentBlock()
         b.content_id = item[0]
         b.content_block_type = int(item[2])
         b.public = string_to_bool(item[3])
         
         if b.content_block_type == ContentBlockTypes.TEXT:
             b.title = item[4]
             b.text = item[5]
         elif b.content_block_type == ContentBlockTypes.AUDIO:
             b.title = item[4]
             b.artists = item[5]
             b.file_id = item[6]
         elif b.content_block_type == ContentBlockTypes.VIDEO:
             b.title = item[4]
             b.youtube_url = item[5]
         elif b.content_block_type == ContentBlockTypes.IMAGE:
             b.title = item[4]
             b.file_id = item[5]
             b.scale_x = float(item[6])
             b.alt_text = item[7]
         elif b.content_block_type == ContentBlockTypes.LINK:
             b.title = item[4]
             b.text = item[5]
             b.link_type = int(item[6])
             b.link_url = item[7]
         elif b.content_block_type == ContentBlockTypes.EBOOK:
             b.title = item[4]
             b.artists = item[5]
             b.file_id = item[6]
         elif b.content_block_type == ContentBlockTypes.CONTENT:
             b.title = item[4]
             b.content_id = item[5]
         elif b.content_block_type == ContentBlockTypes.SOUNDCLOUD:
             b.title = item[4]
             b.soundcloud_url = item[5]
         elif b.content_block_type == ContentBlockTypes.DOWNLOAD:
             b.title = item[4]
             b.text = item[5]
             b.download_type = int(item[6])
             b.file_id = item[7]
         elif b.content_block_type == ContentBlockTypes.SPOTMAP:
             b.title = item[4]
             b.spot_map_tag = item[5]
         else:
             raise Exception("Unknown Content Block Type: " + str(b.content_block_type))
             
         #add to right content and lang
         if self.content.has_key(item[0]):
             if self.content[item[0]].localized_content_information.has_key(item[1]):
                 self.content[item[0]].localized_content_information[item[1]].content_blocks.append(b)
             else:
                 logging.warn("Content Block Data with invalid lang: " + item[0] + "/" + item[1])
         else:
             logging.warn("Content Block Data with invalid content id: " + item[0])