# generate random floating point values
from random import seed
from random import random
import json
import time
import signal
# data point
class DataPoint:
	def __init__(self, data):
		self.data = data

# seed random number generator
seed(2)

try:
	while True:
		# generate random numbers between <min,max>
		min = 0.0
		max = 1.0
		v = min + (random() * (max - min))
		v2 = -30 + (random() * (100 + 30))
		dp = DataPoint(v)
		dp2 = DataPoint(v2)
		# get json string
		jsonStr = json.dumps(dp.__dict__)
		jsonStr2 = json.dumps(dp2.__dict__)
		#save to file
		try:
			datafile = open("chartdata.json","w")
			datafile.write(jsonStr)
			datafile2 = open("chartdata2.json","w")
			datafile2.write(jsonStr2)
		except:
			print("Write Error")
		finally:
			datafile.close()
			datafile2.close()
		#print(jsonStr)
		
		time.sleep(0.1)
		
except KeyboardInterrupt:
	pass