Пример #1
0
	def cargarEstaciones(self):
		try:
			macaron.macaronage("siprem.db")
			estaciones= models.Estacion.select("estado = ?", [1])
			return estaciones
		except Exception, e:
			print e
Пример #2
0
 def testMacaronOption_disabled(self):
     macaron.macaronage(DB_FILE)
     chk = False
     try: macaron.history[0]
     except RuntimeError: chk = True
     self.assert_(chk, "'SQL history is disabled' error has not raised")
     macaron.cleanup()
Пример #3
0
def initialize():
    """Initializes database file"""
    # Deletes database file if exists.
    if os.path.isfile("books.db"): os.unlink("books.db")

    # Initializes Macaron
    macaron.macaronage("books.db")

    # Creates tables
    macaron.execute(SQL_T_TAG)
    macaron.execute(SQL_T_BOOK)

    # Initial data
    tag1 = Tag.create(name="Python")
    tag1.books.append(title="Learning Python",
                      description="Powerful Object-Oriented Programming",
                      rating=5)
    tag1.books.append(title="Expert Python Programming",
                      description="Python best practice for experts.",
                      rating=4)
    tag2 = Tag.create(name="Japanese")
    tag2.books.append(title="K-ON!",
                      description="Highschool band cartoon.",
                      rating=5)

    # Commits
    macaron.bake()
Пример #4
0
 def testMacaronOption_index(self):
     macaron.macaronage(DB_FILE, history=10)
     chk = False
     try: macaron.history[0]
     except IndexError: chk = True
     self.assert_(chk, "Index Error is not raised.")
     macaron.cleanup()
Пример #5
0
    def testMacaronOption_index(self):
        macaron.macaronage(DB_FILE, history=10)

        def _index_error():
            macaron.history[10]

        self.assertRaises(IndexError, _index_error)
        macaron.cleanup()
Пример #6
0
	def obtenerEstacion(self, estacionId):
		try:
			macaron.macaronage("siprem.db")
			estacionObtenida = models.Estacion.get(estacionId)
			return estacionObtenida
		except Exception, e:
			print e
			return None
Пример #7
0
    def testMacaronOption_disabled(self):
        macaron.macaronage(DB_FILE)

        def _history_is_disabled():
            macaron.history[0]

        self.assertRaises(RuntimeError, _history_is_disabled)
        macaron.cleanup()
Пример #8
0
	def obtenerNombreEstacion(self, idEstacionP):
		try:
			macaron.macaronage("siprem.db")
			estacionEncontrada = models.Estacion.get(idEstacionP)
			return estacionEncontrada.nombre
		except Exception, e:
			print e
			return None
Пример #9
0
	def buscarEventos(self, fechaInicialP, fechaFinalP, estacionIdP):
		try:
			macaron.macaronage("siprem.db")
			estacionDao = models.Estacion.get(estacionIdP)
			eventosDao = estacionDao.eventos.select("fecha between ? and ?", [fechaInicialP, fechaFinalP])
			eventos = self.transformarEventosModelo(eventosDao)
			return eventos	
		except Exception, e:
			print e
Пример #10
0
	def buscarRegistros(self, fechaInicialP, fechaFinalP, estacionIdP):
		try:
			macaron.macaronage("siprem.db")
			estacionDaoP = models.Estacion.get(estacionId)
			registrosDao = estacionDaoP.estacionreg.select("fecha between ? and ?", [fechaInicialP, fechaFinalP])
			registros = self.transformarRegistros(registrosDao)
			return registros
		except Exception, e:
			raise e
Пример #11
0
	def obtenerEstacionesDesactivadas(self):
		try:
			macaron.macaronage("siprem.db")
			estaciones = models.Estacion.select("estado = ?", [0])
			if estaciones.count() != 0:
				return estaciones
			else:
				return None
		except Exception, e:
			raise e
Пример #12
0
	def activarEstacion(self, idEstacionP):
		try:
			macaron.macaronage("siprem.db")
			estacion = models.Estacion.get(idEstacionP)
			estacion.estado = 1
			estacion.save()
			macaron.bake()
			return True
		except Exception, e:
			print e
			return False
Пример #13
0
	def pruebaDeserializacion(self):
		try:
			fechaInicio = datetime.date(2007, 8, 20)
			fechaFin =  datetime.date(2007, 10, 20)
			macaron.macaronage('siprem.db')
			result = models.Cevento.select("fechainicio < ? and fechafin > ?", [fechaInicio, fechaFin])
			encapsulado = result[0].binario
			deserializado = self.deserializarObjeto(encapsulado)
			eventos = deserializado.coleccionEventos
			print len(eventos)
			for evento in eventos:
				print evento.entregarHoraInicio()
		except Exception, e:
			print e		
Пример #14
0
	def almacenarRegistros(self, kernelRegistrosP, estacionId):
		try:
			macaron.macaronage("siprem.db")
			estacionDaoP = models.Estacion.get(estacionId)
			for registroP in kernelRegistrosP:
				if registroP.entregarPrecipitacion() != 0 and registroP.entregarPrecipitacion() != "-":
					estacionDaoP.estacionreg.append(
					fecha = str(registroP.entregarFecha()),
					hora = str(registroP.entregarHora()),
					vprec = registroP.entregarPrecipitacion()
					)
			macaron.bake()
		except Exception, e:
			print e
Пример #15
0
	def buscarEventos(self, opcionBusquedaP, diaP, mesP, anoP):
		fechaFin = datetime.date(anoP, 12, 31)
		if opcionBusquedaP == 1:
			fechaBusqueda = datetime.date(anoP, mesP, diaP)
		elif opcionBusquedaP == 2:
			fechaBusqueda = datetime.date(anoP, mesP, 1)
		else:
			fechaBusqueda = datetime.date(anoP, 1, 1)
		macaron.macaronage('siprem.db')
		print fechaBusqueda, fechaFin
		result = models.Cevento.select("fechainicio between ? and ?", [fechaBusqueda, fechaFin])
		coleccionEventos = []
		if result.count() > 0:
			for idx, o in enumerate(result):
				coleccionEventos.append(o)
Пример #16
0
	def crearEstacion(self, nombreEstacionP, ubicacionP, fechaOperacionP):
		response = False
		try:
			macaron.macaronage("siprem.db")
			models.Estacion.create(
				nombre = nombreEstacionP,
				ubicacion = ubicacionP,
				fechaoperacion = fechaOperacionP,
				estado = 1)
			macaron.bake()
			response = True
			return response
		except Exception, e:
			print e
			return response
Пример #17
0
	def buscarEventosAvanzado(self, fechaInicialP, fechaFinalP, estacionIdP, categoriaP, jornadaP):
		try:
			macaron.macaronage("siprem.db")
			estacionDao = models.Estacion.get(estacionIdP)
			if categoriaP == "-----":
				eventosDao = estacionDao.eventos.select("fecha between ? and ? and jorprec = ?", [fechaInicialP, fechaFinalP, jornadaP])
				eventos = self.transformarEventosModelo(eventosDao)
			elif jornadaP == "-----":
				eventosDao = estacionDao.eventos.select("fecha between ? and ? and tipoprec = ?", [fechaInicialP, fechaFinalP, categoriaP])
				eventos = self.transformarEventosModelo(eventosDao)
			else:
				eventosDao = estacionDao.eventos.select("fecha between ? and ? and tipoprec = ? and jorprec = ?", [fechaInicialP, fechaFinalP, categoriaP, jornadaP])
				eventos = self.transformarEventosModelo(eventosDao)
			return eventos	
		except Exception, e:
			print e
Пример #18
0
	def validarRegistros(self, kernelRegistrosP, estacionId):
		registrosValidos = []
		try:
			macaron.macaronage("siprem.db")
			estacion = models.Estacion.get(estacionId)
			for registro in kernelRegistrosP:
				if registro.entregarPrecipitacion() != 0 and registro.entregarPrecipitacion() != "-":
					fecha = registro.entregarFecha()
					hora = registro.entregarHora()
					registroQ = estacion.estacionreg.select("fecha = ? and hora =?", [str(fecha), str(hora)])
					if registroQ.count() == 0:
						registrosValidos.append(registro)
			return registrosValidos
		except Exception, e:
			print e
			return None
Пример #19
0
	def validarEventos(self, eventosP, estacionId):
		eventosValidos = []
		try:
			macaron.macaronage("siprem.db")
			estacion = models.Estacion.get(estacionId)
			for evento in eventosP:
				fecha = evento.entregarFecha() 
				horaInicio = evento.entregarHoraInicio()
				horaFin = evento.entregarHoraFin()
				eventoQ = estacion.eventos.select("fecha = ? and horainicio = ? and horafin = ?", [str(fecha), str(horaInicio), str(horaFin)])
				if eventoQ.count() == 0:
					eventosValidos.append(evento)
			return eventosValidos
		except Exception, e:
			print e
			return None
Пример #20
0
	def modificarEstacion(self, estacionDaoP, nombreEstacionP, ubicacionP, fechaOperacionP):
		response = False
		try:
			macaron.macaronage("siprem.db")
			if estacionDaoP.nombre != nombreEstacionP:
				estacionDaoP.nombre = nombreEstacionP
			if estacionDaoP.ubicacion != ubicacionP:
				estacionDaoP.ubicacion = ubicacionP
			if estacionDaoP.fechaoperacion != fechaOperacionP:
				estacionDaoP.fechaoperacion = fechaOperacionP
			estacionDaoP.save()
			macaron.bake()
			response = True
			return response
		except Exception, e:
			print e
			return response
Пример #21
0
	def obtenerEstaciones(self):
		try:
			estaciones = []
			macaron.macaronage("siprem.db")
			estacionesDao = models.Estacion.select("estado = ?", [1])
			for estacion in estacionesDao:
				estacionV = []
				estacionV.append(estacion)
				registros = models.Registro.select("estacion_id =?", [estacion.id]).order_by("fecha")
				if registros.count() == 0:
					cadena = "No existen registros de precipitacion de la estacion."
				else:
					primerRegistro = registros[0]
					ultimoRegistro = registros[registros.count()-1]
					cadena = "La estacion tiene registros de precipitación desde la fecha " + str(primerRegistro.fecha) + " hasta " + str(ultimoRegistro.fecha)
				estacionV.append(cadena)
				estaciones.append(estacionV)
			return estaciones
		except Exception, e:
			print e
Пример #22
0
def initialize():
    """Initializes database file"""
    # Deletes database file if exists.
    if os.path.isfile("books.db"): os.unlink("books.db")

    # Initializes Macaron
    macaron.macaronage("books.db")

    # Creates tables
    macaron.execute(SQL_T_TAG)
    macaron.execute(SQL_T_BOOK)

    # Initial data
    tag1 = Tag.create(name="Python")
    tag1.books.append(title="Learning Python", description="Powerful Object-Oriented Programming", rating=5)
    tag1.books.append(title="Expert Python Programming", description="Python best practice for experts.", rating=4)
    tag2 = Tag.create(name="Japanese")
    tag2.books.append(title="K-ON!", description="Highschool band cartoon.", rating=5)

    # Commits
    macaron.bake()
Пример #23
0
	def persistenciaColeccionEventos(self, coleccionP, idEstacionP):
		response = False
		coleccion = coleccionP
		fechaInicial = coleccion[0].entregarFecha()
		fechaFinal = coleccion[len(coleccion)-1].entregarFecha()
		objetoASerializar = models.AlmacenSerializado(coleccion)
		objetoSerializado = self.serializarObjeto(objetoASerializar)
		serializadoBinario = self.conversorBinario(objetoSerializado)
		macaron.macaronage("siprem.db")
		try:
			estacionRelacionada= models.Cevento.create(
				idestacion=idEstacionP,
				fechainicio=fechaInicial,
				fechafin=fechaFinal,
				binario=serializadoBinario
				)
			response=True
			return response			
		except Exception, e:
			print e
			return response
Пример #24
0
    def setUp(self):
        macaron.macaronage(":memory:")
        macaron.create_table(Series)
        macaron.create_table(Group)
        macaron.create_table(Movie)
        macaron.create_table(Member)
        macaron.create_table(SubTitle)

        series1 = Series.create(name="Smile Precure")
        group1 = Group.create(name="Smile", series=series1)
        group2 = Group.create(name="Pink", series=series1)
        member1 = Member.create(curename="Happy", mygroup=group1, subgroup=group2, joined=datetime(2012, 2, 6))
        movie1 = Movie.create(title="NewStage")
        subtitle = SubTitle.create(title="Mirai no tomodachi", movie=movie1)
        member1.movies.append(movie1)

        series2 = Series.create(name="Happiness Charge Precure")
        group3 = Group.create(name="Happiness Charge", series=series2)
        group4 = Group.create(name="Purple", series=series2)
        member2 = Member.create(curename="Fortune", mygroup=group3, subgroup=group4, joined=datetime(2014, 2, 9))
        movie2 = Movie.create(title="NewStage2")
        subtitle2 = SubTitle.create(title="Eien no tomodachi", movie=movie2)
        member2.movies.append(movie2)
Пример #25
0
    def setUp(self):
        macaron.macaronage(":memory:")
        macaron.create_table(Series)
        macaron.create_table(Group)
        macaron.create_table(Movie)
        macaron.create_table(Member)
        macaron.create_table(SubTitle)

        series1 = Series.create(name="Smile Precure")
        group1 = Group.create(name="Smile", series=series1)
        group2 = Group.create(name="Pink", series=series1)
        member1 = Member.create(curename="Happy", mygroup=group1, subgroup=group2, joined=datetime(2012, 2, 6))
        movie1 = Movie.create(title="NewStage")
        subtitle = SubTitle.create(title="Mirai no tomodachi", movie=movie1)
        member1.movies.append(movie1)

        series2 = Series.create(name="Happiness Charge Precure")
        group3 = Group.create(name="Happiness Charge", series=series2)
        group4 = Group.create(name="Purple", series=series2)
        member2 = Member.create(curename="Fortune", mygroup=group3, subgroup=group4, joined=datetime(2014, 2, 9))
        movie2 = Movie.create(title="NewStage2")
        subtitle2 = SubTitle.create(title="Eien no tomodachi", movie=movie2)
        member2.movies.append(movie2)
Пример #26
0
	def almacenarEventos(self, coleccionP, estacionId):
		try:
			macaron.macaronage("siprem.db")
			estacionDaoP = models.Estacion.get(estacionId)
			for eventoP in coleccionP:
				vectorMagnitudes = eventoP.entregarVectorMagnitudes()
				vectorSerializado = self.serializarObjeto(vectorMagnitudes)
				vectorBinario = self.conversorBinario(vectorSerializado)
				estacionDaoP.eventos.append(
						fecha= str(eventoP.entregarFecha()),
						horainicio= str(eventoP.entregarHoraInicio()),
						horafin= str(eventoP.entregarHoraFin()),
						magnitud= eventoP.entregarMagnitud(),
						duracion= eventoP.entregarDuracion(),
						intmedia= eventoP.entregarIntensidadMedia(),
						intmaxima= eventoP.entregarIntensidadMaxima(),
						tipoprec= eventoP.entregarTipoLluvia(),
						observ= eventoP.entregarObservaciones(),
						jorprec= eventoP.entregarJornadaEvento(),
						vmagn= vectorBinario
				)
			macaron.bake()
		except Exception, e:
			print e
Пример #27
0
 def setUp(self):
     macaron.macaronage(DB_FILE)
     macaron.create_table(Team)
     macaron.create_table(Member)
Пример #28
0
 def setUp(self):
     macaron.macaronage(DB_FILE, lazy=True)
     macaron.execute(SQL_TEAM)
     macaron.execute(SQL_MEMBER)
Пример #29
0
 def testMacaronOption_index(self):
     macaron.macaronage(DB_FILE, history=10)
     def _index_error(): macaron.history[1]
     self.assertRaises(IndexError, _index_error)
     macaron.cleanup()
Пример #30
0
 def testMacaronOption_disabled(self):
     macaron.macaronage(DB_FILE)
     def _history_is_disabled(): macaron.history[0]
     self.assertRaises(RuntimeError, _history_is_disabled)
     macaron.cleanup()
Пример #31
0
 def testLogger_content(self):
     macaron.macaronage(DB_FILE, history=10)
     macaron.execute(SQL_TEST)
     self.assertEqual(macaron.history[0], "%s\nparams: []" % SQL_TEST)
     macaron.cleanup()
Пример #32
0
 def setUp(self):
     macaron.macaronage(DB_FILE)
     macaron.create_table(Team)
     macaron.create_table(Member)
     macaron.create_table(Song)
     macaron.create_link_tables(Song)
Пример #33
0
 def setUp(self):
     macaron.macaronage(dbfile=DB_FILE, lazy=True)
     macaron.create_table(MyRecord)
Пример #34
0
 def setUp(self):
     macaron.macaronage(dbfile=DB_FILE, lazy=True)
     #macaron.execute(sql_t_myrecord)
     macaron.create_table(MyRecord)
Пример #35
0
 def setUp(self):
     macaron.macaronage(DB_FILE, lazy=True)
     #macaron.execute(SQL_TEAM)
     #macaron.execute(SQL_MEMBER)
     macaron.create_table(Team)
     macaron.create_table(Member)
Пример #36
0
 def setUp(self):
     macaron.macaronage(DB_FILE)
     macaron.create_table(Team)
     macaron.create_table(Member)
Пример #37
0
 def setUp(self):
     macaron.macaronage(":memory:")
     macaron.create_table(Member)
Пример #38
0
 def setUp(self):
     macaron.macaronage(DB_FILE, lazy=True)
     macaron.create_table(Team)
     macaron.create_table(Member)
     macaron.create_table(Song)
Пример #39
0
 def testLogger_content(self):
     macaron.macaronage(DB_FILE, history=10)
     macaron.execute(SQL_TEST)
     self.assertEqual(str(macaron.history[0]), "%s\nparams: []" % SQL_TEST)
     macaron.cleanup()