Beispiel #1
0
    def __init__(self):

        self.const = Constants()

        self.f_raw_requests_per_day = 'data/RequestsPerDay.csv'
        self.f_parsed_requests_per_day = 'data/ParsedRequestsPerDay.csv'
        self.f_raw_requests_per_month = 'data/RequestsPerMonth.csv'
        self.f_parsed_requests_per_month = 'data/ParsedRequestsPerMonth.csv'
        self.f_parsed_requests_per_month = 'data/ParsedRequestsOverTime.csv'
    def init(self):
        constants = Constants()
        self.gridResolution = constants.getGridSize()

        self.topLat = constants.corners[0][0]
        self.bottomLat = constants.corners[2][0]

        self.leftLon = constants.corners[0][1]
        self.rightLon = constants.corners[1][1]
Beispiel #3
0
    def __init__(self):

        self.constants = Constants()

        self._querystartlink = None
        self._queryendlink = None

        self._imagestartlink = None
        self._summarystartlink = None
class DbNode():

    logger = logging.getLogger('dbnodelogger')
    logger.setLevel(logging.DEBUG)
    ch = logging.FileHandler('dbnode.log', 'w')
    formatter = logging.Formatter(
        '[%(asctime)s] %(message)s %(funcName)s:%(lineno)d')
    ch.setFormatter(formatter)
    logger.addHandler(ch)

    constants = Constants()
    zk = KazooClient(hosts='172.25.0.101:2181')
    flask_port = None

    def __init__(self):
        super().__init__()

        DbNode.zk.add_listener(DbNode.connection_listener)
        DbNode.zk.start()
        self.add_myself_to_zookeeper()

    @staticmethod
    def print_error(e):
        print(DbNode.constants.ERROR_PREFIX + e.__str__())

    def add_myself_to_zookeeper(self):
        hostname = socket.gethostname()
        ip = socket.gethostbyname(hostname)
        # ToDo: Remove this after testing
        # ip = '127.0.0.1'
        try:
            # print(ip)
            # print(DbNode.flask_port)
            node_data = {'ip': ip, 'flask_port': DbNode.flask_port}
            DbNode.zk.ensure_path("/nodes")
            DbNode.zk.create("/nodes/node",
                             str.encode(json.dumps(node_data)),
                             ephemeral=True,
                             sequence=True)
            # print('Added myself to /nodes, children list:')
            child_node_list = DbNode.zk.get_children('/nodes')
            if child_node_list:
                print('subnode list:{}'.format(child_node_list))
        except Exception as e:
            DbNode.print_error(e)
        pass

    @staticmethod
    def connection_listener(state):

        if state == KazooState.LOST:
            print('session lost')
        elif state == KazooState.SUSPENDED:
            print('session suspended')
        else:
            print('running in state {}'.format(state))
Beispiel #5
0
def log_control(size = 100000):
    '''limit the number of lines of logfile to size//2 once size is reached'''
    path_log = Constants().files().get("logs.log")

    with open(path_log) as pf:
        data = pf.readlines()
    if len(data) > size:
        size //= -2
        with open(path_log, "w+") as pf:
            pf.writelines(data[size:])
Beispiel #6
0
def test_get_model_error():
    data1 = [[2, 3, 1], [99, 99, 2], [-1, -4, 3], [99, 99, 4]]
    data2 = [[3, 4, 1], [-2, -5, 3]]

    eval.const = Constants()
    eval.const.set_features(2)

    result = eval.get_model_error(data1, data2)

    assert result is not None
Beispiel #7
0
 def load_stopwords(self):
     constants = Constants()
     with open(constants.path_stopwords +
               constants.file_stopwords) as csvfile:
         readcsv = csv.reader(csvfile, delimiter=',')
         for row in readcsv:
             stopword = row[0]
             enabled = row[1]
             stopword = Stopword(stopword, enabled)
             self.stopwords.append(stopword)
    def init(self):
        constants = Constants()
        self.gridResolution = constants.getGridSize()

        self.topLat = constants.corners[0][0]
        self.bottomLat = constants.corners[2][0]
        self.centerLat = self.bottomLat + (self.topLat - self.bottomLat) / 2

        self.leftLon = constants.corners[0][1]
        self.rightLon = constants.corners[1][1]
        self.centerLon = self.leftLon + (self.rightLon - self.leftLon) / 2
def main():

    # RUN TRAINING LOOP

    c = Constants()  # run with default params

    run = Trainer(c)

    run.test()
    run.train()
    run.close()
Beispiel #10
0
class TestAttachment(TestCase):
    c = Constants()

    def _deleteOrCreateTestRecord(self):
        client = ServiceNowClient(self.c.server, self.c.credentials)
        gr = client.GlideRecord('problem')
        gr.add_query('short_description', 'Unit Test - Attachments')
        gr.query()
        if gr.next():
            return gr
        gr.initialize()
        gr.short_description = "Unit Test - Attachments"
        gr.description = "Second Field"
        gr.insert()
        return gr

    def _getOrCreateEmptyTestRecord(self):
        client = ServiceNowClient(self.c.server, self.c.credentials)
        gr = client.GlideRecord('problem')
        gr.add_query('short_description', 'Unit Test - Attachments - Empty')
        gr.query()
        if gr.next():
            return gr
        gr.initialize()
        gr.short_description = "Unit Test - Attachments - Empty"
        gr.description = "Second Field"
        gr.insert()
        return gr

    def test_attachments_for(self):
        gr = self._getOrCreateEmptyTestRecord()
        attachments = gr.get_attachments()
        print(attachments)
        self.assertNotEquals(attachments, None)
        self.assertEquals(len(attachments), 0)

    def test_add_delete(self):
        client = ServiceNowClient(self.c.server, self.c.credentials)
        with TempTestRecord(client, 'problem') as gr:
            attachments = gr.get_attachments()
            self.assertNotEquals(attachments, None)
            self.assertEquals(len(attachments), 0)

            content = "this is a sample attachment"
            gr.add_attachment('test.txt', content)

            attachments = gr.get_attachments()
            self.assertEquals(len(attachments), 1)

            for a in attachments:
                self.assertEquals(a.file_name, 'test.txt')
                f = a.getAsFile()
                self.assertEquals(f.read(), content.encode('utf-8'))
                a.delete()
Beispiel #11
0
    def __init__(self, mapSize):
        self._map = Map(mapSize)
        self._C = Constants()

        self._playerTurn = False
        self._playerPosition = {"x": mapSize * .5, "y": mapSize * .5}

        self._attack = False

        self._playerInCombat = False
        self._playerMovementDirection = self._C.NoMovement
Beispiel #12
0
    def __init__(self: object, max_conn: int) -> object:
        """
		This constructor sets up all required address and
		preliminary configurations.
		"""
        self.FAIL_SAFE_ADDRESS = ('', 8006)
        self.protocols = Constants()
        self.set_up_logger('failsafe-coordinator')
        self.max_conn = max_conn
        self.connected_clients = 0
        self.commit = False
        self.clients = {}
Beispiel #13
0
def quit_driver(driver=None):
    '''
    Quits a selenium driver. If driver is running in
    docker, it stops the docker containers.
    @param driver: selenium driver to quit
    '''
    logger.info('Quitting {} driver'.format(driver))
    const = Constants()
    if driver is not None:
        driver.quit()
    if const.get_docker() is True:
        selenium_docker_container.stop_docker()
Beispiel #14
0
    def __init__(self):

        self.const = Constants()
        self.input_path = self.const.song_dataset
        self.feature_path = self.const.feature_path
        self.output_path = self.const.clustered_music
        self.api_key = self.const.musixmatch_api_key
        self.features = None
        self.details = None
        self.valence = []
        self.arousal = []
        self.clusters = []
Beispiel #15
0
    def __init__(self, handle):
        activity.Activity.__init__(self, handle)
        #flags for controlling the writing to the datastore
        self.I_AM_CLOSING = False
        self.I_AM_SAVED = False
        self.props.enable_fullscreen_mode = False
        self.ui = None
        Constants(self)
        #self.modify_bg(gtk.STATE_NORMAL, Constants.color_black.gColor)

        #wait a moment so that our debug console capture mistakes
        gobject.idle_add(self._initme, None)
Beispiel #16
0
 def load_grammar_rules(self):
     constants = Constants()
     with open(constants.path_grammar_rules +
               constants.file_grammar_rules) as csvfile:
         readcsv = csv.reader(csvfile, delimiter=',')
         for row in readcsv:
             ref = row[0]
             file = row[1]
             category = row[2]
             enabled = row[3]
             grammar = Grammar(ref, file, category, enabled)
             self.grammar_rules.append(grammar)
Beispiel #17
0
 def initialize_channel_parameters(self, assumption_flag = "iid"):
     from constants import Constants
     import numpy as np
     const = Constants()
     self.lambda_id_array = np.ones((self.SOURCE_NUM,), dtype = float)
     if assumption_flag == "iid":
         self.lambda_ij_array = const.LAMBDA_interval[0] + \
         (const.LAMBDA_interval[1]-const.LAMBDA_interval[0])*np.random.rand(self.SOURCE_NUM)
     elif assumption_flag == "niid":
         self.lambda_ij_array = const.LAMBDA_interval[0] + \
         (const.LAMBDA_interval[1]-const.LAMBDA_interval[0])*np.random.rand(self.SOURCE_NUM,self.RELAY_NUM)
     self.lambda_jd_array = const.LAMBDA_interval[0] + \
     (const.LAMBDA_interval[1]-const.LAMBDA_interval[0])*np.random.rand(self.RELAY_NUM,self.SOURCE_NUM)
Beispiel #18
0
    def __init__(self):
        constants = Constants()

        self._stats = constants.PlayerDefaults
        self._equipment = {
            "body": 0,
            "legs": 0,
            "arms": 0,
            "hands": 0,
            "feet": 0
        }

        self._activeEnemy = None
	def __init__(self: object, max_connections: int, fail_safe_address: str) -> object:
		""" 
		This constructor sets up all the required address 
		and preliminary configurations.
		"""
		self.SERVER_ADDRESS = ('', 8005)
		self.FAIL_SAFE_ADDRESS = (fail_safe_address, 8006)
		self.max_connections = max_connections
		self.clients = {}
		self.connected_clients = 0
		self.commit = 0
		self.protocols = Constants()
		self.set_up_logger('main-coordinator')
def generate_manifest(data_dir, mode):
    const = Constants(data_dir, mode)
    # verify the provided path and generate underlying substructure
    EnvGenerator.generate_directories(data_dir)
    logging.debug(
        f"path_datadir == {str(const.get_path_data_dir().resolve())}")
    logging.debug(
        f"path_dataset == {str(const.get_path_data_set().resolve())}")
    logging.debug(
        f"path_calculators == {str(const.get_path_calculators().resolve())}")

    # with a validate data directory structure, we can build the manifest.json
    EnvGenerator.generate_manifest(data_dir, mode)
Beispiel #21
0
class TestAuth(TestCase):
    c = Constants()

    def test_basic(self):
        client = ServiceNowClient(self.c.server, self.c.credentials)
        gr = client.GlideRecord('sys_user')
        gr.fields = 'sys_id'
        self.assertTrue(gr.get('6816f79cc0a8016401c5a33be04be441'))

    def test_basic_fail(self):
        client = ServiceNowClient(self.c.server, ('admin', 'this is not a real password'))
        try:
            gr = client.GlideRecord('sys_user')
            gr.get('does not matter')
            assert 'Exception should have been thrown'
        except exceptions.AuthenticationException as e:
            self.assertTrue('User Not Authenticated' in str(e))
            self.assertTrue('Required to provide Auth information' in str(e))
        except Exception:
            assert 'Should have got an Auth exception'

    def test_oauth(self):
        # Manual setup using legacy oauth
        server = self.c.server
        creds = self.c.credentials

        client_id = '3e57bb02663102004d010ee8f561307a' #mobile

        # get the secret manually
        secret_url = '%s/api/now/mobileapp/plugin/secret' % server
        r = requests.get(secret_url, auth=creds)
        if r.status_code != 200:
            raise Exception('couldnt get secret')
        secret = r.json()['result']['secret']
        self.assertIsNotNone(secret)

        oauth = OAuth2Session(client=LegacyApplicationClient(client_id=client_id))
        token = oauth.fetch_token(token_url='%s/oauth_token.do' % server,
                              username=creds[0], password=creds[1], client_id=client_id,
                              client_secret=secret)

        client = ServiceNowClient(self.c.server, oauth)
        gr = client.GlideRecord('sys_user')
        gr.fields = 'sys_id'
        self.assertTrue(gr.get('6816f79cc0a8016401c5a33be04be441'))

    def test_oauth_builtin(self):
        client = ServiceNowClient(self.c.server, ServiceNowOAuth2(self.c.credentials))
        gr = client.GlideRecord('sys_user')
        gr.fields = 'sys_id'
        self.assertTrue(gr.get('6816f79cc0a8016401c5a33be04be441'))
Beispiel #22
0
 def mapStaticSensors(self, map_obj, plotColor):
     constants = Constants()
     staticCoords = constants.staticSensorCoords()
     plotSensors(map_obj, staticCoords, plotColor)
     for i in range(staticCoords.shape[0]):
         folium.CircleMarker(
             (staticCoords[i][0], staticCoords[i][1]),
             radius=8,
             color='#000000',
             weight=1.0,
             fill_color='#000000',
             fill=True,
             fill_opacity=1,
         ).add_to(map_obj)
    def __init__(self: object,
                 address: str,
                 fail_safe_addr: str = None,
                 timeout: int = 45) -> object:
        """
		This constructor sets up all required address and
		preliminary configurations.
		"""
        self.SERVER_ADDRESS = (address, 8005)
        self.FAIL_SAFE_ADDRESS = (fail_safe_addr, 8006)
        self.protocols = Constants()
        self.timeout = timeout
        self.database_connector = DatabaseConnection()
        self.set_up_logger('participant')
Beispiel #24
0
 def mapExistingSensors(self, map_obj, plotColor):
     constants = Constants()
     existingCoords = constants.getExistingSensorCoords()
     existingNames = constants.getExistingSensorNames()
     #self.plotSensors(map_obj, existingCoords, plotColor)
     for i in range(existingCoords.shape[0]):
         folium.CircleMarker(
             (existingCoords[i][0], existingCoords[i][1]),
             radius=8,
             color=plotColor,
             weight=1.0,
             fill_color=plotColor,
             fill=True,
             fill_opacity=1,
         ).add_child(folium.Popup(existingNames[i])).add_to(map_obj)
Beispiel #25
0
    def test_AlternativeReplacements(self):

        constantJson = {
            'sets': {},
            'specials': {},
            'alternative_names': {
                'carda': 'ca',
                'card b': ['cb', 'cb b']
            }
        }

        with TempJson(constantJson) as json:
            c = Constants(json)
            self.assertEqual(c.translateAlt("ca"), "carda")
            self.assertEqual(c.translateAlt("cb"), "cardb")
            self.assertEqual(c.translateAlt("cc"), "cc")
Beispiel #26
0
    def test_RefreshCardDB(self):
        cardDict = {
            'Quick Shot': {
                'type': 'Spell',
                'hpwn': 14459,
                'cdn': 'https://media-Hearth.cursecdn.com/14459.png',
                'desc': 'Deal 3 damage. Draw a card.',
                'hp': 1,
                'class': 'Hunter',
                'subType': "Mech",
                'set': 'Basic',
                'rarity': 'Common',
                'atk': 3,
                'head': 'quick-shot',
                'name': 'Quick Shot',
                'cost': 2
            }
        }

        constantDict = {
            'sets': {
                '01': {
                    'name': 'Basic'
                }
            },
            'specials': {},
            'alternative_names': {}
        }

        with TempJson(constantDict) as constJson, \
                TempJson(cardDict) as cardJson, \
                TempJson({}) as emptyJson:

            c = Constants(constJson)
            db = CardDB(constants=c,
                        cardJSON=emptyJson,
                        tokenJSON=emptyJson,
                        tempJSON='notexisting.json')

            self.assertEqual(db.cardNames(), [])
            self.assertFalse('quickshot' in db)

            db.tempJSON = cardJson
            db.refreshTemp()

            self.assertTrue('quickshot' in db)
            self.assertTrue('Quick Shot' in db['quickshot'])
Beispiel #27
0
    def __init__(self):
        self.c = Constants()
        self.sm = SceneManager()
        self.mm = MainMenu()
        self.sm.push(self.mm) # Pushing here makes sure the object types are consistent.
        pygame.init()
        pygame.mixer.pre_init(frequency=44100, size=16, channels=2, buffer=312)
        
        self.dt = 0

        # Doublebuf makes use of a better memory management, thus it will increase performance.
        self.screen = pygame.display.set_mode((self.c.screen_width, self.c.screen_height), pygame.DOUBLEBUF) 
        self.screen_rect = self.screen.get_rect()
        pygame.display.set_caption("Game")
        self.fps = 60
        self.clock = pygame.time.Clock()
        self.last_time = time.time()
Beispiel #28
0
    def results(self, age, price, awar, acc, pfmn, size, mtbf):
        con = Constants()

        seg = self._SEGMENT[self.segment]

        pfmn_i = con.pfmn(self.round, self.segment)
        size_i = con.size(self.round, self.segment)

        dif_ideal = math.sqrt(pow(pfmn - pfmn_i, 2) + pow(size - size_i, 2))
        dif_age = age - con.age(self.segment)
        dif_mtbf = mtbf - con.mtbf(self.segment)
        dif_price = price - con.price(self.round, self.segment)

        return (self._CONSTANT[seg] + self._IDEAL[seg] * dif_ideal +
                self._AGE[seg] * dif_age + self._MTBF[seg] * dif_mtbf +
                self._ACC[seg] * (100 * acc) + self._AWAR[seg] * (100 * awar) +
                self._PRICE[seg] * dif_price)
def main():
    log.debug('main() hearthscan-bot starting')

    # load constant values
    constants = Constants()
    # init answered comments sqlite DB
    answeredDB = commentDB.DB()
    # load card DB
    url = 'https://raw.githubusercontent.com/d-schmidt/hearthscan-bot/master/data/tempinfo.json'
    cardDB = CardDB(constants=constants, tempJSONUrl=url)
    # init hs helper for hearthstone stuff
    helper = HSHelper(cardDB, constants)
    # pm spam filter cache
    pmUserCache = {}

    def submissionListener(r, submission):
        answerSubmission(submission, helper)

    def commentListener(r, comment):
        answerComment(r, comment, answeredDB, helper)

    def mentionListener(r, comment):
        answerMention(r, comment, answeredDB, helper)

    def pmListener(r, message):
        answerPM(r, message, pmUserCache, helper)

    def postAction():
        cleanPMUserCache(pmUserCache)
        cardDB.refreshTemp()

    try:
        RedditBot(subreddits=credentials.subreddits,
                    newLimit=250,
                    connectAttempts=5,
                    userBlacklist=set(credentials.userBlacklist)) \
                .withSubmissionListener(submissionListener) \
                .withCommentListener(commentListener) \
                .withMentionListener(mentionListener) \
                .withPMListener(pmListener) \
                .run(postAction)
    except:
        log.exception('main() RedditBot failed unexpectedly')
    finally:
        log.warning('main() leaving hearthscan-bot')
        answeredDB.close()
Beispiel #30
0
    def __init__(self, bot):
        self.bot = bot
        self.view = View()
        self.data = Constants()
        self.dishes = Constants.DISHES_TYPES

        @self.bot.message_handler(commands=["start"])
        def _process_start_message(message):
            self.process_start_message(message)

        @self.bot.message_handler(content_types=["text"])
        def _process_user_message(message):
            self.process_user_message(message)

        @self.bot.callback_query_handler(func=lambda call: True)
        def _process_callback(call):
            self.process_callback(call)