<commit_before>import redis
import json
import time

class DHTStorage():
	def __init__(self, key):
		self.redis = redis.StrictRedis(host='localhost', port=6379, db=0)
		self.key = key

	def get_key(self, name):
		return "%s:%s" % (self.key, name)

	def send(self, name, data):
		pushData = {'time': time.time(), 'value': data}
		self.redis.lpush(self.get_key(name), json.dumps(pushData))

	def add_humidity(self, value):
		self.send('humidity', value)

	def add_temperature(self, value):
		self.send('temperature', value)

	def get_data(self, name, start=0, end=200):
		return self.redis.lrange(name, start, end)

	def get_temperature(self, start=0, end=200):
		return self.get_data(self.get_key('temperature'), start, end)

	def get_humidity(self, start=0, end=200):
		return self.get_data(self.get_key('humidity'), start, end)<commit_msg>Remove old entries (~2 months, keep 100000 entries)<commit_after>import redis
import json
import time

class DHTStorage():
	def __init__(self, key):
		self.redis = redis.StrictRedis(host='localhost', port=6379, db=0)
		self.key = key

	def get_key(self, name):
		return "%s:%s" % (self.key, name)

	def send(self, name, data):
		pushData = {'time': time.time(), 'value': data}
		self.redis.lpush(self.get_key(name), json.dumps(pushData))

	def add_humidity(self, value):
		self.send('humidity', value)
		self.remove_old('humidity')

	def add_temperature(self, value):
		self.send('temperature', value)
		self.remove_old('temperature')

	def get_data(self, name, start=0, end=200):
		return self.redis.lrange(name, start, end)

	def get_temperature(self, start=0, end=200):
		return self.get_data(self.get_key('temperature'), start, end)

	def get_humidity(self, start=0, end=200):
		return self.get_data(self.get_key('humidity'), start, end)

	def remove_old(self, name, len=100000):
		self.redis.ltrim(self.get_key(name), 0, len)
{'fraction_non_alphanumeric': 0.15989304812834224, 'fraction_numerical': 0.025668449197860963, 'mean_word_length': 5.634751773049645, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4284365', 'n_tokens_mistral': 761, 'n_tokens_neox': 683, 'n_words': 155}