Example #1
0
	def appsExecutar(self):
		appsExecutarAgora = []
		resultado = conexaoMySql.consulta(self, "SELECT * FROM aplications WHERE semana LIKE '%" + self.hoje + "%'");

		for i in resultado:
			idApp = i[0]
			AppsAgora = conexaoMySql.consulta(self, "SELECT * FROM history WHERE idaplications = " + str(idApp) + " ORDER BY idhistory DESC LIMIT 1")
			jaExecutados = len(AppsAgora)			
			
			if jaExecutados > 0:

				agora = datetime.now()
				agoraPre = agora.timetuple()
				agoraInt = time.mktime(agoraPre)			

				proxExecucao = (AppsAgora[0][2] + timedelta(seconds=i[4]))
				proxExecucaoPre = proxExecucao.timetuple()
				proxExecucaoInt = time.mktime(proxExecucaoPre)

				diferenca = agoraInt - proxExecucaoInt		
				
				if diferenca >= 0:
					appsExecutarAgora.append(i)
					self.salvaExecutaveisNow(i[0])

			elif jaExecutados == 0:
				appsExecutarAgora.append(i)
				self.salvaExecutaveisNow(i[0])
			
		return appsExecutarAgora
	def consultaData(self, idCondicao):	
		idcondicao = str(idCondicao)
		retorno = datetime(1900, 01, 01, 0, 0, 0)
		consulta = conexaoMySql.consulta(self, "SELECT dia FROM execucoes WHERE idcondicoes = " + idcondicao + " ORDER BY dia DESC LIMIT 1")
		if len(consulta) > 0:
			return consulta[0][0]

		return retorno
Example #3
0
	def getConditions(self):

		aplications = self.appsExecutar()		

		for app in aplications:
			idApp = app[0]
			condicoes = conexaoMySql.consulta(self, "SELECT * FROM condicoes WHERE idaplications = " + str(idApp) + " ORDER BY acao_pai")
			self.condicoesExec.append(condicoes)

		return self.condicoesExec
Example #4
0
	def getAddress(self, idNoApp):
		retorno = []
		try:
			
			resultado = conexaoMySql.consulta(self, "SELECT s.idnodes, s.endereco, a.idsensores FROM sensores AS s, sensor_app As a WHERE a.idsensor_app = " + idNoApp + " AND s.idsensores = a.idsensores")
			#print "Enderecos Reais: ", resultado		
			for result in resultado:
				for r in result:
					retorno.append(r)
			return retorno

		except Exception as e:
			print "Erro no getAdress ", e.message, e.args
Example #5
0
	def getValores(self):		
		saidaValores = []
		pegaValores = getData()
			
		for cond in self.getConditions():
			for c in cond:
				#print "Condicao: ", c
				aplicaoExecutar = conexaoMySql.consulta(self, "SELECT * FROM aplications WHERE idaplications = " + str(c[1]) + "");				
				horaInicio = datetime.now() - timedelta(seconds=aplicaoExecutar[0][4])
				#print "hora de Inicio ", horaInicio
				valorDaCondicao = []
				valorDaCondicao = pegaValores.pegaDados(c, horaInicio)
				saidaValores.append({"condicao":c, "valor":valorDaCondicao})

		del pegaValores
		return saidaValores
Example #6
0
	def salvaExecutaveisNow(self, idApp):
		if idApp > 0:
			conexaoMySql.consulta(self, "INSERT INTO history (idaplications) VALUES ("+ str(idApp) + ")", 2)