def __init__(self, outputDir, outputPrefix='R3_', lastId=0, esminiPath=None, saveImage=True): """ Args: outputDir ([type]): [description] outputPrefix ([type]): [description] lastId (int, optional): [description]. Defaults to 0. """ self.destinationPrefix = os.path.join(outputDir, outputPrefix) self.lastId = lastId self.roadBuilder = RoadBuilder() self.configuration = Configuration() if esminiPath is None: self.esminiPath = self.configuration.get("esminipath") else: self.esminiPath = esminiPath self.saveImage = saveImage if os.path.isdir(self.esminiPath) is False: logging.warn( f"Esmini path not found {self.esminiPath}. Will break if you try to save images using merger." ) pass
def __init__(self): self.config = Configuration() self.countryCode = CountryCodes.getByStr( self.config.get("countryCode")) self.curveBuilder = CurveRoadBuilder() self.name = "ConnectionBuilder" self.uTurnFirstLaneShift = self.config.get("uturn_firstlane_shift")
def setUp(self): self.configuration = Configuration() self.roadBuilder = junctions.RoadBuilder() self.straightRoadBuilder = StraightRoadBuilder() self.roadLinker = RoadLinker()
def __init__(self, outputDir, outputPrefix, lastId=0, straightRoadBuilder=None, straightRoadLen = 2, esminiPath = None, saveImage = False ): self.destinationPrefix = os.path.join(outputDir, outputPrefix) self.configuration = Configuration() self.lastId = lastId self.straightRoadLen = straightRoadLen self.straightRoadBuilder = straightRoadBuilder if straightRoadBuilder is None: self.straightRoadBuilder = StraightRoadBuilder() if esminiPath is None: self.esminiPath = self.configuration.get("esminipath") else: self.esminiPath = esminiPath self.saveImage = saveImage if os.path.isdir(self.esminiPath) is False: logging.warn(f"Esmini path not found {self.esminiPath}. Will break if you try to save images using harvester.") pass
def __init__(self, roadBuilder=None, straightRoadLen=10, minAngle=np.pi / 6, maxAngle=None, country=CountryCodes.US, random_seed=39): self.config = Configuration() self.roadBuilder = roadBuilder if self.roadBuilder is None: self.roadBuilder = RoadBuilder() self.straightRoadBuilder = StraightRoadBuilder() self.laneBuilder = LaneBuilder() self.straightRoadLen = straightRoadLen self.minAngle = minAngle self.maxAngle = maxAngle if self.maxAngle == np.pi: self.maxAngle = 0.99 * np.pi self.laneWidth = self.config.get("default_lane_width") self.minConnectionLength = self.config.get("min_connection_length") self.maxConnectionLength = self.config.get("max_connection_length") self.curveBuilder = CurveRoadBuilder(country=country) self.connectionBuilder = ConnectionBuilder() self.countryCode = country np.random.seed(random_seed) pass
def setUp(self): self.configuration = Configuration() self.esminiPath = self.configuration.get("esminipath") self.harvester = StraightRoadHarvester(outputDir="./output", outputPrefix="harvest-straight-", lastId=0, straightRoadLen=10, esminiPath=self.esminiPath) self.straightRoadBuilder = StraightRoadBuilder() self.pp = pprint.PrettyPrinter(indent=4)
def setUp(self): self.configuration = Configuration() self.esminiPath = self.configuration.get("esminipath") self.roadBuilder = RoadBuilder() self.laneBuilder = LaneBuilder() self.laneLinker = LaneLinker() self.straightRoadBuilder = StraightRoadBuilder()
def setUp(self): self.configuration = Configuration() with(open('F:\\myProjects\\av\\junction-art\\output\\harvested2R2LOrds.dill', 'rb')) as f: self.odrDic = dill.load(f) outputDir = os.path.join(os.getcwd(), 'output') self.merger = JunctionMerger(outputDir=outputDir, outputPrefix="test_")
def setUp(self) -> None: self.configuration = Configuration() self.hdMapBuilder = HDMapBuilder(30, mapSize=(300, 300), cellSize=(60, 60)) with open(logfile, 'w') as f: f.truncate() pass
def setUp(self): self.configuration = Configuration() self.esminiPath = self.configuration.get("esminipath") self.harvester = JunctionHarvester(outputDir="./output", outputPrefix="test-harvest-", lastId=0, esminiPath=self.esminiPath)
def setUp(self): self.configuration = Configuration() self.esminipath = self.configuration.get("esminipath") self.roadBuilder = junctions.RoadBuilder() self.straightRoadBuilder = StraightRoadBuilder() self.roadLinker = RoadLinker() self.connectionBuilder = ConnectionBuilder() self.curveRoadBuilder = CurveRoadBuilder()
def __init__(self, country=CountryCodes.US): self.STD_ROADMARK = pyodrx.RoadMark(pyodrx.RoadMarkType.solid, 0.2, rule=pyodrx.MarkRule.no_passing) self.STD_START_CLOTH = 1 / 1000000000 self.country = country self.laneBuilder = LaneBuilder() self.configuration = Configuration() self.name = 'StraightRoadBuilder' pass
class test_moreHelper(unittest.TestCase): def setUp(self): self.configuration = Configuration() self.esminiPath = self.configuration.get("esminipath") self.rootPath = self.configuration.get('rootPath') def test_saveRoadImageFromFile(self): xodrPath = self.rootPath + "\\output\\test-RightLane.xodr" outputFile = extensions.saveRoadImageFromFile( xodrPath, self.configuration.get("esminipath")) assert os.path.isfile(outputFile)
def setUp(self): self.configuration = Configuration() outputDir = os.path.join(os.getcwd(), 'output') lastId = 0 self.seed = 2 self.builder = ThreeWayJunctionBuilder(minAngle=np.pi / 9, maxAngle=np.pi * .25, straightRoadLen=20) self.randomState = self.configuration.get("random_state") pass
def setUp(self): self.configuration = Configuration() self.roadBuilder = RoadBuilder() self.junctionBuilder = JunctionBuilder() outputDir = os.path.join(os.getcwd(), 'output') lastId = 0 self.harvester = JunctionHarvester(outputDir=outputDir, outputPrefix='test_', lastId=lastId, minAngle=np.pi / 30, maxAngle=np.pi)
class test_Intersection(unittest.TestCase): def setUp(self): self.configuration = Configuration() outputDir = os.path.join(os.getcwd(), 'output') lastId = 0 self.seed = 2 self.builder = SequentialJunctionBuilder(minAngle=np.pi / 4, maxAngle=np.pi * .75, straightRoadLen=10, probLongConnection=0.5, probMinAngle=0.5, probRestrictedLane=0.2, maxConnectionLength=30, minConnectionLength=12, random_seed=self.seed) self.randomState = self.configuration.get("random_state") pass def test_getIncidentPoints(self): maxNumberOfRoadsPerJunction = 4 path = self.configuration.get("harvested_straight_roads") intersection = self.builder.createWithRandomLaneConfigurations( path, 0, maxNumberOfRoadsPerJunction=maxNumberOfRoadsPerJunction, maxLanePerSide=2, minLanePerSide=0, internalConnections=True, cp1=pyodrx.ContactPoint.end, internalLinkStrategy=LaneConfigurationStrategies.SPLIT_FIRST, getAsOdr=False) odr = intersection.odr xmlPath = f"output/test_getIncidentPoints-split-first-{maxNumberOfRoadsPerJunction}.xodr" odr.write_xml(xmlPath) incidentPoints = intersection.getIncidentPoints() translatedPoints = intersection.getIncidentPointsTranslatedToCenter() print(f"width and height: {intersection.getWH()}") print(incidentPoints) print(translatedPoints) extensions.printRoadPositions(odr) extensions.view_road( odr, os.path.join('..', self.configuration.get("esminipath")))
def __init__(self, outputDir, outputPrefix, lastId=0, minAngle = np.pi / 10, maxAngle = np.pi, straightRoadLen = 10, esminiPath = None, saveImage = True): """The angle between two connected roads are >= self.minAngle <= self.maxAngle Args: outputDir ([type]): [description] outputPrefix ([type]): [description] lastId (int, optional): [description]. Defaults to 0. minAngle ([type], optional): [description]. Defaults to np.pi/10. maxAngle ([type], optional): [description]. Defaults to np.pi. straightRoadLen : used both for normal and connection roads esminiPath: Path to esmini to generate images for roads. """ self.destinationPrefix = os.path.join(outputDir, outputPrefix) self.minAngle = minAngle self.maxAngle = maxAngle self.lastId = lastId self.straightRoadLen = straightRoadLen self.roadBuilder = RoadBuilder() self.straightRoadBuilder = StraightRoadBuilder() self.junctionBuilder = JunctionBuilder(self.roadBuilder) self.sequentialJunctionBuilder = SequentialJunctionBuilder(self.roadBuilder, self.straightRoadLen, minAngle=minAngle, maxAngle=maxAngle) self.junctionMerger = JunctionMerger(outputDir, outputPrefix, lastId) self.configuration = Configuration() if esminiPath is None: self.esminiPath = self.configuration.get("esminipath") else: self.esminiPath = esminiPath self.saveImage = saveImage if os.path.isdir(self.esminiPath) is False: logging.warn(f"Esmini path not found {self.esminiPath}. Will break if you try to save images using harvester.") pass
class test_RotateOpenDrive(unittest.TestCase): def setUp(self): self.configuration = Configuration() self.threeWayJunctionBuilder = ThreeWayJunctionBuilder( minAngle=np.pi / 9, maxAngle=np.pi * .25, straightRoadLen=20) def test_RotateOpenDrive(self): angleBetweenRoads = np.pi / 4 odr = self.threeWayJunctionBuilder.ThreeWayJunctionWithAngle( odrId=1, angleBetweenRoads=angleBetweenRoads, maxLanePerSide=4, minLanePerSide=2, cp1=pyodrx.ContactPoint.end) # extensions.view_road(odr, os.path.join('..', self.configuration.get("esminipath"))) # extensions.printRoadPositions(odr) RotatedODR = extensions.rotateOpenDrive(odr=odr, startX=0.0, startY=0.0, heading=np.pi) extensions.printRoadPositions(RotatedODR) extensions.view_road( RotatedODR, os.path.join('..', self.configuration.get("esminipath")))
def fetch(): logger = logging.getLogger("Tankerkoenig") logger.info("... fetching tankerkoenig api") config = Configuration() lati = config.tankerkoenig_lat() longi = config.tankerkoenig_long() api_key = Configuration().tankerkoenig_api_key() tankerkoenig_url = 'https://creativecommons.tankerkoenig.de/json/list.php?lat=' + lati + '&lng=' + longi + '&rad=5&sort=dist&type=all&apikey=' try: r = requests.get(tankerkoenig_url + api_key) json_obj = json.loads(r.content.decode('utf-8')) Persistence.persist('tankerkoenig', {'stations': json_obj['stations']}) except Exception as e: logger.error("Error: %s. Cannot get tankerkoenig api." % e) Persistence.persist('tankerkoenig', {})
def fetch(): logger = logging.getLogger("Posteo") logger.info("fetching posteo mails via imap") config = Configuration() mailhost = 'posteo.de' mailport = 993 username = config.posteo_username() password = config.posteo_password() try: obj = imaplib.IMAP4_SSL(mailhost, mailport) obj.login(username, password) obj.select() count = len(obj.search(None, 'UnSeen')[1][0].split()) Persistence.persist('posteo', {'count': count}) except Exception as e: logger.error("Error: %s. Cannot get posteo mails." % e) Persistence.persist('posteo', {})
def handle(text, slots, scheduler): logger = logging.getLogger('VacuumRobotIntent') logger.info("... executing vacuum robot intent") config = Configuration() ecovacs_password_hash = config.ecovacs_password_hash() ecovacs_email = config.ecovacs_email() ecovacs_device_id = config.ecovacs_device_id() api = EcoVacsAPI(ecovacs_device_id, ecovacs_email, ecovacs_password_hash, "de", "eu") my_vac = api.devices()[0] vacbot = VacBot(api.uid, api.REALM, api.resource, api.user_access_token, my_vac, "eu") vacbot.connect_and_wait_until_ready() answer = "" if "saugen" in text or "staubsaugen" in text: if "Wohnzimmer" in text: vacbot.run(SpotArea('start', area="5")) answer = "Berta, aufwachen! Sauge im Wohnzimmer!" elif "Esszimmer" in text: vacbot.run(SpotArea('start', area="0")) answer = "Berta, aufwachen! Sauge im Esszimmer!" elif "Bad" in text: vacbot.run(SpotArea('start', area="3")) answer = "Berta, aufwachen! Sauge im Bad!" elif "Diele" in text: vacbot.run(SpotArea('start', area="1")) answer = "Berta, aufwachen! Sauge in der Diele!" elif "Garderobe" in text: vacbot.run(SpotArea('start', area="4")) answer = "Berta, aufwachen! Sauge in der Garderobe!" elif "Eingang" in text: vacbot.run(SpotArea('start', area="6")) answer = "Berta, aufwachen! Sauge im Eingangsbereich!" elif "Küche" in text: vacbot.run(SpotArea('start', area="2")) answer = "Berta, aufwachen! Sauge in der Küche!" else: vacbot.run(SpotArea('start', area="0,1,2,3,4,5,6")) answer = "Berta, aufwachen! Fang an zu saugen!" elif "aufladen" in text or "Ladestation" in text: vacbot.run(Charge()) answer = "Berta, geh aufladen!" elif "aufhören" in text or "anhalten" in text: vacbot.run(Stop()) answer = "Berta, sofort aufhören!" return answer
def fetch(): logger = logging.getLogger("Teamup") logger.info("... fetching Teamup API") config = Configuration() teamup_url = config.teamup_url() teamup_token = config.teamup_token() start_date = str(datetime.date.today()) end_date = str(datetime.date.today() + datetime.timedelta(days=2)) url = teamup_url + "/events" + "?startDate=" + start_date + "&endDate=" + end_date headers = {'Teamup-Token': teamup_token} try: req = requests.get(url, headers=headers) events = json.loads(req.text) Persistence.persist('teamup', events) except Exception as e: logger.error("Error: %s. Cannot get teamup calendar." % e) Persistence.persist('teamup', {})
class test_JunctionMerger(unittest.TestCase): def setUp(self): self.configuration = Configuration() with(open('F:\\myProjects\\av\\junction-art\\output\\harvested2R2LOrds.dill', 'rb')) as f: self.odrDic = dill.load(f) outputDir = os.path.join(os.getcwd(), 'output') self.merger = JunctionMerger(outputDir=outputDir, outputPrefix="test_") def test_merge2R2L(self): odrs = self.odrDic['0.3141592653589793'] odrs2 = [odrs[0], odrs[2]] newOdr = self.merger.merge2R2L(odrs2) extensions.view_road(newOdr,os.path.join('..',self.configuration.get("esminipath"))) # odrs = self.odrDic['0.3141592653589793'] # odrs2 = [odrs[1], odrs[2]] # newOdr = self.merger.merge2R2L(odrs2) # extensions.view_road(newOdr,os.path.join('..',self.configuration.get("esminipath"))) # odrs = self.odrDic['0.3141592653589793'] # odrs2 = [odrs[3], odrs[4]] # newOdr = self.merger.merge2R2L(odrs2) # extensions.view_road(newOdr,os.path.join('..',self.configuration.get("esminipath"))) def test_merge2R2L2(self): odrList = [] for angleOdrList in self.odrDic.values(): odrList += angleOdrList numberOfOds = len(odrList) for _ in range(5): try: selectedOdrs = [odrList[np.random.choice(numberOfOds)], odrList[np.random.choice(numberOfOds)]] newOdr = self.merger.merge2R2L(selectedOdrs) extensions.view_road(newOdr,os.path.join('..',self.configuration.get("esminipath"))) except: pass # extensions.save_road_image(newOdr,os.path.join('..',self.configuration.get("esminipath")))
def setUp(self): self.configuration = Configuration() outputDir = os.path.join(os.getcwd(), 'output') lastId = 0 self.seed = 2 self.builder = SequentialJunctionBuilder(minAngle=np.pi / 4, maxAngle=np.pi * .75, straightRoadLen=10, probLongConnection=0.5, probMinAngle=0.5, probRestrictedLane=0.2, maxConnectionLength=30, minConnectionLength=12, random_seed=self.seed) self.randomState = self.configuration.get("random_state") pass
class test_CurveRoadBuilder(unittest.TestCase): def setUp(self): self.configuration = Configuration() self.curveRoadBuilder = CurveRoadBuilder() self.roadLinker = RoadLinker() def test_SimpleCurve(self): roads = [] roads.append( self.curveRoadBuilder.create(0, angleBetweenEndpoints=np.pi / 2, curvature=0.05, isLeftTurnLane=True)) odrName = "test_LeftTurnLaneCurve" odr = extensions.createOdrByPredecessor(odrName, roads, []) extensions.view_road( odr, os.path.join('..', self.configuration.get("esminipath"))) xmlPath = f"output/test_LeftTurnLaneCurve.xodr" odr.write_xml(xmlPath) roads = [] roads.append( self.curveRoadBuilder.create(0, angleBetweenEndpoints=np.pi / 2, curvature=0.05, isRightTurnLane=True)) odrName = "test_RightTurnLaneCurve" odr = extensions.createOdrByPredecessor(odrName, roads, []) extensions.view_road( odr, os.path.join('..', self.configuration.get("esminipath"))) xmlPath = f"output/test_RightTurnLaneCurve.xodr" odr.write_xml(xmlPath)
class test_JunctionHarvester(unittest.TestCase): def setUp(self): self.configuration = Configuration() self.esminiPath = self.configuration.get("esminipath") self.harvester = JunctionHarvester(outputDir="./output", outputPrefix="test-harvest-", lastId=0, esminiPath=self.esminiPath) def test_harvestByPainting2L(self): self.harvester.harvestByPainting2L(maxNumberOfRoadsPerJunction=4, triesPerRoadCount=3, show=True)
def fetch(): logger = logging.getLogger('Telephone') logger.info("requesting fritzbox phonecall infos") last_known_id = 0 try: if Persistence.cache_exists('calls'): old_calls = Persistence.read('calls') if len(old_calls) > 0: last_known_id = sorted(old_calls, key=itemgetter('id'), reverse=True)[0]['id'] config = Configuration() fbox = Fritzbox(config.fritzbox_ip(), 'phone', config.fritzbox_password()) if Persistence.cache_exists('missed_calls'): missed_calls = Persistence.read('missed_calls') else: missed_calls = [] new_calls = fbox.get_call_history() for new_call in new_calls: if last_known_id != 0 and new_call[ 'id'] > last_known_id and new_call[ 'duration'] == "0:00": if new_call['name'] == None: new_call['name'] = Fritzbox.telefonbuch_reverse_lookup( new_call['number']) missed_calls.append(new_call) Persistence.persist('calls', new_calls) Persistence.persist('missed_calls', missed_calls) except Exception as e: logger.error("Error: %s. Cannot get fritzbox api." % e) Persistence.persist('calls', [])
class test_HDMapBuilder(unittest.TestCase): def setUp(self) -> None: self.configuration = Configuration() self.hdMapBuilder = HDMapBuilder(30, mapSize=(300, 300), cellSize=(60, 60)) with open(logfile, 'w') as f: f.truncate() pass def test_buildMap(self): name = 'first_hd_map' odr = self.hdMapBuilder.buildMap(name, plot=True) xmlPath = f"output/test_HDMapBuilder-{name}.xodr" odr.write_xml(xmlPath) extensions.view_road( odr, os.path.join('..', self.configuration.get("esminipath"))) pass
class test_JunctionBuilder(unittest.TestCase): def setUp(self): self.configuration = Configuration() self.junctionBuilder = JunctionBuilder() self.esminiPath = self.configuration.get("esminipath") def test_buildSimpleRoundAbout(self): numRoads = 6 odr = self.junctionBuilder.buildSimpleRoundAbout( odrId=0, numRoads=numRoads, radius=10, cp1=pyodrx.ContactPoint.end) xmlPath = f"output/test-SimpleRoundAbout-{numRoads}.xodr" odr.write_xml(xmlPath) extensions.printRoadPositions(odr) extensions.saveRoadImageFromFile(xmlPath, self.esminiPath) extensions.view_road(odr, os.path.join('..', self.esminiPath)) def test_buildSimpleRoundAboutAndCheckInternalConnection(self): numRoads = 3 odr = self.junctionBuilder.buildSimpleRoundAbout( odrId=0, numRoads=numRoads, radius=10, cp1=pyodrx.ContactPoint.end) xmlPath = f"output/test-SimpleRoundAbout-{numRoads}.xodr" odr.write_xml(xmlPath) extensions.printRoadPositions(odr) extensions.saveRoadImageFromFile(xmlPath, self.esminiPath) extensions.view_road(odr, os.path.join('..', self.esminiPath)) # what's the problem with internal connections? internalConnection = odr.roads['12'].shallowCopy() internalConnection.clearRoadLinks() odr = extensions.createOdr("12 only", [internalConnection], []) xmlPath = f"output/test-SimpleRoundAbout-{numRoads}-road-12.xodr" odr.write_xml(xmlPath) extensions.printRoadPositions(odr) extensions.saveRoadImageFromFile(xmlPath, self.esminiPath) extensions.view_road(odr, os.path.join('..', self.esminiPath))
def fetch(): logger = logging.getLogger("ADAC") logger.info("requesting ADAC-API") adac_token = Configuration().adac_token() adac_50km_radius_rss_url = 'http://routenplaner.adac.de/util/RSSFeed.aspx?type=VerkehrsInfo¶m=' + adac_token try: feed = feedparser.parse(adac_50km_radius_rss_url) incidents = feed['items'] traffic_messages = [] for incident in incidents: title = BeautifulSoup(incident['title'], 'html.parser') summary = BeautifulSoup(incident['summary'], 'html.parser') traffic_messages.append({ 'title': str(title), 'summary': str(summary) }) Persistence.persist('adac', traffic_messages) except Exception as e: logger.error("Error: %s. Cannot get adac." % e) Persistence.persist('adac', {})