def _get_lines_from_line(line: Line, params: list[_Params], include_blockstarts: bool): lines = [line ] if not line.is_block_starter() or include_blockstarts else [] for rule in line.get_rules(_NAME): lines += _get_lines_from_rule(rule, params) return lines
def __init__(self, pos, angle, ticks, vel, number, division_ratio=2, division_angle=45, divide_angles=True, divide_distance=True, color1=(200, 200, 200), color2=(150, 150, 150), fruits=False): self.parent_line = Line(pos, angle, ticks, vel, number, division_angle) self.lines = [] self.grown_lines = [] self.blossoms = [] self.max_number = number self.divide_angles = divide_angles self.divide_distance = divide_distance self.division_ratio = division_ratio self.grown = False self.window_width, self.window_height = WINDOW_WIDTH, WINDOW_HEIGHT self.color1, self.color2 = color1, color2 self.fruits = fruits
def extract(cls, raw_lines: list[str], line_number: int = 1): "Returns all blocks in a from a list of textual lines." if len(raw_lines) == 0: return [] blocks: list[Block] = [Block(line_number)] for raw_line in raw_lines: line = Line(raw_line, line_number) if line.is_block_starter(): blocks.append(Block(line_number)) blocks[-1].lines.append(line) line_number += 1 return blocks
def append_line(type__, parent): self.lines.append( Line(parent=parent, type_=type__, division_ratio=self.division_ratio, divide_angles=self.divide_angles, divide_distance=self.divide_distance))
from classes.plotting import Plotting from classes.thresholding import Thresholding import sys import numpy as np import cv2 import matplotlib.pyplot as plt import matplotlib.image as mpimg from enum import Enum from moviepy.editor import VideoFileClip #-------------- # Globals #-------------- left_lane = Line() right_lane = Line() # Control variables for the sliding window technique to use initiate_sw = True initiate_sw_counter = 0 initiate_sw_limit = 4 # Constants DEBUG = False KERNEL = 7 # Increase for smoother result (odd numbers only) test_image = 'test_images/test11.jpg' video_in = 'project_video.mp4' video_out = 'project_video_output.mp4' video_out_db1 = 'project_video_output_debug_1.mp4'
if count == 1: ts = s if count == 2: t = s count = 0 if ts.isdigit(): # useless! d = {"ip": ip, "ts": int(ts), "t": float(t)} data.append(d) else: count += 1 #consider each packet as a "point" P = (time_of_capture, timestamp) #connect with a line packets having same source IP address #if a packet doesn't belong to the line, then more than one host are behind the same IP address curr_ip = "init" for i in range(len(data) - 1): if (curr_ip != data[i]["ip"]): curr_ip = data[i]["ip"] if data[i]["ip"] != data[i + 1]["ip"]: continue p1 = Point(data[i]["t"], data[i]["ts"]) p2 = Point(data[i + 1]["t"], data[i + 1]["ts"]) l = Line(p1, p2) for j in range(i + 2, len(data)): if data[j]["ip"] == curr_ip: p3 = Point(data[j]["t"], data[j]["ts"]) l.setThreshold(data[j]["ts"] * 0.3) if not l.contains(p3): print data[j]["ip"] break
class Tree: def __init__(self, pos, angle, ticks, vel, number, division_ratio=2, division_angle=45, divide_angles=True, divide_distance=True, color1=(200, 200, 200), color2=(150, 150, 150), fruits=False): self.parent_line = Line(pos, angle, ticks, vel, number, division_angle) self.lines = [] self.grown_lines = [] self.blossoms = [] self.max_number = number self.divide_angles = divide_angles self.divide_distance = divide_distance self.division_ratio = division_ratio self.grown = False self.window_width, self.window_height = WINDOW_WIDTH, WINDOW_HEIGHT self.color1, self.color2 = color1, color2 self.fruits = fruits def move(self): for line in self.lines: line.move() self.parent_line.move() for line in self.grown_lines: line.move() if 2**self.max_number == len(self.lines): self.grown = True for blossom in self.blossoms: blossom.move() def create_new(self): def append_line(type__, parent): self.lines.append( Line(parent=parent, type_=type__, division_ratio=self.division_ratio, divide_angles=self.divide_angles, divide_distance=self.divide_distance)) lines_copy = self.lines.copy() if self.parent_line.grown and self.parent_line not in self.grown_lines and self.parent_line.number > 0: append_line(0, self.parent_line) append_line(1, self.parent_line) self.grown_lines.append(self.parent_line) for i, line in enumerate(lines_copy): if line.number > 0 and line.grown: append_line(0, line) append_line(1, line) self.grown_lines.append(line) self.lines.remove(line) if line.number == 1 and line.grown and self.fruits: self.blossoms.append(Blossom(parent=line)) def move_center(self, dx, dy): for line in self.lines: line.x += dx line.origin_x += dx line.y += dy line.origin_y += dy for line in self.grown_lines: line.x += dx line.origin_x += dx line.y += dy line.origin_y += dy for blossom in self.blossoms: blossom.x += dx blossom.y += dy def draw(self, surface): def inside_screen_line(line, lim1, lim2, window_width, window_height): if line.x > window_width or line.x < lim1: if line.origin_x > window_width or line.origin_x < lim1: return False if line.y > window_height or line.y < lim2: if line.origin_y > window_height or line.origin_y < lim2: return False return True def inside_screen_blossom(blossom, lim1, lim2, window_width, window_height): if blossom.x + blossom.width > window_width or blossom.x < lim1: if blossom.y + blossom.width > window_height or blossom.y < lim2: return False return True for line in self.grown_lines: if inside_screen_line(line, 0, 0, self.window_width, self.window_height): line.draw(surface, color=self.color1) for line in self.lines: if inside_screen_line(line, 0, 0, self.window_width, self.window_height): line.draw(surface, color=self.color2) self.parent_line.draw(surface) for blossom in self.blossoms: if inside_screen_blossom(blossom, 0, 0, self.window_width, self.window_height): blossom.draw(surface)
if count == 2: t=s count = 0 if ts.isdigit(): # useless! d={"ip":ip, "ts":int(ts), "t":float(t)} data.append(d) else: count+=1 #consider each packet as a "point" P = (time_of_capture, timestamp) #connect with a line packets having same source IP address #if a packet doesn't belong to the line, then more than one host are behind the same IP address curr_ip = "init" for i in range(len(data) - 1): if (curr_ip != data[i]["ip"]): curr_ip = data[i]["ip"] if data[i]["ip"] != data[i+1]["ip"]: continue p1 = Point(data[i]["t"], data[i]["ts"]) p2 = Point(data[i+1]["t"], data[i+1]["ts"]) l = Line(p1, p2) for j in range (i+2, len(data)): if data[j]["ip"] == curr_ip: p3 = Point(data[j]["t"], data[j]["ts"]) l.setThreshold(data[j]["ts"] * 0.3) if not l.contains(p3): print data[j]["ip"] break
def swap(self, pattern: str, raw_line: str): """Swaps out every line with the specified pattern outside comments in them for the raw_line provided.""" for i in range(len(self.lines)): if self.lines[i].contains(pattern): self.lines[i] = Line(raw_line, self.lines[i].number)
def append(self, raw_line: str): """Appends the line at the end of the block.""" line_number = self.line_number + len(self.lines) line = Line(raw_line, line_number) self.lines.append(line)