public async Task <IActionResult> Index() { DashBoardV2ViewModel model = new DashBoardV2ViewModel(); SustitutosDataViewModel dataViewModel = new SustitutosDataViewModel(); if (!string.IsNullOrEmpty(this.User.Identity.Name)) { var user = await _userHelper.GetUserAsync(this.User.Identity.Name); if (user != null) { if (this.User.IsInRole("Cliente")) { model.Meses = _combosHelper.GetComboMes(); model.Anios = _combosHelper.GetComboAnio(); dataViewModel.DiasSustitutosViewModel = await _datosRepository.GetDiasSustitutosAsync(user.Cedula, ""); var cuantos = await _datosRepository.GetCuantosSustitutosAsync(user.Cedula, "", "", ""); var gamas = await _context.gamas.ToListAsync(); dataViewModel.SustitutosCuantosViewModel = await getCuantos(dataViewModel.DiasSustitutosViewModel); } else if (this.User.IsInRole("Admin") || this.User.IsInRole("Renting")) { model.Meses = _combosHelper.GetComboMes(); model.Anios = _combosHelper.GetComboAnio(); model.Clientes = _combosHelper.GetComboClientes(); dataViewModel.DiasSustitutosViewModel = await _datosRepository.GetDiasSustitutosAsync("", ""); var cuantos = await _datosRepository.GetCuantosSustitutosAsync("", "", "", ""); dataViewModel.SustitutosCuantosViewModel = await getCuantos(dataViewModel.DiasSustitutosViewModel); } } dataViewModel.DashBoardV2ViewModel = model; } return(View(dataViewModel)); }
public async Task getDataTrips(Vehiculo vehiculo, string clientId, string token) { DateTime now = DateTime.Now; var firstDayOfMonth = new DateTime(now.Year, now.Month, 1, 0, 0, 0); var currentDay = new DateTime(now.Year, now.Month, now.Day, 23, 59, 59); var desde = firstDayOfMonth.ToString("yyyy-MM-ddTHH:mm:ss"); var hasta = currentDay.ToString("yyyy-MM-ddTHH:mm:ss"); var url = "https://fleet-api.location-world.com/devices"; var urlQuery = url + "/" + vehiculo.gps_id + "/trips?clientId=" + clientId + "&from=" + desde + "&to=" + hasta + "&page=0&pageSize=50"; var stringPayload = await Task.Run(() => JsonConvert.SerializeObject("")); var httpContent = new StringContent(stringPayload, Encoding.UTF8, "application/json"); VehiculoGps vehicleGPS = new VehiculoGps(); using (HttpClient cliente = new HttpClient()) { cliente.DefaultRequestHeaders.Add("domain", "fleet"); cliente.DefaultRequestHeaders.Add("subdomain", "condelpi"); cliente.DefaultRequestHeaders.Add("Authorization", "Bearer " + token); using (HttpResponseMessage response = await cliente.GetAsync(urlQuery)) { var content = response.Content.ReadAsStringAsync(); var resp = (JObject)JsonConvert.DeserializeObject(content.Result); var valores = resp["items"]; var date = ""; var day = ""; var year = ""; var month = ""; var trips = 0; var distance = 0M; var sharpAcceleration = 0; var speeding = 0; var hardBreaking = 0; var score = 0M; var longitude = ""; var latitude = ""; var sharpTurn = 0; if (valores.Count() > 0) { foreach (var elem in valores) { distance += elem["distance"].Value <decimal>(); score += elem["score"].Value <decimal>(); speeding += elem["overSpeeds"].Value <int>(); hardBreaking += elem["suddenBreakings"].Value <int>(); sharpAcceleration += elem["harshAccelerations"].Value <int>(); } JArray items = (JArray)valores; var dateDB = valores.First["endedOn"].Value <string>(); var dateDT = DateTime.ParseExact(dateDB, "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture); latitude = valores.First["endLatitude"].Value <string>(); longitude = valores.First["endLongitude"].Value <string>(); //vehicle_id = id; date = dateDT.ToString(); day = dateDT.Day.ToString(); year = dateDT.Year.ToString(); month = dateDT.Month.ToString(); trips = items.Count; //score /= trips; //hardBreaking /= trips; //sharpAcceleration /= trips; var datosgps = await _vehiculoGpsRepository.GetVehiculoByDateAsync(DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year, vehiculo.Id); var vehiculopro = await _vehiculoProvGpsRepository.GetVehiculoByIdAsync(vehiculo.Id); var incidencias = await _incidenciasRepository.GetIncidenciaByNitAsync(vehiculopro.user.Cedula); var conductores = await _datosRepository.GetConductoresAsync(vehiculopro.user.Cedula, vehiculopro.Placa); var talleres = await _datosRepository.GetIngresosTallerAsync(vehiculopro.user.Cedula, vehiculopro.Placa); var siniestros = await _datosRepository.GetSiniestrosAsync(vehiculopro.user.Cedula, vehiculopro.Placa); var sustitutos = await _datosRepository.GetDiasSustitutosAsync(vehiculopro.user.Cedula, vehiculopro.Placa); int diassustitutos = 0; var conductor = await _datosRepository.GetConductorPlacasAsync(vehiculo.Placa); if (sustitutos.Count() > 0) { var strgama = sustitutos.ToList().FirstOrDefault().Gama.ToString(); var diassust = sustitutos.ToList().FirstOrDefault().Dias.ToString(); var gama = await _gamaRepository.GetGamaByTypeAsync(strgama); if (gama != null) { diassustitutos = gama.Monto * Convert.ToInt32(diassust); } } var suma = 0M; if (incidencias != null) { suma = incidencias.ExcesoVelocidad * Convert.ToInt32(speeding) + incidencias.FrenazoBrusco * Convert.ToInt32(hardBreaking) + incidencias.AceleracionesBruscas * Convert.ToInt32(sharpAcceleration) + incidencias.GiroBrusco * Convert.ToInt32(sharpTurn); //TODO } else { suma = 0; } if (distance > 0) { score = 100 - (suma / (Convert.ToDecimal(distance) / 100)); } if (datosgps == null) { VehiculoGps vehiculoGPS = new VehiculoGps { vehiculo = vehiculo, dia = DateTime.Now.Day, mes = DateTime.Now.Month, anio = DateTime.Now.Year, //kilometerstraveled = Convert.ToInt32(response["odometer"].Value<string>().Replace(".","")), kilometerstraveled = distance, trips = trips, speeding = speeding, hardbraking = hardBreaking, sharpacceleration = sharpAcceleration, sharpturn = 0, ///no tiene latitude = latitude, longitude = longitude, score = score, conductores = conductores.Count() > 0 ? conductores.Sum(c => c.Conductores) : 0, talleres = talleres.Count() > 0 ? talleres.Sum(t => t.Ingresos) : 0, siniestros = siniestros.Count() > 0 ? siniestros.Sum(s => s.Total_Siniestros) : 0, ahorro = sustitutos.Count() > 0 ? diassustitutos : 0, usuario = conductor.ToUpper(), }; try { await _vehiculoGpsRepository.CreateAsync(vehiculoGPS); } catch (Exception ex) { var mensaje = ex.Message; } } else { datosgps.kilometerstraveled = distance; datosgps.trips = trips; datosgps.speeding = speeding; datosgps.hardbraking = hardBreaking; datosgps.sharpacceleration = sharpAcceleration; datosgps.sharpturn = 0; datosgps.latitude = latitude; datosgps.longitude = longitude; datosgps.score = score; datosgps.conductores = conductores.Count() > 0 ? conductores.Sum(c => c.Conductores) : 0; datosgps.talleres = talleres.Count() > 0 ? talleres.Sum(t => t.Ingresos) : 0; datosgps.siniestros = siniestros.Count() > 0 ? siniestros.Sum(s => s.Total_Siniestros) : 0; datosgps.ahorro = sustitutos.Count() > 0 ? diassustitutos : 0; datosgps.usuario = conductor.ToUpper(); await _vehiculoGpsRepository.UpdateAsync(datosgps); } //return vehicleGPS; } } } }
public async Task getDataTrips(Vehiculo vehiculo, string clientId, IturanDatosGps ituranDatosGps, int dia, int mes, int año) { var datosgps = await _vehiculoGpsRepository.GetVehiculoByDateAsync(dia, mes, año, vehiculo.Id); var vehiculopro = await _vehiculoProvGpsRepository.GetVehiculoByIdAsync(vehiculo.Id); var incidencias = await _incidenciasRepository.GetIncidenciaByNitAsync(vehiculopro.user.Cedula); var conductores = await _datosRepository.GetConductoresAsync(vehiculopro.user.Cedula, vehiculopro.Placa); var talleres = await _datosRepository.GetIngresosTallerAsync(vehiculopro.user.Cedula, vehiculopro.Placa); var siniestros = await _datosRepository.GetSiniestrosAsync(vehiculopro.user.Cedula, vehiculopro.Placa); var sustitutos = await _datosRepository.GetDiasSustitutosAsync(vehiculopro.user.Cedula, vehiculopro.Placa); int diassustitutos = 0; var conductor = await _datosRepository.GetConductorPlacasAsync(vehiculo.Placa); if (sustitutos.Count() > 0) { var strgama = sustitutos.ToList().FirstOrDefault().Gama.ToString(); var diassust = sustitutos.ToList().FirstOrDefault().Dias.ToString(); var gama = await _gamaRepository.GetGamaByTypeAsync(strgama); if (gama != null) { diassustitutos = gama.Monto * Convert.ToInt32(diassust); } } var distance = ituranDatosGps.kilometros; var suma = 0M; var score = 0M; if (incidencias != null) { suma = incidencias.ExcesoVelocidad * ituranDatosGps.speeding + incidencias.FrenazoBrusco * ituranDatosGps.hardbraking + incidencias.AceleracionesBruscas * ituranDatosGps.sharpacceleration + incidencias.GiroBrusco * ituranDatosGps.sharpturn; } else { suma = 0; } if (distance > 0) { score = 100 - (suma / (Convert.ToDecimal(distance) / 100)); } if (datosgps == null) { VehiculoGps vehiculoGPS = new VehiculoGps { vehiculo = vehiculo, dia = dia, mes = mes, anio = año, //kilometerstraveled = Convert.ToInt32(response["odometer"].Value<string>().Replace(".","")), kilometerstraveled = distance, trips = ituranDatosGps.viajes, speeding = ituranDatosGps.speeding, hardbraking = ituranDatosGps.hardbraking, sharpacceleration = ituranDatosGps.sharpacceleration, sharpturn = ituranDatosGps.sharpturn, ///no tiene latitude = ituranDatosGps.latitud, longitude = ituranDatosGps.longitud, score = score, conductores = conductores.Count() > 0 ? conductores.Sum(c => c.Conductores) : 0, talleres = talleres.Count() > 0 ? talleres.Sum(t => t.Ingresos) : 0, siniestros = siniestros.Count() > 0 ? siniestros.Sum(s => s.Total_Siniestros) : 0, ahorro = sustitutos.Count() > 0 ? diassustitutos : 0, usuario = conductor.ToUpper(), }; try { await _vehiculoGpsRepository.CreateAsync(vehiculoGPS); } catch (Exception ex) { var mensaje = ex.Message; } } else { datosgps.kilometerstraveled = distance; datosgps.trips = ituranDatosGps.viajes; datosgps.speeding = ituranDatosGps.speeding; datosgps.hardbraking = ituranDatosGps.hardbraking; datosgps.sharpacceleration = ituranDatosGps.sharpacceleration; datosgps.sharpturn = ituranDatosGps.sharpturn; datosgps.latitude = ituranDatosGps.latitud; datosgps.longitude = ituranDatosGps.longitud; datosgps.score = score; datosgps.conductores = conductores.Count() > 0 ? conductores.Sum(c => c.Conductores) : 0; datosgps.talleres = talleres.Count() > 0 ? talleres.Sum(t => t.Ingresos) : 0; datosgps.siniestros = siniestros.Count() > 0 ? siniestros.Sum(s => s.Total_Siniestros) : 0; datosgps.ahorro = sustitutos.Count() > 0 ? diassustitutos : 0; datosgps.usuario = conductor.ToUpper(); await _vehiculoGpsRepository.UpdateAsync(datosgps); } }
public async Task <IActionResult> Index() { //DashboardViewModel model = new DashboardViewModel(); //if (!string.IsNullOrEmpty(this.User.Identity.Name)) //{ // var user = await _userHelper.GetUserAsync(this.User.Identity.Name); // if (user != null) // { // if (this.User.IsInRole("Cliente")) // { // model.Placas = await _combosHelper.GetComboPlacas(user.Cedula); // model.Meses = _combosHelper.GetComboMes(); // model.Anios = _combosHelper.GetComboAnio(); // model.VehiculosClientesViewModel = await _datosRepository.GetVehiculosClienteAsync(user.Cedula); // model.novedad = _novedadesRepository.GetNovedadAllNotSolution(user.Cedula); // model.Tramite = _tramitesRepository.GetCountAllTramites(user.Cedula); // model.Capacitaciones = _capacitacionesRepository.GetCountAllCapacitaciones(); // model.Analisis = _analisisRepository.GetCountAllAnalisis(user.Cedula); // model.Transacciones = _tramitesRepository.GetCountAllTramites(user.Cedula) + _analisisRepository.GetCountAllAnalisis(user.Cedula); // model.vehiculos = await _vehiculoProvGpsRepository.GetVehiculosAsync(user.Id); // model.vehiculosGps = _vehiculoGpsRepository.GetVehiculosGPSAsync(DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year,0); // model.Conductores = await _datosRepository.GetConductoresAsync(user.Cedula, ""); // model.ingresosTalleres = await _datosRepository.GetIngresosTallerAsync(user.Cedula, ""); // model.siniestros = await _datosRepository.GetSiniestrosAsync(user.Cedula,""); // } // else if (this.User.IsInRole("Admin") || this.User.IsInRole("Renting")) // { // model.Clientes = _combosHelper.GetComboClientes(); // model.Meses = _combosHelper.GetComboMes(); // model.Anios = _combosHelper.GetComboAnio(); // var vehiculosTotal = await _datosRepository.GetDatosAutoAllAsync(); // model.TotalAutos = vehiculosTotal.Count(); // model.novedad = _novedadesRepository.GetNovedadAllNotSolution(""); // model.Tramite = _tramitesRepository.GetCountAllTramites(""); // model.Capacitaciones = _capacitacionesRepository.GetCountAllCapacitaciones(); // model.Analisis = _analisisRepository.GetCountAllAnalisis(""); // model.Transacciones = _tramitesRepository.GetCountAllTramites("") + _analisisRepository.GetCountAllAnalisis(""); // model.vehiculos = await _vehiculoProvGpsRepository.GetVehiculosAsync(""); // model.vehiculosGps = _vehiculoGpsRepository.GetVehiculosGPSAsync(DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year, 0); // model.Conductores = await _datosRepository.GetConductoresAsync("", ""); // model.ingresosTalleres = await _datosRepository.GetIngresosTallerAsync("", ""); // model.siniestros = await _datosRepository.GetSiniestrosAsync("", ""); // } // } //} DashBoardV2ViewModel model = new DashBoardV2ViewModel(); if (!string.IsNullOrEmpty(this.User.Identity.Name)) { var user = await _userHelper.GetUserAsync(this.User.Identity.Name); if (user != null) { if (this.User.IsInRole("Cliente")) { //model.Placas = await _combosHelper.GetComboPlacas(user.Id); model.Placas = await _combosHelper.GetComboPlacasGPS(user.Cedula); model.Meses = _combosHelper.GetComboMes(); model.Anios = _combosHelper.GetComboAnio(); var vehiculosTotal = await _datosRepository.GetVehiculosClienteAsync(user.Cedula); EstadisticasV1ViewModel estadisticasV1ViewModel = new EstadisticasV1ViewModel { TotalAutos = vehiculosTotal.Count(), novedad = _novedadesRepository.GetNovedadAllNotSolution(user.Cedula), Tramite = _tramitesRepository.GetCountAllTramites(user.Cedula), Capacitaciones = _capacitacionesRepository.GetCountAllCapacitaciones(), Analisis = _analisisRepository.GetCountAllAnalisis(user.Cedula), Transacciones = _tramitesRepository.GetCountAllTramites(user.Cedula) + _analisisRepository.GetCountAllAnalisis(user.Cedula), }; EstadisticasV2ViewModel estadisticasV2ViewModel = new EstadisticasV2ViewModel { vehiculos = await _vehiculoProvGpsRepository.GetVehiculosAsync(user.Cedula), vehiculosGps = _vehiculoGpsRepository.GetVehiculosGPSAsync(DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year, user.Cedula, ""), //Conductores = await _datosRepository.GetConductoresAsync(user.Cedula, ""), //ingresosTalleres = await _datosRepository.GetIngresosTallerAsync(user.Cedula, ""), //siniestros = await _datosRepository.GetSiniestrosAsync(user.Cedula, ""), }; model.EstadisticasV1ViewModel = estadisticasV1ViewModel; model.EstadisticasV2ViewModel = estadisticasV2ViewModel; EstadisticasViewModel estadisticasViewModel = new EstadisticasViewModel(); estadisticasViewModel.EstadisticasV1ViewModel = estadisticasV1ViewModel; estadisticasViewModel.EstadisticasV2ViewModel = estadisticasV2ViewModel; model.EstadisticasViewModel = estadisticasViewModel; //model.EstadisticasViewModel.EstadisticasV1ViewModel = estadisticasV1ViewModel; //model.EstadisticasViewModel.EstadisticasV2ViewModel = estadisticasV2ViewModel; } else if (this.User.IsInRole("Admin") || this.User.IsInRole("Renting")) { model.Clientes = _combosHelper.GetComboClientes(); await GetPlacas("0"); model.Meses = _combosHelper.GetComboMes(); model.Anios = _combosHelper.GetComboAnio(); var cuantos = await _datosRepository.GetDiasSustitutosAsync("", ""); var vehiculosTotal = await _datosRepository.GetDatosAutoAllAsync(); EstadisticasV1ViewModel estadisticasV1ViewModel = new EstadisticasV1ViewModel { TotalAutos = vehiculosTotal.Count(), novedad = _novedadesRepository.GetNovedadAllNotSolution(""), Tramite = _tramitesRepository.GetCountAllTramites(""), Capacitaciones = _capacitacionesRepository.GetCountAllCapacitaciones(), Analisis = _analisisRepository.GetCountAllAnalisis(""), Transacciones = _tramitesRepository.GetCountAllTramites("") + _analisisRepository.GetCountAllAnalisis(""), }; EstadisticasV2ViewModel estadisticasV2ViewModel = new EstadisticasV2ViewModel { vehiculos = await _vehiculoProvGpsRepository.GetVehiculosAsync(""), vehiculosGps = _vehiculoGpsRepository.GetVehiculosGPSAsync(DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year, "", ""), //Conductores = await _datosRepository.GetConductoresAsync("", ""), //ingresosTalleres = await _datosRepository.GetIngresosTallerAsync("", ""), //siniestros = await _datosRepository.GetSiniestrosAsync("", ""), }; model.EstadisticasV1ViewModel = estadisticasV1ViewModel; model.EstadisticasV2ViewModel = estadisticasV2ViewModel; EstadisticasViewModel estadisticasViewModel = new EstadisticasViewModel(); estadisticasViewModel.EstadisticasV1ViewModel = estadisticasV1ViewModel; estadisticasViewModel.EstadisticasV2ViewModel = estadisticasV2ViewModel; model.EstadisticasViewModel = estadisticasViewModel; //model.EstadisticasViewModel.EstadisticasV1ViewModel = estadisticasV1ViewModel; //model.EstadisticasViewModel.EstadisticasV2ViewModel = estadisticasV2ViewModel; } } } return(View(model)); }