Qualcomm技术论坛
直播中

李勇进

7年用户 231经验值
私信 关注
[经验]

基于dragonboard 410c的智能魔镜设计之文本消息检索及自动显示

        在前两个blog中已经跟大家介绍了如何应用dragonbaord 410c来搭建智能魔镜,对系统的整体设计方案和数据库的构建方案进行了分析和设计,给出了详细的设计框架和部分数据库的实现代码,本节将在此基础上向大家介绍,如何实现在镜子上根据不同的用户播放不同的消息的功能。

         


        根据前面的设计,我们已经搭建好了数据库,并且在数据库中构建了一张pushInfo表来管理系统的消息,其表中设计了消息ID,ownerID和pushID等字段,通过ownerID我们可以方便的查询出该消息的发送者,同时通过pushID我们可以查询得到该消息的推送者,这样要检索出当前用户的消息,我们只需要根据摄像头检测出来的用户身份ID在该pushInfo表中以ownerID字段就可以检索出所有的该用户的消息,同时在表中还设置了viewWight和isTop两个字段用于标记该消息的显示顺序,如果isTop表示该消息要显示在最前面,如果该用户有多条的isTop的消息,则按照时间的先后排序,将最近的消息显示在最前面,同时还根据viewWight来判断消息是否被显示,如果该字段设置为0表示该消息已经被显示,无需再显示,根据这一规则,我们可以在MagicMirrorDB数据管理类中设计一个getTextMessageList(self,userID)函数来检索出指定用户的消息,并且结果按照显示先后的顺序进行排序,具体的代码如下:

def getTextMessageList(self,userID):

        self.cu.execute("")

        format="select infoID,pushID,infoSubject,infoContent,pushtime from pushInfo where ownerID==%u and isTop==1 and infoType==0 and viewWeight!=0 order by pushTime desc"

        values=(userID)

        querySQL1=format % values

        self.cu.execute(querySQL1)

        result1=self.cu.fetchone()

        print(querySQL1)

        print(result1)

        #print result

        format="select infoID,pushID,infoSubject,infoContent,pushTime from pushInfo where ownerID=%u and isTop==0 and infoType==0 order by pushTime desc"

        values=(userID)

        querySQL2=format % values

        print(querySQL2)

        self.cu.execute(querySQL2)

        result2=self.cu.fetchone()

        print(result2)

        if result1!=None and result2 != None:

            #result=result1+result2

            print(result1+result2)

            return result1+result2

        elif result1==None and result2!=None:

            #result=result2

            return result2

        elif result1!=None and result2 == None:

            #resutl=result1

            return result1

        else:

            #result==None

            return None


     这个函数将返回检索结果列表,每一条消息的消息ID   infoID,推送者ID  pushID,消息主题:infoContent,消息推送时间:pushTime五个内容,后续我们根据这五个内容就可以方便的将消息进行显示,并且这里返回的消息已经按照我们的规则进行了排序。

       这样在消息显示的时候我们只需要构建一个MagicMirrorDB类,然后调用该方法就可以获取指定用户的文本消息了,并且进行排序,具体的显示我们可以构建如下函数来实现:

        def showPushInfo(self,userID):

        

        MMDB=MMDB=MagicMirrorDB("./MagicMirrorDB.db")

        #update welcome info by userID

        userName=MMDB.getUserName(userID)

        format="

Hello %s Welcome...

"

        values=(userName)

        result=format % values

        self.new.helloWelcome.setText(result)

        #update pushInfo

        #infoID,pushID,infoSubject,infoContent,pushTime

        msgList=MMDB.getTextMessageList(userID)

        print("test0")

        print(msgList)

        print("hello")

        i=0

        pushName=""

        msg_info=""

        pushTime=""

        msgStr=""

        if msgList!=None:

            for msg in msgList:

                print(msgList)

            

                if i==1:

                    print("test1")

                    print(msg)

                    pushName=MMDB.getUserName(msg)

                if i==3:

                    msg_info=msg

                if i==4:

                    #pushTime=time.strftime("%Y-%m-%d %H:%M:%S",msg)

                    msgStr+=("

"+pushName+"to you:"+"

"+msg_info+"

")

                i=i+1

                if i==5:

                    i=0

           

            self.new.webMessageText.setHtml(""+msgStr+"")

            self.new.webMemorandum.setHtml(""+msgStr+"")   

        videoMsgList=MMDB.getUserVideoMessageList(self.current_userID)

         在这里我们使用了qt提供的html支持,采用格式化方式将获取的消息内容格式化到已经定义好的显示的消息样式模板中,然后调用qt的控件进行设置完成消息的显示,

更多回帖

发帖
×
20
完善资料,
赚取积分