예제 #1
0
def addPlant():
    ''' adds a plant to the chain'''

    # get the information from the form
    species = request.form.get("species")
    nickname = request.form.get("nickname")
    size = request.form.get("size")

    # create new plant object
    newPlant = Plant.Plant(species, nickname, size)

    # add new plant to list
    if not Plants.append(newPlant):
        print("New plant added!")

        with open(SAVE_FILE, 'a', newline='\n') as csvfile:
            writer = csv.writer(csvfile)
            writer.writerow(
                [newPlant.species, newPlant.nickname, newPlant.size])

            csvfile.close()

        return render_template("myplants.html", Plants=Plants)

    # if anything goes wrong
    else:
        print("Error, new plant not added to chain.")
        return render_template("error.html")
def test_pr(t=0.24, fs=1000, num_f=1):
    # 参考信号 谐波生成
    x = Signal_Generator.mix_signal(num_f, t, fs)
    n = np.arange(0, t, 1 / fs)
    L = len(n)  # L仿真步数
    # plt.plot(n, x)
    # =========================================
    final_output = 0  # 也即plant最后输出
    final_output_list = []
    setpoint_list = x  # 参考/给定输入
    my_pr = PR_CON.PRControl(kp=0.1,
                             kr=100,
                             wc=5,
                             wr=100 * math.pi,
                             t_sample=1 / fs)
    my_plant = Plant.PlantLC(rl=0.1, l=200e-6, c=5e-6, t_sample=1 / fs)
    for i in range(0, L):
        my_pr.update(x[i] - final_output)  # e(t)→u(t)
        output_control = my_pr.output  # pr输出控制量
        my_plant.update(output_control)  # 控制量输入被控对象 e(t)→u(t)
        final_output = my_plant.output
        final_output_list.append(final_output)  # 在列表末尾添加新的对象。
    plt.plot(n, final_output_list)
    plt.plot(n, setpoint_list)
    plt.xlabel('time (s)')
    plt.ylabel('PR')
    plt.title('TEST PR')
    plt.grid(True)
    plt.show()
예제 #3
0
def main():
    ''' main method '''

    # initialize the main plant chain from the backup save file
    with open(SAVE_FILE, newline='\n') as csvfile:
        reader = csv.reader(csvfile, delimiter=',')
        for row in reader:
            newplant = Plant.Plant(row[0], row[1], row[2])
            Plants.append(newplant)

        csvfile.close

    app.run()
예제 #4
0
 def __init__(self, rl=0.1, l=200e-6, c=5e-6, x=10, t_sample=0.0001):
     self.a_fft1 = 0
     self.a_fft3 = 0
     self.a_fft25 = 0
     self.a_fft47 = 0
     self.a_fft50 = 0
     self.rL = rl
     self.L = l
     self.C = c
     self.X = x
     self.t_sample_feature = t_sample
     self.reset()
     self.A1 = 220
     self.A3 = 150
     self.A25 = 100
     self.A47 = 220
     self.A50 = 150
     self.input = 0.0
     self.output = 0.0
     self.final_output_list = []
     self.goal_list = []
     self.action_view = np.array([0., 0., 0., 0., 0.])
     self.my_plant = Plant.PlantLC(rl=rl, l=l, c=c, t_sample=t_sample)
     self.my_pr = PR_CON.PRControl(kp=0.1,
                                   kr=100,
                                   wc=5,
                                   wr=100 * math.pi,
                                   t_sample=self.t_sample_feature)
     self.my_pr3 = PR_CON.PRControl(kp=0.1,
                                    kr=70,
                                    wc=5,
                                    wr=300 * math.pi,
                                    t_sample=self.t_sample_feature)
     self.my_pr25 = PR_CON.PRControl(kp=0.1,
                                     kr=20,
                                     wc=5,
                                     wr=2500 * math.pi,
                                     t_sample=self.t_sample_feature)
     self.my_pr47 = PR_CON.PRControl(kp=0.1,
                                     kr=20,
                                     wc=5,
                                     wr=4700 * math.pi,
                                     t_sample=self.t_sample_feature)
     self.my_pr50 = PR_CON.PRControl(kp=0.1,
                                     kr=20,
                                     wc=5,
                                     wr=5000 * math.pi,
                                     t_sample=self.t_sample_feature)
     self.last_step_j = 0
     self.last_sum_r = 0
예제 #5
0
def main():
    print("LQR steering control tracking start!!")
    configurations = Configuration.config()
    L = configurations[2]
    max_steer = configurations[4]
    show_animation = configurations[0]
    dt = configurations[1]
    ax, ay, goal, cx, cy, cyaw, ck, s, target_speed = get_path()
    sp = calc_speed_profile(cx, cy, cyaw, target_speed)
    state_plane = 5
    input_plane = 2
    output_plane = 0
    model = Plant.set_plant(state_plane, input_plane, output_plane, dt=0.1)
    t, x, y, yaw, v = closed_loop_prediction(model, cx, cy, cyaw, ck, sp, goal,
                                             dt, show_animation, L, max_steer)
    if show_animation:
        plot_main(ax, ay, cx, cy, cyaw, ck, s, x, y)
예제 #6
0
def monitor():
    plantdata = DropletDB.getAll()
    in_format = '%Y-%m-%d %H:%M:%S'
    out_format = '%H:%M'
    for plant in plantdata:
        for reading in plant['humidity']['data']:
            mysql_timestamp = datetime.datetime.strptime(
                reading['timestamp'], in_format)
            reading['timestamp_formatted'] = mysql_timestamp.strftime(
                out_format)
    plant_ids = DropletDB.getPlantIds()
    plants = []
    for pid in plant_ids:
        plant = Plant.Plant(pid)
        plant.chart_data = plant.getChartAll()
        plants.append(plant)
    return flask.render_template('index.html',
                                 plantdata=plantdata,
                                 plants=plants)
예제 #7
0
    def loadLevel(self, levelNumber):
        f = open("rsc/Levels/levels.lvl")
        lines = f.readlines()
        f.close()

        newlines = []
        for line in lines:
            newline = ""
            for c in line:
                if c != '\n':
                    newline += c
            newlines += [newline]

        lines = newlines

        startIndex = lines.index(str(levelNumber)) + 1
        endIndex = startIndex + 20

        newlines = []
        for line in range(startIndex, endIndex):
            #print lines[line]
            newlines += [lines[line]]
        lines = newlines

        for line in lines:
            print line

        for y, line in enumerate(lines):
            for x, c in enumerate(line):
                if c in "w":  #walls
                    self.walls += [
                        Wall("purplebricks",
                             [x * self.tileSize, y * self.tileSize],
                             self.tileSize)
                    ]
                if c in "x":  #enemies
                    self.enemies += [
                        Enemy([x * self.tileSize, y * self.tileSize],
                              [self.tileSize, self.tileSize])
                    ]
                if c in "%":  #plants
                    self.plants += [
                        Plant([x * self.tileSize, y * self.tileSize],
                              self.tileSize)
                    ]
                if c in "^":  #fire
                    self.fires += [
                        Fire([x * self.tileSize, y * self.tileSize],
                             self.tileSize)
                    ]
                if c in ".":  #groundpoints
                    self.groundpoints += [
                        Groundpoint([x * self.tileSize, y * self.tileSize],
                                    self.tileSize)
                    ]
                if c in "#":  #ladders
                    self.ladders += [
                        Ladder([x * self.tileSize, y * self.tileSize])
                    ]
                if c in "~":  #bridgepoints
                    self.bridgepoints += [
                        Bridgepoint([x * self.tileSize, y * self.tileSize],
                                    self.tileSize)
                    ]
예제 #8
0
 def buildBridge(self, bridgepoints):
     for point in bridgepoints:
         Plant(point.rect.topleft)
예제 #9
0
    def reset(self):
        self.a_fft1 = 0
        self.a_fft3 = 0
        self.a_fft25 = 0
        self.a_fft47 = 0
        self.a_fft50 = 0
        self.rL = np.random.random()
        self.L = np.random.random() * 400e-6
        self.C = np.random.random() * 100e-6
        self.X = np.random.random() * 50
        # self.A1 = 100 + 10 * round(20*np.random.random())
        # self.A3 = 100 + 10 * round(20*np.random.random())
        # self.A25 = 100 + 10 * round(20*np.random.random())
        # self.A47 = 100 + 10 * round(20*np.random.random())
        # self.A50 = 100 + 10 * round(20*np.random.random())

        # self.rL = 0.1
        # self.L = 200e-6
        # self.C = 5e-6
        self.A1 = 220
        self.A3 = 150
        self.A25 = 100
        self.A47 = 220
        self.A50 = 150
        self.last_step_j = 0
        self.last_sum_r = 0
        # self.t_sample_feature=0.001*np.random.random()
        self.input = 0.0
        self.output = 0.0
        self.final_output_list = []
        self.goal_list = []
        self.action_view = np.array(
            [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])
        self.my_pr = PR_CON.PRControl(kp=0.1,
                                      kr=150,
                                      wc=5,
                                      wr=100 * math.pi,
                                      t_sample=self.t_sample_feature)
        self.my_pr3 = PR_CON.PRControl(kp=0.1,
                                       kr=20,
                                       wc=5,
                                       wr=300 * math.pi,
                                       t_sample=self.t_sample_feature)
        self.my_pr25 = PR_CON.PRControl(kp=0.1,
                                        kr=20,
                                        wc=5,
                                        wr=2500 * math.pi,
                                        t_sample=self.t_sample_feature)
        self.my_pr47 = PR_CON.PRControl(kp=0.1,
                                        kr=20,
                                        wc=5,
                                        wr=4700 * math.pi,
                                        t_sample=self.t_sample_feature)
        self.my_pr50 = PR_CON.PRControl(kp=0.1,
                                        kr=20,
                                        wc=5,
                                        wr=5000 * math.pi,
                                        t_sample=self.t_sample_feature)
        self.my_plant = Plant.PlantLC(rl=0.1,
                                      l=200e-6,
                                      c=5e-6,
                                      x=self.X,
                                      t_sample=self.t_sample_feature)
        s = np.concatenate((np.array([self.a_fft1]), np.array([self.a_fft3]),
                            np.array([self.a_fft25]), np.array([self.a_fft47]),
                            np.array([self.a_fft50])))
        # s = np.concatenate((np.array([self.A1]), np.array([self.A3]), np.array([self.A25]),
        #                     np.array([self.A47]), np.array([self.A50]), np.array([self.L * 1e6]),
        #                     np.array([self.C * 1e6]),  np.array([self.X]) ,np.array([self.rL])))
        return s
예제 #10
0
    def step(self, action):
        # self.rL = np.random.random()
        # self.L = np.random.random()*400e-6
        # self.C = np.random.random()*100e-6
        # self.X = np.random.random()*50
        self.A1 = 100 + 10 * round(20 * np.random.random())
        self.A3 = 100 + 10 * round(20 * np.random.random())
        self.A25 = 100 + 10 * round(20 * np.random.random())
        self.A47 = 100 + 10 * round(20 * np.random.random())
        self.A50 = 100 + 10 * round(20 * np.random.random())
        self.my_plant = Plant.PlantLC(rl=self.rL,
                                      l=self.L,
                                      c=self.C,
                                      x=self.X,
                                      t_sample=self.t_sample_feature)
        # action = np.clip(action, *self.action_bound) # 将数组中的元素限制在a_min, a_max之间
        self.action_view[0] = action[0]
        self.action_view[1] = action[1]
        self.action_view[3] = action[2]
        self.action_view[4] = action[3]

        self.action_view[5] = action[4]
        self.action_view[6] = action[5]
        self.action_view[7] = action[6]
        self.action_view[8] = action[7]
        self.action_view[9] = action[8]
        self.action_view[10] = action[9]

        self.my_pr = PR_CON.PRControl(kp=action[0],
                                      kr=action[1],
                                      wc=5,
                                      wr=100 * math.pi,
                                      t_sample=self.t_sample_feature)
        self.my_pr3 = PR_CON.PRControl(kp=action[2],
                                       kr=action[3],
                                       wc=5,
                                       wr=300 * math.pi,
                                       t_sample=self.t_sample_feature)
        self.my_pr25 = PR_CON.PRControl(kp=action[4],
                                        kr=action[5],
                                        wc=5,
                                        wr=2500 * math.pi,
                                        t_sample=self.t_sample_feature)
        self.my_pr47 = PR_CON.PRControl(kp=action[6],
                                        kr=action[7],
                                        wc=5,
                                        wr=4700 * math.pi,
                                        t_sample=self.t_sample_feature)
        self.my_pr50 = PR_CON.PRControl(kp=action[8],
                                        kr=action[9],
                                        wc=5,
                                        wr=5000 * math.pi,
                                        t_sample=self.t_sample_feature)
        step_t = 0.24
        setpoint_list = Signal_Generator.mix_signal(
            self.A1, self.A3, self.A25, self.A47, self.A50, step_t,
            1 / self.t_sample_feature)  # 参考/给定输入
        #对输入信号的FFT测试
        # fft_setpoint_list = fft(setpoint_list,(int)(step_t/self.t_sample_feature))
        # mX = np.abs(fft_setpoint_list)  # magnitude
        # freq_axis = np.arange((int)(step_t/self.t_sample_feature)) / (int)(step_t/self.t_sample_feature) * 1/self.t_sample_feature
        #
        # a_fft1=mX[(int)(50*step_t)]
        # a_fft3=mX[(int)(150*step_t)]
        # a_fft25=mX[(int)(1250*step_t)]
        # a_fft47=mX[(int)(2350*step_t)]
        # a_fft50=mX[(int)(2500*step_t)]
        #
        # print(a_fft1,a_fft3,a_fft25,a_fft47,a_fft50)

        step_every_step = len(np.arange(
            0, step_t, self.t_sample_feature))  # 每个step里运行仿真步数
        sum_r = 0
        self.input = 0.0
        self.output = 0.0
        self.final_output_list = []
        self.goal_list = []
        for step_j in range(step_every_step):
            self.goal = setpoint_list[step_j]
            self.input = self.goal - self.output
            self.my_pr.update(self.input)  # e(t)→u(t)
            self.my_pr3.update(self.input)  # e(t)→u(t)
            output_control = self.my_pr.output + self.my_pr3.output  # e(t)→u(t)  # pr输出控制量
            self.my_plant.update(output_control)  # 控制量输入被控对象 e(t)→u(t)
            self.output = self.my_plant.output
            self.final_output_list.append(self.output)
            self.goal_list.append(self.goal)
            r = -np.abs(
                (self.output - self.goal)) / (self.A1 + self.A3 + self.A25 +
                                              self.A47 + self.A50)
            if np.abs(r) > 1000:
                r = 1000 * r / np.abs(r)
                break
            sum_r = sum_r + r

        self.last_step_j = step_j
        ave_sum_r = 0
        if step_j > step_every_step - 10:
            out_sum_r = 100
            ave_sum_r = sum_r / step_j
            # if np.abs(ave_sum_r) > 20:
            #     out_sum_r = -np.abs(ave_sum_r) + out_sum_r
            if abs(ave_sum_r) < abs(self.last_sum_r):
                out_sum_r = out_sum_r + 100
                # elif np.abs(ave_sum_r) < 20:
                if (np.abs(ave_sum_r) < 0.01):
                    out_sum_r = out_sum_r + 10000
                else:
                    out_sum_r = (1 / np.abs(ave_sum_r)) * 100 + out_sum_r
        else:
            out_sum_r = -1000 + 500 * step_j / step_every_step
        self.action_view[2] = out_sum_r
        self.last_sum_r = ave_sum_r
        # if ave_sum_r>0:
        self.render()
        fft_output_list = fft(self.final_output_list,
                              (int)(step_t / self.t_sample_feature))
        mX = np.abs(fft_output_list)  # magnitude
        self.a_fft1 = mX[(int)(50 * step_t)]
        self.a_fft3 = mX[(int)(3 * 50 * step_t)]
        self.a_fft25 = mX[(int)(25 * 50 * step_t)]
        self.a_fft47 = mX[(int)(47 * 50 * step_t)]
        self.a_fft50 = mX[(int)(50 * 50 * step_t)]
        s = np.concatenate((np.array([self.a_fft1]), np.array([self.a_fft3]),
                            np.array([self.a_fft25]), np.array([self.a_fft47]),
                            np.array([self.a_fft50])))

        # s = np.concatenate((np.array([self.A1]), np.array([self.A3]), np.array([self.A25]),
        # np.array([self.A47]), np.array([self.A50]), np.array([self.L * 1e6]),
        # np.array([self.C * 1e6]),  np.array([self.X]) ,np.array([self.rL])))
        return s, out_sum_r
예제 #11
0
파일: Main.py 프로젝트: tfursten/SI-py
def main(title, maiting_system, n_pix, sphere, init_num_plants, generations, n_markers, n_ovules, n_pollen, mutation_p, del_mut_p, p_mean, s_mean, data_rate):
	
	#----------------------Set Parameters-------------------------------------
	#set average time between mutations
	n_loci = n_markers + 1 #int
	s_mut_p = mutation_p #float
	if n_markers:
		m_mut_p = s_mut_p/n_markers #float

	
	#keep count of the total number of alleles
	total_s_alleles = 2*init_num_plants  #int
	total_m_alleles = n_markers * 2 * init_num_plants #int
	
	#start first mutation countdown
	s_mut_count = new_mut_count(s_mut_p) #int
	m_mut_count = new_mut_count(m_mut_p) #int
	d_mut_count = new_mut_count(del_mut_p) #int 
	
	#set functions to decrement the mutation countdown
	s_decrement_p = decrement_count(1,n_pollen)
	m_decrement_p = decrement_count(n_markers, n_pollen)
	d_decrement_p = decrement_count(1, n_pollen)
	s_decrement_o = decrement_count(1,n_ovules)
	m_decrement_o = decrement_count(n_markers, n_ovules)
	d_decrement_o = decrement_count(1, n_ovules)

	dominance_rank = [random.random() for i in xrange(total_s_alleles)] #list of floats

	#set file information
	pop_file_name = title+'.pkl' #str
	#pop_file = open(pop_file_name, 'w')
	outfile = open(pop_file_name, 'wb') #file
	
	paternal = 0
	maternal = 1
	#----------------------Initialize Population-------------------------------
	
   	pop = Grid(n_pix, n_ovules, title, x_max, y_max) #Population Grid Object
	init_plant_population(pop,init_num_plants,n_loci)
	gen = 0
	#-----------------------------(Disperse Pollen)----------------------------
	print('-'*50)
	print('Gen # \t Time')
	print('-'*50)
	gen_count = 1
	
	

	while generations:
		start_time = time.clock()
		if gen_count % data_rate == 0: collect_data = True
		else: collect_data = False
		
		for pix in xrange(n_pix):
			if pop.cell_weights()[gen][pix]: #list of floats, zero if there is no plant in location
				paternal_plant = pop.population()[gen][pix] #Plant object at location in pop
				x = pix//y_max #int
				y = pix%y_max #int
				check_S_mutation = False
				check_M_mutation = False
				check_D_mutation = False
				#Check if any pollen from this plant will have a mutation and decrement counts
				#Note: this only allows one mutation to occur per plant per loci
				if s_mut_count - n_pollen < 0:
					#determine index of pollen that will have S allele mutation
					s_mut_index = s_mut_count #int
					#reset count adding the remainder
					s_mut_count = new_mut_count(s_mut_p)+ n_pollen-s_mut_index-1 #int
					check_S_mutation = True
				else: 
					s_mut_count = s_decrement_p(s_mut_count) #int
				if m_mut_count - n_pollen*n_markers < 0:
					#determine index of pollen that will have a marker mutation
					m_mut_index = m_mut_count//n_markers #int
					marker_index = m_mut_count % n_markers #int
					#reset count adding the remainder
					m_mut_count = new_mut_count(m_mut_p) + n_pollen*n_markers - m_mut_count -1 #int
					check_M_mutation = True
				else:
					m_mut_count = m_decrement_p(m_mut_count) #int
				if d_mut_count - n_pollen < 0:
					#determine index of pollen that will have d allele mutation
					d_mut_index = d_mut_count #int
					#reset count adding the remainder
					d_mut_count = new_mut_count(del_mut_p) + n_pollen-d_mut_index-1 #int
					check_D_mutation = True
				else: 
					d_mut_count = d_decrement_p(d_mut_count) #int

				pollen_positions = [disperse(p_mean,x,y) for pollen in xrange(n_pollen)] #list of disperal positions-int. -1 if out of range
				#new list to determine if there is a plant in that position 
				occupied_positions = [pop.cell_weights()[gen][position] if position >= 0 else 0 for position in pollen_positions] #list of ints
				for i,occupied in enumerate(occupied_positions):
					if occupied: 
						new_pix = pollen_positions[i] #int
						maternal_plant = pop.population()[gen][new_pix] #plant object
						pollen_haplotype = random.randint(0,1)
						compatible = compatibility(maternal_plant,paternal_plant, pollen_haplotype, dominance_rank)
						if maiting_system == 2 and check_S_mutation and i == s_mut_index:
							compatible = True
						if compatible:
							o = random.randint(0,n_ovules-1)
							ovule_weight = pop.ovule_weights()[new_pix][o] #float
							pollen_weight = random.random() #float
							if ovule_weight < pollen_weight:
								pop.ovule_weights()[new_pix][o] = pollen_weight #float
								pollen = recombination(paternal_plant, pollen_haplotype) #[int,int,int...],[int,int,int...],[int], int]
								pop.ovules()[new_pix][o][paternal] = pollen
								if check_S_mutation:
									if i == s_mut_index:
										print pollen
										mutate(pollen[0],total_s_alleles) #([int,int,int...], int)
										print pollen
										total_s_alleles += 1
										dominance_rank.append(random.random())
								if check_M_mutation:
									if i == m_mut_index:
										mutate(pollen[0],total_m_alleles,marker_index,1) #([int,int,int...],int,int,int)
										total_m_alleles += 1
								if check_D_mutation:
									if i == d_mut_index:
										pollen[2]=[1]
										
		

	
		for pix in xrange(n_pix):
			if pop.cell_weights()[gen][pix]:
				x = pix//y_max  #int
				y = pix%y_max	#int
				maternal_plant = pop.population()[gen][pix] #plant object
				check_S_mutation = False
				check_M_mutation = False
				check_D_mutation = False
				#Check if any ovules from this plant will have a mutation and decrement counts
				#Note: this only allows one mutation to occur per plant per loci
				if s_mut_count - n_ovules < 0:
					#determine index of ovule that will have S allele mutation
					s_mut_index = s_mut_count #int
					#reset count adding the remainder
					s_mut_count = new_mut_count(s_mut_p)+ n_ovules-s_mut_index-1 #int
					check_S_mutation = True
				else: 
					s_mut_count = s_decrement_o(s_mut_count) #int
				if m_mut_count - n_ovules*n_markers < 0:
					#determine index of ovule that will have a marker mutation
					m_mut_index = m_mut_count//n_markers #int
					marker_index = m_mut_count % n_markers #int
					#reset count adding the remainder
					m_mut_count = new_mut_count(m_mut_p) + n_ovules*n_markers - m_mut_count -1 #int
					check_M_mutation = True
				else: 
					m_mut_count = m_decrement_o(m_mut_count)#int
				if d_mut_count - n_pollen < 0:
					#determine index of ovule that will have d allele mutation
					d_mut_index = d_mut_count #int
					#reset count adding the remainder
					d_mut_count = new_mut_count(del_mut_p) + n_ovules-d_mut_index-1 #int
					check_D_mutation = True
				else: 
					d_mut_count = d_decrement_o(d_mut_count) #int

				occupied_ovules = pop.ovule_weights()[pix] #list of floats [float,float,float...n_ovules]
				seed_disperse = [disperse(s_mean,x,y) if ovule else -2 for ovule in occupied_ovules] #list of ints
				for o,new_pix in enumerate(seed_disperse):
					if new_pix >= 0:
						seed_weight = random.random() #float
						cell_weight = pop.cell_weights()[not gen][new_pix] #float
						if seed_weight > cell_weight:
							ovule_haplotype = random.choice((0,1)) #int
							ovule = recombination(maternal_plant,ovule_haplotype) #[int,int,int...],[int,int,int...],[int], int]
							pop.ovules()[pix][o][maternal] = ovule
							if check_S_mutation:
								if o == s_mut_index:
									mutate(ovule[0],total_s_alleles)
									total_s_alleles += 1
									dominance_rank.append(random.random())
							if check_M_mutation:
								if o == m_mut_index:
									mutate(ovule[0],total_m_alleles,marker_index,1)
									total_m_alleles += 1
							if check_D_mutation:
								if o == d_mut_index:
									ovule[2]=[1]
							if not lethal_homozygous(pop.ovules()[pix][o][paternal][2],pop.ovules()[pix][o][maternal][2]):
								plant = Plant(new_pix) #plant object
								plant.set_genotype_ch1([pop.ovules()[pix][o][paternal][0],pop.ovules()[pix][o][maternal][0]]) #list of lists [[int,int,int...],[int,int,int...]]
								plant.set_genotype_ch2([pop.ovules()[pix][o][paternal][2],pop.ovules()[pix][o][maternal][2]]) #list of lists [[int],[int]]
								plant.set_parents(pop.ovules()[pix][o][paternal][3], pop.ovules()[pix][o][maternal][3], n_loci)
								plant.set_grandparents(([pop.ovules()[pix][o][paternal][1], pop.ovules()[pix][o][maternal][1]]))
								pop.cell_weights()[not gen][new_pix] = seed_weight
								pop.population()[not gen][new_pix] = plant
		

		print gen_count,'\t',time.clock()-start_time
		
		weights = [int(ceil(i)) if i else i for i in pop.cell_weights()[not gen]] #list of ints
		#pop_file.write(str(weights)+"\n")

		if collect_data:
			current_pop = Generation_Summary.current_plants(pop.population()[not gen], weights)
			cPickle.dump(current_pop,outfile)
		

		#reset for next generation
		pop.reset_ovule_weights()
		pop.reset_cell_weights(gen)
		gen = not gen
		generations -= 1						
		gen_count += 1
	
	#pop_file.close()	
	outfile.close()
예제 #12
0
def _Communicate(conn):
    plant = Plant.Plant()
    while True:
        data = conn.recv(4)
예제 #13
0
import _thread, socket, time
import Plant
import sqlite3

plants = []

p = Plant.Plant()
p.name = "Franklin"
p.location = "Desk in Spock"
plants.append(p)

p = Plant.Plant()
p.name = "Einstein"
p.location = "Kitchen"
plants.append(p)

p = Plant.Plant()
p.name = "Curie"
p.location = "Teamroom"
plants.append(p)

p = Plant.Plant()
p.name = "Dawkins"
p.location = "Roomy McRoomface"
plants.append(p)

p = Plant.Plant()
p.name = "Dawkins"
p.location = "Roomy McRoomface"
plants.append(p)
예제 #14
0
    def decodeRequestAndWriteToDb(self,requestJson):
        estado = requestJson["statusQualificador"]
        if "Sinônimo" in estado or "sinônimo" in estado or "Sinonimo" in estado or "sinonimo" in estado:
            if('ehSinonimo' in requestJson.keys()):
                result = self.parseSinonimoSource(requestJson["ehSinonimo"])
                return result
            else:
                return 0
        if len(estado)==0:
            return 0
        if "Nome correto" in estado:
            estado = "nome correto"
        elif "Nome aceito" in estado:
            estado = "nome aceito"
        elif "Variante ortográfica" in estado:
            estado = "variante ortografica"
        elif "Nome mal aplicado" in estado:
            estado = "nome mal aplicado"
        if "endemismo" in requestJson.keys():
            endemismo = requestJson["endemismo"]
        else:
            endemismo = ""
        if 'formaVida' in requestJson.keys():
            formaVida = requestJson["formaVida"]
            formaVida = self.arrayToStr(formaVida)
        else:
            formaVida = ""
        if "substrato" in requestJson.keys():
            substrato = requestJson["substrato"]
            substrato = self.arrayToStr(substrato)
        else:
            substrato = ""
        if "tipoVegetacao" in requestJson.keys():
            tipoVegetacao = requestJson["tipoVegetacao"]
            tipoVegetacao = self.arrayToStr(tipoVegetacao)
        else:
            tipoVegetacao = ""
        if "origem" in requestJson.keys():
            origem = requestJson["origem"]
        else:
            origem = ""
        if "nome" in requestJson.keys():
            nome=self.parseNome(requestJson["nome"])
            autor=self.parseAutor(requestJson["nome"])
            nome = nome.strip()+" "+autor.strip()
        else:
            nome=""
            autor=""
        if "dominioFitogeografico" in requestJson.keys():
            dominioFitogeografico=requestJson["dominioFitogeografico"]
            dominioFitogeografico = self.arrayToStr(dominioFitogeografico)
        else:
            dominioFitogeografico=""
        if "hierarquia" in requestJson.keys():
            familia = self.getFamily(requestJson["hierarquia"])
            grupoTaxonomico = self.getGrupoTaxonomico(requestJson["hierarquia"])
        else:
            familia=""
            grupoTaxonomico=""
        fonte="floradobrasil"
        ocorrenciasConfirmadas = self.parseOcorrenciasConfirmadas(requestJson)
        ocorrenciasDuvidosas = self.parseOcorrenciasDuvidosas(requestJson)
        sinonimosList = []
        if "temComoSinonimo" in requestJson.keys():
            sinonimosList=self.parseSinonimos(requestJson["temComoSinonimo"])

        ocorrenciasConfirmadas = self.arrayToStr(ocorrenciasConfirmadas)
        ocorrenciasDuvidosas = self.arrayToStr(ocorrenciasDuvidosas)
        manager = plantManager.PlantsManager()
        manager.addPlant(nome,autor,fonte,estado,grupoTaxonomico,familia,formaVida,substrato,origem,endemismo,ocorrenciasConfirmadas,ocorrenciasDuvidosas,dominioFitogeografico,tipoVegetacao,"")
        for sino in sinonimosList:
            manager.addPlant(sino[0],sino[1],fonte,"sinonimo","","","","","","","","","","",nome)
        if autor=="" or autor is None:
            autor="desconhecido"

        print("nome:"+nome)
        print("autor:"+autor)
        print("fonte: "+fonte)
        print(estado)
        manager.writeAllToDb()
        '''
        print("endemismo:"+endemismo)
        print("grupo grupoTaxonomico: "+grupoTaxonomico)
        print("familia: "+familia)
        print(tipoVegetacao)
        print(dominioFitogeografico)
        print(formaVida)
        print(substrato)
        print(ocorrenciasConfirmadas)
        print(ocorrenciasDuvidosas)
        for sinonimo in sinonimosList:
            print(sinonimo)
        manager.writeAllToDb()
        '''
        return 1