• R/O
  • SSH

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

File Info

Rev. a67d08e91beb148e08bb73b36e54627e8d547b9f
Größe 1,967 Bytes
Zeit 2009-09-22 21:38:20
Autor lorenzo
Log Message

I fixed a bug: now the code really prints out nodes in an edge and isolated
nodes without any repetition.

Content

#!/usr/bin/env python
# loop over 20-second intervals, compute contact graph for each interval, print out the nodes of the graph

import sys
from sociopatterns.loader import Loader
from sociopatterns.analysis import ContactGraphAnalyzer
#import string #Probably I do not need this module any longer.
#Python has a lot of methods already inbuilt for a string object.


#XXTEA_CRYPTO_KEY = ( 0xf6e103d4, 0x77a739f6, 0x65eecead, 0xa40543a9 )

XXTEA_CRYPTO_KEY = ( 0xd2e3fd73, 0xfa70ca9c, 0xe2575826, 0x0fe09946 )


loader = Loader(sys.argv[1:], decode=1, xxtea_crypto_key=XXTEA_CRYPTO_KEY,
                load_contacts=1, unique_contacts=1, load_sightings=0)

#analyzer = ContactGraphAnalyzer(loader, 20, tag_id_min=1100, tag_id_max=2047)

#NB: now I am NOT filtering on the tag IDs

analyzer = ContactGraphAnalyzer(loader, 20,tag_id_min=1100, tag_id_max=2047)


for frame in analyzer:

    all_node_list=frame['graph'].nodes() #raw list containing all the nodes
    # in the graph (regardless of whether the node is isolate or not)

    all_edge_list=frame['graph'].edges() #raw list containing pair of nodes
    #in the same edge


    new_edge_list=[] #create a new empty list

    [new_edge_list.extend(x) for x in all_edge_list ] #reshaping the edge list
    #so that it no longer looks like a chain of pairs
    

    isolate_node_list=[x for x in all_node_list  \
                         if (x not in new_edge_list)] #this is the list of
    #all the isolated nodes (i.e. those which are not inside the edge list)

    #Now reshape the lists in a way convenient for printing and add time.

    total_edge="\n".join(["%d %d %d" %( frame["time"],x, y) \
                          for x,y in all_edge_list])

    total_isolate="\n".join(["%d %d %d" %( frame["time"],x,x) \
                     for x in isolate_node_list ])


    
    if (len(isolate_node_list)>0):

        print total_isolate

    if (len(all_edge_list)>0):

        print total_edge