Ejemplo n.º 1
0
def make_text(chains):
    """Takes a dictionary of markov chains and returns random text
    based off an original text."""
    new_string = ""
    # pick a key
    current_tuple = r_choice(chains.keys())

    while current_tuple in chains.keys():
        first_word = current_tuple[0]
        second_word = current_tuple[1]
        third_word = r_choice(chains.get(current_tuple))

        if len(new_string + first_word) > 139:
            break 
        new_string = new_string + " " + first_word
        if len(new_string + second_word) > 139: 
            break 
        new_string = new_string + " " + second_word
        if len(new_string+ third_word) > 139: 
            break

        new_string = new_string + " " + third_word

        current_tuple = (second_word, third_word)

    # print len(new_string)
    return new_string
Ejemplo n.º 2
0
 def __init__(self, platform='windows', *args, **kwargs):
     super().__init__(*args, **kwargs)
     if platform == 'windows':
         self.s_info, self.s_bit = self.WIN_SYSTEM, self.WIN_SYSTEM_BIT
     elif platform == 'linux':
         self.s_info, self.s_bit = self.LINUX_SYSTEM, self.LINUX_SYSTEM_BIT
     elif platform == 'mac':
         self.s_info, self.s_bit = self.MAC_SYSTEM, self.MAC_SYSTEM_BIT
     else:
         raise TypeError('Unknown platform type: %s' % platform)
     self.version, self.info, self.bit, self.r_version = float(
         randint(10,
                 50)), r_choice(self.s_info), r_choice(self.s_bit), float(
                     randint(10, 50))
Ejemplo n.º 3
0
 def test_bad_posts(self):
     self.good_login()
     # missing title
     rv = self.create_post("", self.post_body, self.post_date,
                           self.post_time, self.post_tags)
     assert "You must provide a title" in rv.data
     # missing body
     rv = self.create_post(self.post_title, "", self.post_date,
                           self.post_time, self.post_tags)
     assert "The body is required" in rv.data
     # too short body
     rv = self.create_post(self.post_title, "ta", self.post_date,
                           self.post_time, self.post_tags)
     assert "The body is required" in rv.data
     # too long body
     rv = self.create_post(self.post_title,
                           ''.join(r_choice(au) for x in range(1048577)),
                           self.post_date, self.post_time, self.post_tags)
     assert "The body is required" in rv.data
     # malformed date
     rv = self.create_post(self.post_title, self.post_body, "AHAHAHHAHA",
                           self.post_time, self.post_tags)
     assert "Invalid date/time input" in rv.data
     # malformed time
     rv = self.create_post(self.post_title, self.post_body, self.post_date,
                           "HAHAHAAHAH", self.post_tags)
     assert "Invalid date/time input" in rv.data
Ejemplo n.º 4
0
 def test_type_1_first_name_mixed_case(self):
     full_name = ''.join(
         r_choice([char, char.upper()]) for char in "firstname")
     name = _.Name(full_name=full_name)
     self.assertEqual(name.name, ["Firstname", "Firstname"])
     self.assertEqual(name.fname, "Firstname")
     self.assertEqual(name.mname, None)
     self.assertEqual(name.lname, None)
Ejemplo n.º 5
0
    def next(self, left):
        if left is None:
            return r_choice(tuple(self._fragments.keys()))

        probabilities = self.probabilities(left)
        rights = tuple(probabilities.keys())
        rights_probabilities = tuple(map(lambda r: probabilities[r], rights))

        return np_choice(rights, p=rights_probabilities)
Ejemplo n.º 6
0
 def test_type_2_middle_name_mixed_case(self):
     full_name = ''.join(
         r_choice([char, char.upper()])
         for char in "lastname, firstname middlename")
     name = _.Name(full_name=full_name)
     self.assertEqual(name.name, [
         "Firstname Middlename Lastname", "Lastname, Firstname Middlename"
     ])
     self.assertEqual(name.fname, "Firstname")
     self.assertEqual(name.mname, "Middlename")
     self.assertEqual(name.lname, "Lastname")
Ejemplo n.º 7
0
 def test_type_2_form_2_name(self):
     full_name = ''.join(
         r_choice([char, char.upper()])
         for char in "lastname, firstname middlename a. amn.")
     name = _.Name(full_name=full_name)
     self.assertEqual(name.name, [
         "Firstname Middlename A. Amn. Lastname",
         "Lastname, Firstname Middlename A. Amn."
     ])
     self.assertEqual(name.fname, "Firstname")
     self.assertEqual(name.mname, "Middlename A. Amn.")
     self.assertEqual(name.lname, "Lastname")
Ejemplo n.º 8
0
 def test_bad_posts(self):
     self.good_login()
     # missing title
     rv = self.create_post("",
                           self.post_body,
                           self.post_date,
                           self.post_time,
                           self.post_tags)
     assert "You must provide a title" in rv.data
     # missing body
     rv = self.create_post(self.post_title,
                           "",
                           self.post_date,
                           self.post_time,
                           self.post_tags)
     assert "The body is required" in rv.data
     # too short body
     rv = self.create_post(self.post_title,
                           "ta",
                           self.post_date,
                           self.post_time,
                           self.post_tags)
     assert "The body is required" in rv.data
     # too long body
     rv = self.create_post(self.post_title,
                           ''.join(r_choice(au) for x in range(1048577)),
                           self.post_date,
                           self.post_time,
                           self.post_tags)
     assert "The body is required" in rv.data
     # malformed date
     rv = self.create_post(self.post_title,
                           self.post_body,
                           "AHAHAHHAHA",
                           self.post_time,
                           self.post_tags)
     assert "Invalid date/time input" in rv.data
     # malformed time
     rv = self.create_post(self.post_title,
                           self.post_body,
                           self.post_date,
                           "HAHAHAAHAH",
                           self.post_tags)
     assert "Invalid date/time input" in rv.data    
Ejemplo n.º 9
0
def evo_gains(odrv):
    robo.start(odrv)
    global traj
    traj = trajectory.build_trajectory(pos1=0,
                                       pos2=pi,
                                       t1=0.95,
                                       t2=0.95,
                                       res=samples_x_traj)

    class Individual:
        def __init__(self, generation, gains):
            self.generation = generation
            self.gains = gains
            configure.gains(odrv, *gains)
            traj_err, stat_err, data = get_exec_errors_data(
                odrv, runs, traj, samples_x_traj)
            self.traj_error = traj_err
            self.stat_error = stat_err
            self.score = traj_err + stat_err
            self.data = data

    global population
    population = []
    global plot_group
    plot_group = []
    #Initiate population randomly
    print("*** Creating 0 generation ***")
    generation = 0
    for n in range(0, pop_size):
        kp = r_uni(k_range[0][0], k_range[0][1])
        kv = r_uni(k_range[1][0], k_range[1][1]) + r_tri(0, .8, 0.01)
        kvi = r_uni(k_range[2][0], k_range[2][1])
        population.append(Individual(0, check_gains([kp, kv, kvi])))
    init_plot = population[0]
    plot_group.append(init_plot)
    population.sort(key=lambda p: p.score)
    win = population[0]
    winners.append(win)
    print_results(population)

    improvs = 0
    while (generation < max_generations) or inf_cycle:
        generation += 1
        print('\n' + "*** Creating " + str(generation) + " generation ***")
        parents = population[:survivors]
        del population[elites:]

        n = 0
        while len(population) < (pop_size - mutts):
            p1 = parents[n % survivors]
            p2 = r_choice(parents)
            population.append(Individual(generation, cross_parents(p1, p2)))
            n += 1
        for m in range(mutts):
            mutt = population[m]
            population.append(Individual(generation, create_mutt(mutt)))

        population.sort(key=lambda p: p.score)
        print_results(population)

        if (population[0] != win):
            win = population[0]
            winners.append(win)
            improvs += 1
            if improvs == 2:
                plot_group.append(win)

    population.sort(key=lambda p: p.score)
    plot_group.append(population[0])
    plots.print_group_trajs(plot_group)
    return (population, plot_group)
Ejemplo n.º 10
0
def get_name(list_of_players) -> str:
    while True:
        name = r_choice(NAMES)
        if not name in list_of_players:
            return name