Example #1
0
        private Highcharts GetPerformerDisciplineChart(IEnumerable <Assignment> assignments)
        {
            var discipline = new Random().Next(1, 100);

            var chart = new Highcharts("PerformerDisciplineChart")
                        .InitChart(new Chart
            {
                PlotShadow          = false,
                PlotBackgroundColor = null,
                PlotBorderWidth     = null,
                MarginTop           = 0
            })
                        .SetExporting(new Exporting()
            {
                Enabled = false
            })
                        .SetTitle(new Title
            {
                Text          = string.Format("{0}%", discipline),
                Align         = HorizontalAligns.Center,
                VerticalAlign = VerticalAligns.Middle,
                Y             = 8,
                Style         = "fontSize: '36px', fontFamily: 'Arial'"
            })
                        .SetTooltip(new Tooltip {
                Enabled = false
            })
                        .SetPlotOptions(new PlotOptions
            {
                Pie = new PlotOptionsPie
                {
                    AllowPointSelect = false,
                    InnerSize        = new PercentageOrPixel(50, true),
                    Size             = new PercentageOrPixel(75, true),
                    Cursor           = Cursors.Pointer,
                    DataLabels       = new PlotOptionsPieDataLabels {
                        Enabled = false
                    },
                    ShowInLegend = false
                }
            })
                        .SetSeries(new Series
            {
                Type = ChartTypes.Pie,
                Name = "Исполнительская дисциплина",
                Data = new Data(new[]
                {
                    new Point()
                    {
                        Y = discipline, Color = ChartColors.Parse("#ffffae18")
                    },
                    new Point()
                    {
                        Y = 100 - discipline, Color = ChartColors.Parse("#ffe0e0e0")
                    }
                })
            });

            return(chart);
        }
Example #2
0
        public async Task <IViewComponentResult> InvokeAsync(string machine)
        {
            var generateChartTask = Task.Run(function: () =>
            {
                if (!_context.SimulationJobs.Any())
                {
                    return(null);
                }

                Chart chart = new Chart();

                // charttype
                chart.Type = Enums.ChartType.Pie;

                // use available hight in Chart
                chart.Options = new Options {
                    MaintainAspectRatio = true
                };
                var data = new Data();

                // create Dataset for each Lable
                data.Datasets = new List <Dataset>();

                var endSum   = _context.SimulationJobs.Where(predicate: x => x.CapabilityProvider == machine).Sum(selector: x => x.End);
                var startSum = _context.SimulationJobs.Where(predicate: x => x.CapabilityProvider == machine).Sum(selector: x => x.Start);
                var max      = _context.SimulationJobs.Max(selector: x => x.End);
                var work     = endSum - startSum;
                var wait     = max - work;
                var cc       = new ChartColors();
                data.Datasets.Add(item: new PieDataset {
                    Data = new List <double?> {
                        work, wait
                    },
                    BackgroundColor = new List <ChartColor> {
                        cc.Get(2), cc.Get(0)
                    }
                });

                data.Labels = new string[] { "Work " + Math.Round(d: Convert.ToDecimal(value: work) / max * 100, decimals: 2) + " %",
                                             "Wait " + Math.Round(d: Convert.ToDecimal(value: wait) / max * 100, decimals: 2) + " %" };

                chart.Data    = data;
                chart.Options = new Options()
                {
                    MaintainAspectRatio = false, Responsive = true
                };

                return(chart);
            });

            // create JS to Render Chart.
            ViewData[index : "chart"]   = await generateChartTask;
            ViewData[index : "machine"] = machine;

            return(View(viewName: $"MachineWorkload"));
        }
Example #3
0
        private static Point[] GetSeries(IEnumerable <Assignment> assignments, ControllerContext context)
        {
            var i     = 0;
            var group = assignments.GroupBy(x => x.TaskTypeGuid)
                        .OrderByDescending(x => x.Count())
                        .Select(x => new Point
            {
                Name   = Model.Repository.TaskTypes[x.Key],
                Y      = x.Count(),
                Color  = ChartColors.GetByIndex(i++),
                Events = new PlotOptionsSeriesPointEvents()
                {
                    Click = "function() {window.location.href = \""
                            + new UrlHelper(context.RequestContext).Action("Index", "AsgList", new { taskTypeGuid = x.Key })
                            + "\"}"
                }
            }).ToArray();

            return(group);
        }
Example #4
0
        public async Task <IViewComponentResult> InvokeAsync(List <string> paramsList)
        {
            SimulationType simType = (paramsList[index : 1].Equals(value : "Decentral")) ? SimulationType.Decentral : SimulationType.Central;
            var            kpis    = _context.Kpis.Where(predicate: x => x.KpiType == KpiType.LayTime &&
                                                         x.SimulationConfigurationId == Convert.ToInt32(paramsList[0]) &&
                                                         x.SimulationType == simType &&
                                                         x.SimulationNumber == Convert.ToInt32(paramsList[2]) &&
                                                         x.IsKpi == true).OrderBy(keySelector: x => x.Name).ToList();
            var maxVal = _context.Kpis.Where(predicate: x => x.KpiType == KpiType.LayTime &&
                                             x.SimulationConfigurationId == Convert.ToInt32(paramsList[0]) &&
                                             x.SimulationNumber == Convert.ToInt32(paramsList[2]) &&
                                             x.IsKpi == true).Max(selector: x => x.ValueMax);

            maxVal = Math.Ceiling(a: maxVal / 100) * 100;

            var generateChartTask = Task.Run(function: () =>
            {
                if (!_context.SimulationOperations.Any())
                {
                    return(null);
                }

                Chart chart = new Chart();
                var lables  = new List <string>();
                var cc      = new ChartColors();
                // charttype
                chart.Type = Enums.ChartType.HorizontalBar;

                var data = new Data {
                    Datasets = new List <Dataset>()
                };

                var min = new BarDataset {
                    Type            = Enums.ChartType.HorizontalBar,
                    Data            = new List <double>(),
                    BackgroundColor = new List <ChartColor>() // { cc.Color[8], cc.Color[4], cc.Color[1] }
                };
                var avg = new BarDataset {
                    Type            = Enums.ChartType.HorizontalBar,
                    Data            = new List <double>(),
                    BackgroundColor = new List <ChartColor>() // { cc.Color[8], , cc.Color[1] }
                };
                var max = new BarDataset {
                    Type            = Enums.ChartType.HorizontalBar,
                    Data            = new List <double>(),
                    BackgroundColor = new List <ChartColor>() // { cc.Color[8], cc.Color[4], cc.Color[1] }
                };

                foreach (var kpi in kpis)
                {
                    lables.Add(item: kpi.Name);
                    min.Data.Add(item: kpi.ValueMin);
                    avg.Data.Add(item: kpi.Value - kpi.ValueMin);
                    max.Data.Add(item: kpi.ValueMax - kpi.Value);
                    min.BackgroundColor.Add(item: ChartColors.Transparent);
                    avg.BackgroundColor.Add(item: cc.Color[index: 4]);
                    max.BackgroundColor.Add(item: cc.Color[index: 1]);
                }

                data.Datasets.Add(item: min);
                data.Datasets.Add(item: avg);
                data.Datasets.Add(item: max);
                data.Labels = lables;

                var xAxis = new List <Scale>()
                {
                    new CartesianScale
                    {
                        Stacked = true, Display = true, Ticks = new CartesianLinearTick {
                            Max = Convert.ToInt32(value: maxVal), Display = true
                        },
                        Id = "first-x-axis", Type = "linear", ScaleLabel = new ScaleLabel {
                            LabelString = "Time in min", Display = true, FontSize = 12
                        }
                    },
                };
                var yAxis = new List <Scale>()
                {
                    new CartesianScale {
                        Stacked = true, Display = true
                    }
                };                                                                                       // Ticks = new Tick { BeginAtZero = true, Min = 0, Max = 100 }
                //var yAxis = new List<Scale>() { new BarScale{ Ticks = new CategoryTick { Min = "0", Max  = (yMaxScale * 1.1).ToString() } } };
                chart.Options = new Options()
                {
                    Scales = new Scales {
                        XAxes = xAxis, YAxes = yAxis
                    }, MaintainAspectRatio = false, Responsive = true, Legend = new Legend {
                        Display = false
                    }
                };
                chart.Data = data;
                return(chart);
            });

            // create JS to Render Chart.
            ViewData[index : "chart"] = await generateChartTask;
            ViewData[index : "Type"]  = paramsList[index : 1];
            ViewData[index : "Data"]  = kpis.ToList();
            return(View(viewName: $"IdlePeriod"));
        }
Example #5
0
        public async Task <IViewComponentResult> InvokeAsync(List <string> paramsList)
        {
            var generateChartTask = Task.Run(function: () =>
            {
                if (!_context.SimulationJobs.Any())
                {
                    return(null);
                }

                Chart chart    = new Chart();
                ChartColors cc = new ChartColors();
                // charttype
                chart.Type    = Enums.ChartType.Scatter;
                var simConfig = _context.SimulationConfigurations.Single(predicate: a => a.Id == Convert.ToInt32(paramsList[0]));
                // use available hight in Chart
                var maxY      = Math.Floor(d: (decimal)simConfig.SimulationEndTime / 1000) * 1000;
                var maxX      = 100;
                chart.Options = new LineOptions()
                {
                    MaintainAspectRatio = false,
                    Responsive          = true,
                    Scales = new Scales
                    {
                        YAxes = new List <Scale> {
                            new CartesianScale {
                                Id      = "first-y-axis", Type = "linear", Display = true
                                , Ticks = new CartesianLinearTick {
                                    Max = maxX, Min = 0, Display = true
                                }
                                , ScaleLabel = new ScaleLabel {
                                    LabelString = "Quantity", Display = true, FontSize = 12
                                }
                            }
                        },
                        XAxes = new List <Scale> {
                            new CartesianScale {
                                Id      = "first-x-axis", Type = "linear", Display = true
                                , Ticks = new CartesianLinearTick {
                                    Max = Convert.ToInt32(value: maxY), Min = 0, Display = true
                                }
                                , ScaleLabel = new ScaleLabel {
                                    LabelString = "Time in min", Display = true, FontSize = 12
                                }
                            }
                        }
                    },
                    Legend = new Legend {
                        Position = "bottom", Display = true, FullWidth = true
                    },
                    Title = new Title {
                        Text = "Order Evolution", Position = "top", FontSize = 24, FontStyle = "bold"
                    }
                };


                SimulationType simType = (paramsList[index: 1].Equals(value: "Decentral")) ? SimulationType.Decentral : SimulationType.Central;
                var kpis = _context.SimulationOrders.Where(predicate: x => x.SimulationConfigurationId == Convert.ToInt32(paramsList[0]) &&
                                                           x.SimulationNumber == Convert.ToInt32(paramsList[2]) &&
                                                           x.SimulationType == simType &&
                                                           x.FinishingTime != 0); // filter unfinished orders

                var data = new Data {
                    Datasets = new List <Dataset>()
                };

                var startVal = 0;
                var ts       = simConfig.DynamicKpiTimeSpan;
                var input    = new List <LineScatterData> {
                    new LineScatterData {
                        X = "0", Y = "0"
                    }
                };
                var progress = new List <LineScatterData> {
                    new LineScatterData {
                        X = "0", Y = "0"
                    }
                };
                var output = new List <LineScatterData> {
                    new LineScatterData {
                        X = "0", Y = "0"
                    }
                };
                for (var i = ts; i < simConfig.SimulationEndTime; i = i + ts)
                {
                    input.AddRange(collection: kpis.Where(predicate: x => x.CreationTime >= startVal &&
                                                          x.CreationTime < i)
                                   .Select(selector: x => new { time = i, value = (decimal)x.Name.Count() })
                                   .GroupBy(keySelector: g => g.time)
                                   .Select(selector: n => new LineScatterData {
                        X = Convert.ToDouble(n.Key).ToString(), Y = Convert.ToDouble(n.Count()).ToString()
                    }).ToList());

                    progress.AddRange(collection: kpis.Where(predicate: x => x.CreationTime <= i &&
                                                             x.FinishingTime > i)
                                      .Select(selector: x => new { time = i, value = x.Name.Count() })
                                      .GroupBy(keySelector: g => g.time)
                                      .Select(selector: n => new LineScatterData {
                        X = Convert.ToDouble(n.Key).ToString(), Y = Convert.ToDouble(n.Count()).ToString()
                    }).ToList());

                    output.AddRange(collection: kpis.Where(predicate: x => x.FinishingTime >= startVal &&
                                                           x.FinishingTime < i)
                                    .Select(selector: x => new { time = i, value = x.Name.Count() })
                                    .GroupBy(keySelector: g => g.time)
                                    .Select(selector: n => new LineScatterData {
                        X = Convert.ToDouble(n.Key).ToString(), Y = Convert.ToDouble(n.Count()).ToString()
                    }).ToList());
                    startVal = i;
                }

                data.Datasets.Add(item: new LineScatterDataset()
                {
                    Data = new List <LineScatterData> {
                        new LineScatterData {
                            X = "0", Y = maxX.ToString()
                        }, new LineScatterData {
                            X = simConfig.SettlingStart.ToString(), Y = maxX.ToString()
                        }
                    },
                    BorderWidth     = 1,
                    Label           = "Settling time",
                    BackgroundColor = ChartColor.FromRgba(0, 0, 0, 0.1),
                    BorderColor     = ChartColor.FromRgba(0, 0, 0, 0.3),
                    ShowLine        = true,
                    Fill            = "true",
                    //SteppedLine = false,
                    LineTension = 0,
                    PointRadius = new List <int> {
                        0, 0
                    }
                });

                data.Datasets.Add(item: new LineScatterDataset()
                {
                    Data            = input,
                    BorderWidth     = 3,
                    Label           = "Input",
                    BackgroundColor = cc.Color[index: 3],
                    BorderColor     = cc.Color[index: 3],
                    ShowLine        = true,
                    Fill            = "false",
                    //SteppedLine = false,
                    LineTension = 0.5
                });

                data.Datasets.Add(item: new LineScatterDataset()
                {
                    Data            = progress,
                    BorderWidth     = 3,
                    Label           = "Processing",
                    BackgroundColor = cc.Color[index: 0],
                    BorderColor     = cc.Color[index: 0],
                    ShowLine        = true,
                    Fill            = "false",
                    //SteppedLine = false,
                    LineTension = 0.5
                });

                data.Datasets.Add(item: new LineScatterDataset()
                {
                    Data            = output,
                    BorderWidth     = 3,
                    Label           = "Output",
                    BackgroundColor = cc.Color[index: 2],
                    BorderColor     = cc.Color[index: 2],
                    Fill            = "false",
                    ShowLine        = true,
                    //SteppedLine = false,
                    LineTension = 0.5
                });



                chart.Data = data;
                return(chart);
            });

            // create JS to Render Chart.
            ViewData[index : "chart"] = await generateChartTask;
            ViewData[index : "Type"]  = paramsList[index : 1];
            return(View(viewName: $"OrderEvolution"));
        }
Example #6
0
        public Highcharts GetEncounterDurationOverTime(int bossFightId, int difficultyId, int guildId, string guildName, string bossFightName)
        {
            var graphTitle = string.Format("{0} vs {1}: Encounter duration over time", guildName.Replace("'", "\\\'"), bossFightName);
            var stats      = _recordsRepository.GetEncounterDurationOverTime(bossFightId, difficultyId, guildId);

            if (!stats.Any())
            {
                return(null);
            }

            #region Build chart series

            //var dpsSeries = new Series() { Name = "Damage" };
            //var dpsDataList = new List<object[]>();
            //var hpsSeries = new Series() { Name = "Healing", PlotOptionsSpline = new PlotOptionsSpline() { Visible = false } };
            //var hpsDataList = new List<object[]>();
            //var apsSeries = new Series() { Name = "Absorption", PlotOptionsSpline = new PlotOptionsSpline() { Visible = false } };
            //var apsDataList = new List<object[]>();
            var durationSeries = new Series()
            {
                Name = "Duration"
            };
            var durationDataList = new List <object[]>();

            foreach (var stat in stats)
            {
                //dpsDataList.Add(new object[] { stat.Date, stat.AverageDps });
                //hpsDataList.Add(new object[] { stat.Date, stat.AverageHps });
                //apsDataList.Add(new object[] { stat.Date, stat.AverageAps });
                durationDataList.Add(new object[] { stat.Date, new DateTime().Add(stat.Duration) });
            }

            //dpsSeries.Data = new Data(dpsDataList.ToArray());
            //hpsSeries.Data = new Data(hpsDataList.ToArray());
            //apsSeries.Data = new Data(apsDataList.ToArray());
            durationSeries.Data = new Data(durationDataList.ToArray());

            //var chartSeries = new Series[] { dpsSeries, hpsSeries, apsSeries };
            var chartSeries = durationSeries;
            #endregion

            var chart = new Highcharts(string.Format("bf{0}d{1}g{2}duration", bossFightId, difficultyId, guildId))
                        .InitChart(new Chart
            {
                DefaultSeriesType = ChartTypes.Spline,
                ZoomType          = ZoomTypes.Xy,
                Height            = 400,
                BackgroundColor   = new BackColorOrGradient(new Gradient
                {
                    LinearGradient = new[] { 0, 0, 0, 400 },
                    Stops          = new object[, ]
                    {
                        { 0, Color.FromArgb(13, 255, 255, 255) },
                        { 1, Color.FromArgb(13, 255, 255, 255) }
                    }
                }),
                Style = ChartColors.WhiteTextStyle
            })
                        .SetCredits(ChartDefaults.Credits)
                        .SetOptions(new GlobalOptions
            {
                Colors = ChartColors.ColorArrayBlackBg(),
                Global = new Global {
                    UseUTC = false
                }
            })
                        .SetTitle(new Title
            {
                Text  = graphTitle,
                Style = ChartColors.WhiteTextStyle
            })
                        .SetXAxis(new XAxis
            {
                Type = AxisTypes.Datetime,
                DateTimeLabelFormats = new DateTimeLabel {
                    Month = "%e %b", Year = "%e %b", Day = "%e %b", Week = "%e %b"
                },
                LineColor = Color.White,
                TickColor = Color.White,
                Labels    = new XAxisLabels {
                    Style = ChartColors.WhiteTextStyle
                },
            })
                        .SetYAxis(new YAxis
            {
                Title = new YAxisTitle {
                    Text = "Encounter time", Style = ChartColors.WhiteTextStyle
                },
                Type = AxisTypes.Datetime,
                DateTimeLabelFormats = new DateTimeLabel {
                    Hour = "%Mm %Ss", Minute = "%Mm %Ss", Second = "%Mm %Ss"
                },
                //Min = 0
                TickColor = Color.White,
                LineColor = Color.White,
                Labels    = new YAxisLabels {
                    Style = ChartColors.WhiteTextStyle
                },
            })
                        //.SetTooltip(new Tooltip() { ValueSuffix = " per second" })
                        .SetTooltip(new Tooltip {
                Formatter = @"function() { return  '<b>' + this.series.name +'</b><br/>' +
                    Highcharts.dateFormat('%Mm %Ss',new Date(this.y)); }"
            })
                        .SetSeries(chartSeries)
                        .SetExporting(new Exporting {
                Enabled = false
            })
                        .SetLegend(new Legend()
            {
                ItemStyle = ChartColors.WhiteTextStyle, ItemHoverStyle = "color: '#bbb'"
            })
            ;

            return(chart);
        }
Example #7
0
        public Highcharts GuildPlayerXpsOverTime(int bossFightId, int difficultyId, int guildId, string guildName, string bossFightName,
                                                 string xpsType, int topX)
        {
            var graphTitle    = string.Format("{0} vs {1}: Top {2} {3} over time", guildName.Replace("'", "\\\'"), bossFightName, topX, xpsType);
            var stats         = _recordsRepository.GetTopXpsOverTime(bossFightId, difficultyId, guildId, xpsType);
            var yAxisText     = "";
            var yAxisPlotLine = new YAxisPlotLines()
            {
                Color = Color.Red,
                Width = 1,
            };

            switch (xpsType)
            {
            case "APS":
                yAxisText = "Absorption per second";
                break;

            case "HPS":
                yAxisText = "Healing per second";
                break;

            default:
            case "DPS":
                yAxisText = "Damage per second";
                break;
            }

            if (!stats.Any())
            {
                return(null);
            }

            var seriesList = new List <Series>();

            #region Overall single top XPS series
            var topList = new List <EncounterPlayerStatistics>();
            EncounterPlayerStatistics prevStat = null;
            var statGroup = stats.GroupBy(g => g.Encounter.Date.ToShortDateString());
            #region Stat loop
            foreach (var statList in statGroup)
            {
                switch (xpsType)
                {
                case "HPS":
                    var topHPSStat = statList.OrderByDescending(s => s.HPS).First();
                    if (prevStat == null)
                    {
                        topList.Add(topHPSStat);
                        prevStat = topHPSStat;
                    }
                    else
                    {
                        if (topHPSStat.HPS > prevStat.HPS)
                        {
                            topList.Add(topHPSStat);
                            prevStat = topHPSStat;
                        }
                    }
                    break;

                case "APS":
                    var topAPSStat = statList.OrderByDescending(s => s.APS).First();
                    if (prevStat == null)
                    {
                        topList.Add(topAPSStat);
                        prevStat = topAPSStat;
                    }
                    else
                    {
                        if (topAPSStat.APS > prevStat.APS)
                        {
                            topList.Add(topAPSStat);
                            prevStat = topAPSStat;
                        }
                    }
                    break;

                default:
                case "DPS":
                    var topDPSStat = statList.OrderByDescending(s => s.DPS).First();
                    if (prevStat == null)
                    {
                        topList.Add(topDPSStat);
                        prevStat = topDPSStat;
                    }
                    else
                    {
                        if (topDPSStat.DPS > prevStat.DPS)
                        {
                            topList.Add(topDPSStat);
                            prevStat = topDPSStat;
                        }
                    }
                    break;
                }
            }
            #endregion

            var topSeries = new Series {
                Name = string.Format("Highest {0}", xpsType), PlotOptionsSpline = new PlotOptionsSpline()
                {
                    Visible = true
                }
            };
            var topOverallList = new List <object[]>();
            foreach (var stat in topList)
            {
                switch (xpsType)
                {
                case "APS":
                    topOverallList.Add(new object[] { stat.Encounter.Date, stat.APS });
                    break;

                case "HPS":
                    topOverallList.Add(new object[] { stat.Encounter.Date, stat.HPS });
                    break;

                default:
                case "DPS":
                    topOverallList.Add(new object[] { stat.Encounter.Date, stat.DPS });
                    break;
                }
            }
            topSeries.Data = new Data(topOverallList.ToArray());
            seriesList.Add(topSeries);
            #endregion

            #region Top X unique players

            var orderedStats = new List <EncounterPlayerStatistics>();
            var topValue     = 0L;
            switch (xpsType)
            {
            case "APS":
                orderedStats = stats.OrderByDescending(s => s.APS).ToList();
                topValue     = topList.Last().APS;
                break;

            case "HPS":
                orderedStats = stats.OrderByDescending(s => s.HPS).ToList();
                topValue     = topList.Last().HPS;
                break;

            default:
            case "DPS":
                orderedStats = stats.OrderByDescending(s => s.DPS).ToList();
                topValue     = topList.Last().DPS;
                break;
            }
            yAxisPlotLine.Value = topValue;
            yAxisPlotLine.Label = new YAxisPlotLinesLabel()
            {
                Text = string.Format("Top {0}: {1}", xpsType, topValue)
            };

            var topXPlayerIds = new List <int>();
            foreach (var orderedStat in orderedStats.TakeWhile(orderedStat => topXPlayerIds.Count != topX))
            {
                if (!topXPlayerIds.Contains(orderedStat.PlayerId))
                {
                    topXPlayerIds.Add(orderedStat.PlayerId);
                }
            }
            var top3VisiblePlayers = new List <int>();
            foreach (var orderedStat in orderedStats.TakeWhile(orderedStat => top3VisiblePlayers.Count != 3))
            {
                if (!top3VisiblePlayers.Contains(orderedStat.PlayerId))
                {
                    top3VisiblePlayers.Add(orderedStat.PlayerId);
                }
            }
            #endregion

            var topXPlayerStatGroup =
                stats.Where(s => topXPlayerIds.Contains(s.PlayerId))
                .GroupBy(s => new { s.PlayerId, s.Player.Name })
                .OrderBy(s => s.Key.Name);

            foreach (var playerStats in topXPlayerStatGroup)
            {
                var thisSeries = new Series()
                {
                    Name = playerStats.Key.Name.Replace("'", "\\\'")
                };
                thisSeries.PlotOptionsSpline = top3VisiblePlayers.Contains(playerStats.Key.PlayerId)
                    ? new PlotOptionsSpline()
                {
                    Visible = true
                }
                    : new PlotOptionsSpline()
                {
                    Visible = false
                };
                var dataList = new List <object[]>();
                foreach (var playerRecord in playerStats.OrderBy(s => s.Encounter.Date))
                {
                    switch (xpsType)
                    {
                    case "APS":
                        dataList.Add(new object[] { playerRecord.Encounter.Date, playerRecord.APS });
                        break;

                    case "HPS":
                        dataList.Add(new object[] { playerRecord.Encounter.Date, playerRecord.HPS });
                        break;

                    default:
                    case "DPS":
                        dataList.Add(new object[] { playerRecord.Encounter.Date, playerRecord.DPS });
                        break;
                    }
                }

                thisSeries.Data = new Data(dataList.ToArray());
                seriesList.Add(thisSeries);
            }

            var chart =
                new Highcharts(string.Format("bf{0}d{1}{2}{3}", bossFightId, difficultyId, guildId, xpsType))
                .InitChart(new Chart
            {
                DefaultSeriesType = ChartTypes.Spline,
                ZoomType          = ZoomTypes.Xy,
                Height            = 400,
                BackgroundColor   = new BackColorOrGradient(new Gradient
                {
                    LinearGradient = new[] { 0, 0, 0, 400 },
                    Stops          = new object[, ]
                    {
                        { 0, Color.FromArgb(13, 255, 255, 255) },
                        { 1, Color.FromArgb(13, 255, 255, 255) }
                    }
                }),
                Style = ChartColors.WhiteTextStyle
            })
                .SetCredits(ChartDefaults.Credits)
                .SetOptions(new GlobalOptions
            {
                Colors = ChartColors.ColorArrayBlackBg(),
                Global = new Global {
                    UseUTC = false
                }
            })
                .SetTitle(new Title
            {
                Text  = graphTitle,
                Style = ChartColors.WhiteTextStyle
            })
                .SetXAxis(new XAxis
            {
                Type = AxisTypes.Datetime,
                DateTimeLabelFormats = new DateTimeLabel {
                    Month = "%e %b", Year = "%e %b", Day = "%e %b", Week = "%e %b"
                },
                LineColor = Color.White,
                TickColor = Color.White,
                Labels    = new XAxisLabels {
                    Style = ChartColors.WhiteTextStyle
                },
            })
                .SetYAxis(new YAxis
            {
                Title = new YAxisTitle {
                    Text = yAxisText, Style = ChartColors.WhiteTextStyle
                },
                //Min = 0
                TickColor = Color.White,
                LineColor = Color.White,
                Labels    = new YAxisLabels {
                    Style = ChartColors.WhiteTextStyle
                },
                PlotLines = new[]
                {
                    yAxisPlotLine
                }
            })
                .SetSeries(seriesList.ToArray())
                .SetExporting(new Exporting {
                Enabled = false
            })
                .SetLegend(new Legend()
            {
                ItemStyle = ChartColors.WhiteTextStyle, ItemHoverStyle = "color: '#bbb'"
            })
            ;



            return(chart);
        }
Example #8
0
        public Highcharts GuildKillTimers(int bossFightId, int difficultyId)
        {
            const string graphTitle = "Kill times by guild";

            var guildKillTimes = _encounterRepository.GetDateSortedKills(bossFightId, difficultyId);

            #region Build chart series
            // Determine the guild IDs of those we wish to show by default.
            // Default this chart to the 4 guilds with the lowest kill times
            var visibleGuildIds = new List <int>();
            var lowestTimeList  = guildKillTimes.OrderBy(s => s.Duration.TotalSeconds);
            foreach (var guildKill in lowestTimeList.TakeWhile(kill => visibleGuildIds.Count != 4))
            {
                if (!visibleGuildIds.Contains((int)guildKill.GuildId))
                {
                    visibleGuildIds.Add((int)guildKill.GuildId);
                }
            }
            var seriesList = new List <Series>();
            var killGroup  = guildKillTimes.OrderBy(g => g.UploadGuild.Name).GroupBy(e => new { e.GuildId, e.UploadGuild.Name });
            foreach (var guildKillGroup in killGroup)
            {
                var thisSeries = new Series {
                    Name = guildKillGroup.Key.Name.Replace("'", "\\\'")
                };

                thisSeries.PlotOptionsSpline = visibleGuildIds.Contains((int)guildKillGroup.Key.GuildId)
                    ? new PlotOptionsSpline()
                {
                    Visible = true
                }
                    : new PlotOptionsSpline()
                {
                    Visible = false
                };

                thisSeries.Data = new Data(guildKillGroup.Select(guildKill => new object[] { guildKill.Date, guildKill.Duration.TotalSeconds }).ToArray());
                seriesList.Add(thisSeries);
            }

            var seriesArray = seriesList.ToArray();
            #endregion

            var chart =
                new Highcharts(string.Format("bf{0}f{1}gkt", bossFightId, difficultyId))
                .InitChart(new Chart
            {
                DefaultSeriesType = ChartTypes.Spline,
                ZoomType          = ZoomTypes.Xy,
                Height            = 400,
                BackgroundColor   = new BackColorOrGradient(new Gradient
                {
                    LinearGradient = new[] { 0, 0, 0, 400 },
                    Stops          = new object[, ]
                    {
                        { 0, Color.FromArgb(13, 255, 255, 255) },
                        { 1, Color.FromArgb(13, 255, 255, 255) }
                    }
                }),
                Style = ChartColors.WhiteTextStyle
            })
                .SetCredits(ChartDefaults.Credits)
                .SetOptions(new GlobalOptions
            {
                Colors = ChartColors.ColorArray(),
                Global = new Global {
                    UseUTC = false
                }
            })
                .SetTitle(new Title
            {
                Text  = graphTitle,
                Style = ChartColors.WhiteTextStyle
            })
                .SetXAxis(new XAxis
            {
                Type = AxisTypes.Datetime,
                DateTimeLabelFormats = new DateTimeLabel {
                    Month = "%e %b", Year = "%e %b", Day = "%e %b", Week = "%e %b"
                },
                LineColor = Color.White,
                TickColor = Color.White,
                Labels    = new XAxisLabels {
                    Style = ChartColors.WhiteTextStyle
                },
            })
                .SetYAxis(new YAxis
            {
                Title = new YAxisTitle {
                    Text = "Encounter length (seconds)", Style = ChartColors.WhiteTextStyle
                },
                //Min = 0
                TickColor = Color.White,
                LineColor = Color.White,
                Labels    = new YAxisLabels {
                    Style = ChartColors.WhiteTextStyle
                },
            })
                .SetSeries(seriesArray)
                .SetExporting(new Exporting {
                Enabled = false
            })
                .SetLegend(new Legend()
            {
                ItemStyle = ChartColors.WhiteTextStyle, ItemHoverStyle = "color: '#bbb'"
            })
            ;
            return(chart);
        }
Example #9
0
        public Highcharts GuildHybridXpsOverTime(int bossFightId, int difficultyId, int guildId, string guildName, string bossFightName)
        {
            var graphTitle = string.Format("{0} vs {1}: Raid performance over time", guildName.Replace("'", "\\\'"), bossFightName);
            var stats      = _recordsRepository.GetGuildStatsOverTimeHybrid(bossFightId, difficultyId, guildId);

            if (!stats.Any())
            {
                return(null);
            }

            #region Build chart series

            var dpsSeries = new Series()
            {
                Name = "Damage"
            };
            var dpsDataList = new List <object[]>();
            var hpsSeries   = new Series()
            {
                Name = "Healing", PlotOptionsSpline = new PlotOptionsSpline()
                {
                    Visible = false
                }
            };
            var hpsDataList = new List <object[]>();
            var apsSeries   = new Series()
            {
                Name = "Absorption", PlotOptionsSpline = new PlotOptionsSpline()
                {
                    Visible = false
                }
            };
            var apsDataList    = new List <object[]>();
            var durationSeries = new Series()
            {
                Name              = "Encounter duration",
                YAxis             = "1",
                PlotOptionsSpline = new PlotOptionsSpline()
                {
                    Color = Color.FromArgb(255, 124, 181, 236),
                }
            };
            var durationDataList = new List <object[]>();

            foreach (var stat in stats)
            {
                dpsDataList.Add(new object[] { stat.Date, stat.AverageDps });
                hpsDataList.Add(new object[] { stat.Date, stat.AverageHps });
                apsDataList.Add(new object[] { stat.Date, stat.AverageAps });
                durationDataList.Add(new object[] { stat.Date, new DateTime().Add(stat.Duration) });
            }

            dpsSeries.Data      = new Data(dpsDataList.ToArray());
            hpsSeries.Data      = new Data(hpsDataList.ToArray());
            apsSeries.Data      = new Data(apsDataList.ToArray());
            durationSeries.Data = new Data(durationDataList.ToArray());

            var chartSeries = new Series[] { dpsSeries, hpsSeries, apsSeries, durationSeries };
            #endregion

            #region Build Y-Axes

            var yAxes = new List <YAxis>();
            // Standard Y
            yAxes.Add(
                new YAxis
            {
                Title = new YAxisTitle {
                    Text = "Per second", Style = ChartColors.WhiteTextStyle
                },
                TickColor = Color.White,
                LineColor = Color.White,
                Labels    = new YAxisLabels {
                    Style = ChartColors.WhiteTextStyle
                }
            });
            yAxes.Add(
                new YAxis
            {
                Title = new YAxisTitle {
                    Text = "Encounter duration", Style = ChartColors.WhiteTextStyle
                },
                Type = AxisTypes.Datetime,
                DateTimeLabelFormats = new DateTimeLabel {
                    Hour = "%Mm %Ss", Minute = "%Mm %Ss", Second = "%Mm %Ss"
                },
                TickColor = Color.White,
                LineColor = Color.White,
                Labels    = new YAxisLabels {
                    Style = ChartColors.WhiteTextStyle
                },
                Opposite = true,
            });
            #endregion

            var chart = new Highcharts(string.Format("bf{0}d{1}g{2}hybrid", bossFightId, difficultyId, guildId))
                        .InitChart(new Chart
            {
                DefaultSeriesType = ChartTypes.Spline,
                ZoomType          = ZoomTypes.Xy,
                Height            = 400,
                BackgroundColor   = new BackColorOrGradient(new Gradient
                {
                    LinearGradient = new[] { 0, 0, 0, 400 },
                    Stops          = new object[, ]
                    {
                        { 0, Color.FromArgb(13, 255, 255, 255) },
                        { 1, Color.FromArgb(13, 255, 255, 255) }
                    }
                }),
                Style = ChartColors.WhiteTextStyle
            })
                        .SetCredits(ChartDefaults.Credits)
                        .SetOptions(new GlobalOptions
            {
                Colors = ChartColors.ColorArrayBlackBg(),
                Global = new Global {
                    UseUTC = false
                }
            })
                        .SetTitle(new Title
            {
                Text  = graphTitle,
                Style = ChartColors.WhiteTextStyle
            })
                        .SetXAxis(new XAxis
            {
                Type = AxisTypes.Datetime,
                DateTimeLabelFormats = new DateTimeLabel {
                    Month = "%e %b", Year = "%e %b", Day = "%e %b", Week = "%e %b"
                },
                LineColor = Color.White,
                TickColor = Color.White,
                Labels    = new XAxisLabels {
                    Style = ChartColors.WhiteTextStyle
                },
            })
                        //.SetYAxis(new YAxis
                        //{
                        //    Title = new YAxisTitle { Text = "Per second", Style = ChartColors.WhiteTextStyle },
                        //    TickColor = Color.White,
                        //    LineColor = Color.White,
                        //    Labels = new YAxisLabels { Style = ChartColors.WhiteTextStyle }
                        //})
                        .SetYAxis(yAxes.ToArray())

                        // Combined tooltip
                        // There's an if/else if/else statement in there to format the tooltips differently depending on the series name
                        // The DPS chart has a tooltip that will convert the value to thousands / millions / billions etc.
                        // Eg 1500000DPS will be 1.50M DPS

                        .SetTooltip(new Tooltip()
            {
                Formatter =
                    @"function() {
                var text = '';
                if(this.series.name == 'Encounter duration') 
                {
                    text = '<b>' + this.series.name +'</b><br/>' + Highcharts.dateFormat('%Mm %Ss',new Date(this.y));
                } else if (this.series.name == 'Healing')  {
                    text = '<b>' + this.y + '</b> HPS';
                } else if (this.series.name == 'Absorption') {
                    text = '<b>' + this.y + '</b> APS';
                } else {
                    var ret = '',
                    multi,
                    axis = this.series.yAxis,
                    numericSymbols = ['k', 'M', 'B', 'T', 'P', 'E'],
                    i = numericSymbols.length;
                    while (i-- && ret === '') {
                        multi = Math.pow(1000, i);
                        if (axis.tickInterval >= multi && numericSymbols[i] !== null) {
                            ret = '<b>' + Highcharts.numberFormat(this.y / multi / 1000, 2) + numericSymbols[i] + '</b> DPS';
                        }
                }
                return ret;
                }
                return text;
            }"
            })
                        // Tooltip for XPS
                        //.SetTooltip(new Tooltip() { ValueSuffix = " per second" })

                        // Tooltip for Duration
                        //.SetTooltip(new Tooltip { Formatter = @"function() { return  '<b>' + this.series.name +'</b><br/>' +
                        //       Highcharts.dateFormat('%Mm %Ss',new Date(this.y)); }" })

                        .SetSeries(chartSeries)
                        .SetExporting(new Exporting {
                Enabled = false
            })
                        .SetLegend(new Legend()
            {
                ItemStyle = ChartColors.WhiteTextStyle, ItemHoverStyle = "color: '#bbb'"
            })
            ;

            return(chart);
        }
        private Task <Chart> GenerateChartTask(List <string> paramsList)
        {
            var generateChartTask = Task.Run(function: () =>
            {
                if (!_resultContext.SimulationJobs.Any())
                {
                    return(null);
                }

                SimulationType simType = (paramsList[index: 1].Equals(value: "Decentral"))
                    ? SimulationType.Decentral
                    : SimulationType.Central;

                Chart chart = new Chart
                {
                    Type = Enums.ChartType.Bar
                };

                // charttype

                // use available hight in Chart
                // use available hight in Chart
                var machines = _resultContext.Kpis.Where(predicate: x => x.SimulationConfigurationId == Convert.ToInt32(paramsList[0]) &&
                                                         x.SimulationType == simType &&
                                                         x.KpiType == KpiType.ResourceUtilization &&
                                                         x.IsKpi &&
                                                         x.IsFinal && x.SimulationNumber == Convert.ToInt32(paramsList[2]))
                               .OrderByDescending(keySelector: g => g.Name)
                               .ToList();
                var data = new Data {
                    Labels = machines.Select(selector: n => n.Name).ToList()
                };

                // create Dataset for each Lable
                data.Datasets = new List <Dataset>();

                var i  = 0;
                var cc = new ChartColors();

                //var max = _context.SimulationWorkschedules.Max(x => x.End) - 1440;
                var barDataSet = new BarDataset {
                    Data = new List <double?>(), BackgroundColor = new List <ChartColor>(), HoverBackgroundColor = new List <ChartColor>(), YAxisID = "y-normal"
                };
                var barDiversityInvisSet = new BarDataset {
                    Data = new List <double?>(), BackgroundColor = new List <ChartColor>(), HoverBackgroundColor = new List <ChartColor>(), YAxisID = "y-diversity"
                };
                var barDiversitySet = new BarDataset {
                    Data = new List <double?>(), BackgroundColor = new List <ChartColor>(), HoverBackgroundColor = new List <ChartColor>(), YAxisID = "y-diversity"
                };
                foreach (var machine in machines)
                {
                    var percent = Math.Round(value: machine.Value * 100, digits: 2);
                    // var wait = max - work;
                    barDataSet.Data.Add(item: percent);
                    barDataSet.BackgroundColor.Add(item: cc.Get(i, 0.4));
                    barDataSet.HoverBackgroundColor.Add(item: cc.Get(i, 0.7));

                    var varianz = machine.Count * 100;

                    barDiversityInvisSet.Data.Add(item: percent - Math.Round(value: varianz / 2, digits: 2));
                    barDiversityInvisSet.BackgroundColor.Add(item: ChartColors.Transparent);
                    barDiversityInvisSet.HoverBackgroundColor.Add(item: ChartColors.Transparent);

                    barDiversitySet.Data.Add(item: Math.Round(value: varianz, digits: 2));
                    barDiversitySet.BackgroundColor.Add(item: cc.Get(i, 0.8));
                    barDiversitySet.HoverBackgroundColor.Add(item: cc.Get(i, 1));
                    i++;
                }

                data.Datasets.Add(item: barDataSet);
                data.Datasets.Add(item: barDiversityInvisSet);
                data.Datasets.Add(item: barDiversitySet);

                chart.Data = data;

                // Specifie xy Axis
                var xAxis = new List <Scale>()
                {
                    new CartesianScale {
                        Stacked = true, Id = "x-normal", Display = true
                    }
                };
                var yAxis = new List <Scale>()
                {
                    new CartesianScale {
                        Stacked = true, Display = true, Ticks = new CartesianLinearTick {
                            BeginAtZero = true, Min = 0, Max = 100
                        }, Id = "y-normal"
                    },
                    new CartesianScale {
                        Stacked = true, Ticks = new CartesianLinearTick {
                            BeginAtZero = true, Min = 0, Max = 100
                        }, Display = false,
                        Id = "y-diversity", ScaleLabel = new ScaleLabel {
                            LabelString = "Value in %", Display = false, FontSize = 12
                        },
                    },
                };
                //var yAxis = new List<Scale>() { new BarScale{ Ticks = new CategoryTick { Min = "0", Max  = (yMaxScale * 1.1).ToString() } } };
                chart.Options = new Options()
                {
                    Scales = new Scales {
                        XAxes = xAxis, YAxes = yAxis
                    },
                    MaintainAspectRatio = false,
                    Responsive          = true,
                    Title = new Title {
                        Text = "Machine Workloads", Position = "top", FontSize = 24, FontStyle = "bold", Display = true
                    },
                    Legend = new Legend {
                        Position = "bottom", Display = false
                    }
                };

                return(chart);
            });

            return(generateChartTask);
        }
        private Task <Chart> GenerateChartTaskOverTime(List <string> paramsList)
        {
            var generateChartTask = Task.Run(function: () =>
            {
                if (!_resultContext.SimulationJobs.Any())
                {
                    return(null);
                }

                SimulationType simType = (paramsList[index: 1].Equals(value: "Decentral"))
                    ? SimulationType.Decentral
                    : SimulationType.Central;

                Chart chart = new Chart {
                    Type = Enums.ChartType.Scatter
                };

                // charttype
                var cc = new ChartColors();
                // use available hight in Chart
                // use available hight in Chart
                var machinesKpi = _resultContext.Kpis.Where(predicate: x => x.SimulationConfigurationId == Convert.ToInt32(paramsList[0]) &&
                                                            x.SimulationType == simType &&
                                                            x.KpiType == KpiType.ResourceUtilization &&
                                                            !x.IsKpi &&
                                                            !x.IsFinal && x.SimulationNumber == Convert.ToInt32(paramsList[2]))
                                  .ToList();
                var settlingTime = _resultContext.SimulationConfigurations.First(predicate: x => x.Id == Convert.ToInt32(paramsList[0])).SettlingStart;
                var machines     = machinesKpi.Select(selector: n => n.Name).Distinct().ToList();
                var data         = new Data {
                    Labels = machines
                };

                // create Dataset for each Lable
                data.Datasets = new List <Dataset>();

                var i = 0;
                foreach (var machine in machines)
                {
                    // add zero to start
                    var kpis = new List <LineScatterData> {
                        new LineScatterData {
                            X = "0", Y = "0"
                        }
                    };
                    kpis.AddRange(collection: machinesKpi.Where(predicate: x => x.Name == machine).OrderBy(keySelector: x => x.Time)
                                  .Select(selector: x => new LineScatterData {
                        X = x.Time.ToString(), Y = (x.Value * 100).ToString()
                    }).ToList());

                    var lds = new LineScatterDataset()
                    {
                        Data            = kpis,
                        BorderWidth     = 2,
                        Label           = machine,
                        ShowLine        = true,
                        Fill            = "false",
                        BackgroundColor = cc.Get(i),
                        BorderColor     = cc.Get(i++),
                        LineTension     = 0
                    };
                    data.Datasets.Add(item: lds);
                }


                data.Datasets.Add(item: new LineScatterDataset()
                {
                    Data = new List <LineScatterData> {
                        new LineScatterData {
                            X = "0", Y = "100"
                        }, new LineScatterData {
                            X = Convert.ToDouble(value: settlingTime).ToString(), Y = "100"
                        }
                    },
                    BorderWidth     = 1,
                    Label           = "Settling time",
                    BackgroundColor = ChartJSCore.Helpers.ChartColor.FromRgba(0, 0, 0, 0.1),
                    BorderColor     = ChartJSCore.Helpers.ChartColor.FromRgba(0, 0, 0, 0.3),
                    ShowLine        = true,
                    //Fill = true,
                    //SteppedLine = false,
                    LineTension = 0,
                    PointRadius = new List <int> {
                        0, 0
                    }
                });

                chart.Data = data;

                // Specifie xy Axis
                var xAxis = new List <Scale>()
                {
                    new CartesianScale {
                        Stacked = false, Display = true
                    }
                };
                var yAxis = new List <Scale>()
                {
                    new CartesianScale()
                    {
                        Stacked = false, Ticks = new CartesianLinearTick {
                            BeginAtZero = true, Min = 0, Max = 100
                        }, Display = true,
                        Id = "first-y-axis", Type = "linear", ScaleLabel = new ScaleLabel {
                            LabelString = "Value in %", Display = true, FontSize = 12
                        },
                    }
                };
                //var yAxis = new List<Scale>() { new BarScale{ Ticks = new CategoryTick { Min = "0", Max  = (yMaxScale * 1.1).ToString() } } };
                chart.Options = new Options()
                {
                    Scales = new Scales {
                        XAxes = xAxis, YAxes = yAxis
                    },
                    Responsive          = true,
                    MaintainAspectRatio = true,
                    Legend = new Legend {
                        Position = "bottom", Display = true, FullWidth = true
                    },
                    Title = new Title {
                        Text = "Machine Workload over Time", Position = "top", FontSize = 24, FontStyle = "bold", Display = true
                    }
                };

                return(chart);
            });

            return(generateChartTask);
        }
        public async Task <IViewComponentResult> InvokeAsync(List <string> paramsList)
        {
            // Determine Type and Data
            SimulationType simType = (paramsList[index : 1].Equals(value : "Decentral")) ? SimulationType.Decentral : SimulationType.Central;
            var            kpi     = _context.Kpis.Where(predicate: x => x.KpiType == KpiType.Timeliness &&
                                                         x.SimulationConfigurationId == Convert.ToInt32(paramsList[0]) &&
                                                         x.SimulationNumber == Convert.ToInt32(paramsList[2]) &&
                                                         x.SimulationType == simType);
            var generateChartTask = Task.Run(function: () =>
            {
                if (!_context.SimulationJobs.Any())
                {
                    return(null);
                }

                Chart chart = new Chart();

                // charttype
                chart.Type = Enums.ChartType.Doughnut;

                // use available hight in Chart
                chart.Options = new PieOptions {
                    MaintainAspectRatio = false, Responsive = true
                    , CutoutPercentage  = 80
                    , Rotation          = 0.8 * Math.PI
                    , Circumference     = 1.4 * Math.PI
                    , Legend            = new Legend {
                        Position = "bottom", Display = false
                    }
                    , Title = new Title {
                        Text = "Timeliness", Position = "top", FontSize = 24, FontStyle = "bold"
                    }
                };

                var cc   = new ChartColors();
                var data = new Data
                {
                    Datasets = new List <Dataset>
                    {
                        new PieDataset
                        {
                            BackgroundColor = new[] { cc.Get(4, 0.3), cc.Get(4, 0.3) },
                            BorderColor     = new[] { cc.Get(4, 0.8), cc.Get(4, 0.8) },
                            BorderWidth     = 1,
                        }
                    },
                    Labels = new[] { "Early", "Overdue" },
                };

                var avg = kpi.Sum(selector: x => x.Value) / kpi.Count() * 100;

                //var end = ((int)Math.Ceiling(max / 100.0)) * 100;


                //data.Datasets[0].Data = new List<double> { 0, (int)(min/end*100), (int)(avg /end*100), (int)(max /end*100), end };
                data.Datasets[index: 0].Data = new List <double?> {
                    avg, 100 - avg
                };
                chart.Data = data;
                return(chart);
            });

            // create JS to Render Chart.
            ViewData[index : "chart"]      = await generateChartTask;
            ViewData[index : "Type"]       = paramsList[index : 1];
            ViewData[index : "Percentage"] = Math.Round(value : kpi.Sum(selector : x => x.Value) / kpi.Count() * 100, digits : 0);
            ViewData[index : "Data"]       = kpi.ToList();
            return(View(viewName: $"OrderTimeliness"));
        }
        private Task <Chart> GenerateChartTask(List <string> paramsList)
        {
            var generateChartTask = Task.Run(function: () =>
            {
                if (!_context.SimulationOperations.Any())
                {
                    return(null);
                }

                Chart chart = new Chart
                {
                    Type    = Enums.ChartType.Bar,
                    Options = new Options {
                        MaintainAspectRatio = true
                    }
                };

                var machines = new List <Kpi>();
                // charttype
                foreach (var sim in _simList)
                {
                    var trick17 = _context.Kpis.Where(predicate: x => x.SimulationConfigurationId == sim.Item1 &&
                                                      x.KpiType == KpiType.MachineUtilization &&
                                                      x.IsKpi && x.SimulationType == sim.Item2 &&
                                                      x.SimulationNumber == 1 &&
                                                      x.IsFinal).OrderByDescending(keySelector: g => g.Name);
                    machines.AddRange(collection: trick17.ToList());
                }



                var data = new Data {
                    Labels = machines.Select(selector: n => n.Name).Distinct().ToList()
                };

                // create Dataset for each Lable
                data.Datasets = new List <Dataset>();

                var i  = 0;
                var cc = new ChartColors();

                //var max = _context.SimulationWorkschedules.Max(x => x.End) - 1440;
                foreach (var t1 in _simList.OrderBy(keySelector: x => x.Item1))
                {
                    var barDataSet = new BarDataset {
                        Data = new List <double>(), BackgroundColor = new List <ChartColor>(), HoverBackgroundColor = new List <ChartColor>(), YAxisID = "y-normal"
                    };
                    var barDiversityInvisSet = new BarDataset {
                        Data = new List <double>(), BackgroundColor = new List <ChartColor>(), HoverBackgroundColor = new List <ChartColor>(), YAxisID = "y-diversity"
                    };
                    var barDiversitySet = new BarDataset {
                        Data = new List <double>(), BackgroundColor = new List <ChartColor>(), HoverBackgroundColor = new List <ChartColor>(), YAxisID = "y-diversity"
                    };
                    barDataSet.Label = "Sim Id:" + t1.Item1 + " " + t1.Item2;
                    foreach (var machineName in data.Labels)
                    {
                        Kpi machine = null;
                        var t       = machines.Where(predicate: x => x.Name == machineName && x.SimulationConfigurationId == t1.Item1 && x.SimulationType == t1.Item2).Distinct();
                        machine     = t.Single();

                        var percent = Math.Round(value: machine.Value * 100, digits: 2);
                        // var wait = max - work;
                        barDataSet.Data.Add(item: percent);
                        barDiversitySet.BackgroundColor.Add(item: cc.Get(i, 0.4));
                        barDiversitySet.HoverBackgroundColor.Add(item: cc.Get(i, 0.7));

                        //var varianz = machine.Count * 100;

                        //barDiversityInvisSet.Data.Add(percent - Math.Round(varianz / 2, 2));
                        //barDiversityInvisSet.BackgroundColor.Add(ChartColor.Transparent);
                        //barDiversityInvisSet.HoverBackgroundColor.Add(ChartColor.Transparent);
                        //
                        //barDiversitySet.Data.Add(Math.Round(varianz, 2));
                        //barDiversitySet.BackgroundColor.Add(cc.Color[i].Substring(0, cc.Color[1].Length - 4) + (t + 0.3) + ")");
                        //barDiversitySet.HoverBackgroundColor.Add(cc.Color[i].Substring(0, cc.Color[1].Length - 4) + "1)");
                    }
                    i++;
                    i++;
                    data.Datasets.Add(item: barDataSet);
                    //data.Datasets.Add(barDiversityInvisSet);
                    //data.Datasets.Add(barDiversitySet);
                }

                chart.Data = data;

                // Specifie xy Axis
                var xAxis = new List <Scale>()
                {
                    new CartesianScale {
                        Stacked = false, Id = "x-normal", Display = true
                    }
                };
                var yAxis = new List <Scale>()
                {
                    new CartesianScale {
                        Stacked = false, Display = true, Ticks = new CartesianLinearTick {
                            BeginAtZero = true, Min = 0, Max = 100
                        }, Id = "y-normal"
                    },
                    new CartesianScale {
                        Stacked = false, Ticks = new CartesianLinearTick {
                            BeginAtZero = true, Min = 0, Max = 100
                        }, Display = false,
                        Id = "y-diversity", ScaleLabel = new ScaleLabel {
                            LabelString = "Value in %", Display = false, FontSize = 12
                        },
                    },
                };
                //var yAxis = new List<Scale>() { new BarScale{ Ticks = new CategoryTick { Min = "0", Max  = (yMaxScale * 1.1).ToString() } } };
                chart.Options = new Options()
                {
                    Scales = new Scales {
                        XAxes = xAxis, YAxes = yAxis
                    },
                    MaintainAspectRatio = false,
                    Responsive          = true,
                    Legend = new Legend {
                        Display = false
                    }
                };

                return(chart);
            });

            return(generateChartTask);
        }
        public async Task <IViewComponentResult> InvokeAsync(List <string> paramsList)
        {
            // Determine Type and Data
            // Determine Type and Data
            _simList.Add(item: new Tuple <int, SimulationType>(item1: Convert.ToInt32(value: paramsList[index: 0]), item2: (paramsList[index: 1] == "Central") ? SimulationType.Central : SimulationType.Decentral));
            if (paramsList.Count() == 8)
            {
                _simList.Add(item: new Tuple <int, SimulationType>(item1: Convert.ToInt32(value: paramsList[index: 6]), item2: (paramsList[index: 7] == "Central") ? SimulationType.Central : SimulationType.Decentral));
            }
            if (paramsList.Count() >= 6)
            {
                _simList.Add(item: new Tuple <int, SimulationType>(item1: Convert.ToInt32(value: paramsList[index: 4]), item2: (paramsList[index: 5] == "Central") ? SimulationType.Central : SimulationType.Decentral));
            }
            if (paramsList.Count() >= 4)
            {
                _simList.Add(item: new Tuple <int, SimulationType>(item1: Convert.ToInt32(value: paramsList[index: 2]), item2: (paramsList[index: 3] == "Central") ? SimulationType.Central : SimulationType.Decentral));
            }
            _simList = _simList.OrderBy(keySelector: x => x.Item2).ThenBy(keySelector: x => x.Item1).ToList();
            var displayData = new List <Kpi>();
            var kpi         = new List <Kpi>();

            // charttype
            foreach (var sim in _simList)
            {
                var trick17 = _context.Kpis.Where(predicate: x => x.KpiType == KpiType.LeadTime &&
                                                  x.SimulationConfigurationId == sim.Item1 &&
                                                  x.SimulationNumber == 1);
                //&& x.SimulationType == sim.Item2);
                kpi.AddRange(collection: trick17.ToList());
            }
            var maxValue = kpi.Max(selector: x => x.Value);


            var generateChartTask = Task.Run(function: () =>
            {
                if (!kpi.Any())
                {
                    return(null);
                }

                var chart    = new List <BoxPlot>();
                var products = kpi.Select(selector: x => x.Name).Distinct().ToList();
                var colors   = new ChartColors();
                int i        = 0;

                foreach (var sim in _simList)
                {
                    displayData.AddRange(collection: kpi.Where(predicate: x => x.IsKpi &&
                                                               x.SimulationConfigurationId == sim.Item1 &&
                                                               x.SimulationType == sim.Item2).OrderBy(keySelector: x => x.Value).ToList());


                    foreach (var product in products)
                    {
                        var boxplotValues = kpi.Where(predicate: x => x.IsKpi == false && x.Name == product &&
                                                      x.KpiType == KpiType.LeadTime &&
                                                      x.SimulationConfigurationId == sim.Item1 &&
                                                      x.SimulationNumber == 1 &&
                                                      x.IsFinal &&
                                                      x.SimulationType == sim.Item2).OrderBy(keySelector: x => x.Value).ToList();
                        if (boxplotValues.Count == 0)
                        {
                            continue;
                        }
                        chart.Add(item: new BoxPlot
                        {
                            HeigestSample = (decimal)boxplotValues.ElementAt(index: 4).Value,
                            UpperQartile  = (decimal)boxplotValues.ElementAt(index: 3).Value,
                            Median        = (decimal)boxplotValues.ElementAt(index: 2).Value,
                            LowerQuartile = (decimal)boxplotValues.ElementAt(index: 1).Value,
                            LowestSample  = (decimal)boxplotValues.ElementAt(index: 0).Value,
                            Name          = product + "<br> SimId:" + sim.Item1 + " " + sim.Item2,
                            Color         = colors.Get(i).ToString()
                        });
                        if (_simList.Count() == 1)
                        {
                            i++;
                        }
                    }
                    i = i + 2;
                }

                //new BoxPlot{ HeigestSample=337, UpperQartile=195, Median=163, LowerQuartile= 136, LowestSample = 73, Name="Race-Truck", Color = "rgba(0,102,255," }
                return(chart);
            });

            // create JS to Render Chart.
            var boxPlot = await generateChartTask;

            ViewData[index : "BoxPlot"] = boxPlot;
            ViewData[index : "Type"]    = paramsList[index : 1];
            ViewData[index : "Data"]    = displayData.Distinct().ToList();
            ViewData[index : "Max"]     = Math.Ceiling(a : maxValue / 100) * 100;
            //ViewData["Max"] = Math.Ceiling((double)boxPlot.Max(x => x.HeigestSample)/100)*100;
            return(View(viewName: $"ProductLeadTimeBoxPlot"));
        }
Example #15
0
        /// <summary>
        /// 1st = Param[0] = SimulationId
        /// 2st = Param[1] = SimulationType
        /// 3nd = Param[2] = SimulationNumber
        /// </summary>
        /// <param name="paramsList"></param>
        /// <returns></returns>
        public async Task <IViewComponentResult> InvokeAsync(List <string> paramsList)
        {
            // Determine Type and Data
            _simList.Add(item: new Tuple <int, SimulationType>(item1: Convert.ToInt32(value: paramsList[index: 0]), item2: (paramsList[index: 1] == "Central") ? SimulationType.Central : SimulationType.Decentral));
            if (paramsList.Count() == 8)
            {
                _simList.Add(item: new Tuple <int, SimulationType>(item1: Convert.ToInt32(value: paramsList[index: 6]), item2: (paramsList[index: 7] == "Central") ? SimulationType.Central : SimulationType.Decentral));
            }
            if (paramsList.Count() >= 6)
            {
                _simList.Add(item: new Tuple <int, SimulationType>(item1: Convert.ToInt32(value: paramsList[index: 4]), item2: (paramsList[index: 5] == "Central") ? SimulationType.Central : SimulationType.Decentral));
            }
            if (paramsList.Count() >= 4)
            {
                _simList.Add(item: new Tuple <int, SimulationType>(item1: Convert.ToInt32(value: paramsList[index: 2]), item2: (paramsList[index: 3] == "Central") ? SimulationType.Central : SimulationType.Decentral));
            }

            var kpi = new List <Kpi>();

            // charttype
            foreach (var sim in _simList)
            {
                var trick17 = _context.Kpis.Where(predicate: x => x.KpiType == KpiType.LeadTime &&
                                                  x.SimulationConfigurationId == sim.Item1 &&
                                                  x.SimulationNumber == 1 &&
                                                  x.SimulationType == sim.Item2);
                kpi.AddRange(collection: trick17.ToList());
            }

            var max = kpi.Max(selector: m => m.Value);

            var generateChartTask = Task.Run(function: () =>
            {
                if (!_context.SimulationOperations.Any())
                {
                    return(null);
                }


                Chart chart = new Chart();

                // charttype
                chart.Type = Enums.ChartType.Bar;

                // use available hight in Chart
                chart.Options = new Options()
                {
                    MaintainAspectRatio = false,
                    Responsive          = true,
                    Legend = new Legend {
                        Position = "bottom", Display = false
                    },
                    Title = new Title {
                        Text = "BoxPlot LeadTimes", Position = "top", FontSize = 24, FontStyle = "bold", Display = true
                    },
                    Scales = new Scales {
                        YAxes = new List <Scale> {
                            new CartesianScale {
                                Stacked = true, Display = true, Ticks = new CartesianLinearTick {
                                    Max = ((int)Math.Ceiling(a: max / 100.0)) * 100
                                }
                            }
                        },
                        XAxes = new List <Scale> {
                            new CartesianScale {
                                Stacked = true, Display = true
                            }
                        },
                    },
                    Tooltips = new ToolTip {
                        Mode = "x", Callbacks = new Callback {
                            Label = BoxplotCallback()
                        }
                    }
                };

                var labels = kpi.Select(selector: n => n.Name).Distinct().ToList();

                var data = new Data
                {
                    Datasets = new List <Dataset>(),
                    Labels   = labels,
                };
                var dsClear = new BarDataset {
                    Data = new List <double>(), Label = "dsClear", BackgroundColor = new List <ChartColor>(), BorderWidth = new List <int>(), BorderColor = new List <ChartColor>()
                };
                var lowerStroke = new BarDataset {
                    Data = new List <double>(), Label = "lowerStroke", BackgroundColor = new List <ChartColor>(), BorderWidth = new List <int>(), BorderColor = new List <ChartColor>()
                };
                var firstQuartile = new BarDataset {
                    Data = new List <double>(), Label = "fQ", BackgroundColor = new List <ChartColor>(), BorderWidth = new List <int>(), BorderColor = new List <ChartColor>()
                };
                var secondQuartile = new BarDataset {
                    Data = new List <double>(), Label = "Med", BackgroundColor = new List <ChartColor>(), BorderWidth = new List <int>(), BorderColor = new List <ChartColor>()
                };
                var thirdQuartile = new BarDataset {
                    Data = new List <double>(), Label = "uQ", BackgroundColor = new List <ChartColor>(), BorderWidth = new List <int>(), BorderColor = new List <ChartColor>()
                };
                var fourthQuartile = new BarDataset {
                    Data = new List <double>(), Label = "line", BackgroundColor = new List <ChartColor>(), BorderWidth = new List <int>(), BorderColor = new List <ChartColor>()
                };
                var upperStroke = new BarDataset {
                    Data = new List <double>(), Label = "upperStroke", BackgroundColor = new List <ChartColor>(), BorderWidth = new List <int>(), BorderColor = new List <ChartColor>()
                };


                var products = kpi.Select(selector: x => x.Name).Distinct().ToList();
                var colors   = new ChartColors();
                int i        = 0;

                foreach (var sim in _simList)
                {
                    foreach (var product in products)
                    {
                        var boxplotValues = kpi.Where(predicate: x => x.IsKpi == false && x.Name == product &&
                                                      x.SimulationConfigurationId == sim.Item1 &&
                                                      x.SimulationType == sim.Item2).OrderBy(keySelector: x => x.Value)
                                            .ToList();

                        dsClear.Data.Add(item: (double)boxplotValues.ElementAt(index: 0).Value);
                        dsClear.BackgroundColor.Add(item: ChartColors.Transparent);
                        dsClear.BorderColor.Add(item: ChartColors.Transparent);
                        dsClear.BorderWidth.Add(item: 0);

                        lowerStroke.Data.Add(item: 5);
                        lowerStroke.BackgroundColor.Add(item: ChartColors.Transparent);
                        lowerStroke.BorderColor.Add(item: ChartColor.FromRgba(50, 50, 50, 1));
                        lowerStroke.BorderWidth.Add(item: 2);

                        var fq = (double)(boxplotValues.ElementAt(index: 1).Value - boxplotValues.ElementAt(index: 0).Value - 5);
                        firstQuartile.Data.Add(item: fq);
                        firstQuartile.BackgroundColor.Add(item: ChartColor.FromRgba(50, 50, 50, 1));// .Add(colors.Color[i].Substring(0, colors.Color[i].Length - 4) + "0.8)");
                        firstQuartile.BorderColor.Add(item: ChartColor.FromRgba(50, 50, 50, 1));
                        firstQuartile.BorderWidth.Add(item: 0);

                        var m = (double)(boxplotValues.ElementAt(index: 2).Value - boxplotValues.ElementAt(index: 1).Value);
                        secondQuartile.Data.Add(item: m);
                        secondQuartile.BackgroundColor.Add(item: colors.Get(i, 0.8));
                        secondQuartile.BorderColor.Add(item: ChartColor.FromRgba(50, 50, 50, 1));
                        secondQuartile.BorderWidth.Add(item: 1);

                        var up = (double)(boxplotValues.ElementAt(index: 3).Value - boxplotValues.ElementAt(index: 2).Value);
                        thirdQuartile.Data.Add(item: up);
                        thirdQuartile.BackgroundColor.Add(item: colors.Get(i, 0.8));
                        thirdQuartile.BorderColor.Add(item: ChartColor.FromRgba(50, 50, 50, 1));
                        thirdQuartile.BorderWidth.Add(item: 1);

                        var hs = (double)(boxplotValues.ElementAt(index: 4).Value - boxplotValues.ElementAt(index: 3).Value - 5);
                        fourthQuartile.Data.Add(item: hs);
                        fourthQuartile.BackgroundColor.Add(item: ChartColor.FromRgba(50, 50, 50, 1)); //.Add(colors.Color[i].Substring(0, colors.Color[i].Length - 4) +  "0.8)");
                        fourthQuartile.BorderColor.Add(item: ChartColor.FromRgba(50, 50, 50, 1));
                        fourthQuartile.BorderWidth.Add(item: 0);

                        upperStroke.Data.Add(item: 5);
                        upperStroke.BackgroundColor.Add(item: ChartColors.Transparent);
                        upperStroke.BorderColor.Add(item: ChartColor.FromRgba(50, 50, 50, 1));
                        upperStroke.BorderWidth.Add(item: 2);
                        i = i + 2;
                    }
                }


                data.Datasets.Add(item: dsClear);
                data.Datasets.Add(item: lowerStroke);
                data.Datasets.Add(item: firstQuartile);
                data.Datasets.Add(item: secondQuartile);
                data.Datasets.Add(item: thirdQuartile);
                data.Datasets.Add(item: fourthQuartile);
                data.Datasets.Add(item: upperStroke);

                var avg = kpi.Sum(selector: x => x.Value) / kpi.Count();
                var min = kpi.Min(selector: x => x.Value);
                var end = ((int)Math.Ceiling(a: max / 100.0)) * 100;


                //data.Datasets[0].Data = new List<double> { 0, (int)(min/end*100), (int)(avg /end*100), (int)(max /end*100), end };
                //data.Datasets[0].Data = new List<double> { min, avg, 10, max, end-max };

                chart.Data = data;
                return(chart);
            });

            // create JS to Render Chart.
            ViewData[index : "chart"]      = await generateChartTask;
            ViewData[index : "Type"]       = paramsList[index : 1];
            ViewData[index : "Data"]       = kpi.Where(predicate : w => w.IsFinal && w.IsKpi).ToList();
            ViewData[index : "percentage"] = Math.Round(value : kpi.Sum(selector : x => x.Value) / kpi.Count(), digits : 0);
            return(View(viewName: $"ProductLeadTime"));
        }