def get_pattern_addition_two():
     patterns = [
         Pattern('{domain1} {property} {nr1} {range1} and {nr2} {range2}.',
                 2, 1, 1),
         Pattern('if {nr1} {range1} are added to {nr2} {range2}', 1, 0, 0)
     ]
     return random.choice(patterns)
    def get_pattern_addition_one():

        patterns = [
            Pattern(' {nr1} of them are added. ', 0, 0, 0),
            Pattern('to those {range1}, we add {nr1} more', 1, 0, 0)
        ]
        return random.choice(patterns)
 def get_pattern_division_one():
     patterns = [
         Pattern(
             ' and at the end, it is decided to share all to {nr1} friends'
         ),
         Pattern('finally, we need to divide all this by {nr1}')
     ]
     return random.choice(patterns)
 def get_pattern_division_two():
     patterns = [
         Pattern(
             'There is {domain1} that {property} {nr1} {range1}. {range1} is divided by {nr2}.',
             1, 1, 1, 0),
         Pattern(
             'We have {nr1} {range1}, but we are told that we have to divide all by {nr2}',
             1, 0, 0, 0)
     ]
     return random.choice(patterns)
 def get_pattern_multiplication_two():
     patterns = [
         Pattern(
             'There is {domain1} that {property} {nr1} {range1}. If we add {nr2} times the same quantity to {domain1}',
             1, 1, 1, 0),
         Pattern(
             'Being given {nr1} {range1}, someone decides to multiply this by {nr1}',
             1, 0, 0, 0)
     ]
     return random.choice(patterns)
    def get_pattern_subtraction_two():

        patterns = [
            Pattern(
                'There is {domain1} that {property} {nr1} {range1}, but {nr2} of them disappear.',
                1, 1, 1),
            Pattern('From {nr1} {range1} someone decides to remove {nr2}.', 1,
                    0, 0)
        ]
        return random.choice(patterns)
Exemple #7
0
def load_patterns():
    '''Loads patterns from local .txt and .png files'''
    Pattern(filename="glider", pat_list=Pattern.pattern_list)
    Pattern(filename="pentadecathlon", pat_list=Pattern.pattern_list)
    Pattern(filename="t_tetro", pat_list=Pattern.pattern_list)
    Pattern(filename="gosper", pat_list=Pattern.pattern_list)
    Pattern(filename="inf_10_cell", pat_list=Pattern.pattern_list)
    Pattern(filename="copperhead", pat_list=Pattern.pattern_list)
    Pattern(filename="light_w", pat_list=Pattern.pattern_list)
    Pattern(filename="r_pento", pat_list=Pattern.pattern_list)
    Pattern(filename="schick_engine", pat_list=Pattern.pattern_list)
    Pattern(filename="schick_tagalong", pat_list=Pattern.pattern_list)

    #Sorting because keeping everything orginized is nice
    try:
        Pattern.pattern_list.sort(key=lambda pattern: pattern.name)
    except AttributeError as error:
        print(error)
        print("Please make sure all patterns are loaded correctly...")
def check_reason(job):
    pattern = Pattern(PATTERN_FILE)
    patterns = pattern.patterns

    msg = {'tag': 'infra', 'reason': 'Reason was not found'}

    for job_key, job_file in TRIPLEOCI.iteritems():
        LOG.debug('Checking {} - {}'.format(job_key, job_file))
        #  try:
        full_log = job['log_url'] + job_file
        LOG.debug('Downloading {}'.format(full_log))
        r = requests.get(full_log)
        if r.status_code == 200:
            found = False
            for line in r.iter_lines():
                for p in patterns.get(job_key, {}):
                    line_matched = (line_match(p["pattern"],
                                               line,
                                               exclude=p.get("exclude")))
                    if line_matched:
                        LOG.debug('Line matched! - {}'.format(p['pattern']))
                        msg['tag'] = p['tag']
                        msg['reason'] = p['msg'].format(
                            line_match(p["pattern"], line))
                        found = True
                        break
                if found:
                    return msg
        else:
            LOG.debug('Could not download {}'.format(full_log))
            msg['tag'] = 'infra'
            msg['reason'] = 'Could not download log'
        #  except Exception:
        #  LOG.debug('Could not download {}'.format(full_log))
        #  msg['tag'] = 'infra'
        #  msg['reason'] = 'Failed to fetch logs'

    return msg
Exemple #9
0
def generate(x=10, y=10, z=10, time_steps=10):
    return Pattern(data=[
        [[[calculate_rgb(x, y, z, t) for zi in range(z)] for yi in range(y)] for xi in range(x)]
        for t in range(time_steps)
    ])
 def get_obj_pattern_subtraction():
     patterns = [
         Pattern(' how many {generic} are left?', number_generic=1),
         Pattern(' this being given, what is the left number?')
     ]
     return random.choice(patterns)
 def get_obj_pattern_addition():
     patterns = [
         Pattern(' what is the total now?'),
         Pattern(' how many do we have now?')
     ]
     return random.choice(patterns)
 def get_pattern_multiplication_one():
     patterns = [
         Pattern(' after, we multiply all by {nr1}'),
         Pattern('if we add {nr1} times the same amount')
     ]
     return random.choice(patterns)
 def get_pattern_subtraction_one():
     patterns = [
         Pattern(' and from that amount {nr1} is removed from the total'),
         Pattern(' somehow, {nr1} dissapear')
     ]
     return random.choice(patterns)