예제 #1
0
        public dynamic caculateErrorNameInFactoryLine(string id_factory, string id_factory_line)
        {
            DateTime Now = DateTime.Now;
            ApexData ErrorNameOfFactoryLine = new ApexData();
            //  List<dynamic> listErrorNameOfFactoryLine = _context.quality_error_check_lists.Where(d => d.create_date.Date == Now.Date).ToList().GroupBy(d => new { d.id_factory, d.id_factory_line }).Select(g => new
            // {
            //     id_factory = g.Key.id_factory,
            //     id_factory_line = g.Key.id_factory_line,
            //     error_name = g.Select(g => _context.quality_errors.Where(e => e.id == g.id_error).Select(e => e.name)),
            //     number_error = g.Count()
            // }).ToList<dynamic>();
            List <dynamic> listErrorNameOfFactoryLine = _context.quality_error_check_lists.Where(d => d.create_date.Date == Now.Date && d.id_factory == id_factory && d.id_factory_line == id_factory_line).GroupBy(d => d.id_error).Select(g => new
            {
                error_name   = _context.quality_errors.Where(e => e.id == g.Key).Select(e => e.name).SingleOrDefault(),
                number_error = g.Count()
            }).ToList <dynamic>();

            for (int i = 0; i < listErrorNameOfFactoryLine.Count; i++)
            {
                ErrorNameOfFactoryLine.labels.Add(listErrorNameOfFactoryLine[i].error_name);
                ErrorNameOfFactoryLine.series.Add(listErrorNameOfFactoryLine[i].number_error);
            }
            return(new
            {
                ErrorNameOfFactoryLine = ErrorNameOfFactoryLine
            });
        }
예제 #2
0
        public dynamic caculateReportInDay(string id_factory)
        {
            DateTime      Now  = DateTime.Now;
            List <string> YEAR = new List <string> {
                "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"
            };
            List <string> WEEK = new List <string> {
                "Thứ 2", "Thứ 3", "Thứ 4", "Thứ 5", "Thứ 6", "Thứ 7", "Chủ nhật"
            };
            List <string> LIST_FACTORY_LINE = _context.sys_factory_lines.Where(d => d.id_factory == id_factory).Where(t => t.status_del == 1).Select(d => d.name).ToList();
            List <production_progress_factory_line_model> listProgressFactoryLine = new List <production_progress_factory_line_model>();
            List <progress_production_model> listProcessProduction = new List <progress_production_model>();
            List <data_chart> LIST_PERFORM_FACTORY_LINE            = new List <data_chart> {
            };
            ApexData          ratioErrorFactoryLine                 = new ApexData();
            ApexData          ratioErrorAndKpiFactoryLineInYear     = new ApexData();
            List <data_chart> StackedChartqualityRepairOfWeek       = new List <data_chart>();
            List <data_chart> ColumnChartqualityOfWeek              = new List <data_chart>();
            List <data_chart> ColumnChartRepairOfWeek               = new List <data_chart>();
            ApexData          PieChartErrorNameFactoryLineInDay     = new ApexData();
            ApexData          PieChartErrorQuantityFactoryLineInDay = new ApexData();
            var rnd = new Random();

            // Caculate for colunm chart
            for (int i = 0; i < LIST_FACTORY_LINE.Count; i++)
            {
                LIST_PERFORM_FACTORY_LINE.Add(new data_chart
                {
                    name   = LIST_FACTORY_LINE[i],
                    series = new List <series>
                    {
                        new series {
                            name  = "Số lượng đã sản xuất",
                            value = rnd.Next(100, 200)
                        },
                        new series {
                            name  = "Số lượng sản phẩm còn lại",
                            value = rnd.Next(30, 50)
                        }
                    }
                });
            }
            // Caculate for PieChartErrorQuantityFactoryLineInDay
            for (int FACTORY_LINE = 0; FACTORY_LINE < LIST_FACTORY_LINE.Count; FACTORY_LINE++)
            {
                PieChartErrorQuantityFactoryLineInDay.labels.Add(LIST_FACTORY_LINE[FACTORY_LINE]);
                PieChartErrorQuantityFactoryLineInDay.series.Add(rnd.Next(20, 100));
            }
            // Caculate for colunm chart
            for (int i = 0; i < LIST_FACTORY_LINE.Count; i++)
            {
                double quantity_need    = LIST_PERFORM_FACTORY_LINE[i].series[0].value + LIST_PERFORM_FACTORY_LINE[i].series[1].value;
                double quantity_error   = rnd.Next(1, 5);
                double quantity_product = LIST_PERFORM_FACTORY_LINE[i].series[0].value;

                listProgressFactoryLine.Add(new production_progress_factory_line_model
                {
                    error_percent     = Math.Round(quantity_error / quantity_need * 100),
                    max_error_percent = Math.Round(quantity_error / quantity_need * 100) + rnd.Next(2, 5),
                    factory_line_name = LIST_FACTORY_LINE[i],
                    factory_name      = _context.sys_factorys.Where(d => d.id == id_factory).Select(d => d.name).SingleOrDefault(),
                    progress_percent  = Math.Round(quantity_product / quantity_need * 100),
                    quantity          = quantity_need,
                    quantity_error    = quantity_error,
                    quantity_need     = quantity_need,
                    quantity_product  = quantity_product,
                });
            }
            // Caculate line chart and column chart error percent all factory line
            for (int i = 0; i < LIST_FACTORY_LINE.Count; i++)
            {
                ratioErrorFactoryLine.labels.Add(LIST_FACTORY_LINE[i]);
                ratioErrorFactoryLine.LineSeries.Add(listProgressFactoryLine[i].max_error_percent);
                ratioErrorFactoryLine.ColumnSeries.Add(listProgressFactoryLine[i].error_percent);
            }
            // Caculate line chart and column chart error and KPI all factory line in year
            for (int i = 0; i < YEAR.Count; i++)
            {
                ratioErrorAndKpiFactoryLineInYear.labels.Add(YEAR[i]);
                ratioErrorAndKpiFactoryLineInYear.LineSeries.Add(Math.Abs(listProgressFactoryLine[0].max_error_percent + rnd.Next(-40, 30)));
                ratioErrorAndKpiFactoryLineInYear.ColumnSeries.Add(Math.Abs(listProgressFactoryLine[0].error_percent + rnd.Next(-20, 30)));
            }
            return(new
            {
                productedQuantityInDay = new
                {
                    count = 1,
                    label = "quality.productedQuantityInDay"
                },
                processQuantityInDay = new
                {
                    count = 1,
                    label = "quality.processQuantityInDay"
                },
                errorQuantityInDay = new
                {
                    count = 1,
                    label = "quality.errorQuantityInDay"
                },
                errorPercentInDay = new
                {
                    count = 1,
                    label = "quality.errorPercentInDay"
                },
                listProgressFactoryLine = listProgressFactoryLine,
                PieChartErrorQuantityFactoryLineInDay = PieChartErrorQuantityFactoryLineInDay,
                ratioErrorFactoryLine = ratioErrorFactoryLine,
                ratioErrorAndKpiFactoryLineInYear = ratioErrorAndKpiFactoryLineInYear
            });
        }