public ActionResult Register() { SGEContext db = new SGEContext(); ViewBag.TransformadorId = new SelectList(db.Zonas.Include("Transformadores").Where(z => z.Transformadores.Count > 0).ToList(), "Id", "Nombre"); return(View()); }
public JsonResult ejecutarSimplex() { Dictionary <string, double> resultadoSimplex = ejecucionSimplex(); var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext())); var user = UserManager.FindById(User.Identity.GetUserId()); SGEContext db = new SGEContext(); if (resultadoSimplex == null) { return(Json(new { success = false, error = "No se puede ejecutar el simplex" })); } BaseRepositorio <Inteligente> repoInteligente = new BaseRepositorio <Inteligente>(db); var includesCliente = new List <Expression <Func <Inteligente, object> > >() { i => i.RegistroDeActivaciones, i => i.Clientes }; Inteligente inteligente = null; foreach (KeyValuePair <string, double> item in resultadoSimplex) { if (item.Value > 0 && item.Key != "TotalHorasRestantes" && item.Key != "ConsumoRestanteTotal") { inteligente = repoInteligente.Single(i => i.Nombre == item.Key && i.Clientes.Any(c => c.NombreUsuario == user.UserName), includesCliente); inteligente.Encender(); repoInteligente.Update(inteligente); } } return(Json(new { success = true })); }
public JsonResult CargarAccionesYSensores(int idInteligente) { SGEContext db = new SGEContext(); var jsonSerialiser = new JavaScriptSerializer(); List <object> acciones = new List <object>(); Inteligente inteligente = db.Inteligentes.First(i => i.Id == idInteligente); Catalogo catalogo = db.Catalogos.Include("Acciones").Include("Sensores").First(c => c.Id == inteligente.CatalogoId); foreach (Accion accion in catalogo.Acciones) { var objeto = Json(new { accion.Id, accion.Descripcion }).Data; acciones.Add(objeto); } List <object> sensores = new List <object>(); foreach (SensorFisico sensor in db.SensoresFisicos.Where(s => s.IdDispositivo == idInteligente).ToList()) { var objeto = Json(new { sensor.Id, sensor.Descripcion }).Data; sensores.Add(objeto); } return(Json(new { success = true, sensores = jsonSerialiser.Serialize(sensores), acciones = jsonSerialiser.Serialize(acciones) })); }
public JsonResult EjecutarRegla(int IdRegla) { SGEContext db = new SGEContext(); BaseRepositorio <Regla> repoRegla = new BaseRepositorio <Regla>(db); var includesRegla = new List <Expression <Func <Regla, object> > >() { r => r.Acciones, r => r.Condiciones, r => r.Inteligente }; Regla regla = repoRegla.Single(r => r.ReglaId == IdRegla, includesRegla); BaseRepositorio <Condicion> repoCondicion = new BaseRepositorio <Condicion>(db); var includesCondicion = new List <Expression <Func <Condicion, object> > >() { c => c.Sensor, c => c.Operador }; regla.Acciones.ToList().ForEach(a => a.Dispositivo = regla.Inteligente); regla.Condiciones.ToList().ForEach(c => c = repoCondicion.Single(co => co.CondicionId == c.CondicionId, includesCondicion)); regla.Condiciones.ToList().ForEach(c => c.Sensor.Dispositivo = regla.Inteligente); regla.Condiciones.ToList().ForEach(c => c.Sensor.TipoSensor = db.Sensores.Include("Catalogos").First(s => s.Id == c.SensorId)); regla.Condiciones.ToList().ForEach(c => c.Sensor.TipoSensor.Dispositivo = regla.Inteligente); regla.Ejecutar(); repoRegla.Update(regla); return(Json(new { success = true })); }
public Inteligente() { this.Clientes = new List <Cliente>(); Context = new SGEContext(); this.RegistroDeActivaciones = new List <Activacion>(); this.Sensores = new List <SensorFisico>(); }
public Inteligente(string nombre, decimal consumo) : base(nombre, consumo) { this.Clientes = new List <Cliente>(); this.RegistroDeActivaciones = new List <Activacion>(); this.Sensores = new List <SensorFisico>(); Context = new SGEContext(); }
public JsonResult CambiarEstado(int idInteligente, EstadoDispositivo estado) { SGEContext context = new SGEContext(); BaseRepositorio <Inteligente> repoInteligente = new BaseRepositorio <Inteligente>(context); Inteligente inteligente = repoInteligente.Single(i => i.Id == idInteligente); inteligente.Context = context; switch (estado) { case EstadoDispositivo.AhorroEnergia: inteligente.ColocarEnAhorroEnergia(); break; case EstadoDispositivo.Apagado: inteligente.Apagar(); break; case EstadoDispositivo.Encendido: inteligente.Encender(); break; default: return(Json(new { success = false, error = "Estado desconocido" })); } repoInteligente.Update(inteligente); return(Json(new { success = true })); }
//• Consumo por hogar/periodo. public static decimal consumoPorHogarYPeriodo(int idUsuario, DateTime fechaDesde, DateTime fechaHasta) { SGEContext context = new SGEContext(); BaseRepositorio <Cliente> repoCliente = new BaseRepositorio <Cliente>(context); decimal consumo = 0; var includesCliente = new List <Expression <Func <Cliente, object> > >() { c => c.Inteligentes }; Cliente cliente = repoCliente.Single(u => u.Id == idUsuario, includesCliente); var includesInteligente = new List <Expression <Func <Inteligente, object> > >() { i => i.RegistroDeActivaciones }; foreach (Inteligente inteligente in cliente.Inteligentes) { BaseRepositorio <Inteligente> repoInteligente = new BaseRepositorio <Inteligente>(context); Inteligente inte = repoInteligente.Single(i => i.Id == inteligente.Id, includesInteligente); consumo += inte.ObtenerConsumoPeriodo(fechaDesde, fechaHasta); } foreach (Estandar estandar in cliente.Estandars) { consumo += estandar.ConsumoAproximado((int)Math.Ceiling(fechaHasta.Subtract(fechaDesde).TotalHours)); } return(consumo); }
public Inteligente(string nombre, string id) : base(nombre) { this.Clientes = new List <Cliente>(); this.RegistroDeActivaciones = new List <Activacion>(); this.ConsumoEnergia = Convert.ToDecimal(DispositivosHelper.GetInstace().Dispositivos.Where(x => x.Id == id).Single().Consumo); this.IdentificadorFabrica = id; this.Sensores = new List <SensorFisico>(); Context = new SGEContext(); }
public JsonResult EliminarRegla(int IdRegla) { SGEContext db = new SGEContext(); BaseRepositorio <Regla> repoRegla = new BaseRepositorio <Regla>(db); Regla regla = repoRegla.Single(r => r.ReglaId == IdRegla); repoRegla.Delete(regla); return(Json(new { success = true })); }
public void SimplexNormal() { SimplexNormal simplex = new SimplexNormal(); SGEContext db = new SGEContext(); List <Inteligente> inteligentes = db.Inteligentes.Include("RegistroDeActivaciones").ToList(); simplex.AgregarRestriccion(inteligentes[0]); //simplex.AgregarRestriccion(inteligentes[1]); simplex.Resolver(); Assert.IsTrue(simplex.Resultado["ConsumoRestanteTotal"] > 0 && simplex.Resultado["ConsumoRestanteTotal"] < 440640); }
public JsonResult Agregar(int idCatalogo) { var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext())); var user = UserManager.FindById(User.Identity.GetUserId()); SGEContext db = new SGEContext(); BaseRepositorio <Cliente> repoCliente = new BaseRepositorio <Cliente>(db); Cliente cliente = repoCliente.Single(c => c.NombreUsuario == user.UserName); BaseRepositorio <Catalogo> repoCatalogo = new BaseRepositorio <Catalogo>(db); Catalogo Catalogo = repoCatalogo.Single(c => c.Id == idCatalogo); Inteligente inteligente = new Inteligente() { ConsumoEnergia = Catalogo.ConsumoEnergia, IdentificadorFabrica = Catalogo.IdentificadorFabrica, Catalogo = Catalogo, CatalogoId = Catalogo.Id }; string nombreInteligente = Catalogo.Nombre + "_" + DateTime.Now.ToString("ddMMyyHHmmss"); nombreInteligente = nombreInteligente.Replace(" ", "_"); inteligente.Nombre = nombreInteligente; inteligente.Clientes.Add(cliente); BaseRepositorio <Inteligente> repoInteligente = new BaseRepositorio <Inteligente>(db); repoInteligente.Create(inteligente); db = new SGEContext(); List <Sensor> sensores = db.Sensores.Where(s => s.Catalogos.Any(c => c.Id == Catalogo.Id)).ToList(); foreach (Sensor sensor in sensores) { SGEContext db2 = new SGEContext(); SensorFisico sensorFisico = new SensorFisico() { //TipoSensor = sensor, //Dispositivo = inteligente, IdDispositivo = inteligente.Id, IdTipoSensor = sensor.Id, Descripcion = sensor.Descripcion }; sensorFisico.Mediciones = null; //repoSensorFisico.Create(sensorFisico); db2.SensoresFisicos.Add(sensorFisico); db2.SaveChanges(); } return(Json(new { success = true })); }
public ActionResult Editar(int idRegla) { SGEContext db = new SGEContext(); BaseRepositorio <Operador> repoOperador = new BaseRepositorio <Operador>(); ViewBag.Operadores = new SelectList(repoOperador.GetAll(), "Id", "Descripcion"); Regla regla = db.Reglas.Include("Acciones").FirstOrDefault(r => r.ReglaId == idRegla); ViewBag.Condiciones = db.Condiciones.Include("Sensor").Include("Operador").Where(c => c.ReglaId == regla.ReglaId); return(View(regla)); }
private decimal ObtenerConsumoUltimoMes() { var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext())); var user = UserManager.FindById(User.Identity.GetUserId()); SGEContext contexto = new SGEContext(); BaseRepositorio <Cliente> repoCliente = new BaseRepositorio <Cliente>(contexto); Cliente cliente = repoCliente.Single(c => c.NombreUsuario == user.UserName); DateTime fDesde = DateTime.Now.AddMonths(-1); DateTime fHasta = DateTime.Now; return(Reporte.consumoPorHogarYPeriodo(cliente.Id, fDesde, fHasta)); }
public JsonResult AgregarRegla(string nombreRegla, int idInteligente, long[] idsAcciones, List <Condicion> condiciones) { SGEContext db = new SGEContext(); BaseRepositorio <Regla> repoRegla = new BaseRepositorio <Regla>(db); Regla regla = new Regla() { Nombre = nombreRegla, IdInteligente = idInteligente, Condiciones = condiciones }; regla.Acciones = db.Acciones.Where(a => idsAcciones.Any(x => x == a.Id)).ToList(); repoRegla.Create(regla); return(Json(new { success = true })); }
//Inicio public ActionResult Index() { var jsonSerialiser = new JavaScriptSerializer(); BaseRepositorio <Zona> repoZona = new BaseRepositorio <Zona>(); SGEContext db = new SGEContext(); List <object> objetos = new List <object>(); foreach (Transformador transformador in db.Transformadores.Include("Clientes").Include("Clientes.Inteligentes").ToList()) { var objeto = Json(new { transformador.Latitud, transformador.Longitud, Consumo = transformador.ObtenerConsumo() }).Data; objetos.Add(objeto); } ViewBag.transformadores = jsonSerialiser.Serialize(objetos); ViewBag.zonas = jsonSerialiser.Serialize(repoZona.GetAll()); return(View()); }
private Dictionary <string, double> ejecucionSimplex() { var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext())); var user = UserManager.FindById(User.Identity.GetUserId()); SGEContext db = new SGEContext(); BaseRepositorio <Inteligente> repoInteligente = new BaseRepositorio <Inteligente>(db); var includesCliente = new List <Expression <Func <Inteligente, object> > >() { i => i.RegistroDeActivaciones, i => i.Clientes }; List <Inteligente> inteligentes = repoInteligente.Filter(i => i.Clientes.Any(c => c.NombreUsuario == user.UserName), includesCliente); Cliente cliente = new Cliente(); cliente.Inteligentes = inteligentes; return(cliente.HogarEficiente()); }
public ActionResult DeleteConfirmed(int id) { var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext())); var user = UserManager.FindById(User.Identity.GetUserId()); SGEContext contexto = new SGEContext(); BaseRepositorio <Cliente> repoCliente = new BaseRepositorio <Cliente>(contexto); Cliente cliente = repoCliente.Single(c => c.NombreUsuario == user.UserName); BaseRepositorio <Inteligente> repoInteligente = new BaseRepositorio <Inteligente>(contexto); var includesInteligente = new List <Expression <Func <Inteligente, object> > >() { i => i.Clientes }; Inteligente inteligente = repoInteligente.Single(i => i.Id == id, includesInteligente); inteligente.Clientes.Remove(cliente); repoInteligente.Update(inteligente); return(RedirectToAction("Index")); }
public JsonResult Buscar(string fechaDesde, string fechaHasta) { var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext())); var user = UserManager.FindById(User.Identity.GetUserId()); SGEContext contexto = new SGEContext(); BaseRepositorio <Cliente> repoCliente = new BaseRepositorio <Cliente>(contexto); Cliente cliente = repoCliente.Single(c => c.NombreUsuario == user.UserName); DateTime fDesde = Convert.ToDateTime(fechaDesde); DateTime fHasta = DateTime.Now; if (!String.IsNullOrEmpty(fechaHasta)) { fHasta = Convert.ToDateTime(fechaHasta); } var consumo = Reporte.consumoPorHogarYPeriodo(cliente.Id, fDesde, fHasta); return(Json(new { success = true, resultado = consumo })); }
private ICollection <dynamic> ObtenerUltimasMediciones() { var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext())); var user = UserManager.FindById(User.Identity.GetUserId()); ICollection <dynamic> salida = new List <dynamic>(); SGEContext contexto = new SGEContext(); BaseRepositorio <Inteligente> repoInteligente = new BaseRepositorio <Inteligente>(contexto); var includesInteligente = new List <Expression <Func <Inteligente, object> > >() { i => i.Catalogo }; var inteligentes = repoInteligente.Filter(i => i.Clientes.Any(c => c.NombreUsuario == user.UserName), includesInteligente); BaseRepositorio <Medicion> repoMedicion = new BaseRepositorio <Medicion>(contexto); foreach (Inteligente inteligente in inteligentes) { if (inteligente.Catalogo.Sensores != null && inteligente.Catalogo.Sensores.Count > 0) { foreach (SensorFisico sensor in inteligente.Sensores) { dynamic customMedicion = new ExpandoObject(); customMedicion.dispositivo = inteligente.Nombre; customMedicion.sensor = sensor.Id; customMedicion.medicion = sensor.Mediciones.LastOrDefault(); salida.Add(customMedicion); } } } return(salida); }
public BaseRepositorio(SGEContext contexto) { this.context = contexto; }
public TurmaController(SGEContext context) { _context = context; }
public UserSecretariaController(SGEContext context) { _context = context; }
public AlunoResponsavelController(SGEContext context) { _context = context; }
private ICollection <dynamic> ObtenerReglasActivas() { ICollection <dynamic> salida = new List <dynamic>(); var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext())); var user = UserManager.FindById(User.Identity.GetUserId()); SGEContext contexto = new SGEContext(); BaseRepositorio <Inteligente> repoInteligente = new BaseRepositorio <Inteligente>(contexto); var includesInteligente = new List <Expression <Func <Inteligente, object> > >() { i => i.Reglas }; var inteligentes = repoInteligente.Filter(i => i.Clientes.Any(c => c.NombreUsuario == user.UserName), includesInteligente); BaseRepositorio <Accion> repoAccion = new BaseRepositorio <Accion>(contexto); var includesAccion = new List <Expression <Func <Accion, object> > >() { a => a.Reglas }; BaseRepositorio <Condicion> repoCondicion = new BaseRepositorio <Condicion>(contexto); var includesCondicion = new List <Expression <Func <Condicion, object> > >() { c => c.Operador, c => c.Sensor }; foreach (Inteligente inteligente in inteligentes) { foreach (Regla regla in inteligente.Reglas) { var reglaId = regla.ReglaId; var condiciones = repoCondicion.Filter(c => c.ReglaId == reglaId, includesCondicion); if (condiciones.Count > 0) { string strCondiciones = ""; foreach (Condicion condicion in condiciones) { if (strCondiciones != "") { strCondiciones += " | "; } string strTipoOperacion = condicion.Operador.Descripcion; strCondiciones += condicion.Sensor.Descripcion + " " + strTipoOperacion.ToLower() + " a " + condicion.ValorReferencia.ToString() + " "; } string strAcciones = ""; foreach (Accion accion in regla.Acciones) { if (strAcciones != "") { strAcciones += " | "; } strAcciones += accion.Descripcion; } dynamic customRegla = new ExpandoObject(); customRegla.regla = regla.Nombre; customRegla.condicion = "{" + strCondiciones + "} => {" + strAcciones + "}"; salida.Add(customRegla); } } } return(salida); }
public PortalUpdate_000(SGEContext _context, AppConfiguration _keyVersion) : base(_context, _keyVersion) { }
public TipoUsuariosController(SGEContext context) { _context = context; }
public TurmaDisciplinasController(SGEContext context) { _context = context; }
public AlunoController(SGEContext context) { _context = context; }
public TurmaProfessorController(SGEContext context) { _context = context; }