Commit 3a85c10d authored by Ahmad Reza Cheraghi's avatar Ahmad Reza Cheraghi
Browse files

some code cleaning based on the results of sonarqube

parent f688e95e
...@@ -31,7 +31,7 @@ read = 0 ...@@ -31,7 +31,7 @@ read = 0
write = 1 write = 1
particle_counter=0 particle_counter=0
class Particle(matter.matter): class Particle(matter.Matter):
"""In the classe location all the methods for the characterstic of a location is included""" """In the classe location all the methods for the characterstic of a location is included"""
def __init__(self, sim, x, y, color=black, alpha=1, mm_limit=0, mm_size=0): def __init__(self, sim, x, y, color=black, alpha=1, mm_limit=0, mm_size=0):
...@@ -118,10 +118,9 @@ class Particle(matter.matter): ...@@ -118,10 +118,9 @@ class Particle(matter.matter):
:return: True: Success Moving; False: Non moving :return: True: Success Moving; False: Non moving
""" """
dir_coord = self.sim.get_coords_in_dir(self.coords, dir) dir_coord = self.sim.get_coords_in_dir(self.coords, dir)
#sim = self.sim_to_coords(dir_coord[0], dir_coord[1])
#print ("sim actual coord "+ str(sim)) if self.sim.border==1 and (abs(dir_coord[0]) > self.sim.get_sim_x_size() \
if self.sim.border==1: or abs(dir_coord[1]) > self.sim.get_sim_y_size()) :
if abs(dir_coord[0]) > self.sim.get_sim_x_size() or abs(dir_coord[1]) > self.sim.get_sim_y_size() :
dir = dir - 3 if dir > 2 else dir + 3 dir = dir - 3 if dir > 2 else dir + 3
dir_coord = self.sim.get_coords_in_dir(self.coords, dir) dir_coord = self.sim.get_coords_in_dir(self.coords, dir)
if self.sim.check_coords(dir_coord[0], dir_coord[1]): if self.sim.check_coords(dir_coord[0], dir_coord[1]):
...@@ -244,14 +243,11 @@ class Particle(matter.matter): ...@@ -244,14 +243,11 @@ class Particle(matter.matter):
def get_matter_in_dir(self, matter="tile", dir=E): def get_matter_in_dir(self, matter="tile", dir=E):
if matter=="tile": if matter=="tile" and self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_tile_map_coords():
if self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_tile_map_coords():
return self.sim.get_tile_map_coords()[self.sim.get_coords_in_dir(self.coords, dir)] return self.sim.get_tile_map_coords()[self.sim.get_coords_in_dir(self.coords, dir)]
if matter=="particle": if matter=="particle" and self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_particle_map_coords():
if self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_particle_map_coords():
return self.sim.get_particle_map_coords()[self.sim.get_coords_in_dir(self.coords, dir)] return self.sim.get_particle_map_coords()[self.sim.get_coords_in_dir(self.coords, dir)]
if matter=="location": if matter=="location" and self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_location_map_coords():
if self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_location_map_coords():
return self.sim.get_location_map_coords()[self.sim.get_coords_in_dir(self.coords, dir)] return self.sim.get_location_map_coords()[self.sim.get_coords_in_dir(self.coords, dir)]
...@@ -312,29 +308,13 @@ class Particle(matter.matter): ...@@ -312,29 +308,13 @@ class Particle(matter.matter):
def get_matter_in_dir(self, matter="tile", dir=E): def get_matter_in_dir(self, matter="tile", dir=E):
if matter=="tile": if matter=="tile" and self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_tile_map_coords():
if self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_tile_map_coords():
return self.sim.get_tile_map_coords()[self.sim.get_coords_in_dir(self.coords, dir)] return self.sim.get_tile_map_coords()[self.sim.get_coords_in_dir(self.coords, dir)]
if matter=="particle": if matter=="particle" and self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_particle_map_coords():
if self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_particle_map_coords():
return self.sim.get_particle_map_coords()[self.sim.get_coords_in_dir(self.coords, dir)] return self.sim.get_particle_map_coords()[self.sim.get_coords_in_dir(self.coords, dir)]
if matter=="location": if matter=="location" and self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_location_map_coords():
if self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_location_map_coords():
return self.sim.get_location_map_coords()[self.sim.get_coords_in_dir(self.coords, dir)] return self.sim.get_location_map_coords()[self.sim.get_coords_in_dir(self.coords, dir)]
def scan_for_matter_within(self, matter='all', hop=1): def scan_for_matter_within(self, matter='all', hop=1):
""" """
Scans for particles, tiles, or location on a given hop distance and all the matters within the hop distance Scans for particles, tiles, or location on a given hop distance and all the matters within the hop distance
...@@ -377,33 +357,22 @@ class Particle(matter.matter): ...@@ -377,33 +357,22 @@ class Particle(matter.matter):
y_scan_coord_pos = self.coords[1] + cnt y_scan_coord_pos = self.coords[1] + cnt
if cnt == 0: if cnt == 0:
if matter == "particles": if matter == "particles":
# if self.coords in self.sim.particle_map_coords:
# hop_list.append(self.sim.particle_map_coords[self.coords])
if (x_scan_pos, y_scan_coord_neg) in self.sim.particle_map_coords: if (x_scan_pos, y_scan_coord_neg) in self.sim.particle_map_coords:
hop_list.append(self.sim.particle_map_coords[(x_scan_pos, y_scan_coord_neg)]) hop_list.append(self.sim.particle_map_coords[(x_scan_pos, y_scan_coord_neg)])
if (x_scan_neg, y_scan_coord_neg) in self.sim.particle_map_coords: if (x_scan_neg, y_scan_coord_neg) in self.sim.particle_map_coords:
hop_list.append(self.sim.particle_map_coords[(x_scan_neg, y_scan_coord_neg)]) hop_list.append(self.sim.particle_map_coords[(x_scan_neg, y_scan_coord_neg)])
elif matter == "locations": elif matter == "locations":
# if self.coords in self.sim.location_map_coords:
# hop_list.append(self.sim.location_map_coords[self.coords])
if (x_scan_pos, y_scan_coord_neg) in self.sim.location_map_coords: if (x_scan_pos, y_scan_coord_neg) in self.sim.location_map_coords:
hop_list.append(self.sim.location_map_coords[(x_scan_pos, y_scan_coord_neg)]) hop_list.append(self.sim.location_map_coords[(x_scan_pos, y_scan_coord_neg)])
if (x_scan_neg, y_scan_coord_neg) in self.sim.location_map_coords: if (x_scan_neg, y_scan_coord_neg) in self.sim.location_map_coords:
hop_list.append(self.sim.location_map_coords[(x_scan_neg, y_scan_coord_neg)]) hop_list.append(self.sim.location_map_coords[(x_scan_neg, y_scan_coord_neg)])
elif matter == "tiles": elif matter == "tiles":
# if self.coords in self.sim.tile_map_coords:
# hop_list.append(self.sim.tile_map_coords[self.coords])
if (x_scan_pos, y_scan_coord_neg) in self.sim.tile_map_coords: if (x_scan_pos, y_scan_coord_neg) in self.sim.tile_map_coords:
hop_list.append(self.sim.tile_map_coords[(x_scan_pos, y_scan_coord_neg)]) hop_list.append(self.sim.tile_map_coords[(x_scan_pos, y_scan_coord_neg)])
if (x_scan_neg, y_scan_coord_neg) in self.sim.tile_map_coords: if (x_scan_neg, y_scan_coord_neg) in self.sim.tile_map_coords:
hop_list.append(self.sim.tile_map_coords[(x_scan_neg, y_scan_coord_neg)]) hop_list.append(self.sim.tile_map_coords[(x_scan_neg, y_scan_coord_neg)])
elif matter == "all": elif matter == "all":
# if self.coords in self.sim.tile_map_coords:
# hop_list.append(self.sim.tile_map_coords[self.coords])
# if self.coords in self.sim.location_map_coords:
# hop_list.append(self.sim.location_map_coords[self.coords])
# if self.coords in self.sim.particle_map_coords:
# hop_list.append(self.sim.particle_map_coords[self.coords])
if (x_scan_pos, y_scan_coord_neg) in self.sim.tile_map_coords: if (x_scan_pos, y_scan_coord_neg) in self.sim.tile_map_coords:
hop_list.append(self.sim.tile_map_coords[(x_scan_pos, y_scan_coord_neg)]) hop_list.append(self.sim.tile_map_coords[(x_scan_pos, y_scan_coord_neg)])
if (x_scan_neg, y_scan_coord_neg) in self.sim.tile_map_coords: if (x_scan_neg, y_scan_coord_neg) in self.sim.tile_map_coords:
...@@ -925,7 +894,7 @@ class Particle(matter.matter): ...@@ -925,7 +894,7 @@ class Particle(matter.matter):
def delete_tile_on(self, x=None, y=None): def delete_tile_on(self, x=None, y=None):
""" """
Deletes a tile either on a given x,y coordinates Deletes a tile either on a given x,y coordinates
, ,
:param x: x coordinate :param x: x coordinate
:param y: y coordinate :param y: y coordinate
:return: True: Deleting successful; False: Deleting unsuccessful :return: True: Deleting successful; False: Deleting unsuccessful
...@@ -1670,7 +1639,6 @@ class Particle(matter.matter): ...@@ -1670,7 +1639,6 @@ class Particle(matter.matter):
logging.info("particle could not be taken") logging.info("particle could not be taken")
return False return False
else: else:
pass
logging.info("particl is not in the sim") logging.info("particl is not in the sim")
else: else:
logging.info("particle cannot be taken") logging.info("particle cannot be taken")
...@@ -1832,7 +1800,6 @@ class Particle(matter.matter): ...@@ -1832,7 +1800,6 @@ class Particle(matter.matter):
coords = self.sim.get_coords_in_dir(self.coords, dir) coords = self.sim.get_coords_in_dir(self.coords, dir)
logging.info("Going to create a location in %s on position %s", str(dir), str(coords)) logging.info("Going to create a location in %s on position %s", str(dir), str(coords))
if self.sim.add_location(coords[0], coords[1], color, alpha) == True: if self.sim.add_location(coords[0], coords[1], color, alpha) == True:
# self.sim.new_location_flag = True
logging.info("Created location on coords %s", str(coords)) logging.info("Created location on coords %s", str(coords))
self.sim.csv_round_writer.update_locations_num(len(self.sim.get_location_list())) self.sim.csv_round_writer.update_locations_num(len(self.sim.get_location_list()))
self.sim.csv_round_writer.update_metrics( location_created=1) self.sim.csv_round_writer.update_metrics( location_created=1)
...@@ -1858,7 +1825,6 @@ class Particle(matter.matter): ...@@ -1858,7 +1825,6 @@ class Particle(matter.matter):
coords = (x, y) coords = (x, y)
logging.info("Going to create a location on position %s", str(coords)) logging.info("Going to create a location on position %s", str(coords))
if self.sim.add_location(coords[0], coords[1], color, alpha) == True: if self.sim.add_location(coords[0], coords[1], color, alpha) == True:
# self.sim.new_location_flag = True
logging.info("Created location on coords %s", str(coords)) logging.info("Created location on coords %s", str(coords))
self.sim.csv_round_writer.update_locations_num(len(self.sim.get_location_list())) self.sim.csv_round_writer.update_locations_num(len(self.sim.get_location_list()))
self.sim.csv_round_writer.update_metrics( location_created=1) self.sim.csv_round_writer.update_metrics( location_created=1)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment