Exemplo n.º 1
0
def getRuleList(roomName = None):

	query = "SELECT * FROM `rules`"
	if roomName: 
		query = "SELECT * FROM `rules` WHERE room_name = '" + roomName +"'"

	print query

	database = Database()
	database.open()
	queryResult = database.executeReadQuery(query)
	database.close()


	ruleList = []
	
	for record in queryResult:
		recDict = {}
		recDict["id"] = record[0]
		recDict["priority"] = record[1]
		recDict["category"] = record[2]
		recDict["buildingName"] = record[3]
		recDict["groupId"] = record[4]
		recDict["roomName"] = record[5]
		recDict["authorUuid"] = record[6]
		recDict["antecedent"] = record[7]
		recDict["consequent"] = record[8]
		recDict["enabled"] = record[9]
		recDict["deleted"] = record[10]
		recDict["creationTimestamp"] = record[11] 
		recDict["lastEditTimestamp"] = record[12]

		ruleList.append(recDict)

	return ruleList
Exemplo n.º 2
0
def getTimeConflictData(recordFilter):

	if recordFilter == "ALL":
		query = "SELECT * FROM `logs` WHERE `logMessage` LIKE '%RoomRuleVerification%'"
	elif recordFilter == "SUCCESS":
		query = "SELECT * FROM `logs` WHERE `logMessage` LIKE '%RoomRuleVerification [SUCCESS]%'"
	elif recordFilter == "FAILED":
		query = "SELECT * FROM `logs` WHERE `logMessage` LIKE '%RoomRuleVerification [FAILED]%'"
	else:
		print "error filter"
		sys.exit()

	database = Database()
	database.open()
	queryResult = database.executeReadQuery(query)
	database.close()


	ruleVerificationStats_cardinality = {}
	ruleVerificationStats_avg = {}
	ruleVerificationStats_stdev = {}
	ruleVerificationStats_sum = {}
	ruleVerificationStats_squareSum = {}
	ruleVerificationStats_max = {}
	ruleVerificationStats_min = {}

	for record in queryResult:
		
		numberOfRulesStrIndex = record[2].find("#rules=") + len("#rules=")
		numberOfRules = record[2][numberOfRulesStrIndex:].split("-")[0].strip()

		millisecondsStrIndex = record[2].find("opTimeMilliseconds:") + len("opTimeMilliseconds:")
		milliseconds = record[2][millisecondsStrIndex:].strip()

		numberOfRules = int(numberOfRules)
		milliseconds = int(milliseconds)

		if numberOfRules not in ruleVerificationStats_cardinality.keys(): ruleVerificationStats_cardinality[numberOfRules] = 0
		ruleVerificationStats_cardinality[numberOfRules] += 1

		if numberOfRules not in ruleVerificationStats_sum.keys(): ruleVerificationStats_sum[numberOfRules] = 0
		if numberOfRules not in ruleVerificationStats_squareSum.keys(): ruleVerificationStats_squareSum[numberOfRules] = 0
		ruleVerificationStats_sum[numberOfRules] += milliseconds
		ruleVerificationStats_squareSum[numberOfRules] += (milliseconds * milliseconds)

		if numberOfRules not in ruleVerificationStats_max.keys(): ruleVerificationStats_max[numberOfRules] = 0
		if milliseconds > ruleVerificationStats_max[numberOfRules]: ruleVerificationStats_max[numberOfRules] = milliseconds
		
		if numberOfRules not in ruleVerificationStats_min.keys(): ruleVerificationStats_min[numberOfRules] = sys.maxint
		if milliseconds < ruleVerificationStats_min[numberOfRules]: ruleVerificationStats_min[numberOfRules] = milliseconds


	# Computing average
	for numberOfRules in ruleVerificationStats_cardinality.keys():
		ruleVerificationStats_avg[numberOfRules] = ruleVerificationStats_sum[numberOfRules] / ruleVerificationStats_cardinality[numberOfRules]
		mean = ruleVerificationStats_avg[numberOfRules]
		ruleVerificationStats_stdev[numberOfRules] = math.sqrt((ruleVerificationStats_squareSum[numberOfRules] / ruleVerificationStats_cardinality[numberOfRules]) - (mean * mean)) 

	return ruleVerificationStats_avg, ruleVerificationStats_max, ruleVerificationStats_min, ruleVerificationStats_stdev
Exemplo n.º 3
0
def getRoomList():

	query = "SELECT DISTINCT room_name FROM `rooms`"

	database = Database()
	database.open()
	queryResult = database.executeReadQuery(query)
	database.close()

	roomList = []
	
	for record in queryResult:
		roomList.append(record[0])

	return roomList