Exemplo n.º 1
0
def index():
    ldb = LiteDB()
    d = ldb.get_one()
    return render_template('index.html',
                           title='Butler',
                           timestamp=d['ts'],
                           state=d['st'])
Exemplo n.º 2
0
def handler(cmd, chn):
    resp = 'All I can say is that it\'s a bouillon spoon'
    kw = ['water', 'temperature', 'ready']
    if any(w in cmd for w in kw):
        ldb = LiteDB()
        d = ldb.get_one()
        resp = 'Last time I checked ({ts}), it was {st}'.format(ts=d['ts'],
                                                                st=d['st'])
    slackc.api_call('chat.postMessage', as_user=True, channel=chn, text=resp)
Exemplo n.º 3
0
def load_data(path, file_dict):
	all_dbs = os.listdir(path)
	assert(set(all_filenames.values()).issubset(set(all_dbs)))
	db = LiteDB()
	all_keynames = {}
	read_keynames = set()
	for read_tracename, read_filename in all_filenames.iteritems():
		db.load(os.path.join(path, read_filename))
		read_keyname = set(db.keys()).difference(read_keynames).pop()
		all_keynames.__setitem__(read_tracename, read_keyname)
		read_keynames.add(read_keyname)
	return(db, all_keynames)
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)
	if enableVerbose:
		print ("inputFile: %s" % inputFile)
		print ("outputFile: %s" % outputFile)
		print ("dataName: %s" % dataName)
		print ("enableVerbose: %s" % enableVerbose)
		print ("heteNames: %s" % heteNames)
		print ("asDirected: %s" % asDirected)

	if outputFile is not None:
		outputDir = os.path.dirname(outputFile)
		if outputDir and not (os.path.exists(outputDir)):
			os.makedirs(outputDir)
	else:
		print ("There is no output")

	db = LiteDB()
	if os.path.exists(outputFile) and enable_appendant:
		db.load(outputFile)
	
	for f in inputFile: 
		print ("processing %s" % f)
		if not os.path.exists(f): next

		if inputFileType == 'gpickle':		# a graph
			g = nx.read_gpickle(file(f, "r"))
		elif inputFileType == 'edgelist':	# edgelist
			g = nx.read_edgelist(f, nodetype = int, create_using = nx.DiGraph()) if asDirected else nx.read_edgelist(f, nodetype = int, create_using = nx.Graph())
		elif inputFileType == 'cpickle':	# a list of graphs
			g = cPickle.load(file(f, "r"))

		graphs = list()
Exemplo n.º 6
0
 def save_db(self):
     ldb = LiteDB()
     ts = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
     ldb.post(ts=ts, st=self.rslt)