コード例 #1
0
ファイル: util.py プロジェクト: mgerring/mcom_139_tweets
def build_wordcount(db,collection=None):
	db = pymongo.Connection()[db]
	word_counts = pymongo.Connection()['word_counts']
	min_time, max_time = v.get_time_bounds(collection = collection)

	start 	= min_time
	end 	= min_time + timedelta(minutes=2)
	
	while time.mktime(end.timetuple()) <= time.mktime(max_time.timetuple()):
		results = v.get_from_db(collection,start,end)

		for i1, result in enumerate(results):
			for i2, x in enumerate(result):
				results[i1][i2] = (x[0].decode('utf-8','replace'), x[1])
		
		if word_counts[collection].insert({'timestamp':start, 'results':results}):
			print 'O DANG'

		start = end
		
		if time.mktime(end.timetuple()) == time.mktime(max_time.timetuple()):
			break

		end = end + timedelta(minutes=2)

		if time.mktime(end.timetuple()) > time.mktime(max_time.timetuple()):
			end = max_time
コード例 #2
0
ファイル: util.py プロジェクト: mgerring/mcom_139_tweets
def build_choosetwo(collection=None):
	db = pymongo.Connection()['word_counts']
	word_counts = pymongo.Connection()['word_counts']
	min_time, max_time = v.get_time_bounds(collection = collection)
	start = min_time

	while start < max_time:

		timestamps = [start]

		data = [Counter(),Counter(),Counter(),Counter()]

		while max_time not in timestamps:
			
			data = aggregate_and_save(db, collection, timestamps, data)

			new_stamp = timestamps[ len(timestamps) - 1 ] + timedelta( minutes=2 )

			if new_stamp > max_time:
				break

			timestamps.append( new_stamp )

		start += timedelta( minutes=2 )