def startFileValidate():
    print("Using this as terms file:%s" % termsfile)
    print("Using this as source document:%s" % xlfFile)
    if termsfile != "" and xlfFile != "":
        Validator.main(termsfile, xlfFile)

        root.destroy()
Example #2
0
    def process_file(self, inputfile, outputdir, filename):
        rename = str(filename).replace('.csv', '.txt')
        output_file = outputdir + "/" + rename
        failed = True
        csv_file = open(inputfile, 'r')
        csv_file1 = open(inputfile, 'r')
        input_file = csv.reader(csv_file, delimiter=',')
        input_file1 = csv.reader(csv_file1, delimiter=',')
        validator = Validator()
        header_problems = validator.header_validator(input_file1)
        value = len(header_problems)
        self.log.info("header validation completed with " + str(value) +
                      " problems")
        if value != 0:
            write_problems(header_problems, open(output_file, 'w'))
            Mail().send_mail(rename, output_file)
            return failed
        else:
            data_problems = validator.data_validator(input_file)
            value = len(data_problems)
            self.log.info("data validation completed with " + str(value) +
                          " problems")
            if value != 0:
                write_problems(data_problems, open(output_file, 'w'))
                Mail().send_mail(rename, output_file)
                return failed

        return False
Example #3
0
def performJob():


    # construct Train & Test Data
    xTrain, yTrain, xTest, yTest = DatasetManipulator.getTrainAndTestData()

    # training the classifier
    classifier = ClassifierTrainer.trainClassifier(xTrain, yTrain)

    #predicting
    yPred = classifier.predict(xTest)

    #assessing the performance
    Validator.performValidation(yPred, yTest)
Example #4
0
def Test_ValidateExpense():
    try:
        Validator.ValidateExpense({"day":2,"ammount":4.0,"category":"altele"})
        assert True
    except:
        assert False
    try:
        Validator.ValidateExpense("lala")
        assert False
    except:
        assert True
    try:
        Validator.ValidateExpense({"day":"ha","ammount":[],"category":0.0})
        assert False
    except:
        assert True
Example #5
0
def interpret_test(test):
    c = chain.Chain()
    b = mk_block_from_prevstate(c, timestamp=c.state.timestamp + 1)
    for tx in casper_init_txs:
        b.transactions.append(tx)
    
    c.add_block(b)
    head = c.head_hash
    validators = [Validator(privkey=sha3(str(i))) for i in range(20)]
    markers = {}
    txs = []
    
    for token in test.split(''):
        letters, numbers = re.match('([A-Za-z]*)([0-9]*)', token).groups()
        if letters+numbers != token:
            raise Exception("Bad token: %s" % token)
        numbers = int(numbers)
        # Adds a block to the current head
        if letters == 'B':
            if head == c.head:
                b = mk_block_from_prevstate(c, timestamp=c.state.timestamp + 1)
            else:
                s = c.mk_poststate_of_blockhash(head)
                b = mk_block_from_prevstate(c, state=s, timestamp=s.timestamp + 1)
            b.txs = txs
            c.add_block(b)
            txs = []
        # Saves a marker (eg "S5" creates a marker called 5 and sets the current head to that)
        elif letters == 'S':
            self.markers[numbers] = head
        # Changes the head to a marker (eg "C5" changes the head to the marker 5)
        elif letters == 'C':
            assert len(txs) == 0
            head = self.markers[numbers]
        # Adds a join transaction to the tx list (eg. "J5" adds a join for validator 5)
        elif letters == 'J':
            txs.append(validators[numbers].mk_join_transaction())
        # Adds a prepare to the tx list (eg. "P5" adds a prepare for validator 5)
        elif letters == 'P':
            txs.append(validators[numbers].mk_prepare())
        # Adds a commit to the tx list (eg. "C5" adds a commit for validator 5)
        elif letters == 'C':
            txs.append(validators[numbers].mk_commit())

    on_longest_chain = head == c.head_hash
    balances = {}
    active = {}
    for i in range(100):
        validator_addr = call_casper(c.head_state, 'get_validator__addr', i)
        if validator_addr in validator_lookup_map:
            balances[validator_lookup_map[validator_addr]] = call_casper(c.head_state, 'get_validator__deposit', i)
            active[validator_lookup_map[validator_addr]] = call_casper(c.head_state, 'is_validator_active', i)
    epoch = call_casper(c.head_state, 'get_current_epoch')
    total_deposits = call_casper(c.head_state, 'get_total_deposits', epoch)
    return {
        'on_longest_chain': on_longest_chain,
        'balances': balances,
        'active': active,
        'total_deposits': total_deposits
    }
def getUndefModMassesFromTopResults(connection, fracs, prob_cutoff=0.99):
    frac_ids = [fracs[0] for frac in fracs]

    undef_mods = defaultdict(list)

    stmt = select([results.c.mods
                   ]).where(results.c.fraction_id.in_(frac_ids)).where(
                       results.c.em_probability >= prob_cutoff)
    response = connection.execute(stmt)

    for row in response:
        mods = [
            mod for mod in eval(row[0]) if mod[0][0] != 'Isobaric Substitution'
        ]

        if len(mods) == 1 and mods[0][0][0] == 'Undefined Mass Shift':
            undef_mods[Validator.getUniqueModTuple(mods)[0]].add(mods[0])

    # Now calculate masses of mods as average of undef mods binned together
    for undef_mod in undef_mods:
        mod_mass = sum([mod[0][1] for mod in undef_mods[undef_mod]]) / len(
            undef_mods[undef_mod])
        undef_mods[undef_mod] = ('Undefined Mass Shift', mod_mass, ())

    return undef_mods
Example #7
0
 def test_email_invalid_inputs(self):
     emails = [
         "plainaddress",
         "#@%^%#$@#$@#.com",
         "@example.com",
         "Joe Smith <*****@*****.**>",
         "email.example.com",
         "email@[email protected]",
         "*****@*****.**",
         "*****@*****.**",
         "*****@*****.**",
         "[email protected]",
         "[email protected] (Joe Smith)",
         "email@example",
         "*****@*****.**",
         "*****@*****.**",
         "[email protected]",
         "*****@*****.**",
         "*****@*****.**",
     ]
     failed = []
     for email in emails:
         if not Validator.is_email(email):
             failed.append(email)
     if len(failed) > 0:
         self.fail("Accidentally Validated: " + str(failed))
Example #8
0
    def XML_Reader(self, file_Location, error_File_Location):
        MyValidator = Validator()
        my_Employees = {}
        tree = ET.parse(file_Location)
        root = tree.getroot()
        for user in root.findall('user'):
            # Need to Validate all given data
            empid = user.get('EMPID')
            gender = user.find('gender').text
            age = MyValidator.Validate_Age(user.find('age').text)
            sales = user.find('sales').text
            bmi = user.find('BMI').text
            salary = user.find('salary').text
            birthday = MyValidator.Validate_Birthday(
                user.find('birthday').text, age)
            #For each item in new Employee need to check that they have a value after being vlaidated

            #new_Employee = Employee(empid, gender, int(age), int(sales), bmi, int(salary), birthday)
            #my_Employees[new_Employee.EMPID] = new_Employee
        return my_Employees
Example #9
0
def Test_ValidateCommandId():
    try:
        Validator.ValidateCommandId("5")
        assert True
    except:
        assert False
    try:
        Validator.ValidateCommandId("-1")
        assert False
    except:
        assert True
    try:
        Validator.ValidateCommandId("%$#&")
        assert False
    except:
        assert True
    try:
        Validator.ValidateCommandId("60")
        assert False
    except:
        assert True
Example #10
0
def filterToFDR(proc_tag_graph, desired_fdr=0.01, write_roc=False):
    scores, crit = [], []

    for item in proc_tag_graph.values():
        scores += [float(item['Alignment Score'])]
        crit += [0] if item['Decoy Status'] == 'Yes' else [1]

    sens, prec, score_cutoffs = Validator.getSensitivityAndPrecisionArrs(np.array(scores), np.array(crit), numPoints=200)
    
    if write_roc:
        Validator.writeSensitivityAndPrecisionToFile(np.array(scores), sens, prec, getOutputName(outBase, 'ROC', '.tdv'))
    
    # This logic is not very pythonic
    # Maximize sensitivity if under the desired FDR, else just try to minimize the FDR
    sens_under, under_ind = 0, -1
    fdr_over, over_ind = 1, -1
    for i in range(len(prec)):
        if sens[i] > 0:
            fdr = 1 - prec[i]
            
            if fdr > desired_fdr and fdr - desired_fdr < fdr_over:
                fdr_over = fdr - desired_fdr
                over_ind = i
            elif fdr <= desired_fdr and sens_under < sens[i]:
                sens_under = sens[i]
                under_ind = i

    if under_ind < 0:
        fdr = 1 - prec[over_ind]
        score_cutoff = score_cutoffs[over_ind]
        print 'Could not filter to desired FDR %f %%. Filtering to FDR of %f %% instead...'%(100*desired_fdr, 100*fdr)
    else:
        fdr = 1 - prec[under_ind]
        score_cutoff = score_cutoffs[under_ind]
        print 'Filtering to FDR of %f %%...'%(100*fdr,)

    # Filtering...
    for scanF in proc_tag_graph.keys():
        if float(proc_tag_graph[scanF]['Alignment Score']) < score_cutoff:
            del proc_tag_graph[scanF]
Example #11
0
def main(args):
    name = ""
    population = 0
    action = 0
    # This creates a directory if there isn't one
    # FileIOHelper.createDir()
    # This creates a file if there isn't one
    # FileIOHelper.createOurFile()
    while not action == 3:
        print("\n\nWelcome to the Countries Maintenance Application!")
        print("1 - See the list of countries\n2 - Add a country\n3 - Exit\n")
        action = Validator.getInt("Enter a number: ", 1, 3)
        if action == 1:
            FileIOHelper.readFromFile()
        elif action == 2:
            country = Validator.getString("Enter country: ")
            population = Validator.getInteger("Enter population: ")
            new_country = Country(country, population)
            FileIOHelper.writeToFile(new_country)
        else:
            print("Buh-bye!")
            break
Example #12
0
def testParameterPerformance():
    startTime = time.time()
    allAlgorithmStartTime = startTime

    # define sizes
    trainDataSize = 10000
    testDataSize = 100000

    trainData,testData = utils.getDifferentTrainAndTestData(trainDataSize,testDataSize)

    #in order to assure that we have members form each class present
    testData = testData.append(dataReader.getSuffixDataFrame())

    classifier = trainClassifierOnTrainingData(trainData=trainData)

    xTest,yTest = constructTestData(testData)

    yPred = classifier.predict(xTest)

    validator.performValidation(yPred, yTest)


    print("Total run time:{} s".format((time.time() - allAlgorithmStartTime)))
Example #13
0
def GetCommandId():
    """
    gets a command id from the user
    
    Returns:
        int: a valid command id
    """
    commandId = Input("Introduceti numarul comenzii dorite: ")
    try:
        Validator.ValidateCommandId(commandId)
        return commandId
    except Exception as ex:
        OutputException(ex)
        return GetCommandId()
def negative_test(data, current_test):
    if not 'rules' in data or not 'input' in data or not 'errors' in data:
        return
    validator = Validator.Validator(data['rules'])
    validator.validate(data['input'])
    """ If need to debug uncoment next code"""
    standard_errors = data['errors']
    current_errors = validator.get_errors()
    if standard_errors == current_errors:
        print('Test \'{0}\' is Passed!!'.format(current_test))
    else:
        print(
            'Test \'{}\' is NOT passed \n Gives:\n\n{}\n\n Must give:\n\n{}\n\n'
            .format(current_test, current_errors, standard_errors))

    return [data['errors'], validator.get_errors()]
Example #15
0
 def test_email_valid_inputs(self):
     emails = [
         "*****@*****.**", "*****@*****.**",
         "*****@*****.**", "*****@*****.**",
         "[email protected]", "email@[123.123.123.123]",
         "*****@*****.**", "*****@*****.**",
         "*****@*****.**", "*****@*****.**",
         "*****@*****.**", "*****@*****.**",
         "*****@*****.**"
     ]
     failed = []
     for email in emails:
         if not Validator.is_email(email):
             failed.append(email)
     if len(failed) > 0:
         self.fail("Failed to Validate: " + str(failed))
Example #16
0
def updateLocalWhitelistOnBoot():
	# get the latest whitelist from the Seltzer DB on script boot and save to file
	if is_connected():
		try:

			print "Updating the local whitelist..."
			HACCSY_app_log.info('Updating local whitelist to file: ' + WHITELISTFILENAME)
			whitelist = Validator.getWhitelist()
			with open(WHITELISTPATH, "w+") as text_file:
				# text_file.write(str(whitelist))
				json.dump(whitelist,text_file)
			HACCSY_app_log.info("Updated whitelist to file OK")
			print "Updated whitelist OK!"

		except Exception as ex:
			HACCSY_app_log.info("Couldn't update the whitelist." + str(ex.message))
			print "couldn't update the witelist"
Example #17
0
    def __CreateTable(self, stmt):
        start_time = time.time()
        args = Validator.CreateTable(stmt, self._Integer, self._Char,
                                     self._Varchar)
        if not args:
            return self.__Result(self.__ErrorStatus, start_time,
                                 'Sintax error')

        table_name = args[0]
        fields = args[1:]
        # Creating pages
        if (self._CreateMetaPage(table_name, fields)):
            self._CreatePage(table_name, 0)
            return self.__Result(self.__SuccessStatus, start_time)
        else:
            return self.__Result(self.__ErrorStatus, start_time,
                                 'Table already exists')
Example #18
0
def invite_friend1():
    response = None
    db_manager = DBManager()
    content = request.json
    email = content['email']
    if email is not None:
        if Validator.isValidEmail(email):
            db_manager.send_email_invite_friend(email)
            response = {"status": "success"}
        else:
            response = {"status": "failed", "message": "Invalid email!"}
    else:
        response = {
            "status": "failed",
            "message": "Unable to process the request. Please try again later"
        }
    return json.dumps(response)
def getModInfo(connection, fracs, spectrum_score_cutoff=0):
    indexed_results = defaultdict(lambda: -1000)
    inf = float("inf")
    top_mods_info = []
    all_mods_info = defaultdict(list)
    for fraction_id, fraction_name in fracs:
        stmt = select([
            results.c.scan, results.c.composite_score, results.c.mods,
            results.c.spectrum_score
        ]).where(results.c.fraction_id == fraction_id).where(
            results.c.spectrum_score > spectrum_score_cutoff).order_by(
                results.c.scan).order_by(desc(results.c.composite_score))
        response = connection.execution_options(
            stream_results=True).execute(stmt)
        for row in SFW.string_folding_wrapper(response):
            scan_name = fraction_name + ':' + str(row[0])
            mods = [
                mod for mod in eval(row[2])
                if mod[0][0] != 'Isobaric Substitution'
            ]
            mod_tuple = Validator.getUniqueModTuple(
                mods, undef_mod_round_precision=2)
            if len(mod_tuple) == 0:
                # Make sure no values can be added for a scan if an unmodified peptide has been found
                indexed_results[scan_name] = inf
                all_mods_info[scan_name] = tuple()
                continue

            if includeInHash(mod_tuple):
                try:
                    all_mods_info[scan_name] += [(mods, mod_tuple, row[3],
                                                  round(mods[0][0][1]))]
                except TypeError:
                    continue

                score = round(row[1], 2)
                if score >= indexed_results[scan_name]:
                    top_mods_info += [(mods, mod_tuple)]
                    indexed_results[scan_name] = score

    for scan_name in all_mods_info.keys():
        if len(all_mods_info[scan_name]) == 0:
            del all_mods_info[scan_name]

    return top_mods_info, all_mods_info, len(indexed_results)
Example #20
0
def GetExpense():
    """
    gets an expense from the user
    
    Returns:
        dictionary: an expense
    """
    OutputText("Introduceti cheltuiala dorita: ")
    try:
        day = int(Input("Ziua: "))
        ammount = float(Input("Suma: "))
        category = str(Input("Tipul cheltuielii: "))
        expense = Expenses.MakeExpense(day, ammount, category)
        Validator.ValidateExpense(expense)
        return expense
    except Exception as ex:
        OutputException(ex)
        return GetExpense()
    def getDepartments(self, pageCode):
        # 生成获取科室信息的正则表达式对象
        pattern = re.compile(
            '<a class="kfyuks_islogin" href="(.*?)">(.*?)</a>', re.S)
        items = re.findall(pattern, pageCode)

        # 遍历结果
        for item in items:
            print(item[0], item[1])

            if Validator.compileurl(self.baseUrl + item[0]):
                ids = self.parseUrl(item[0])
                self.departments.append([item[0], item[1], ids[0], ids[1]])
            else:
                result = self.combineUrlComponent(item[0])
                self.departments.append(
                    [result[0], item[1], result[1], result[2]])

        return self.departments
def positive_test(data, current_test):
    if not 'rules' in data or not 'input' in data or not 'output' in data:
        return
    validator = Validator.Validator(data['rules'])
    result = validator.validate(data['input'])
    """ If need to debug uncoment next code"""
    standart_output = data['output']
    if result:
        if standart_output == result:
            print('Test \'{0}\' is Passed!!'.format(current_test))
        else:
            print(
                'Test \'{0}\' is NOT passed\nGives result:\n\n{1}\n\nMust give:\n\n{2}\n\n'
                .format(current_test, result, standart_output))
    else:
        print(
            'Test \'{0}\' is NOT passed\nGives errors:\n\n{1}\n\n Must give:\n\n{2}\n\n'
            .format(current_test, validator.get_errors(), standart_output))
    return [data['output'], result]
def getIndexedResultsFromDB(connection, fracs, motifs):
    indexed_results = defaultdict(list)
    for fraction_id, fraction_name in fracs:
        stmt = select([
            results.c.scan, results.c.id, results.c.spectrum_score,
            results.c.ppm, results.c.context, results.c.mod_context,
            results.c.mods, results.c.proteins, results.c.matching_tag_length,
            results.c.charge
        ]).where(results.c.fraction_id == fraction_id).order_by(
            results.c.scan).order_by(desc(results.c.composite_score))
        response = connection.execution_options(
            stream_results=True).execute(stmt)

        for row in SFW.string_folding_wrapper(response):
            indexed_results[fraction_name + ':' + str(row[0])] += [
                Validator.precalculateEMAttributesForItem(row[1:], motifs)
            ]

    return indexed_results
Example #24
0
def transaction_details():
    response = None
    try:
        content = request.json
        if Validator.isValidDollarAmount(content["amount"]):
            db_manager = DBManager()
            payee_id = session["user_id"]
            data = db_manager.get_id_from_email(content['payer_id'])
            if data is None:
                response = {
                    "status": "failed",
                    "message": "Friend not registered"
                }
            else:
                payer_id = data[0]
                now = time.strftime('%Y-%m-%d %H:%M:%S')
                db_manager.insert_transaction_details(payer_id, payee_id,
                                                      content['amount'],
                                                      'Pending', now)
                response = {"status": "success"}
        else:
            response = {"status": "failed", "message": "Not a valid Amount"}
    except DatabaseError as e:
        logging.exception(e)
        response = {
            "status": "failed",
            "message": "Unable to process the request. Please try again later"
        }
    except Exception as e:
        logging.exception(e)
        response = {
            "status": "failed",
            "message": "Unable to process the request. Please try again later"
        }
    finally:
        if response is None:
            response = {
                "status": "failed",
                "message":
                "Unable to process the request. Please try again later"
            }
    return json.dumps(response)
Example #25
0
def send_auth_code():
    response = None
    db_manager = DBManager()
    content = request.json
    email = content['email']
    if email is not None:
        if Validator.isValidEmail(email):
            if db_manager.get_profile_details_email(email) is not None:
                db_manager.send_email_auth_code(email)
                response = {"status": "success"}
            else:
                response = {"status": "failed", "message": "User Not found"}
        else:
            response = {"status": "failed", "message": "Invalid email!"}
    else:
        response = {
            "status": "failed",
            "message": "Unable to process the request. Please try again later"
        }
    return json.dumps(response)
Example #26
0
def aliase_negative_test(data, current_test):

    if not 'rules' in data or not 'input' in data or not 'errors' in data or not 'aliases' in data:
        return
    validator = Validator.Validator(data['rules'])

    for alias in data['aliases']:
        validator.register_aliased_rule(alias)
    validator.validate(data['input'])
    """ If need to debug uncoment next code"""
    # standard_errors = data['errors']
    # current_errors = validator.get_errors()
    # if standard_errors == current_errors:
    #   print('Test \'{0}\' is Passed!!'.format(current_test))
    # else:
    #   print('Test \'{0}\' is NOT passed \n Gives:\n\n{1}\n\n Must give:\n\n{2}\n\n'.format(current_test,
    #                                                                                         current_errors,
    #                                                                                         standard_errors))

    return [data['errors'], validator.get_errors()]
def getUniqueCandidates(candidate_list, spec_score_cut_for_list=0):

    unique_candidates = {}
    for candidate in candidate_list:
        item_key = (candidate['context'],
                    Validator.getUniqueModTuple(candidate['mods']))
        if item_key not in unique_candidates:
            unique_candidates[item_key] = [candidate]
        elif unique_candidates[item_key][0]['spectrum_score'] < candidate[
                'spectrum_score']:
            unique_candidates[item_key] = [candidate]
        elif unique_candidates[item_key][0]['spectrum_score'] == candidate[
                'spectrum_score'] and candidate[
                    'spectrum_score'] > spec_score_cut_for_list and candidate[
                        'mod_context'] not in [
                            item['mod_context']
                            for item in unique_candidates[item_key]
                        ]:
            unique_candidates[item_key] += [candidate]

    return stringify(unique_candidates.items())
Example #28
0
    def __InsertInto(self, stmt):
        start_time = time.time()
        args = Validator.InsertInto(stmt)
        if not args:
            return self.__Result(self.__ErrorStatus, start_time,
                                 'Sintax error')

        table_name = args[0]
        values = args[1:]
        offset = 0
        if (self._FileExists(self._Page(table_name, self._MetaData))):
            result = self._CreateFrame(table_name, offset, values)
            if isinstance(result, str):
                return self.__Result(self.__ErrorStatus, start_time, result)
            elif not result:
                return self.__Result(self.__ErrorStatus, start_time,
                                     'Internal error')
            else:
                return self.__Result(self.__SuccessStatus, start_time)
        else:
            return self.__Result(self.__ErrorStatus, start_time,
                                 'Table not found')
Example #29
0
    def getAllKYYDate(self, pageCode):
        self.days = int(self.getKYYDays(pageCode))
        # 根据天数计算可预约周数
        weeknum = self.days / 7
        # 获取当前页日期信息
        self.getKYYDate(pageCode)

        while weeknum > 1:
            # 获取下一页link
            pattern = re.compile(
                '<div class="ksorder_cen_l_r">.*?href="(.*?)".*?></a>', re.S)
            result = re.search(pattern, pageCode)

            link = result.group(1).strip()
            print(link)

            if not Validator.compileurl(self.baseUrl + link):
                link = self.combineUrlComponent(link)
            pageCode = self.loadPage(link)
            self.getKYYDate(pageCode)
            # 可预约周数减1
            weeknum -= 1
Example #30
0
def aliase_positive_test(data, current_test):
    if not 'rules' in data or not 'input' in data or not 'output' in data or not 'aliases' in data:
        return
    validator = Validator.Validator(data['rules'])

    for alias in data['aliases']:
        validator.register_aliased_rule(alias)
    result = validator.validate(data['input'])
    """ If need to debug uncoment next code"""
    # standart_output = data['output']
    # if result:
    #     if standart_output == result:
    #         print('Test \'{0}\' is Passed!!'.format(current_test))
    #     else:
    #         print('Test \'{0}\' is NOT passed\nGives result:\n\n{1}\n\nMust give:\n\n{2}\n\n'.format(current_test,
    #                                                                                             result,
    #                                                                                             standart_output))
    # else:
    #     print('Test \'{0}\' is NOT passed\nGives errors:\n\n{1}\n\n Must give:\n\n{2}\n\n'.format(current_test,
    #                                                                                         validator.get_errors(),
    #                                                                                         standart_output))

    return [data['output'], result]
class CleanCoverageTests(unittest.TestCase):

    def setUp(self):
        self.v = Validator()

    def test_clean_id(self):
        the_input = "a558,F,08,885,Normal,517"
        output = self.v.clean_input(the_input)
        self.assertEqual(output, ["A558","F","08","885","Normal","517"])

    def test_clean_gender(self):
        the_input = "A558,f,08,885,Normal,517"
        output = self.v.clean_input(the_input)
        self.assertEqual(output, ["A558","F","08","885","Normal","517"])

    def test_clean_age(self):
        the_input = "A558,F,8,885,Normal,517"
        output = self.v.clean_input(the_input)
        self.assertEqual(output, ["A558","F","08","885","Normal","517"])

    def test_clean_sales_1(self):
        the_input = "A558,F,08,85,Normal,517"
        output = self.v.clean_input(the_input)
        self.assertEqual(output, ["A558","F","08","085","Normal","517"])

    def test_clean_sales_2(self):
        the_input = "A558,F,08,5,Normal,517"
        output = self.v.clean_input(the_input)
        self.assertEqual(output, ["A558","F","08","005","Normal","517"])

    def test_clean_bmi(self):
        the_input = "A558,F,08,885,normal,517"
        output = self.v.clean_input(the_input)
        self.assertEqual(output, ["A558","F","08","885","Normal","517"])

    def test_clean_income(self):
        the_input = "A558,F,08,85,Normal,7"
        output = self.v.clean_input(the_input)
        self.assertEqual(output, ["A558","F","08","085","Normal","07"])
Example #32
0
updater.sendGameState(gs)
time.sleep(1)
board.addRoad(22,23,1)
updater.sendGameState(gs)
time.sleep(1)
corner3 = board.corners[23]
corner3.addBuilding(1,"settlement")
updater.sendGameState(gs)
time.sleep(1)

#board.getLongestRoad()
gs.players[0].resources['brick']=1
gs.players[0].resources['wood']=1
gs.players[0].resources['wheat']=1
gs.players[0].resources['sheep']=1
check = Validator(gs)
gs.phase = 'standard'
move1 = Move(0,'build',{'structure':'settlement', 'location':25})
updater.sendGameState(gs)
time.sleep(1)


gs.players[1].resources['ore']=3
gs.players[1].resources['wood']=1
gs.players[1].resources['wheat']=2
gs.players[1].resources['sheep']=1
check = Validator(gs)
move2 = Move(1,'build',{'structure':'city', 'location':34})

print check.validateMove(move1)
print check.validateMove(move2)
Example #33
0
					HACCSY_app_log.info("Check IN/OUT Button pressed")
					
					# PRINT LCD
					writeLCDMessage('Checking...',0)

					CARDS = readLocalWhitelist()

					if match in CARDS:

						HACCSY_app_log.info('Card authorized via whitelist: ' + str(match))

						# PRINT LCD
						writeLCDMessage('Whitelist OK!', 1)

						# Communicate with REST API to process Check IN/OUT
						checkInJsonResponse = Validator.processCheckIn(match)
						HACCSY_app_log.info('processCheckIn() json response: ' + str(checkInJsonResponse))
						checkInJsonString_errors = checkInJsonResponse['hasErrors']
						checkInJsonString_message = checkInJsonResponse['message']
						checkInJsonString_firstName = checkInJsonResponse['firstName']
						checkInJsonString_lastName = checkInJsonResponse['lastName']

						if (checkInJsonString_errors == 0):

							HACCSY_app_log.info('processCheckIn() json string: ' + str(checkInJsonString_errors) + ' errors | ' + checkInJsonString_firstName + ' ' + checkInJsonString_lastName + ' | ' + str(match) + ' | ' + checkInJsonString_message)
							
							if (checkInJsonString_message == "Checkin successful!"):

								HACCSY_app_log.info('Checked IN. ACCESS GRANTED: ' + str(match))

								writeLCDMessage('Check IN\nsuccessful!',1)
### Main function

# FEATURE 1 - Match with the McDonald Dictionary
dataset = get_dataset("../mdatest/")
dico = matcher.get_dico(dataset)        # dico is a column with the matching scores of the MDAs versus the Finance Dictionary 
df=pd.DataFrame(dataset)
df[3] = pd.Series(dico)
df.columns = ['MD&A_Text','Filename','Actual','MatchDico'] 

# FEATURE 2 and 3 - Match with the Compustat financial data to get the indices 'delta_sales' and 'delta_at'
compustat = pd.read_csv('compustat_filenames.csv', sep=',')
de = compustat['delta_sale']
dt = compustat['delta_at']
ds = pd.merge(df, compustat, left_on='Filename', right_on='Filename')


# We split the global matrix "result" into a training and a testing set
train, test = validator.split(ds,0.5)

# We fit a Random Forest model 	 (n_estimators default=10, min_samples_leaf default=1)
rf = RandomForestClassifier(n_estimators=100)
rf.fit(train[3].reshape(-1, 1), train[2].reshape(-1, 1))
predictions = rf.predict(test[3].reshape(-1, 1))
test[5] = pd.Series(predictions, index=test.index)

test.columns = ['MD&A_Text','Filename','Actual','MatchDico','WordCrisis','Predicted'] 
print(test)

tab = pd.crosstab(test['Actual'], test['Predicted'], rownames=['Actual'], colnames=['Predicted'], margins=True) # Print confusion matrix
print(tab)
print(classification_report(test['Actual'], test['Predicted'])) # Print accuracy, precision, recall, F measure
Example #35
0
import Validator as Validator

if __name__ == "__main__":

    print(
        "Type \"quit\" to stop program\nType \"details 0/1\" to stop show or not show parser details.\n"
    )
    showdetails = False

    txt = input(">> ")

    while (txt != "quit"):
        if txt.startswith("details") and len(txt.split()) == 2:
            if txt.split()[1] == "1": showdetails = True
            if txt.split()[1] == "0": showdetails = False
        else:
            if Validator.validate(txt):
                expression = Parser.parse(txt)
                result = Arithmetic.calculate(expression)
                if showdetails:
                    tokens = Parser.tokenize(txt)
                    tokenstring = "tokens: "
                    for t in tokens:
                        tokenstring += str(t)
                    print(tokenstring)
                    print("Parser:", expression)
                    print("Arithmetic:", result)
                else:
                    print(result)

        txt = input(">> ")
Example #36
0
from InputProcessor import InputProcessor
from HtmlGenerator import HtmlGenerator
import Validator

INPUT_FILE_PATH = "../data/smells.txt"
OUTPUT_PATH = "../smellCatalogHtml/"
SMELL_CATEGORY_FILE_PATH = "../data/smell-category.txt"
REF_FILE_PATH = "../data/references.txt"
TOOL_FILE_PATH = "../data/tools.txt"

input_processor = InputProcessor(INPUT_FILE_PATH)
tools_list = input_processor.get_tools_list(TOOL_FILE_PATH)
smell_list = input_processor.get_smell_list()
input_processor.populate_aka_obj(smell_list)
category_list = input_processor.get_category_list(SMELL_CATEGORY_FILE_PATH)
ref_list = input_processor.get_ref_list(REF_FILE_PATH)

Validator.validateAll(tools_list, smell_list, category_list, ref_list)

sorted_smell_list = sorted(smell_list, key=lambda smell: smell.name)

html_generator = HtmlGenerator(OUTPUT_PATH, sorted_smell_list, category_list,
                               tools_list)
html_generator.generate()
class ValidationCoverageTests(unittest.TestCase):

    def setUp(self):
        self.v = Validator()

    def test_bad_id(self):
        the_input = self.v.clean_input("A58,F,08,885,Normal,517")
        output = self.v.isvalid(the_input)
        self.assertFalse(output)

    def test_good_id(self):
        the_input = self.v.clean_input("A558,F,08,885,Normal,517")
        output = self.v.isvalid(the_input)
        self.assertTrue(output, True)

    def test_bad_gender(self):
        the_input = self.v.clean_input("A558,D,08,885,Normal,517")
        output = self.v.isvalid(the_input)
        self.assertFalse(output)

    def test_good_gender_female(self):
        the_input = self.v.clean_input("A558,F,08,885,Normal,517")
        output = self.v.isvalid(the_input)
        self.assertTrue(output)

    def test_good_gender_male(self):
        the_input = self.v.clean_input("A558,M,08,885,Normal,517")
        output = self.v.isvalid(the_input)
        self.assertTrue(output)

    def test_bad_age(self):
        the_input = self.v.clean_input("A58,F,sdf,885,Normal,517")
        output = self.v.isvalid(the_input)
        self.assertFalse(output)

    def test_good_age(self):
        the_input = self.v.clean_input("A558,F,49,885,Normal,517")
        output = self.v.isvalid(the_input)
        self.assertTrue(output)

    def test_bad_sales(self):
        the_input = self.v.clean_input("A58,F,08,string,Normal,517")
        output = self.v.isvalid(the_input)
        self.assertFalse(output)

    def test_good_sales(self):
        the_input = self.v.clean_input("A558,F,08,885,Normal,517")
        output = self.v.isvalid(the_input)
        self.assertTrue(output)

    def test_bad_bmi(self):
        the_input = self.v.clean_input("A58,F,08,885,superfat,517")
        output = self.v.isvalid(the_input)
        self.assertFalse(output)

    def test_good_bmi(self):
        the_input = self.v.clean_input("A558,F,08,885,Normal,517")
        output = self.v.isvalid(the_input)
        self.assertTrue(output)

    def test_bad_income(self):
        the_input = self.v.clean_input("A58,F,08,885,Normal,NAN")
        output = self.v.isvalid(the_input)
        self.assertFalse(output)

    def test_good_income(self):
        the_input = self.v.clean_input("A558,F,08,885,Normal,517")
        output = self.v.isvalid(the_input)
        self.assertTrue(output)
Example #38
0
import Config
import Validator
import Updater

if __name__ == '__main__':
    """
    AutoUpdater Client
    """
    config = Config.Config()
    validator = Validator.Validator(config.get_checksum_list())
    updater = Updater.Updater(config.get_channel(), validator,
                              config.get_current_version())
    print(updater.has_new_version())
 def setUp(self):
     self.v = Validator()