too much error correction made the code more worse

时间:2016-07-14 22:20:00

标签: python-3.x

This is my first time with python and I have written this program to simulate a node trying to find mobile phones in an area. first i am taking the distance converting them to RSS and based on that deciding the direction of the node to find all mobile phones. the code worked fine till 2 days ago but when i expanded to area and no of nodes, some errors started to come and i kept correcting them. now it doesn't run and I have made it more worse: is there any hint or guidance I can get from the experts? and yes I have overwritten the code without saving it to some other place. Or maybe someone can really help me by having a look at it. its really messy though. thanks

Here is a part of the code i am having the most trouble with.

def pos_y(uav_current_cord,area,uav_step_size,flag):
detected_y = 0
detected_nodes_pos_y = 0 
if flag == 1:
    span = area+uav_step_size -  uav_current_cord[1]  
    #print(span)
    for y in range(uav_current_cord[1],area+uav_step_size,uav_step_size):
        global distance_covered 
        distance_covered += uav_step_size             
        UAV_new = [uav_current_cord[0],y]
        y_last_pos = UAV_new        
        plot((*UAV_new), marker='o', color='r', ls='')
        distance_new=[]
        for i in nodes:
            temp_x_axis = euclid_dist(UAV_new,node_cord[i]) 
            ss_x_axis = dist_to_ss(temp_x_axis)
            if (ss_x_axis > threshold):
                detected_nodes_pos_y += 1
        detected_y = (detected_nodes_pos_y)

    if y >= area+uav_step_size:
        uav_current_cord = UAV_new
        flag = 1
        keep_moving = neg_x(uav_current_cord,span,uav_step_size,flag,y_last_pos)
        uav_current_new = keep_moving[0]
        distance_covered_back = keep_moving[1]
        nodes_detected_final = keep_moving[2]
        uav_current_new = keep_moving[3]
        #return [uav_current_new, distance_covered, nodes_detected_final, uav_current_new]     
        #uav_current_new = y_last_pos
    return [y_last_pos, distance_covered, detected_y, y_last_pos]
if flag == 1:
    area1 = area*2
for y in range(uav_current_cord[1],area,uav_step_size):
    UAV_new = [uav_current_cord[0],y]
    #print('Pos_Y movement of UAV',UAV_new)
    #print('ye loop chal raha hai')
    y_last_pos = UAV_new        
    plot((*UAV_new), marker='o', color='g', ls='')
    distance_new=[]
    for i in nodes:
        temp_x_axis = euclid_dist(UAV_new,node_cord[i]) 
        ss_x_axis = dist_to_ss(temp_x_axis)
        if (ss_x_axis > threshold):
            detected_nodes_pos_y += 1
    detected_y = (detected_nodes_pos_y)
    #print('nodes detected in pos Y  ',detected_y)    
    #print('last position in pos y =', y_last_pos)  
for y in range(UAV_new[1],uav_current_cord[1],-uav_step_size):
   # print('ab ye chala hai')
    UAV_new=[uav_current_cord[0],y]
    plot((*UAV_new), marker='o', color='g', ls='')
distance_covered_back = area*2
return [UAV_new, distance_covered_back, detected_y, y_last_pos]

2 个答案:

答案 0 :(得分:1)

正如其他人所说,使用git,但要知道其他选择。

如果你对版本控制不熟悉,那么从Git开始将暂时是一个很大的帮助或障碍,但无论如何,学习Git都将是有价值的。

如果您有MSDN帐户,还可以使用Visual Studio的内置修订控件。它对于快速原型设计很有用,但与git没有真正的优势。

另一个非常简单的常见选择是TortoiseSVN。这很容易使用。

或者,如果您不介意将您的代码公开为免费帐户或每月支付少量私人费用,您可以使用GitHub通过浏览器完成所有提交。对于版本控制新手来说,这是最简单的选择。它的主要缺点是多文件提交的灵活性有限。

我对BitBucket和GitHub的其他一些常见替代品几乎没有任何有意义的经验。

答案 1 :(得分:0)

我很抱歉,但我们无法帮助你...你不是第一个遇到这个问题的人,不幸的是不是最后一个问题。

为了帮助防止此类问题,存在Git等软件。它让你做以下事情(image reference):

enter image description here

根文件是。这是你的工作脚本。如果您想要更改/添加/删除某些内容,您可以创建一个所谓的分支,您可以在其中执行任何操作。如果您已对其进行了测试,则可以提交更改(即,将其作为带有注释的脚本的新版本存储)并将合并是,将更改添加到主脚本)。如果出现问题,您可以随时返回到以前版本的脚本。

Git的documentation非常好:阅读并明智地使用它!