コード例 #1
0
 def getDocs(
     self
 ):  #reads files in the library file directory and converts to Document.
     if not os.path.exists('docfiles'):
         os.makedirs('docfiles')
     for filename in os.listdir(
             'docfiles'):  # get the directory '.' + 'os.sep' +
         if filename.endswith('.txt'):
             with open('docfiles' + os.sep + filename, "rt") as f:
                 contents = f.read()
             doctags = []
             docContents = []
             pagetags = []
             convertedTagList = []
             pages = []
             section = contents.split("(/)")[1:]
             try:
                 assert (section[0].startswith("Title:"))
                 assert (section[1].startswith("Doctags:"))
                 assert (section[2].startswith("Pages:"))
                 assert (section[3].startswith("Pagetags:"))
             except AssertionError:
                 print("Attempted to read invalid document.")
                 continue
             title = section[0][len("Title:"):].strip()
             if not section[1][len("Doctags:"):].isspace():
                 doctagstr = section[1][len("Doctags:"):].strip()
                 for tag in doctagstr.split(","):
                     doctags.append(Tag(tag.strip()))
             if not section[2][len("Pages:"):].isspace():
                 pagestr = section[2][len("Pages:"):].strip()
                 for elem in pagestr.split("<pwords>"):
                     docContents.append(str(elem.strip()))
             pagetagstr = section[3][len("Pagetags:"):].strip()
             for elem in pagetagstr.split("<tname>"):
                 if not elem.isspace():
                     pagetags.append(elem.strip(
                     ))  # pagetags is a list with a string of tags
             for taglist in pagetags:
                 convertedPageTags = []
                 for tag in taglist.split(","):
                     if not tag.isspace() and not tag == "":
                         convertedPageTags.append(Tag(tag.strip()))
                 convertedTagList.append(convertedPageTags)
             makeTime = os.path.getctime
             editTime = os.path.getmtime
             for i in range(len(docContents)):
                 pages.append(
                     Page(self, docContents[i], convertedTagList[i]))
             self.documents.append(
                 Document(self, filename, title, f"{makeTime}",
                          f"{editTime}", doctags, pages))
コード例 #2
0
def sourceLIDARThread(pipeFromC, pipeToC, network_send_queue, start_time, interval):
    # Start the connection with the LIDAR through pipes
    lidarDevice = communication.connectLIDAR(pipeFromC, pipeToC)
    target = interval

    # Init the LIDAR processing class
    lidarRecognition = lidar_recognition.LIDAR(time.time())

    # Wait for 1 second before we start everything
    time.sleep(2)

    start, end = lidarDevice.getFromC()
    lidarcoordinates, lidartimestamp = lidarRecognition.processLidarFrame(lidarDevice.parseFromC(), start)

    index = 0

    # Now wait for input
    while 1:
        if (round(time.time(),3) % target) == 0.000:
            # Take the LIDAR frame and process
            #print ( "LIDAR start " + str(time.time()))
            start, end = lidarDevice.getFromC()
            #print ( "LIDAR got " + str(time.time()))

            lidarcoordinates, lidartimestamp = lidarRecognition.processLidarFrame(lidarDevice.parseFromC(), start)
            localization = [lidarDevice.localizationX, lidarDevice.localizationY, lidarDevice.localizationYaw, index, start]
            #print ( "LIDAR detect " + str(time.time()))

            # Prep value to be sent to the part of the program
            output_tag = Tag.Tag('local_fusion', 'localization', start, end)
            output_token = Token.Token(output_tag, localization)
            recipient_name = 'CAV1'
            network_send_queue.put((output_token, recipient_name)) #send to named device, e.g. CAV1, RSU

            # Prep value to be sent to the part of the program
            output_tag = Tag.Tag('local_fusion', 'lidar_obs', start, end)
            output_token = Token.Token(output_tag, lidarcoordinates)
            recipient_name = 'CAV1'
            network_send_queue.put((output_token, recipient_name)) #send to named device, e.g. CAV1, RSU

            # Prep value to be sent to the part of the program
            output_tag = Tag.Tag('actuate', 'response', start, end)
            output_token = Token.Token(output_tag, [localization,None])
            recipient_name = 'CAV1'
            network_send_queue.put((output_token, recipient_name)) #send to named device, e.g. CAV1, RSU

            # Log this to a file
            index += 1
コード例 #3
0
def preprocessTag(df, gradeDict, grade):
    """
    Preprocesses and individual Tag Excel Sheet into Tag Objects that are held 
    in a Dictionary of arrays where each key corresponds to an array of tag objects
    """
    tempDf = pd.DataFrame()

    #innerCount is used to track the number of rows we've iterated through and comes this to numRows
    #to determine if we've reached the end of that loc
    innerCount = 0

    #locCount counts which loc we're at so we know whether to put the dataframe in loc1, loc2, or loc3
    locCount = 0

    for index, row in df.iterrows():
        #Gets the number of rows that are NaN, in this case we care about the ones that have 3 and 4 nulls
        if (row.isnull().sum() == 0):
            #instantiate a new obj and append it to the dictionary's array
            obj = Tag.Tag()
            #Call the setInitialRow function that sets all of the attributes other the loc1, loc2, and loc3
            obj.setInitialRow(row)

            #appends the object we just created to the end of the array
            gradeDict[grade].append(obj)

        elif (row.isnull().sum() == 5):
            #row that tells the number of materials in a given location
            innerCount = 0
            locCount += 1

            #Get the number of rows to iterate through for the next elif
            numRows = row[0]

        elif (row.isnull().sum() == 4):
            #row that contains a material code and a location
            tempDf = tempDf.append(row)

            #Finishes up by renaming the columns, dropping the ones we don't need
            #and the distributing the df in loc1,2,or 3 depending on which count we're on
            if (numRows == innerCount):
                tempDf["materialCode"] = tempDf["Tag"]
                tempDf["materialAmt"] = tempDf["Grade"]
                tempDf = tempDf.drop(columns=[
                    "Tag", "Grade", "Oxygen", "Power", "Tap Wgt", "Time"
                ])
                tempDf = pd.DataFrame()

                if (locCount == 1):
                    gradeDict[grade][len(gradeDict[grade]) - 1].setLoc1(tempDf)
                elif (locCount == 2):
                    gradeDict[grade][len(gradeDict[grade]) - 1].setLoc2(tempDf)
                elif (locCount == 3):
                    gradeDict[grade][len(gradeDict[grade]) - 1].setLoc3(tempDf)

        innerCount += 1
コード例 #4
0
def tag(bot, update):
    prep_query = re.findall('#\w+', update.message.text)
    if not prep_query:
        info = """
        Usage: /tag <tagName>
        """
        bot.send_message(chat_id=update.message.chat_id, text=info)
    else:
        t = Tag(prep_query[0])
        urls = t.show()
        bot.send_message(chat_id=update.message.chat_id, text=urls)
コード例 #5
0
 def construir(self, p_lista_diccionario):
     """
     Construimos la lista a partir de los datos que nos trae un diccionario
     :param p_lista_diccionario: Un diccionario con los datos
     :return:
     """
     for diccionario in p_lista_diccionario:
         un_tag = Tag.Tag(diccionario['IdTag'], diccionario['NombreTag'],
                          diccionario['Descripcion'],
                          diccionario['FechaCreacion'],
                          diccionario['IdUsuario'], None)
         self.lista.append(un_tag)
コード例 #6
0
    def calculate_item(self, end):
        if end.type == cad.DigitizeType.DIGITIZE_NO_ITEM_TYPE:
            return False

        if (self.TempObject() != None) and (self.TempObject().GetType() !=
                                            Tag.type):
            self.ClearObjectsMade()

        if self.TempObject() == None:
            tag = Tag.Tag()
            self.AddToTempObjects(tag)
        else:
            self.TempObject().pos.x = end.point.x
            self.TempObject().pos.y = end.point.y
        return True
コード例 #7
0
def seeds_articles():
    """
    seeds 2 categories => c1, c2

    seeds 2 tags => t1 belongs to c1, t2 belongs to c2

    seeds 2 articles => a1 has t1, a2 has t2
    """
    c1 = Category('c1').save()
    c2 = Category('c2') .save()

    t1 = Tag('t1', c1) .save()
    t2 = Tag('t2', c2) .save()

    a1 = Article(title="a1",
                 description="a1 description",
                 body="a1 body")
    a1.tags.append(t1)
    a1.save()
    a2 = Article(title="a2",
                 description="a2 description",
                 body="a2 body")
    a2.tags.append(t2)
    a2.save()
コード例 #8
0
def sourceImagesThread(settings, camSpecs, network_send_queue, start_time, interval):
    # Init the camera class
    cameraRecognition = camera_recognition.Camera(settings, camSpecs)
    target = interval

    # Now wait for input
    while 1:
        if (round(time.time(),3) % target) == 0.000:
            now = time.time()

            # Take the camera frame and process
            camcoordinates, camtimestamp_start, camtimestamp_end  = cameraRecognition.takeCameraFrame()

            # Prep value to be sent to the part of the program
            output_tag = Tag.Tag('local_fusion', 'camera', camtimestamp_start, camtimestamp_end)
            output_token = Token.Token(output_tag, camcoordinates)
            recipient_name = 'CAV1'
            network_send_queue.put((output_token, recipient_name)) #send to named device, e.g. CAV1, RSU
コード例 #9
0
def tagUpdate(bot, update):
    chat_id = update.message.chat_id
    # if isAdmin(chat_id):
    msg_text = update.message.text
    prep_query = re.findall('(#\w+)\s(https?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),])+)', msg_text)

    if not prep_query :
        
        info = """
        Update tag info or added tag into DB.
        Usage: /tagupdate #nameTag http://link.to/post?or=another&url=1
        """
        
        bot.send_message(chat_id, text=info)
    else:
        tag = prep_query[0][0]
        url = prep_query[0][1]
            # TODO: save to DB
        t = Tag(tag, url)
        print(tag)
        st = t.save()
        bot.send_message(chat_id, text=st)
コード例 #10
0
ファイル: CamApp.py プロジェクト: danheeks/PyCAM
def CreateTag(): return Tag.Tag()
def CreateScriptOp(): return ScriptOp.ScriptOp()
コード例 #11
0
        # price=results[3]#价格
        # bind=results[4]#装帧
        # isbn=results[5]
        yield {
            'title': title,
            'url': detail_url,
            'img_url': img_url,
            'writers': writers,
            'press': press,
            'date': date,
            'page_numbers': page_numbers,
            'price': price,
            'ISBN': ISBN,
            'evaluate_stars': evaluate_stars,
            'evaluate_persons': evaluate_persons,
            'intro': intro,
        }

    def save2mysql(self, item):
        with open('result.txt', 'a', encoding='utf-8') as f:
            f.write(json.dumps(item, ensure_ascii=False) + '\n')


if __name__ == '__main__':
    d = douban()
    t = Tag.Tag()
    tags = t.tags(
        'https://book.douban.com/tag/?view=type&icn=index-sorttags-all')[1:]
    for tag in tags:
        url = r'https://book.douban.com/tag/' + quote(tag) + '?start=0&type=T'
        d.parse(url)
コード例 #12
0
 def addDocTag(self, newTags):
     """Adds tags to the list of tags."""
     for elem in newTags:
         self.doctags.append(Tag(elem.lower()))
     self.updateTags()
     self.saveFile()
コード例 #13
0
def tag(category):
    yield Tag(name="cat", category=category)
コード例 #14
0
    def actuate(self, response, time_overlap=Interval(0,.1249)):

        '''
        args supplied by the synchronized WM function
        '''
        try:
            #print ( response )

            if response != None:
                localization = response[0]
                response_json = response[1]
            else:
                print ( " Nones " + str(response) )
                localization = None
                response_json = None


            if localization == None:
                self.egoVehicle.emergencyStop()
                print ( "Emergency stop!" )
            else:
                # Check if we have been initialized
                if self.planner == None:
                    if response_json != None:
                        print ( " settign planner start " )
                        self.planner = planning_control.Planner()
                        self.planner.initialVehicleAtPosition(response_json["t_x"], response_json["t_y"], response_json["t_yaw"], response_json["route_x"], response_json["route_y"], response_json["route_TFL"], 1, False)
                        self.egoVehicle.emergencyStop()
                        self.r_queue.put(True)
                        print ( " settign planner end " )
                    else:
                        print ( " skipping planner ", str(response_json) )
                        self.egoVehicle.emergencyStop()
                        print ( "Emergency stop!" )
                elif response_json!= None:
                    # Make sure we have not skipped a step and missed our localization
                    if self.localization != None:
                        # Update our various pieces
                        self.planner.targetVelocityGeneral = float(response_json["v_t"])
                        self.planner.update_localization([self.localization[0], self.localization[1], self.localization[2]])
                    else:
                        # The clocalization on the packet is used here as a fallback. Should only happen once
                        self.planner.targetVelocityGeneral = float(response_json["v_t"])
                        self.planner.update_localization([localization[0], localization[1], localization[2]])
                    self.planner.recieve_coordinate_group_commands(response_json["tfl_state"])
                    self.planner.pure_pursuit_control()
 
                    # Now update our current PID with respect to other vehicles
                    self.planner.check_positions_of_other_vehicles_adjust_velocity(response_json["veh_locations"], self.vehicle_id)

                    # We can't update the PID controls until after all positions are known
                    self.planner.update_pid()

                    # Finally, issue the commands to the motors
                    steering_ppm, motor_pid = self.planner.return_command_package()
                    self.egoVehicle.setControlMotors(steering_ppm, motor_pid)
                else:
                    # Only update our steering, use the last positions of all things as it should not matter!
                    # Update our various pieces
                    self.localization = localization
                    self.planner.update_localization([localization[0], localization[1], localization[2]])
                    self.planner.pure_pursuit_control()

                    # Finally, issue the commands to the motors
                    steering_ppm, motor_pid = self.planner.return_command_package()
                    self.egoVehicle.setControlMotors(steering_ppm, motor_pid)

                    tag_deadline = Tag.Tag('actuate', 'DEADLINE', time.time(), time.time() + 0.1000)
                    token_deadline = Token.Token(tag_deadline, None)
                    recipient_name = 'CAV1'
                    self.network_send_queue.put((token_deadline, recipient_name)) #send to named device, e.g. CAV1, RSU

            if localization == None:
                test = "inf"
                test2 = time.time()
            else:
                test = localization[3]
                test2 = time.time()  - localization[4]
            print(str(test) + "," + str(test2) + "\n")
            #file1.write(str(test) + "," + str(test2) + "\n")
            print('Actuation achieved!')
        except Exception as e:
            self.egoVehicle.emergencyStop()
            print ( "    Exception in actuate! " , str(e) )
コード例 #15
0
    def local_fusion(self, camera, localization, lidar_obs, time_overlap=Interval(0,.125)):

        '''
        args supplied by the synchronized WM function
        '''
        if camera == None and lidar == None:
            print(" Missed both! ")
            fused = []
        elif camera == None:
            print(" Missed Camera! ")
            fused = lidar_obs
        elif lidar_obs == None:
            print(" Missed LIDAR! ")
            fused = camera
        else:
            #print(" Got them both! ")
            fused = camera + lidar_obs

        #print('Local fusion function running!')
        #print(time_overlap)
        try:
            rec = self.r_queue.get(block=False, timeout=.001)
            if rec != None:
                 print ( "Got rec ----------------------", rec )
                 self.register = False
        except:
            pass

        if self.register:
            # data to be sent to api 
            packet = {'key':self.key, 
                    'id':self.vehicle_id,
                    'type':0,
                    'register':True,
                    'timestamp':time.time(),
                    'x':localization[0],
                    'y':localization[1],
                    'z':0.0,
                    'roll':0.0,
                    'pitch':0.0,
                    'yaw':localization[2],
                    'detections':fused}
        else:
            packet = {'key':self.key, 
                    'id':self.vehicle_id, 
                    'type':0,
                    'register':False,
                    'timestamp':time.time(),
                    'x':localization[0],
                    'y':localization[1],
                    'z':0.0,
                    'roll':0.0,
                    'pitch':0.0,
                    'yaw':localization[2],
                    'detections':fused}

        # Prep value to be sent to the part of the program
        output_tag = Tag.Tag('global_fusion', 'cav1', time_overlap.begin, time_overlap.end)
        output_token = Token.Token(output_tag, packet)
        recipient_name = 'RSU'
        self.network_send_queue.put((output_token, recipient_name)) #send to named device, e.g. CAV1, RSU
コード例 #16
0
ファイル: Page.py プロジェクト: Gli51/DocuTags
 def addPageTag(self, newTags:str):
     #newTag is just the name of the new tag
     for elem in newTags:     
         self.tags.append(Tag(elem.lower()))
         self.app.editmode.currDoc.updateTags()