예제 #1
0
 def writemeca(self,ID,time,p,v,a):
     """
     write mecanic information into the mysql db
     """
     self.insertitem1("TruePosition",('NodeID',
                                         'Timestamp',
                                         'X',
                                         'Y',
                                         'Z',
                                         'ReferencePointID'),
                                         (eval(ID),
                                         pyu.timestamp(time),
                                         p[0],
                                         p[1],
                                         'NULL',
                                         'NULL'))
     self.insertitem1("CEASensorMeasurements",('NodeID',
                                                  'Timestamp',
                                                  'CEA_MagX',
                                                  'CEA_MagY',
                                                  'CEA_AccX',
                                                  'CEA_AccY'),
                                                  (eval(ID),
                                                   pyu.timestamp(time),
                                                   v[0],
                                                   v[1],
                                                   a[0],
                                                   a[1] ))
예제 #2
0
 def writemeca(self,ID,time,p,v,a):
     """
     write mecanic information into the mysql db
     """
     self.insertitem1("TruePosition",('NodeID',
                                         'Timestamp',
                                         'X',
                                         'Y',
                                         'Z',
                                         'ReferencePointID'),
                                         (eval(ID),
                                         pyu.timestamp(time),
                                         p[0],
                                         p[1],
                                         'NULL',
                                         'NULL'))
     self.insertitem1("CEASensorMeasurements",('NodeID',
                                                  'Timestamp',
                                                  'CEA_MagX',
                                                  'CEA_MagY',
                                                  'CEA_AccX',
                                                  'CEA_AccY'),
                                                  (eval(ID),
                                                   pyu.timestamp(time),
                                                   v[0],
                                                   v[1],
                                                   a[0],
                                                   a[1] ))
예제 #3
0
    def dual_save(self,S):
        """
        save txt 



        Attributes:
        ----------
        
        S        : Simulation
                   Scipy.Simulation object

        """

        pos=nx.get_node_attributes(self,'p')
        pclust = nx.get_node_attributes(self,'pe_clust')
        typ = nx.get_node_attributes(self,'type')
        if self.idx == 0:
            entete = 'Timestamp, True Position x, True Position y, Est Position1 x, Est Position1 y,Est Position2 x, Est Position2 y\n'
            file=open(basename+'/' + pstruc['DIRNETSAVE'] +'/toa.txt','write')
            file.write(entete)
            file.close()
            file2=open(basename+'/' + pstruc['DIRNETSAVE'] +'/rsslink.txt','write')
            entete2 = 'Timestamp, link, linkid, Pr, Prstd\n'
            file2.write(entete2)
            file2.close()
            file3=open(basename+'/' + pstruc['DIRNETSAVE'] +'/anchorposition.txt','write')
            data3 = 'node,pos x, pos y\n'
            file3.write(data3)
            for n in self.nodes():
                data3= n + ',' + str(self.node[n]['p'][0]) + ',' + str(self.node[n]['p'][1]) + '\n'
                file3.write(data3)
            file3.close()

        try:
            file=open(basename+'/' + pstruc['DIRNETSAVE'] +'/toa.txt','a')
            file2=open(basename+'/' + pstruc['DIRNETSAVE'] +'/rsslink.txt','a')
            for n in self.nodes():
                if n == '1':
                    data =  pyu.timestamp(S.now()) +','+ str(pos[n][0]) + ',' + str(pos[n][1]) + ',' + str(pclust[n][0,0]) + ',' + str(pclust[n][0,1]) + ',' + str(pclust[n][1,0]) + ',' + str(pclust[n][1,1]) +'\n'
                    for e in self.edge[n].keys():
                        if e != '6' and e !='7':
                            try:
                                data2 = data2 +',link,' + str(e) + ',' + str(self.edge[n][e]['rat1']['Pr'][0]) +',' + str(self.edge[n][e]['rat1']['Pr'][1]) 
                            except:
                                data2 = pyu.timestamp(S.now()) + ',link,' + str(e) + ',' + str(self.edge[n][e]['rat1']['Pr'][0]) +',' + str(self.edge[n][e]['rat1']['Pr'][1]) 

            data2=data2 + '\n'
            file.write(data)
            file2.write(data2)
            
            file.close()
            file2.close()
            self.idx = self.idx +1
        except:
            pass
예제 #4
0
 def writenet(self, net, t):
     """
     write mecanic information into the mysql db
     """
     for e in net.edges_iter(data=True):
         self.insertitem1(
             "ACOLinkMeasurements",
             ('NodeID', 'ACO_PeerID', 'ACO_RSSI', 'Timestamp'),
             (eval(e[0]), eval(e[1]), e[2]['Pr'][0], pyu.timestamp(t)))
         self.insertitem1(
             "CEALinkMeasurements",
             ('NodeID', 'Timestamp', 'CEA_PeerID', 'CEA_Dist'),
             (eval(e[0]), pyu.timestamp(t), eval(e[1]), e[2]['d']))
예제 #5
0
파일: pymysqldb.py 프로젝트: Zulko/pylayers
 def writemeca(self, ID, time, p, v, a):
     """
     write mecanic information into the mysql db
     """
     self.insertitem1(
         "TruePosition",
         ("NodeID", "Timestamp", "X", "Y", "Z", "ReferencePointID"),
         (eval(ID), pyu.timestamp(time), p[0], p[1], "NULL", "NULL"),
     )
     self.insertitem1(
         "CEASensorMeasurements",
         ("NodeID", "Timestamp", "CEA_MagX", "CEA_MagY", "CEA_AccX", "CEA_AccY"),
         (eval(ID), pyu.timestamp(time), v[0], v[1], a[0], a[1]),
     )
예제 #6
0
파일: pymysqldb.py 프로젝트: Zulko/pylayers
 def writenet(self, net, t):
     """
     write mecanic information into the mysql db
     """
     for e in net.edges_iter(data=True):
         self.insertitem1(
             "ACOLinkMeasurements",
             ("NodeID", "ACO_PeerID", "ACO_RSSI", "Timestamp"),
             (eval(e[0]), eval(e[1]), e[2]["Pr"][0], pyu.timestamp(t)),
         )
         self.insertitem1(
             "CEALinkMeasurements",
             ("NodeID", "Timestamp", "CEA_PeerID", "CEA_Dist"),
             (eval(e[0]), pyu.timestamp(t), eval(e[1]), e[2]["d"]),
         )
예제 #7
0
    def ini_save(self,S,filename='simulnet_data.ini',height=1.5):
        """
        ----------
        DEPRECATED
        ----------
        Save an .ini file of node position . 
        Only links  which involve mobile nodes (type 'ag') are kept.

        The produced init file is filled as follow:

            [timestamp]
            nodeID1_nodeID2 = x1,y1,z1,x2,y2,z2
            nodeID2_nodeID4 = x2,y2,z2,x4,y4,z4
            ....


        Attributes:
        ----------
        
        S        : Simulation
                   Scipy.Simulation object

        filename  : string
                   name of the saved ini file

        height    : float
                   height of the nodes





        """

        assert len(self.SubNet.keys()) == 1 , NameError('when network.ini_save() \
        is used , only 1 rat must be involved in the Network.\
        Please modify agent.ini')


        if self.idx == 0:
            file=open(pyu.getlong(filename ,'output'),'w')
        else:
            file=open(pyu.getlong(filename ,'output'),'a')

        config = ConfigParser.ConfigParser()
        timestamp = pyu.timestamp(S.now())
        config.add_section(timestamp)
        for e in self.edges():
            if not ((self.node[e[0][0]]['type'] == 'ap') and  (self.node[e[1][0]]['type'] == 'ap')):
                key=str(e[0]) +'_' +str(e[1])
                value1 = str(self.node[e[0][0]]['p'][0])+ ',' +str(self.node[e[0][0]]['p'][1])+','+str(height)
                value2 = str(self.node[e[1][0]]['p'][0])+ ',' +str(self.node[e[1][0]]['p'][1])+','+str(height)
                config.set(timestamp, key, value1 + ' , ' + value2)

        config.write(file)
        file.close()

        self.idx=self.idx+1
예제 #8
0
    def ini_save(self,S,filename='simulnet_data.ini',height=1.5):
        """
        ----------
        DEPRECATED
        ----------
        Save an .ini file of node position . 
        Only links  which involve mobile nodes (type 'ag') are kept.

        The produced init file is filled as follow:

            [timestamp]
            nodeID1_nodeID2 = x1,y1,z1,x2,y2,z2
            nodeID2_nodeID4 = x2,y2,z2,x4,y4,z4
            ....


        Attributes:
        ----------
        
        S        : Simulation
                   Scipy.Simulation object

        filename  : string
                   name of the saved ini file

        height    : float
                   height of the nodes





        """

        assert len(self.SubNet.keys()) == 1 , NameError('when network.ini_save() \
        is used , only 1 rat must be involved in the Network.\
        Please modify agent.ini')


        if self.idx == 0:
            file=open(pyu.getlong(filename ,'output'),'w')
        else:
            file=open(pyu.getlong(filename ,'output'),'a')

        config = ConfigParser.ConfigParser()
        timestamp = pyu.timestamp(S.now())
        config.add_section(timestamp)
        for e in self.edges():
            if not ((self.node[e[0][0]]['type'] == 'ap') and  (self.node[e[1][0]]['type'] == 'ap')):
                key=str(e[0]) +'_' +str(e[1])
                value1 = str(self.node[e[0][0]]['p'][0])+ ',' +str(self.node[e[0][0]]['p'][1])+','+str(height)
                value2 = str(self.node[e[1][0]]['p'][0])+ ',' +str(self.node[e[1][0]]['p'][1])+','+str(height)
                config.set(timestamp, key, value1 + ' , ' + value2)

        config.write(file)
        file.close()

        self.idx=self.idx+1
예제 #9
0
 def writenet(self,net,t):
     """
     write mecanic information into the mysql db
     """
     for e in net.edges_iter(data=True):
         self.insertitem1("ACOLinkMeasurements",('NodeID',
                                             'ACO_PeerID',
                                             'ACO_RSSI',
                                             'Timestamp'),
                                             (eval(e[0]),
                                             eval(e[1]),
                                             e[2]['Pr'][0],
                                             pyu.timestamp(t)))
         self.insertitem1("CEALinkMeasurements",('NodeID',
                                             'Timestamp',
                                             'CEA_PeerID',
                                             'CEA_Dist'),
                                             (eval(e[0]),
                                             pyu.timestamp(t),
                                             eval(e[1]),
                                             e[2]['d']))
예제 #10
0
    def dual_save(self,S):
        """
        DEPRECATED 

        REPLACED BY pylayers.util.save

        DEPRECATED 



        save txt 



        Parameters
        ----------
        
        S        : Simulation
                   Scipy.Simulation object

        """

        pos=nx.get_node_attributes(self,'p')
        pclust = nx.get_node_attributes(self,'pe_clust')
        typ = nx.get_node_attributes(self,'type')
        if self.idx == 0:
            entete = 'Timestamp, True Position x, True Position y, Est Position1 x, Est Position1 y,Est Position2 x, Est Position2 y\n'
            file=open(basename+'/' + pstruc['DIRNETSAVE'] +'/pos.txt','write')
            file.write(entete)
            file.close()
            file2=open(basename+'/' + pstruc['DIRNETSAVE'] +'/rsslink.txt','write')
            entete2 = 'Timestamp, link, linkid, Pr, distance\n'
            file2.write(entete2)
            file2.close()
            file3=open(basename+'/' + pstruc['DIRNETSAVE'] +'/anchorposition.txt','write')
            data3 = 'node,pos x, pos y\n'
            file3.write(data3)
            for n in self.nodes():
                data3= n + ',' + str(self.node[n]['p'][0]) + ',' + str(self.node[n]['p'][1]) + '\n'
                file3.write(data3)
            file3.close()
            file4=open(basename+'/' + pstruc['DIRNETSAVE'] +'/toa.txt','w')
            entete4 = 'Timestamp, type, toaid, toa,distance\n'
            file4.write(entete4)
            file4.close()

        try:

            file=open(basename+'/' + pstruc['DIRNETSAVE'] +'/pos.txt','a')
            file2=open(basename+'/' + pstruc['DIRNETSAVE'] +'/rsslink.txt','a')
            file4=open(basename+'/' + pstruc['DIRNETSAVE'] +'/toa.txt','a')
            for n in self.nodes():
                if n == '1':
                    data =  pyu.timestamp(S.now()) +','+ str(pos[n][0]) + ',' + str(pos[n][1]) + ',' + str(pclust[n][0,0]) + ',' + str(pclust[n][0,1]) + ',' + str(pclust[n][1,0]) + ',' + str(pclust[n][1,1]) +'\n'
                    for e in self.edge[n].keys():
                        if e != '6' and e !='7':
                            try:
                                data2 = data2 +',link,' + str(e) + ',' + str(self.edge[n][e]['rat1']['Pr'][0]) +',' + str(np.sqrt(np.sum((pos[n]-pos[e])**2)))
                            except:
                                data2 = pyu.timestamp(S.now()) + ',link,' + str(e) + ',' + str(self.edge[n][e]['rat1']['Pr'][0]) +',' + str(np.sqrt(np.sum((pos[n]-pos[e])**2)))
                        else :
                            try:
                                data4 = data4 +',toa,' + str(e) + ',' + str(self.edge[n][e]['rat1']['TOA'][0]) +',' + str(np.sqrt(np.sum((pos[n]-pos[e])**2)))
                            except:

                                data4 = pyu.timestamp(S.now()) + ',toa,' + str(e) + ',' + str(self.edge[n][e]['rat1']['TOA'][0]) +',' +str(np.sqrt(np.sum((pos[n]-pos[e])**2)))

            data2=data2 + '\n'
            data4=data4 + '\n'
            file.write(data)
            file2.write(data2)
            file4.write(data4)


            file.close()
            file2.close()
            file4.close()
            self.idx = self.idx +1
        except:
            pass
예제 #11
0
    def loc_save(self,S):
        """
        DEPRECATED 

        REPLACED BY pylayers.util.save

        DEPRECATED 


        save txt 
        node ID , True pos x , True pos y , est pos x , est pos y , timestamp


        Parameters
        ----------
        
        S        : Simulation
                   Scipy.Simulation object

        """

        pos=nx.get_node_attributes(self,'p')
        pe=nx.get_node_attributes(self,'pe_alg')
        typ = nx.get_node_attributes(self,'type')
        if self.idx == 0:
            entete = 'NodeID, True Position x, True Position y, Est Position x, Est Position y, Timestamp\n'
            file=open(basename+'/' + pstruc['DIRNETSAVE'] +'/simulation.txt','write')
            file.write(entete)
            file.close()

        try:
            file=open(basename+'/' + pstruc['DIRNETSAVE'] +'/simulation.txt','a')
            for n in self.nodes():
                if typ[n] != 'ap':
                    data = n + ',' + str(pos[n][0]) + ',' + str(pos[n][1]) + ',' + str(pe[n][0][0]) + ',' + str(pe[n][0][1]) + ',' +pyu.timestamp(S.now()) +',\n'
                    file.write(data)
            file.close()
            self.idx = self.idx +1
        except:
            pass
예제 #12
0
    def dual_save(self,S):
        """
        DEPRECATED 

        REPLACED BY pylayers.util.save

        DEPRECATED 



        save txt 



        Attributes:
        ----------
        
        S        : Simulation
                   Scipy.Simulation object

        """

        pos=nx.get_node_attributes(self,'p')
        pclust = nx.get_node_attributes(self,'pe_clust')
        typ = nx.get_node_attributes(self,'type')
        if self.idx == 0:
            entete = 'Timestamp, True Position x, True Position y, Est Position1 x, Est Position1 y,Est Position2 x, Est Position2 y\n'
            file=open(basename+'/' + pstruc['DIRNETSAVE'] +'/pos.txt','write')
            file.write(entete)
            file.close()
            file2=open(basename+'/' + pstruc['DIRNETSAVE'] +'/rsslink.txt','write')
            entete2 = 'Timestamp, link, linkid, Pr, distance\n'
            file2.write(entete2)
            file2.close()
            file3=open(basename+'/' + pstruc['DIRNETSAVE'] +'/anchorposition.txt','write')
            data3 = 'node,pos x, pos y\n'
            file3.write(data3)
            for n in self.nodes():
                data3= n + ',' + str(self.node[n]['p'][0]) + ',' + str(self.node[n]['p'][1]) + '\n'
                file3.write(data3)
            file3.close()
            file4=open(basename+'/' + pstruc['DIRNETSAVE'] +'/toa.txt','w')
            entete4 = 'Timestamp, type, toaid, toa,distance\n'
            file4.write(entete4)
            file4.close()

        try:

            file=open(basename+'/' + pstruc['DIRNETSAVE'] +'/pos.txt','a')
            file2=open(basename+'/' + pstruc['DIRNETSAVE'] +'/rsslink.txt','a')
            file4=open(basename+'/' + pstruc['DIRNETSAVE'] +'/toa.txt','a')
            for n in self.nodes():
                if n == '1':
                    data =  pyu.timestamp(S.now()) +','+ str(pos[n][0]) + ',' + str(pos[n][1]) + ',' + str(pclust[n][0,0]) + ',' + str(pclust[n][0,1]) + ',' + str(pclust[n][1,0]) + ',' + str(pclust[n][1,1]) +'\n'
                    for e in self.edge[n].keys():
                        if e != '6' and e !='7':
                            try:
                                data2 = data2 +',link,' + str(e) + ',' + str(self.edge[n][e]['rat1']['Pr'][0]) +',' + str(np.sqrt(np.sum((pos[n]-pos[e])**2)))
                            except:
                                data2 = pyu.timestamp(S.now()) + ',link,' + str(e) + ',' + str(self.edge[n][e]['rat1']['Pr'][0]) +',' + str(np.sqrt(np.sum((pos[n]-pos[e])**2)))
                        else :
                            try:
                                data4 = data4 +',toa,' + str(e) + ',' + str(self.edge[n][e]['rat1']['TOA'][0]) +',' + str(np.sqrt(np.sum((pos[n]-pos[e])**2)))
                            except:

                                data4 = pyu.timestamp(S.now()) + ',toa,' + str(e) + ',' + str(self.edge[n][e]['rat1']['TOA'][0]) +',' +str(np.sqrt(np.sum((pos[n]-pos[e])**2)))

            data2=data2 + '\n'
            data4=data4 + '\n'
            file.write(data)
            file2.write(data2)
            file4.write(data4)


            file.close()
            file2.close()
            file4.close()
            self.idx = self.idx +1
        except:
            pass
예제 #13
0
    def loc_save(self,S):
        """
        DEPRECATED 

        REPLACED BY pylayers.util.save

        DEPRECATED 


        save txt 
        node ID , True pos x , True pos y , est pos x , est pos y , timestamp


        Attributes:
        ----------
        
        S        : Simulation
                   Scipy.Simulation object

        """

        pos=nx.get_node_attributes(self,'p')
        pe=nx.get_node_attributes(self,'pe_alg')
        typ = nx.get_node_attributes(self,'type')
        if self.idx == 0:
            entete = 'NodeID, True Position x, True Position y, Est Position x, Est Position y, Timestamp\n'
            file=open(basename+'/' + pstruc['DIRNETSAVE'] +'/simulation.txt','write')
            file.write(entete)
            file.close()

        try:
            file=open(basename+'/' + pstruc['DIRNETSAVE'] +'/simulation.txt','a')
            for n in self.nodes():
                if typ[n] != 'ap':
                    data = n + ',' + str(pos[n][0]) + ',' + str(pos[n][1]) + ',' + str(pe[n][0][0]) + ',' + str(pe[n][0][1]) + ',' +pyu.timestamp(S.now()) +',\n'
                    file.write(data)
            file.close()
            self.idx = self.idx +1
        except:
            pass