示例#1
0
        /// <summary>
        /// 执行计算
        /// </summary>
        public bool DoCalc(out IList <SensorAcqResult> sensordatum)
        {
            sensordatum = new List <SensorAcqResult>();
            bool flag = false;

            try
            {
                flag = DataCalc.Calc(_calcGroup, sensordatum);
            }
            catch (Exception ex)
            {
                _logger.WarnFormat("二次计算出现异常 GROUP_ID={0} GROUP_TYPE={1} ERR={2}", _calcGroup.GroupId, _calcGroup.GroupType, ex.Message);
                flag = false;
            }
            var items = _calcGroup.GetAllItems();

            foreach (var groupItem in items)
            {
                if (groupItem.Value != null && groupItem.Value.IsOK)
                {
                    sensordatum.Add(groupItem.Value);
                }
            }
            return(flag);
        }
        public void init()
        {
            int totalRegisters;
            int totalAccidents;
            var accidents  = new List <AccidentsVM>();
            var accidentes = new List <accident>();
            var employees  = new List <employee>();
            var modas      = AccidentAlgorytm.startAlgorytm();
            List <AccidentsVM> posibleAccidents = null;

            using (var ctx = new EmployeeEntity())
                employees = ctx.employees.ToList();

            int i = 0;

            foreach (var employee in employees)
            {
                var birthDate  = DataCalc.getBirthDate(employee.curp);
                var LivingDays = DataCalc.daysLived(birthDate);

                accidents.Add(new AccidentsVM(i,
                                              employee.curp,
                                              employee.fecha_nacimiento,
                                              CalcBiorrytm(LivingDays, BiorytmDays.biorritmo_fisico),
                                              CalcBiorrytm(LivingDays, BiorytmDays.biorritmo_emocional),
                                              CalcBiorrytm(LivingDays, BiorytmDays.biorritmo_intelectual),
                                              CalcBiorrytm(LivingDays, BiorytmDays.biorritmo_intuicional)));

                i++;
            }
            if (modas != null)
            {
                posibleAccidents = accidents.Where(x => x.residuo_fisico == modas.biorritmoFisico &&
                                                   x.residuo_emocional == modas.biorritmoEmocional &&
                                                   x.residuo_intelectual == modas.biorritmoIntelectual &&
                                                   x.residuo_intuicional == modas.biorritmoIntuicional).ToList();
            }



            using (var ctx = new EmployeeEntity())
                totalRegisters = ctx.employees.totalRegisters();
            using (var ctx = new EmployeeEntity())
                totalAccidents = ctx.accidents.totalAccidents();

            lbAccidentNum.Content = totalAccidents.ToString();
            lbEmployeeNum.Content = totalRegisters.ToString();

            empleado.ItemsSource = posibleAccidents;

            var totalriskEmployees = empleado.Items.Count;

            lbltotalRiskEmployees.Content = totalriskEmployees;
        }
        private void btnCalculate_Click(object sender, RoutedEventArgs e)
        {
            var livingDaysFirstMoth = DataCalc.daysLived(_fechaNacimiento, DataCalc.getFirstDayMonth());

            _userControl(new EmployeeBiorytm(tbDiasVividos.Text, livingDaysFirstMoth));

            //dias = int.Parse(tbDiasVividos.Text);
            //var biorritmoFisico = CalcularBiorritmo(dias,23);
            //var biorritmoEmocional = CalcularBiorritmo(dias, 28);
            //var biorritmoIntelectual = CalcularBiorritmo(dias, 33);
            //var biorritmoIntuicional = CalcularBiorritmo(dias, 38);

            //var results = new Results(tbAccidentes.Text,_fechaNacimiento.ToString(),tbCurp.Text,biorritmoFisico,biorritmoEmocional,biorritmoIntelectual,biorritmoIntuicional);
            //results.ShowDialog();
        }
        public async Task <GetEmployeeDataGridResponse> Handle(GetEmployeeDataGridCommand request, CancellationToken cancellationToken)
        {
            var response = new GetEmployeeDataGridResponse();

            request.curp = request.curp?.Trim();

            var parameters = new List <SqlParameter>();

            parameters.Add(new SqlParameter("@search_term", $"%{request.curp}%"));

            string addtitionalFilters = $" WHERE curp LIKE @search_term";

            var query = $@"
                             SELECT
                             curp,
                             fecha_nacimiento
                             from Employee";


            /*query += $@"    {additionalFilters}
             *                  ORDER BY {request.orderBy} {request.orderType} OFFSET {request.offset} ROWS
             *                                          FETCH NEXT {request.rowsPerPage} ROWS ONLY
             *             ";*/

            if (!string.IsNullOrEmpty(request.curp))
            {
                query += $@"{addtitionalFilters}";
            }

            response.data = await _ctx.Database.SqlQuery <employeeGridItem>(query, parameters.ToArray()).ToListAsync();

            foreach (employeeGridItem item in response.data)
            {
                int days = DataCalc.daysLived(item.fecha_nacimiento);
                item.dias_vividos = days;
            }

            return(response);
        }
        private async void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(vm.curp))
            {
                lblErrorCurp.Content    = "El CURP no puede ser vacio";
                lblErrorCurp.Visibility = Visibility.Visible;
                return;
            }

            if (vm.curp.Length != 18)
            {
                lblErrorCurp.Content    = "El CURP debe ser a 18 digitos";
                lblErrorCurp.Visibility = Visibility.Visible;
                return;
            }

            if (!InputValidators.validateCURP(vm.curp))
            {
                lblErrorCurp.Content    = "Ingresa un CURP valido";
                lblErrorCurp.Visibility = Visibility.Visible;
                return;
            }

            using (var ctx = new EmployeeEntity())
            {
                var result = ctx.employees.Where(x => x.curp == vm.curp).Select(x => x.curp).FirstOrDefault();
                if (result != null)
                {
                    lblErrorCurp.Content    = "Ya existe un empleado registrado con ese CURP";
                    lblErrorCurp.Visibility = Visibility.Visible;
                    return;
                }
            }

            vm.fecha_nacimiento = DataCalc.getBirthDate(vm.curp);
            DateTime fecha_nacimiento = DataCalc.getBirthDate(vm.curp);
            int      livedDays        = DataCalc.daysLived(fecha_nacimiento);

            if (livedDays < 0)
            {
                lblErrorCurp.Content    = "Error: La edad maxima 100";
                lblErrorCurp.Visibility = Visibility.Visible;
                return;
            }

            var createCommand = new CreateEmployeeCommand(vm.curp, vm.fecha_nacimiento, tbFechaAccidente.SelectedDate);

            try
            {
                await _mediator.Send(createCommand);
            }
            catch (Exception)
            {
                MessageBox.Show("Ha ocurrido un error al registrar al empleado");
                return;
            }

            if (tbFechaAccidente.SelectedDate != null)
            {
                vm.fecha_accidente = tbFechaAccidente.SelectedDate ?? DateTime.Now;
                var biorritmoFisico      = CalcularBiorritmo(livedDays, BiorytmDays.biorritmo_fisico);
                var biorritmoEmocional   = CalcularBiorritmo(livedDays, BiorytmDays.biorritmo_emocional);
                var biorritmoIntelectual = CalcularBiorritmo(livedDays, BiorytmDays.biorritmo_intelectual);
                var biorritmoIntuicional = CalcularBiorritmo(livedDays, BiorytmDays.biorritmo_intuicional);

                var registerAccident = new RegisterAccidentCommand(vm.curp, vm.fecha_accidente, biorritmoFisico, biorritmoEmocional, biorritmoIntelectual, biorritmoIntuicional);
                await _mediator.Send(registerAccident);
            }
            var response = $"{vm.curp} registrado con exito";

            MessageBox.Show(response);
            Close();
        }
示例#6
0
        public static List <int> checkCritics()
        {
            var accidentes = new List <accident>();

            using (var ctx = new EmployeeEntity())
                foreach (var item in ctx.accidents.ToList())
                {
                    accidentes.Add(item);
                }

            if (!accidentes.Any())
            {
                return(new List <int>());
            }

            var accidentOnCritic         = new List <accident>();
            var accidentOnPerfectCritics = new List <accident>();
            var ocurredOnFisic           = new List <Double?>();
            var ocurredOnEmotional       = new List <Double?>();
            var ocurredOnIntuitional     = new List <Double?>();
            var ocurredOnIntelectual     = new List <Double?>();

            foreach (var item in accidentes)
            {
                var date             = DataCalc.getBirthDate(item.curp);
                var days             = DataCalc.daysLived(date, item.fecha_accidente);
                var RegistrosFisicos = DataCalc.CalculateBiorritm(days, BiorytmDays.biorritmo_fisico);
                var wasFisicCritic   = calculateCritics(RegistrosFisicos);
                if (wasFisicCritic != null)
                {
                    ocurredOnFisic.Add(wasFisicCritic);
                }
                var RegistrosEmocionales = DataCalc.CalculateBiorritm(days, BiorytmDays.biorritmo_emocional);
                var wasEmotionalCritic   = calculateCritics(RegistrosEmocionales);
                if (wasEmotionalCritic != null)
                {
                    ocurredOnEmotional.Add(wasEmotionalCritic);
                }
                var RegistrosIntuicionales = DataCalc.CalculateBiorritm(days, BiorytmDays.biorritmo_intuicional);
                var wasIntuitionalCritic   = calculateCritics(RegistrosIntuicionales);
                if (wasIntuitionalCritic != null)
                {
                    ocurredOnIntuitional.Add(wasIntuitionalCritic);
                }
                var RegistrosIntelectuales = DataCalc.CalculateBiorritm(days, BiorytmDays.biorritmo_intelectual);
                var wasIntelectualCritic   = calculateCritics(RegistrosIntelectuales);
                if (wasIntelectualCritic != null)
                {
                    ocurredOnIntelectual.Add(wasIntelectualCritic);
                }

                if (wasFisicCritic != null ||
                    wasEmotionalCritic != null ||
                    wasIntelectualCritic != null ||
                    wasIntuitionalCritic != null)
                {
                    accidentOnCritic.Add(item);
                    if (wasFisicCritic != null &&
                        wasEmotionalCritic != null &&
                        wasIntelectualCritic != null &&
                        wasIntuitionalCritic != null)
                    {
                        accidentOnPerfectCritics.Add(item);
                    }
                }
            }

            var critics = new List <int>();

            critics.Add(accidentes.Count);
            critics.Add(ocurredOnFisic.Count);
            critics.Add(ocurredOnEmotional.Count);
            critics.Add(ocurredOnIntuitional.Count);
            critics.Add(ocurredOnIntelectual.Count);
            critics.Add(accidentOnPerfectCritics.Count);
            critics.Add(accidentOnCritic.Count);

            return(critics);
        }
示例#7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="timer"></param>
        public void UpdateData(DispatcherTimer timer)
        {
            DataArb = new DataCalc();

            if (SecFut.NotIsNull())
            {
                labelFutLot.Text       = SecFut.Lot.ToString();
                labelFutGo.Text        = SecFut.Params.SellDepo.ToString();
                labelFutPriceStep.Text = SecFut.StepPrice.ToString();
                labelFutPrice.Text     = SecFut.LastPrice.ToString() + " ( " + (SecFut.LastPrice / SecFut.Lot).ToString() + ")";
            }
            else
            {
                labelFutLot.Text       = "0";
                labelFutGo.Text        = "0.0";
                labelFutPriceStep.Text = "0.0";
                labelFutPrice.Text     = "0.0";
            }

            if (SecBase.NotIsNull())
            {
                labelBaseSecLot.Text   = SecBase.Lot.ToString();
                labelBaseSecPrice.Text = SecBase.LastPrice.ToString();
            }
            else
            {
                labelBaseSecLot.Text   = "0";
                labelBaseSecPrice.Text = "0.0";
            }

            if (SecFut.NotIsNull() && SecBase.NotIsNull())
            {
                DataArb.futPrice  = SecFut.LastPrice;
                DataArb.basePrice = SecBase.LastPrice;

                var priceFut = DataArb.futPrice / SecFut.Lot;
                DataArb.diffPrice = priceFut > DataArb.basePrice
                    ? priceFut - DataArb.basePrice
                    : DataArb.basePrice - priceFut;
                DataArb.diffPrice = DataArb.diffPrice * SecFut.Lot;

                DataArb.sumFutPos  = SecFut.Params.SellDepo * numericUpDownFutPos.Value;
                DataArb.basePos    = Math.Round(numericUpDownFutPos.Value * SecFut.Lot / SecBase.Lot, 1);
                DataArb.sumBasePos = DataArb.basePos * SecBase.Lot * DataArb.basePrice;


                var posFut = Trader.Objects.tPositions.SearchFirst(p => p.Sec == SecFut);
                if (posFut.NotIsNull())
                {
                    DataArb.futCurPos = posFut.Data.CurrentNet;
                }
                var posBase = Trader.Objects.tPositions.SearchFirst(p => p.Sec == SecBase && p.Data.Type == 2);
                if (posBase.NotIsNull())
                {
                    DataArb.baseCurPos = posBase.Data.CurrentNet;
                }

                ControlEvent();
            }
            else
            {
                DataArb.diffPrice  = 0;
                DataArb.sumFutPos  = 0;
                DataArb.basePos    = 0;
                DataArb.sumBasePos = 0;
            }
            //fut
            labelDiffPrice.Text  = DataArb.diffPrice.ToString();
            labelFutSumPos.Text  = DataArb.sumFutPos.ToString();
            labelFutCurrPos.Text = DataArb.futCurPos.ToString();
            //base
            labelBasePos.Text     = DataArb.basePos.ToString();
            labelBaseSumPos.Text  = DataArb.sumBasePos.ToString();
            labelBaseCurrPos.Text = DataArb.baseCurPos.ToString();
        }
        /*private async void registerall()
         * {
         *  var accidents = new List<accident>();
         *
         *  using (var ctx = new EmployeeEntity())
         *      accidents = ctx.accidents.ToList();
         *
         *  foreach(var item in accidents)
         *  {
         *      var birthDate = DataCalc.getBirthDate(item.curp);
         *      int dias = DataCalc.daysLived(birthDate, item.fecha_accidente);
         *      var biorritmoFisico = CalcularBiorritmo(dias, BiorytmDays.biorritmo_fisico);
         *      var biorritmoEmocional = CalcularBiorritmo(dias, BiorytmDays.biorritmo_emocional);
         *      var biorritmoIntelectual = CalcularBiorritmo(dias, BiorytmDays.biorritmo_intelectual);
         *      var biorritmoIntuicional = CalcularBiorritmo(dias, BiorytmDays.biorritmo_intuicional);
         *
         *      using (var ctx = new EmployeeEntity())
         *      {
         *          var some = ctx.accidents.Where(x => x.curp == item.curp).First();
         *          some.residuo_fisico = biorritmoFisico;
         *          some.residuo_emocional = biorritmoEmocional;
         *          some.residuo_intelectual = biorritmoIntelectual;
         *          some.residuo_intuicional = biorritmoIntuicional;
         *          ctx.SaveChanges();
         *      }
         *
         *  }
         *
         *
         * }*/

        private async void btnRegister_Click(object sender, RoutedEventArgs e)
        {
            bool errors = false;

            if (string.IsNullOrEmpty(vm.curp))
            {
                lblErrorCurp.Content    = "El CURP no puede ser vacio";
                lblErrorCurp.Visibility = Visibility.Visible;
                errors = true;
            }

            if (vm.curp.Length != 18)
            {
                lblErrorCurp.Content    = "El CURP debe ser a 18 digitos";
                lblErrorCurp.Visibility = Visibility.Visible;
                errors = true;
            }

            if (tbFechaAccidente.SelectedDate == null)
            {
                lblErrorDate.Content    = "La fecha del accidente no puede ser vacia";
                lblErrorDate.Visibility = Visibility.Visible;
                errors = true;
            }

            if (!InputValidators.validateCURP(vm.curp))
            {
                lblErrorCurp.Content    = "Ingresa un CURP valido";
                lblErrorCurp.Visibility = Visibility.Visible;
                errors = true;
            }

            if (errors)
            {
                return;
            }

            employee empleado = new employee();

            using (var ctx = new EmployeeEntity())
                empleado = ctx.employees.Where(x => x.curp == vm.curp).FirstOrDefault();

            if (empleado == null)
            {
                lblErrorCurp.Content    = "No hay un empleado registrado con ese CURP";
                lblErrorCurp.Visibility = Visibility.Visible;
                return;
            }

            DateTime fecha_nacimiento     = DataCalc.getBirthDate(vm.curp);
            int      dias                 = DataCalc.daysLived(fecha_nacimiento);
            var      biorritmoFisico      = CalcularBiorritmo(dias, 23);
            var      biorritmoEmocional   = CalcularBiorritmo(dias, 28);
            var      biorritmoIntelectual = CalcularBiorritmo(dias, 33);
            var      biorritmoIntuicional = CalcularBiorritmo(dias, 38);

            try
            {
                var createCommand = new RegisterAccidentCommand(vm.curp, vm.fecha_accidente, biorritmoFisico, biorritmoEmocional, biorritmoIntelectual, biorritmoIntuicional);
                await _mediator.Send(createCommand);

                MessageBox.Show("Accidente registrado con exito");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ha ocurrido un error al registrar el accidente" + ex.Message);
                return;
            }
            Close();
        }
示例#9
0
        public void init()
        {
            generador.CalcularBiorritmo(_livingDaysFirstDayMonth, BiorytmDays.biorritmo_fisico);
            //Tabla.ItemsSource = null;
            //Tabla.ItemsSource = generador.Puntos;
            PlotModel  model = new PlotModel();
            LinearAxis ejeX  = new LinearAxis();

            ejeX.Minimum  = double.Parse("1");
            ejeX.Maximum  = double.Parse("30");
            ejeX.Position = AxisPosition.Bottom;

            LinearAxis ejeY = new LinearAxis();

            ejeY.Minimum  = generador.Puntos.Min(p => p.Y);
            ejeY.Maximum  = generador.Puntos.Max(p => p.Y);
            ejeY.Position = AxisPosition.Left;

            model.Axes.Add(ejeX);
            model.Axes.Add(ejeY);
            model.Title = "Biorritmo";
            LineSeries Fisico = new LineSeries();

            foreach (var item in generador.Puntos)
            {
                Fisico.Points.Add(new DataPoint(item.X, item.Y));
            }
            Fisico.Title = "Fisico";
            Fisico.Color = OxyColor.FromRgb(byte.Parse(r.Next(0, 255).ToString()), byte.Parse(r.Next(0, 255).ToString()), byte.Parse(r.Next(0, 255).ToString()));

            generador.CalcularBiorritmo(_livingDaysFirstDayMonth, BiorytmDays.biorritmo_emocional);
            LineSeries Emocional = new LineSeries();

            foreach (var item in generador.Puntos)
            {
                Emocional.Points.Add(new DataPoint(item.X, item.Y));
            }
            Emocional.Title = "Emocional";
            Emocional.Color = OxyColor.FromRgb(byte.Parse(r.Next(0, 255).ToString()), byte.Parse(r.Next(0, 255).ToString()), byte.Parse(r.Next(0, 255).ToString()));

            generador.CalcularBiorritmo(_livingDaysFirstDayMonth, BiorytmDays.biorritmo_intelectual);
            LineSeries Intelectual = new LineSeries();

            foreach (var item in generador.Puntos)
            {
                Intelectual.Points.Add(new DataPoint(item.X, item.Y));
            }
            Intelectual.Title = "Intelectual";
            Intelectual.Color = OxyColor.FromRgb(byte.Parse(r.Next(0, 255).ToString()), byte.Parse(r.Next(0, 255).ToString()), byte.Parse(r.Next(0, 255).ToString()));

            generador.CalcularBiorritmo(_livingDaysFirstDayMonth, BiorytmDays.biorritmo_intuicional);
            LineSeries Intuicional = new LineSeries();

            foreach (var item in generador.Puntos)
            {
                Intuicional.Points.Add(new DataPoint(item.X, item.Y));
            }
            Intuicional.Title = "Intuicional";
            Intuicional.Color = OxyColor.FromRgb(byte.Parse(r.Next(0, 255).ToString()), byte.Parse(r.Next(0, 255).ToString()), byte.Parse(r.Next(0, 255).ToString()));

            LineSeries Cero = new LineSeries();

            Cero.Points.Add(new DataPoint(0, 0));
            Cero.Points.Add(new DataPoint(30, 0));
            Cero.Color = OxyColor.FromRgb(0, 0, 0);

            model.Series.Add(Fisico);
            model.Series.Add(Emocional);
            model.Series.Add(Intelectual);
            model.Series.Add(Intuicional);
            model.Series.Add(Cero);
            asd.Model = model;

            var fisic       = DataCalc.CalculateBiorritm(Convert.ToInt32(_livingDays), BiorytmDays.biorritmo_fisico);
            var emotional   = DataCalc.CalculateBiorritm(Convert.ToInt32(_livingDays), BiorytmDays.biorritmo_emocional);
            var intelectual = DataCalc.CalculateBiorritm(Convert.ToInt32(_livingDays), BiorytmDays.biorritmo_intelectual);
            var intuitional = DataCalc.CalculateBiorritm(Convert.ToInt32(_livingDays), BiorytmDays.biorritmo_intuicional);

            lblFisicBiorytm.Content       = "Fisico: " + fisic[1];
            lblEmotionalBiorytm.Content   = "Emocional: " + emotional[1];
            lblIntelectualBiorytm.Content = "Intelectual: " + intelectual[1];
            lblIntuitionalBiorytm.Content = "Intuicional: " + intuitional[1];

            if (AccidentAlgorytm.calculateCritics(fisic) == null)
            {
                lblFisicCritic.Content = "Fisico: OK...";
            }
            else
            {
                lblFisicCritic.Content    = "Fisico: CRITICO";
                lblFisicCritic.Foreground = new SolidColorBrush(Colors.Red);
            }
            if (AccidentAlgorytm.calculateCritics(emotional) == null)
            {
                lblEmotionalCritic.Content = "Emocional: OK...";
            }
            else
            {
                lblEmotionalCritic.Content    = "Emocional: CRITICO";
                lblEmotionalCritic.Foreground = new SolidColorBrush(Colors.Red);
            }
            if (AccidentAlgorytm.calculateCritics(intelectual) == null)
            {
                lblIntelectualCritic.Content = "Intelectual: OK...";
            }
            else
            {
                lblIntelectualCritic.Content    = "Intelectual: CRITICO";
                lblIntelectualCritic.Foreground = new SolidColorBrush(Colors.Red);
            }
            if (AccidentAlgorytm.calculateCritics(intuitional) == null)
            {
                lblIntuitionalCritic.Content = "Intuicional: OK...";
            }
            else
            {
                lblIntuitionalCritic.Content    = "Intuicional: CRITICO";
                lblIntuitionalCritic.Foreground = new SolidColorBrush(Colors.Red);
            }
        }