Example #1
0
 def test_nested(self):
     """Tests for nested Params."""
     a = Params()
     a.define("x", 0, "")
     self.assertEqual(str(a), "{\n  x: 0\n}")
     b = Params()
     a.define("y", b, "")
     b.define("z", "z", "")
     self.assertEqual(str(a), '{\n  x: 0\n  y: {\n    z: "z"\n  }\n}')
     self.assertRaises(AttributeError, lambda: a.get("w"))
     self.assertEqual(a.get("x"), 0)
     self.assertEqual(type(a.get("y")), Params)
     self.assertRaises(AttributeError, lambda: a.get("y.w"))
     self.assertEqual(a.get("y.z"), "z")
     self.assertRaises(AttributeError, lambda: a.get("y.z.w"))
Example #2
0
    def __init__(self, environment, general_nn=None, inherit_nn=None):
        self.params = Params()
        if self.params.seed:
            seed(self.params.seed)
        self.creatures = []
        self.entity_grid = np.zeros(
            (self.params.grid_size, self.params.grid_size,
             4))  # 4 is for has_entity, id, strength, energy
        self.environment = environment
        if self.params.general_nn:  # T
            self.random_policy = True
        else:
            self.random_policy = False

        self.general_nn = general_nn
        self.inherit_nn = inherit_nn

        self.exploration_rate = self.params.exploration_rate

        for _ in range(self.params.starting_creatures):
            self.spawn_creature()

        if self.params.verbose:
            self.logs = Logs(self.environment)
            self.logs.log_run()
            self.logs.log_header()
            self.batch_counter = self.general_nn.align_counter  # starts 1
            self.logs_random = not self.params.logs_random and self.random_policy
class TestRegionMapper(unittest.TestCase):
    params = Params()
    params.retina_enabled = True
    params.retina_kwidth = 15
    params.s1_kwidth = 11
    params.s1_scaling = 2
    params.c1_kwidth = 5
    params.c1_scaling = 2
    params.s2_kwidth = 7
    params.c2_kwidth = 3
    params.c2_scaling = 2
    rm = RegionMapper(params)

    def testRetinaToImage(self):
        self.assertEqual(slice(0, 15), self.rm.MapRetinaToImage(slice(0, 1)))

    def testS1ToImage(self):
        self.assertEqual(slice(0, 25), self.rm.MapS1ToImage(slice(0, 1)))

    def testC1ToImage(self):
        self.assertEqual(slice(0, 33), self.rm.MapC1ToImage(slice(0, 1)))

    def testS2ToImage(self):
        self.assertEqual(slice(0, 57), self.rm.MapS2ToImage(slice(0, 1)))

    def testC2ToImage(self):
        self.assertEqual(slice(0, 73), self.rm.MapC2ToImage(slice(0, 1)))
Example #4
0
def test_matchzoo():
    
    params = Params()
    config_file = 'config/qalocal.ini'    # define dataset in the config
    params.parse_config(config_file)
    params.network_type = "anmm.ANMM"
    
    reader = qa.setup(params)
    qdnn = models.setup(params)
    model = qdnn.getModel()
    
    
    model.compile(loss = params.loss,
                optimizer = units.getOptimizer(name=params.optimizer,lr=params.lr),
                metrics=['accuracy'])
    model.summary()
    
#    generators = [reader.getTrain(iterable=False) for i in range(params.epochs)]
#    q,a,score = reader.getPointWiseSamples()
#    model.fit(x = [q,a],y = score,epochs = 1,batch_size =params.batch_size)
    
    def gen():
        while True:
            for sample in reader.getPointWiseSamples(iterable = True):
                yield sample
    model.fit_generator(gen(),epochs = 2,steps_per_epoch=1000)
Example #5
0
def run_evaluation(model_type):
    params = Params('params/' + model_type + '.json')
    
    score, scores = evaluate_actor_critic(params, 'models/' + model_type + '.pt')

    print('Average reward after 100 episodes: {0:.2f}'.format(score))
    plot_performance(scores)
Example #6
0
    def __init__(self):
        self.model = Model()
        self.params = Params()
        self.screen = Screen()

        self.fzf = FzfPrompt()
        self.info = ''
Example #7
0
 def test_eq_ne(self):
     """Tests equality methods."""
     a = Params()
     b = Params()
     self.assertEqual(a, b)
     a.define("x", 0, "")
     self.assertNotEqual(a, b)
     b.define("x", 0, "")
     self.assertEqual(a, b)
     a.x = 1
     self.assertNotEqual(a, b)
     a.x = 0
     self.assertEqual(a, b)
     c = Params()
     c.define("y", 0, "")
     self.assertNotEqual(b, c)
Example #8
0
    def __init__(self, answers, APP, nodeps = False, update = False, target_path = None, dryrun = False, **kwargs):
        run_path = os.path.dirname(os.path.realpath(__file__))
        self.dryrun = dryrun
        recursive = not nodeps

        app = APP #FIXME

        self.params = Params(recursive, update, target_path)
        self.utils = utils.Utils(self.params)

        if os.path.exists(app):
            logger.info("App path is %s, will be populated to %s" % (app, target_path))
            app = self.utils.loadApp(app)
        else:
            logger.info("App name is %s, will be populated to %s" % (app, target_path))
            
        if not target_path:
            if self.params.app_path:
                self.params.target_path = self.params.app_path
            else: 
                self.params.target_path = os.getcwd()

        self.params.app = app

        self.answers_file = answers
Example #9
0
    def __init__(self, address, protocol, vehicle):
        self.address = address
        self.vehicle = vehicle
        self.protocol = protocol

        # Queue is filled with incoming messages (receive_thread) and emptied by receive worker (receive_task_thread)
        self.msg_queue = Queue.Queue()

        # Loads the initial vehicle's values according to class Params
        self.vehicle_params = Params(network=self, vehicle=vehicle)

        # For collision avoidance purposes
        self.drones = []
        self.context = {'mode': None, 'mission': None, 'next_wp': None}
        self.priority = None

        # First entry in drones list will be our own vehicle
        self.drones.append(self.vehicle_params)

        # Normally it is kept as is until the first receive_thread
        # self.populate_drones('two_dummies')

        self.sock_send = None
        self.sock_receive = None

        # Create transceiver and worker threads
        self.t_send = SendThread(self, self.address)
        self.t_receive = ReceiveThread(self, self.msg_queue)
        self.t_task = ReceiveTaskThread(self, self.msg_queue)

        self.receive_count = self.t_receive.count
        self.task_count = self.t_task.count
Example #10
0
    def test_roi(self):
        """Upload an roi and test it's fields"""

        # Make a skeleton
        makeAnno(p, 9)

        # test the parent
        parent = random.randint(0, 65535)
        f = setField(p, 'parent', parent)
        f = getField(p, 'parent')
        assert parent == int(f.content)

        # make a bunch of children ROIs
        q = Params()
        q.token = 'unittest'
        q.resolution = 0
        q.channels = ['unit_anno']

        childids = []
        for i in range(0, 4):
            makeAnno(q, 9)
            f = setField(q, 'parent', p.annoid)
            childids.append(q.annoid)

        # Test children
        f = getField(p, 'children')
        rchildids = f.content.split(',')
        for cid in rchildids:
            assert int(cid) in childids
        assert len(rchildids) == 4
Example #11
0
    def __init__(self):
        self.params = Params()

        if self.params.seed:
            seed(self.params.seed)

        self.action_space = [i for i in range(self.params.action_size)]
        self.state_size = (self.params.vision_grid, self.params.vision_grid,
                           self.params.state_features)

        self.experience_replay = deque(maxlen=self.params.memory_size)

        self.run_counter = 1  # creature counter
        self.align_counter = 1  # batch retrain counter
        self.q_eval = DeepQNetwork()
        self.q_next = DeepQNetwork()

        # tensorboard
        if self.params.tensorboard:
            self.writer = self.board()
        self.cum_reward = 0

        self.align_target()
        self.random_action = True
        self.loss = 0
        self.agent_hash = randint(1, 10000000)
Example #12
0
    def test_node(self):
        """Upload a skeleton node and test it's fields"""

        # Make a node
        makeAnno(p, 7)

        # test the nodetype
        nodetype = random.randint(0, 100)
        f = setField(p, 'nodetype', nodetype)
        f = getField(p, 'nodetype')
        assert nodetype == int(f.content)

        # test the skeletonid
        skeletonid = random.randint(0, 65535)
        f = setField(p, 'skeletonid', skeletonid)
        f = getField(p, 'skeletonid')
        assert skeletonid == int(f.content)

        # test the pointid
        pointid = random.randint(0, 65535)
        f = setField(p, 'pointid', pointid)
        f = getField(p, 'pointid')
        assert pointid == int(f.content)

        # test the parentid
        parentid = random.randint(0, 65535)
        f = setField(p, 'parentid', parentid)
        f = getField(p, 'parentid')
        assert parentid == int(f.content)

        # test the radius
        radius = random.random()
        f = setField(p, 'radius', radius)
        f = getField(p, 'radius')
        assert abs(radius - float(f.content)) < 0.001

        # test the location
        location = [random.random(), random.random(), random.random()]
        f = setField(p, 'location', ','.join([str(i) for i in location]))
        f = getField(p, 'location')
        assert ','.join([str(i) for i in location]) == f.content

        # make a bunch of children
        q = Params()
        q.token = 'unittest'
        q.resolution = 0
        q.channels = ['unit_anno']

        childids = []
        for i in range(0, 4):
            makeAnno(q, 9)
            f = setField(q, 'parent', p.annoid)
            childids.append(q.annoid)

        # Test children
        f = getField(p, 'children')
        rchildids = f.content.split(',')
        for cid in rchildids:
            assert int(cid) in childids
        assert len(rchildids) == 4
Example #13
0
def make_sorted_gt():
    # only keep video snapshots that contain at least 10 face crops from each video.
    # the sorted gt will only include ground truth from videos that satistfies the minimal requirement.
    # im_list is a variable that saves a list of images, sorted by the ground truth's video sequence.
    # you may edit im_list to make a image list for caffe, or other frameworks.

    p = Params(config_path='params.cfg')
    cha_raw_gt = pd.read_pickle(p.cha_gt_file)
    new_gt = pd.DataFrame(columns=list(cha_raw_gt.columns.values))
    video_list = cha_raw_gt.index.tolist()

    face_img_names = listdir(p.crop_face_im_dir)
    im_list, im_count_list = [], []
    for cur_ind, cur_video in enumerate(video_list):
        if cur_ind % 100 == 0:
            print '{}-th video out of {}...'.format(cur_ind, len(video_list))
        pattern = cur_video[:-4]
        subset = fnmatch.filter(face_img_names, pattern+'*.jpg')
        if len(subset) > p.lower_bound_frame_num:
            im_list.extend(subset)
            im_count_list.append(len(subset))
            new_gt.loc[cha_raw_gt.index[cur_ind]] = cha_raw_gt.iloc[cur_ind]
        else:
            print 'video {} only contains {} image snapshots. Not included in the selection'.format(cur_video, len(subset))

    new_gt['img_frame_num'] = pd.Series(im_count_list, index=new_gt.index)
    new_gt.to_pickle(p.mapped_gt_file)
    print 'New gt length = {}'.format(len(new_gt))  # how many videos are kept.

    return
Example #14
0
def main(args):
    if args.debug:
        import pdb; pdb.set_trace()
    # objects
    radius = 5.0
    manip_obj = Circle(radius, Position(5.0,radius))
    finger0 = Circle(1.0, Position(-5.0, -5.0))
    finger1 = Circle(1.0, Position(15.0, -5.0))

    # initial contact information
    contact_state = OrderedDict([(finger0, Contact(f=(0.0, 0.0), ro=(-7., -7.), c=.5)),
                                 (finger1, Contact(f=(0.0, 0.0), ro=(7., -7.), c=.5))])
    goals = [Position(5.0, 20.0)]

    world = World(manip_obj, [finger0, finger1], contact_state)

    stage_weights=[StageWeights(w_CI=0.1, w_physics=0.1, w_kinematics=0.0, w_task=1.0),
                    StageWeights(w_CI=10.**1, w_physics=10.**0, w_kinematics=0., w_task=10.**1)]
    p = Params(world, K=10, delT=0.05, delT_phase=0.5, mass=1.0,
                    mu=0.9, lamb=10**-3, stage_weights=stage_weights)

    if args.single:
        stage_info = CIO(goals, world, p, single=True)
    else:
        stage_info = CIO(goals, world, p)

    if args.save:
        save_run(args.save, p, world, stage_info)
Example #15
0
def menu():
    url = load_wsdl_url()
    while True:
        print("Выберите операцию:")
        print("1. Сложение")
        print("2. Вычитание")
        print("3. Умножение")
        print("4. Деление")
        print("0. Выход")
        option = int(input())

        if option not in range(5):
            print("Неверный ввод!")
            continue
        if option == 0:
            break

        operation = ''
        if option == 1:
            operation = 'add'
        if option == 2:
            operation = 'sub'
        if option == 3:
            operation = 'mul'
        if option == 4:
            operation = 'div'
        print("Введите 1 операнд:")
        arg1 = input()
        print("Введите 2 операнд:")
        arg2 = input()
        params = Params(arg1, arg2, operation)
        print(f"Результат: {soap_request(url, params)}")
        print('---------------------------------')
Example #16
0
    def check_yaml(path: str) -> Params:
        import yaml

        yml = yaml.safe_load(open(path, 'r'))

        if (Checker.url(yml['url']) and Checker.tag_type(yml['tag_type'])
                and Checker.tag_identifier(yml['tag_identifier'])
                and Checker.tag_value(yml['tag_value'])
                and Checker.freq_val(yml['freq_val'])
                and Checker.freq_type(yml['freq_type'])):
            return Params(yml)
        else:
            if not Checker.url(yml['url']):
                print(f"URL '{yml['url']}' was not valid.")

            if not Checker.tag_type(yml['tag_type']):
                print(f"Tag type '{yml['tag_type']}' was not valid.")

            if not Checker.tag_identifier(yml['tag_identifier']):
                print(
                    f"Tag identifier '{yml['tag_identifier']}' was not valid.")

            if not Checker.tag_value(yml['tag_value']):
                print(f"'{yml['tag_value']}' was not valid.")

            if not Checker.freq_val(yml['freq_val']):
                print(f"Frequency '{yml['freq_val']}' was not valid.")

            if not Checker.freq_type(yml['freq_type']):
                print(f"Time measure '{yml['freq_type']}' was not valid.")
Example #17
0
def main():
    logging.basicConfig(filename='load_balancer.log', level=logging.INFO)
    logging.info('Started')

    #This takes input and validates it
    params = Params()

    #This is how you access the required params
    print params.vip_interface
    print params.vip_port
    print params.vip_ip
    print params.target_ip #do remember that the string eements of the list are in unicode
    print params.load_balancer_algorithm

    #After opening the socket, and receiving the entire packet in sampleFrame
    sampleFrame = '\x00\x02\x157\xa2D\x00\xae\xf3R\xaa\xd1\x08\x00E\x00\x00C\x00\x01\x00\x00@\x06x<\xc0\xa8\x05\x15B#\xfa\x97\x00\x14\x00P\x00\x00\x00\x00\x00\x00\x00\x00P\x02 \x00\xbb9\x00\x00GET /index.html HTTP/1.0 \n\n'
    
    #Instantiate the frame
    frame = Frame(sampleFrame)


    try:
        s = socket.socket( socket.AF_PACKET , socket.SOCK_RAW , socket.ntohs(0x0003))
        s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    except ValueError:
        print "cant open socket"
    print 'socket opened'

    s.bind(("virtual0",0))
    print 'socket binded to virtual0'
    
    logging.info('Finished')
Example #18
0
 def makeEvolutionMatrix(age):
     params = Params(age)
     matrix = EvolutionMatrix()
     matrix._matrix[State.EXPOSED][
         State.PRODROMIC_INFECTIOUS] = 1 / params['inv_epsilon']
     matrix._matrix[State.PRODROMIC_INFECTIOUS][
         State.ASYMPTOMATIC_INFECTIOUS] = params['p_a'] / params['inv_mu_p']
     matrix._matrix[State.PRODROMIC_INFECTIOUS][State.MILD_INFECTIOUS] = (
         1 - params['p_a']) * params['p_ms'] / params['inv_mu_p']
     matrix._matrix[State.PRODROMIC_INFECTIOUS][State.SEVERE_INFECTIOUS] = (
         1 - params['p_a']) * params['p_ss'] / params['inv_mu_p']
     matrix._matrix[State.PRODROMIC_INFECTIOUS][
         State.PAUCYSYMPTOMATIC_INFECTIOUS] = (
             1 - params['p_a']) * params['p_ps'] / params['inv_mu_p']
     matrix._matrix[State.ASYMPTOMATIC_INFECTIOUS][
         State.RECOVERED] = 1 / params['inv_mu']
     matrix._matrix[State.MILD_INFECTIOUS][
         State.RECOVERED] = 1 / params['inv_mu']
     matrix._matrix[State.PAUCYSYMPTOMATIC_INFECTIOUS][
         State.RECOVERED] = 1 / params['inv_mu']
     matrix._matrix[State.SEVERE_INFECTIOUS][
         State.HOSPITAL] = 1 / params['inv_mu'] * (1 - params['p_ICU'])
     matrix._matrix[State.SEVERE_INFECTIOUS][
         State.ICU] = 1 / params['inv_mu'] * (params['p_ICU'])
     matrix._matrix[State.HOSPITAL][State.DEAD] = params['lambda_H_D']
     matrix._matrix[State.HOSPITAL][State.RECOVERED] = params['lambda_H_R']
     matrix._matrix[State.ICU][State.DEAD] = params['lambda_ICU_D']
     matrix._matrix[State.ICU][State.RECOVERED] = params['lambda_ICU_R']
     matrix.set_diagonal()
     return matrix
Example #19
0
 def test_serialization(self):
     """Tests serialization methods."""
     p = Params()
     p.define("x", 0, "x desc")
     p.define("y", 1, "")
     p.y = 2
     self.assertEqual(p, Params.loads(p.dumps()))
Example #20
0
def AE(X, AE_Model, AE_Model_var):
    model = AE_Model_var
    if model == None:
        print('training')
        print('AE_Model', AE_Model)
        params = Params("hparams.yaml", AE_Model)
        net = getattr(models, params.model_name)
        input_dim = X.shape[-1]
        model = net(input_dim, l1_factor=params.l1_factor)
        X = X.astype('float32').values
        model.compile(loss=losses.mean_squared_error,
                      optimizer=Adam(lr=params.lr),
                      metrics=['mse'])
        training_logs = model.fit(X,
                                  X,
                                  epochs=params.num_epochs,
                                  verbose=0,
                                  batch_size=params.batch_size,
                                  shuffle=True)
    else:
        print('already trained')
        X = X.astype('float32').values

    preds = np.array(model.predict(X))
    mse = np.mean((X - preds)**2, axis=1)

    return mse, model
Example #21
0
def sample_all_video():
    start_time = time.time()
    p = Params(config_path='params.cfg')
    generate_mp4_list(p)

    if not os.path.exists(p.crop_full_im_dir):
        os.makedirs(p.crop_full_im_dir)

    if not os.path.exists(p.crop_face_im_dir):
        os.makedirs(p.crop_face_im_dir)

    with open(p.mp4_list_file) as f:  # Iteratively process all 6000 videos.
        file_list = f.readlines()

    face_counts_per_video = []
    time_points = np.linspace(0, p.video_total_msec, p.upper_bound_frame_num)
    face_cascade = cv2.CascadeClassifier(
        p.face_detector_file)  # initialize face detector
    for i, cur_v_path in enumerate(file_list):
        v_path = cur_v_path.strip()
        face_count = sample_one_video(v_path, p, time_points, face_cascade)
        face_counts_per_video.append(face_count)
        if i % 20 == 0:
            print 'Current video num {} out of {}. Total elapsed time: {} seconds. \n'.\
                format(i, len(file_list), time.time() - start_time)

    df = pd.DataFrame({
        'filename': file_list,
        'image_count': face_counts_per_video
    })
    df.to_pickle(p.sample_num_record_file)
    return
Example #22
0
def test_domain_2d(modelFile="tests/2dTests/test2d_for_intervals_single_delay.json"):
    
    if type(modelFile) == str:
        model = get_model_for_tests(modelFile)
    else:
        model = modelFile

    params = Params()

    # for funcNamesStack and bounds and ics from params
    params.set_params_for_centrals(model)
    
    params.set_params_for_bounds_2d(model)

    # for namesAndNumbers
    params.set_params_for_array()

    params.set_params_for_dom_centrals(model)
    try:
        params.set_params_for_dom_interconnects()
    except:
        pass

    params.set_params_for_dom_bounds(model)
    
    out = str(params.functionMaps)
    to_file(out, "from_test_domain_2d.txt")

    return(params.functionMaps)
Example #23
0
def run_inference(model_type):
    params = Params('params/' + model_type + '.json')
    
    score, scores = actor_critic_inference(params, 'models/' + model_type + '.pt')

    print('Total score: {0:.2f}'.format(score))
    plot_performance(scores)
Example #24
0
def test_template_definitions(modelFile="tests/brusselator1d_bound_U.json"):
    '''
    DESCRIPTION:
    Generate cpp for centrals from
    template.

    template in :
       'criminal/templates/definitions.template'

    out will be in:
       'tests/introduction/src/from_test_template_definitions.cpp'

    '''
    if type(modelFile) == str:
        model = get_model_for_tests(modelFile)
    else:
        model = modelFile

    # model = get_model_for_tests(modelFile)

    params = Params()
    cppGen = CppOutGen()

    # parameters for definitions
    params.set_params_for_definitions(model)
    
    out = cppGen.get_out_for_definitions(params)

    to_file(out, 'from_test_template_definitions.cpp')

    return(out)
Example #25
0
    def __init__(self):
        self.params = Params()
        self.y_boundary = None
        self.o_height = 400
        self.o_width = 400
        self.height = 400
        self.width = 400

        self.quit_command = False

        self.color = Color()

        self.click_pos_x = None
        self.click_pos_y = None

        self.gap = None
        self.box_size = None
        self.padding_width = None
        self.padding_height = None
        self.hovered_x = None
        self.hovered_y = None

        pygame.init()
        self.canvas = pygame.display.set_mode((self.width, self.height), pygame.RESIZABLE)
        pygame.display.set_caption('Ecosystem Simulator')

        self.mouse_pos_x = pygame.mouse.get_pos()[0]
        self.mouse_pos_y = pygame.mouse.get_pos()[1]
Example #26
0
    def __init__(self,
                 autogenerated,
                 entity_grid,
                 pos_x=None,
                 pos_y=None,
                 strength=None,
                 energy=None,
                 creature_id=None,
                 general_nn=None,
                 inherit_nn=None):
        self.params = Params()
        if self.params.seed:
            seed(self.params.seed)
        self.life_time = 1

        self.pos_x = pos_x
        self.pos_y = pos_y

        self.strength = strength
        self.energy = energy
        self.creature_id = creature_id

        self.inherit_nn = inherit_nn
        self.neural_net = general_nn

        if autogenerated:
            self.spawn_random(entity_grid)
def read_test_result_from_metrics_file(path: str) -> Result:
    els = path.split('/')
    filename = els[-1]
    classifier = els[-2]
    dirname = els[-3]
    stacked = '_on_' in dirname
    balanced = 'balanced_' in classifier
    to_binary = 'binary_' in classifier
    use_only_ab = '_using_only_ab' in dirname
    features_str = filename[:-len('_metrics.txt')]
    features = features_str.split('__')
    with open(path, 'r', encoding="utf-8") as f:
        lines = f.readlines()
        accuracy = float(lines[0].split(': ')[1])
        f1_score = None
        balanced_accuracy_adjusted = None
        for line in lines:
            if 'f1_score' in line:
                f1_score = float(line.split(': ')[1])
            if 'balanced_accuracy_adjusted' in line:
                balanced_accuracy_adjusted = float(line.split(': ')[1])

        metrics = Metrics(accuracy, balanced_accuracy_adjusted=balanced_accuracy_adjusted, f1_score=f1_score)
        # TODO read f1 scores and more here as well
        # TODO pca is hardset to False

        return Result(metrics=metrics,
                      params=Params(features=features, classifier=classifier, dirname=dirname, stacked=stacked,
                                    params={'balanced': balanced}, to_binary=to_binary, use_only_ab=use_only_ab,
                                    pca=False))
Example #28
0
    def on_press(self):
        _findchild = self.parent.findChild  # for leaner code

        url = _findchild(UrlInput, UrlInput.name).text()
        tag_type = _findchild(TagType, TagType.name).currentText()
        tag_identifier = _findchild(TagIdentifier,
                                    TagIdentifier.name).currentText()
        tag_value = _findchild(TagIdentifierValue,
                               TagIdentifierValue.name).text()
        freq_type = _findchild(FreqType, FreqType.name).currentText()
        freq_val = _findchild(FreqValue, FreqValue.name).value()

        if (Checker.url(url) and Checker.tag_type(tag_type)
                and Checker.tag_identifier(tag_identifier)
                and Checker.tag_value(tag_value) and Checker.freq_val(freq_val)
                and Checker.freq_type(freq_type)):
            # start monitoring
            params = Params({
                'url': url,
                'tag_type': tag_type,
                'tag_identifier': tag_identifier,
                'tag_value': tag_value,
                'freq_type': freq_type,
                'freq_val': freq_val,
            })
            monitor = Monitor(params)
            monitor.start_thread(self.on_html_tag_change)

            # insert result label
            self.result_lab = ResultLab(self.parent)
            _findchild(QHBoxLayout, 'row5').addWidget(self.result_lab)

            # start animation
            self.result_lab.animate()
        else:
            # handle error
            error_msg = "Your input had the following errors:\n"
            if not Checker.url(url):
                error_msg += f"- URL '{url}' was not valid. Make sure it's not empty, does not contain spaces and starts with 'http://'\n"

            if not Checker.tag_type(tag_type):
                error_msg += f"- Tag type '{tag_type}' is not a valid HTML tag.\n"

            if not Checker.tag_identifier(tag_identifier):
                error_msg += f"- Tag identifier '{tag_identifier}' must be either 'id' or 'class'.\n"

            if not Checker.tag_value(tag_value):
                error_msg += f"- Tag identifier '{tag_value}' must not be empty and must not contain spaces.\n"

            if not Checker.freq_val(freq_val):
                error_msg += f"- Frequency '{freq_val}' must be at least 1.\n"

            if not Checker.freq_type(freq_type):
                error_msg += f"- Time measure '{freq_type}' must be one of 'seconds', 'minutes' or 'hours'. Shortcuts 's', 'm' and 'h' are also accepted.\n"

            error_dialog = QMessageBox()
            error_dialog.setIcon(QMessageBox.Critical)
            error_dialog.setText(error_msg)
            error_dialog.setWindowTitle("Errore!")
            error_dialog.exec_()
Example #29
0
def calcular(bot, update):
    chat_id = update.message.chat_id
    data[chat_id] = Params()
    update.message.reply_text('Hola, ¿tipo de escritura?',
                              reply_markup=ReplyKeyboardMarkup(
                                  ESCRITURAS_KEYBOARD, one_time_keyboard=True))
    return CHECK_TIPO_ESCRITURA
Example #30
0
 def __init__(self, id, start, end, caps, subnet):
     IpRange.__init__(self, start, end)
     self.__id = id
     self.__start = start
     self.__end = end
     self.__caps = caps
     self.__subnet = subnet
     self.__params = Params(Context.RANGE)