def main(argv): """ load the temporal series, and calculat the - preferential attachment porb. - new communication distance """ inputFile = None asDirected = False outputFile = None dataName = None packType = "all" timestampformat = "%Y%m%d" outputTimeFormat = "%Y-%m-%d" base_duration = 60 extended_duration = 60 ofs = "," def usage(): """print the usage""" print ("----------------------------------------") print ("read the temporal edge list, output the longitude properties") print print ("-h, --help: print this usage") print ("-i ...: path, read temporal edgelist") print ("-b ...: int, the length of the base period") print ("-e ...: int, the length of the extended period") print ("-T [all|pa|cr|cd]: the type of pack, default = all") print ("\tall = pa + cr + cd") print ("\tpa = preferential attachment") print ("\tcr = clustering relative prob.") print ("\tcd = closure distance") print ("-o ...: path, output .db file") print ("----------------------------------------") try: opts, args = getopt.getopt(argv, "hi:b:e:T:o:", ["help"]) except getopt.GetoptError: print ("The given argv incorrect") usage() print (err) sys.exit(2) for opt, arg in opts: if opt in ("-h", "--help"): usage() sys.exit() elif opt in ("-i"): inputFile = arg elif opt in ("-b"): base_duration = int(arg) elif opt in ("-e"): extended_duration = int(arg) elif opt in ("-T"): packType = arg elif opt in ("-o"): outputFile = arg timeLoadStart = time.time() eDict, tDict = read_temporal_edges(read_path = inputFile, as_directed = False, enable_verbose = False) timeLoadEnd = time.time() print ("[Load Time] %.2f sec" % (timeLoadEnd - timeLoadStart)) # set large lifespan to make it always be cumulative gSeries = EdgeSeries(is_directed = False, lifespan = 1000) gSeries.update(tDict) gSeries.setup() gSeries.next(step = base_duration) g = gSeries.forward() gSeries.next(step = extended_duration) later_g = gSeries.forward() print ("[GraphOrder] g: %d / later_g: %d" % (g.order(), later_g.order())) print ("[GraphSize] g: %d / later_g: %d" % (g.size(), later_g.size())) db = LiteDB() fillinName = re.sub(".[^\.]+$", "", os.path.basename(inputFile)) if dataName is None else dataName timeinfo = "--".join([ min(tDict.keys()).strftime("%Y-%m-%d"), max(tDict.keys()).strftime("%Y-%m-%d") ]) graph_key = "_".join([fillinName, timeinfo, 'd']) timePackStart = time.time() if db.__contains__(graph_key): if packType == "all": print ('updating in longitude mode') db[graph_key].update(longitude_pack(g, later_g, base_len = base_duration, extended_len = extended_duration)) elif packType == "pa": print ('updating in pa mode') db[graph_key].update(pref_pack(g, later_g, base_len = base_duration, extended_len = extended_duration)) elif packType == "cr": print ('updating in cr mode') db[graph_key].update(clust_pack(g, later_g, base_len = base_duration, extended_len = extended_duration)) elif packType == "cd": print ('updating in cd mode') db[graph_key].update(closure_pack(g, later_g, base_len = base_duration, extended_len = extended_duration)) else: print ('do nothing') else: if packType == "all": print ('writing in longitude mode') db[graph_key] = longitude_pack(g, later_g, base_len = base_duration, extended_len = extended_duration) elif packType == "pa": print ('writing in pa mode') db[graph_key] = pref_pack(g, later_g, base_len = base_duration, extended_len = extended_duration) elif packType == "cr": print ('writing in cr mode') db[graph_key] = clust_pack(g, later_g, base_len = base_duration, extended_len = extended_duration) elif packType == "cd": print ('writing in cd mode') db[graph_key] = closure_pack(g, later_g, base_len = base_duration, extended_len = extended_duration) timePackEnd = time.time() print ("[Pack Time] %.2f sec" % (timePackEnd - timePackStart)) db.save(outputFile)
net = DiNet(gg) if g.is_directed() else Net(gg) graphs.extend(net.extract_multiple_edges(*heteNames)) else: if inputFileType in ('gpickle', 'edgelist'): graphs.append(g) elif inputFileType in ('cpickle'): graphs.extend(g) else: print ('empty file') sys.exit() for graph in iter(graphs): autoName = re.sub(".%s" % inputFileType, "", os.path.basename(f)) fillinName = autoName if dataName is None else dataName graph_key = "_".join([fillinName, str(graph), 'd' if graph.is_directed() else 'u']) if db.__contains__(graph_key) and not forceSave: if packType == 'easy': print ('updating in easy-pack mode') db[graph_key].update(easy_pack(graph, **metalabels)) elif packType == 'degree_seq': print ('updating in degree-seq-pack mode') db[graph_key].update(degree_seq_pack(graph, **metalabels)) elif packType == 'degree': print ('updating in degree-pack mode') db[graph_key].update(degree_pack(graph, **metalabels)) elif packType == 'dist': print ('updating in dist-pack mode') db[graph_key].update(dist_pack(graph, **metalabels)) elif packType == 'frac': print ('updating in frac-pack mode') db[graph_key].update(frac_pack(graph, **metalabels))