"""
	Date: 04/29/2016
	Author: Charles A. Kingston

	clear_historical_database.py:

	This is a script that was used during testing so
	that the database could be cleared quickly of the
	information not needed

"""
# Third party imports

from historical_database import Historical_Database

db = Historical_Database(False)

db.clear_database()
예제 #2
0
 def __init__(self, value: str):
     # get the opcode
     self._opcode = value.split('%')[0]
     # open the alert settings file and read in each line to an array
     f = open('alerts.txt', 'r')
     alert_settings = []
     for line in f:
         alert_settings.append(line)
     # if the opcode is 00 we just have a generic report for historical data
     if self._opcode == "00":
         # create a database instance and add the event to the database
         db = Historical_Database(False)
         new_event = Historical_Database_Interface(value)
         db.add_row(new_event)
         # get all of the events
         all_rows = db.get_all()
         #print(all_rows)
         to_write = ""
         for item in all_rows:
             # Call write report to get the string methods so that the website can
             # decipher all of the data being written in the file
             it = WriteReport(item)
             to_write += str(it) + "\n\n"
         # write the historical data file with all the events in the database
         f = open("historical_data.txt", "w")
         f.write(to_write)
         f.close()
     # if opcode is 01 we have an alert for a valve being stuck on or off
     elif self._opcode == "01":
         # get the node and valve where the issue is happening
         node = value.split('%')[1]
         status = value.split('%')[2]
         currentFlowRate = value.split('%')[3]
         # determine if stuck on or off
         if status == "1":
             status_text = "correctly not allowing water to flow"
         elif status == "2":
             status_text = "correctly allowing water to flow"
         elif status == "5":
             status_text = "stuck off"
         elif status == "6":
             status_text = "stuck on"
         # Set the text for the Alert email
         TEXT = "Hello GardeNet User," \
             "\n\nYour gateway has notified the alert system that node " + node + \
             " is " + status_text + " and is recording a flow rate of: " + currentFlowRate + \
             " GPM.\n\nRegards, \nGardeNet"
         #check if the user has selected to be notified for this alert
         if str(alert_settings[0]).split('\t')[2].split(
                 '\n')[0].upper() == "TRUE":
             # send the email if the user has selected this alert
             Alert(TEXT)
     # if opcode is 02 we have an alert that the mesh network has gone down
     elif self._opcode == "02":
         mesh_status = value.split('%')[1]
         mesh_status_text = ""
         if mesh_status == "0":
             mesh_status_text = "All nodes are correctly functioning."
         elif mesh_status == "1":
             mesh_status_text = "The radio network did not begin correctly."
         elif mesh_status == "2":
             mesh_status_text = "Some of the nodes are reported to be down."
         elif mesh_status == "3":
             mesh_status_text = "All of the nodes have been reported as down."
         # set the text for the email
         TEXT = "Hello GardeNet User," \
          "\n\nYour gateway has reported a status update of the radio network. The message received from " \
             "the gateway was:\n\n" + mesh_status_text + "\n\nRegards, \nGardeNet"
         # if the user has signed up for this alert
         if str(alert_settings[3]).split('\t')[2].split(
                 '\n')[0].upper() == "TRUE":
             # send the email
             Alert(TEXT)
     # if opcode is 03 we have an alert that the gateway has reset itself
     elif self._opcode == "03":
         # set the text for the email
         TEXT = "Hello GardeNet User," \
          "\n\nYour gateway has reset itself.\n\nRegards, \nGardeNet"
         # if the user has signed up for this alert
         if str(alert_settings[2]).split('\t')[2].split(
                 '\n')[0].upper() == "TRUE":
             # send the email
             Alert(TEXT)
     # if the opcode is 04 we have an alert for a voltage level issue
     elif self._opcode == "04":
         # get the node and valve were the issue is occuring
         node = value.split('%')[1]
         voltageState = value.split('%')[2]
         # determine the voltage level issue
         if voltageState == "0":
             voltageState_text = "proper"
         elif voltageState == "1":
             voltageState_text = "low"
         else:
             voltageState_text = "high"
         # set the text for the email
         TEXT = "Hello GardeNet User," \
          "\n\nYour gateway has reported that node " + node +" has a " + voltageState_text + \
           " voltage level.\n\nRegards, \nGardeNet"
         # if the user has signed up for this alert
         if str(alert_settings[1]).split('\t')[2].split(
                 '\n')[0].upper() == "TRUE":
             # send the email
             Alert(TEXT)
     elif self._opcode == "05":
         power_file = open("garden_power_status.txt", "w")
         power_status = value.split('%')[1]
         if power_status == "0":
             power_file.write("false")
         elif power_status == "1":
             power_file.write("true")
예제 #3
0
	def __init__(self, value: str):
		# get the opcode
		self._opcode = value.split('%')[0]
		# open the alert settings file and read in each line to an array
		f = open('alerts.txt', 'r')
		alert_settings = []
		for line in f:
			alert_settings.append(line)
		# if the opcode is 00 we just have a generic report for historical data
		if self._opcode == "00":
			# create a database instance and add the event to the database
			db = Historical_Database(False)
			new_event = Historical_Database_Interface(value)
			db.add_row(new_event)
			# get all of the events
			all_rows = db.get_all()
			#print(all_rows)
			to_write = ""
			for item in all_rows:
				# Call write report to get the string methods so that the website can
				# decipher all of the data being written in the file
				it = WriteReport(item)
				to_write += str(it) + "\n\n"
			# write the historical data file with all the events in the database
			f = open("historical_data.txt", "w")
			f.write(to_write)
			f.close()
		# if opcode is 01 we have an alert for a valve being stuck on or off
		elif self._opcode == "01":
			# get the node and valve where the issue is happening
			node = value.split('%')[1]
			status = value.split('%')[2]
			currentFlowRate = value.split('%')[3]
			# determine if stuck on or off
			if status == "1":
				status_text = "correctly not allowing water to flow"
			elif status == "2":
				status_text = "correctly allowing water to flow"
			elif status == "5":
				status_text = "stuck off"
			elif status == "6":
				status_text = "stuck on"
			# Set the text for the Alert email
			TEXT = "Hello GardeNet User," \
							"\n\nYour gateway has notified the alert system that node " + node + \
							" is " + status_text + " and is recording a flow rate of: " + currentFlowRate + \
							" GPM.\n\nRegards, \nGardeNet"
			#check if the user has selected to be notified for this alert
			if str(alert_settings[0]).split('\t')[2].split('\n')[0].upper() == "TRUE":
				# send the email if the user has selected this alert
				Alert(TEXT)
		# if opcode is 02 we have an alert that the mesh network has gone down
		elif self._opcode == "02":
			mesh_status = value.split('%')[1]
			mesh_status_text = ""
			if mesh_status == "0":
				mesh_status_text = "All nodes are correctly functioning."
			elif mesh_status == "1":
				mesh_status_text = "The radio network did not begin correctly."
			elif mesh_status == "2":
				mesh_status_text = "Some of the nodes are reported to be down."
			elif mesh_status == "3":
				mesh_status_text = "All of the nodes have been reported as down."
			# set the text for the email
			TEXT = "Hello GardeNet User," \
				"\n\nYour gateway has reported a status update of the radio network. The message received from " \
				   "the gateway was:\n\n" + mesh_status_text + "\n\nRegards, \nGardeNet"
			# if the user has signed up for this alert
			if str(alert_settings[3]).split('\t')[2].split('\n')[0].upper() == "TRUE":
				# send the email
				Alert(TEXT)
		# if opcode is 03 we have an alert that the gateway has reset itself
		elif self._opcode == "03":
			# set the text for the email
			TEXT = "Hello GardeNet User," \
				"\n\nYour gateway has reset itself.\n\nRegards, \nGardeNet"
			# if the user has signed up for this alert
			if str(alert_settings[2]).split('\t')[2].split('\n')[0].upper() == "TRUE":
				# send the email
				Alert(TEXT)
		# if the opcode is 04 we have an alert for a voltage level issue
		elif self._opcode == "04":
			# get the node and valve were the issue is occuring
			node = value.split('%')[1]
			voltageState = value.split('%')[2]
			# determine the voltage level issue
			if voltageState == "0":
				voltageState_text = "proper"
			elif voltageState == "1":
				voltageState_text = "low"
			else:
				voltageState_text = "high"
			# set the text for the email
			TEXT = "Hello GardeNet User," \
				"\n\nYour gateway has reported that node " + node +" has a " + voltageState_text + \
					" voltage level.\n\nRegards, \nGardeNet"
			# if the user has signed up for this alert
			if str(alert_settings[1]).split('\t')[2].split('\n')[0].upper() == "TRUE":
				# send the email
				Alert(TEXT)
		elif self._opcode == "05":
			power_file = open("garden_power_status.txt", "w")
			power_status = value.split('%')[1]
			if power_status == "0":
				power_file.write("false")
			elif power_status == "1":
				power_file.write("true")
"""
	Date: 04/29/2016
	Author: Charles A. Kingston

	clear_historical_database.py:

	This is a script that was used during testing so
	that the database could be cleared quickly of the
	information not needed

"""
# Third party imports

from historical_database import Historical_Database

db = Historical_Database(False)

db.clear_database()