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)
else: print ('updating in normal-pack mode') db[graph_key].update(pack(graph, **metalabels)) else: if packType == 'easy': print ("writing in easy-pack mode") db.__setitem__(graph_key, easy_pack(graph, **metalabels)) elif packType == 'degree_seq': print ('writing in degree-seq-pack mode') db.__setitem__(graph_key, degree_seq_pack(graph, **metalabels)) elif packType == 'degree': print ('writing in degree-pack mode') db.__setitem__(graph_key, degree_pack(graph, **metalabels)) elif packType == 'dist': print ("writing in dist-pack mode") db.__setitem__(graph_key, dist_pack(graph, **metalabels)) elif packType == 'frac': print ("writing in frac-pack mode") db.__setitem__(graph_key, frac_pack(graph, **metalabels)) elif packType == 'knn': print ("writing in knn-pack mode") db.__setitem__(graph_key, knn_pack(graph, **metalabels)) else: print ("writing in normal-pack mode") db.__setitem__(graph_key, pack(graph, **metalabels)) db.save(outputFile) if __name__ == "__main__": main(sys.argv[1:])