public async Task <List <LineChartViewModel> > GetLineChartCountAsync(int categoryId)
        {
            List <LineChartViewModel> lineCharts = new List <LineChartViewModel>();
            var query = from g in context.Garbages
                        join sub in context.GCSubCategories on g.SubId equals sub.SubId
                        join cate in context.GCCategories on sub.CategoryId equals cate.CategoryId
                        where cate.CategoryId == categoryId
                        group new { g.GCSubCategories.GCCategories, g } by new {
                g.GCSubCategories.GCCategories.CategoryId,
                g.CreatedTime
            } into g
                select new LineChartViewModel {
                Qty         = g.Sum(p => p.g.RecyclingQty),
                CreatedTime = g.Key.CreatedTime.ToShortDateString()
            };

            if (query.Any())
            {
                foreach (var item in query)
                {
                    var lineChart = new LineChartViewModel();
                    lineChart.Qty         = item.Qty;
                    lineChart.CreatedTime = item.CreatedTime;
                    lineCharts.Add(lineChart);
                }
            }
            return(lineCharts);
        }
예제 #2
0
        public LineChartView()
        {
            InitializeComponent();

            _viewModel  = new LineChartViewModel();
            DataContext = _viewModel;
        }
        public JsonResult Query([FromBody] QueryModel input)
        {
            LineChartViewModel result = new LineChartViewModel();

            result = agent.get(input.location, input.sttime, input.edtime);
            return(Json(result));
        }
예제 #4
0
        public ActionResult GalleriesLineChart()
        {
            int scale = 50;
            List <LineChartViewModel> stat      = new List <LineChartViewModel>();
            List <Gallery>            galleires = caller.ListOfAllGalleries().OrderByDescending(o => o.maxCapacity).ToList();

            if (scale < galleires.First().maxCapacity)
            {
                int sections = (int)galleires.First().maxCapacity / scale;
                int oldScale = 0;
                int tmpScale = scale;
                for (int i = 0; i < sections + 1; i++)
                {
                    //  if (galleires.Count(g => oldScale <= g.maxCapacity && g.maxCapacity < tmpScale)!=0)
                    // {
                    LineChartViewModel tmp = new LineChartViewModel();
                    tmp.x = tmpScale;
                    tmp.y = galleires.Count(g => oldScale <= g.maxCapacity && g.maxCapacity < tmpScale);
                    stat.Add(tmp);
                    // }//

                    oldScale = tmpScale;
                    tmpScale = tmpScale + scale;
                }
            }
            return(View(stat));
        }
예제 #5
0
        public JsonResult ServerLineChartsData()
        {
            string[] _months = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };

            List <ChartSerieViewModel> series = new List <ChartSerieViewModel>();

            for (int i = 0; i < 5; i++)
            {
                decimal   d      = 2 + i;
                decimal[] _datas = { d, 6.90m, 9.50m, 14.50m, 18.20m, 4.56m, d, 26.50m, 23.30m, 18.30m, 13.90m, d };

                ChartSerieViewModel lineChartSerieViewModel = new ChartSerieViewModel();
                lineChartSerieViewModel.SeriesName  = "Tokyo : " + i;
                lineChartSerieViewModel.SeriesDatas = _datas;

                series.Add(lineChartSerieViewModel);
            }

            var model = new LineChartViewModel();

            model.TitleText          = "Monthly Average Temperature";
            model.SubTitleText       = "Source: WorldClimate.com";
            model.XAxisCategories    = _months;
            model.YAxisTitleText     = "Temperature (°C)";
            model.TooltipValueSuffix = "°C";
            model.Series             = series.ToArray();

            return(Json(model, JsonRequestBehavior.AllowGet));
        }
        public ActionResult RefreshLineChart(DateTime start, DateTime end, string nutrient)
        {
            var                     viewModel = new LineChartViewModel();
            List <string>           categories;
            List <string>           names;
            List <List <decimal?> > data;

            if (nutrient.ToLower() == "macronutrient ratios")
            {
                categories = _chartServices.GetDates(start, end, UserId);
                names      = _chartServices.GetMacronutrientRatioCategories();
                data       = _chartServices.CalculateMacronutrientRatioData(start, end, UserId);
            }
            else
            {
                categories = _chartServices.GetDates(start, end, UserId);
                names      = _chartServices.GetMacronutrientTitle(nutrient);
                data       = _chartServices.CalculateMacronutrientByDay(start, end, new List <string> {
                    nutrient
                }, UserId);
            }

            viewModel.Categories = categories;
            viewModel.MapToSeries(data, names);

            return(Json(viewModel, JsonRequestBehavior.AllowGet));
        }
예제 #7
0
        public IActionResult Index(LineChartViewModel model)
        {
            LineChart chart = this.GetChart(model.MinValue, model.MaxValue,
                                            this.GetMeanFrequencies(
                                                model.SampleSize, model.NumberOfSamples, model.MinValue, model.MaxValue));

            model.LineChart = chart;
            return(View(model));
        }
예제 #8
0
        public static LineChartViewModel BuildLineChartViewModel(List <LineChartResponse> lineChartsResponse)
        {
            var lineChartViewModel = new LineChartViewModel();

            foreach (var lineChartResponse in lineChartsResponse)
            {
                var lineChart = new LineChart
                {
                    LineChartId   = lineChartResponse.LineChartId,
                    TargetName    = lineChartResponse.TargetName,
                    IndicatorName = lineChartResponse.IndicatorName,
                    Rows          = BuildRows(lineChartResponse.Rows)
                };
                lineChartViewModel.LineCharts.Add(lineChart);
            }

            // Return
            return(lineChartViewModel);
        }
예제 #9
0
        public async Task <IViewComponentResult> InvokeAsync()
        {
            int graphLenght           = 20;
            int graphLenghtIntoFuture = 1;

            LineChartViewModel monthlyProgression = await Task.Run(() =>
            {
                LineChartViewModel vm           = new LineChartViewModel();
                List <BankAccount> bankAccounts = _myFinanceService.GetBankAccounts(User.GetUserId());

                bankAccounts.Where(x => x.IsVisible).ToList().ForEach(bankAccount =>
                {
                    decimal lastKnownValue = 0;

                    bankAccount.Movements = _myFinanceService.GetBankAccountMovements(User.GetUserId(), bankAccount.Id, DateTime.Now.AddDays(-graphLenght), DateTime.Now);

                    lastKnownValue = GetLastKnownValue(bankAccount, lastKnownValue);

                    var currentDay = DateTime.Now.AddDays(-graphLenght).Date;
                    for (int i = 1; i < graphLenght + graphLenghtIntoFuture; i++)
                    {
                        currentDay   = currentDay.AddDays(1);
                        var movement = bankAccount.Movements.FirstOrDefault(x => x.MovementDate.Date == currentDay);

                        lastKnownValue = UpdateLastKnownValue(bankAccount, lastKnownValue, movement);

                        vm.Movements.Add(new LineChartItemViewModel()
                        {
                            XAxis  = currentDay.ToShortDateString(),
                            Amount = lastKnownValue,
                            Color  = bankAccount.Color,
                            Group  = bankAccount.Bank.ToString(),
                        });
                    }
                });

                return(vm);
            });

            return(View(monthlyProgression));
        }
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            (_helper as IViewContextAware).Contextualize(ViewContext);
            output.TagName = "div";
            output.TagMode = TagMode.StartTagAndEndTag;

            var viewModel = new LineChartViewModel()
            {
                Name = Name,

                ChartUrl   = ChartUrl,
                Title      = Title,
                SubTitle   = SubTitle,
                YAxisTitle = YAxisTitle,
                MaxWidth   = MaxWidth
            };

            var partialView = "~/Views/_LineChart.cshtml";
            var content     = await _helper.PartialAsync(partialView, viewModel);

            output.Content.SetHtmlContent(content);
        }
예제 #11
0
        public ActionResult RefreshLineChart(DateTime start, DateTime end, string nutrient)
        {
            start = end.AddDays(-6);

            User user = _userServices.GetUser(User.Identity.Name);

            List <Day>     days      = _foodItemServices.GetDays(start, end, user.Id).ToList();
            List <Product> products  = _productServices.GetProducts(days).ToList();
            var            viewModel = new LineChartViewModel();

            if (nutrient.ToLower() == "alcohol")
            {
                viewModel.BarNames   = _chartServices.GetDates(days);
                viewModel.ChartTitle = _chartServices.GetTitle(nutrient);
                viewModel.BarData    = _chartServices.CalculateAlcoholByDay(days, products);
            }
            else
            {
                viewModel.BarNames   = _chartServices.GetDates(days);
                viewModel.ChartTitle = _chartServices.GetTitle(nutrient);
                viewModel.BarData    = _chartServices.CalculateNutrientByDay(days, products, nutrient);
            }
            return(Json(viewModel, JsonRequestBehavior.AllowGet));
        }
        public LineChartViewModel GetLineChartData(ReportFilterViewModel filterModel)
        {
            var data = _context.AddmissionMasters.Where(a => a.IsActive && (!a.RegistrationMaster.IsMedicalClear.HasValue || a.RegistrationMaster.IsMedicalClear.Value) && a.AddmissionDetails.FirstOrDefault().BatchMaster.IsActive && a.AddmissionDetails.FirstOrDefault().BatchMaster.Name != "Batch 0").Select(item => new
            {
                AdmissionId = item.Id,
                CourseId = item.CourseId,
                CourseName = item.CourseMaster.CourseName,
                AdmissionDate = item.AddmissionDate,
                BatchId = item.AddmissionDetails.FirstOrDefault().BatchId,
                BatchName = item.AddmissionDetails.FirstOrDefault().BatchMaster.Name,
                State = item.AddressDetails.FirstOrDefault().PerState,
                City = item.AddressDetails.FirstOrDefault().PerCity
            }).AsQueryable();

            if (!string.IsNullOrWhiteSpace(filterModel.CourseId))
            {
                var courseArr = filterModel.CourseId.Split(',').Select(Int32.Parse).ToList();
                if (courseArr.Count > 0)
                    data = data.Where(t => courseArr.Any(c => c == t.CourseId));
            }
            if (!string.IsNullOrWhiteSpace(filterModel.BatchId))
            {
                var batchArr = filterModel.BatchId.Split(',').Select(Int32.Parse).ToList();
                if (batchArr.Count > 0)
                    data = data.Where(t => batchArr.Any(c => c == t.BatchId));
            }
            if (!string.IsNullOrEmpty(filterModel.State))
            {
                data = data.Where(x => x.State == filterModel.State);
                if (!string.IsNullOrEmpty(filterModel.City))
                    data = data.Where(x => x.City == filterModel.City);
            }
            LineChartViewModel Model = new LineChartViewModel();
            if (filterModel.Year > 0 && filterModel.Month == 0)
            {
                var AdmInfo = data.Where(d => d.AdmissionDate.Value.Year == filterModel.Year)
                   .GroupBy(x => new { x.CourseName, x.AdmissionDate.Value.Month }).Select(items => new
                   {
                       CourseName = items.Key.CourseName,
                       Month = items.Key.Month,
                       Count = items.Count()
                   }).OrderBy(o => o.Month).ToList();

                var BBAinfo = AdmInfo.Where(a => a.CourseName == "BBA").ToList();
                var MBAinfo = AdmInfo.Where(a => a.CourseName == "MBA").ToList();
                var PHTinfo = AdmInfo.Where(a => a.CourseName == "PHT").ToList();
                int[] BBABarX = new int[12];
                int[] MBABarY = new int[12];
                int[] PHTBarZ = new int[12];
                for (int i = 1; i <= 12; i++)
                {
                    var a = BBAinfo.Where(n => n.Month == i).FirstOrDefault();
                    var b = MBAinfo.Where(n => n.Month == i).FirstOrDefault();
                    var c = PHTinfo.Where(n => n.Month == i).FirstOrDefault();

                    if (a != null)
                        BBABarX[i - 1] = a.Count;
                    else
                        BBABarX[i - 1] = 0;

                    if (b != null)
                        MBABarY[i - 1] = b.Count;
                    else
                        MBABarY[i - 1] = 0;

                    if (c != null)
                        PHTBarZ[i - 1] = c.Count;
                    else
                        PHTBarZ[i - 1] = 0;
                }
                Model.line = new List<Line>
                {
                    new Line{ Label="BBA",value=BBABarX },
                    new Line{Label="MBA",value=MBABarY},
                    new Line{Label="PHT",value=PHTBarZ}
                };
                Model.LineChartLbl = new string[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Set", "Oct", "Nov", "Dec" };
            }
            else if (filterModel.Month > 0)
            {
                var AdmInfo = data.Where(d => d.AdmissionDate.Value.Year == filterModel.Year && d.AdmissionDate.Value.Month == filterModel.Month)
                             .GroupBy(x => new { x.CourseName, x.AdmissionDate.Value.Day }).Select(items => new
                             {
                                 CourseName = items.Key.CourseName,
                                 Day = items.Key.Day,
                                 Count = items.Count()
                             }).OrderBy(o => o.Day).ToList();

                var BBAinfo = AdmInfo.Where(a => a.CourseName == "BBA").ToList();
                var MBAinfo = AdmInfo.Where(a => a.CourseName == "MBA").ToList();
                var PHTinfo = AdmInfo.Where(a => a.CourseName == "PHT").ToList();
                int[] BBABarX = new int[DateTime.DaysInMonth(filterModel.Year, filterModel.Month)];
                int[] MBABarY = new int[DateTime.DaysInMonth(filterModel.Year, filterModel.Month)];
                int[] PHTBarZ = new int[DateTime.DaysInMonth(filterModel.Year, filterModel.Month)];

                for (int i = 1; i <= DateTime.DaysInMonth(filterModel.Year, filterModel.Month); i++)
                {
                    var a = BBAinfo.Where(n => n.Day == i).FirstOrDefault();
                    var b = MBAinfo.Where(n => n.Day == i).FirstOrDefault();
                    var c = PHTinfo.Where(n => n.Day == i).FirstOrDefault();
                    if (a != null)
                        BBABarX[i - 1] = a.Count;
                    else
                        BBABarX[i - 1] = 0;

                    if (b != null)
                        MBABarY[i - 1] = b.Count;
                    else
                        MBABarY[i - 1] = 0;

                    if (c != null)
                        PHTBarZ[i - 1] = c.Count;
                    else
                        PHTBarZ[i - 1] = 0;
                }
                Model.line = new List<Line>
                {
                    new Line{ Label="BBA",value=BBABarX },
                    new Line{Label="MBA",value=MBABarY},
                    new Line{Label="PHT",value=PHTBarZ}
                };
                int daysMonth = DateTime.DaysInMonth(filterModel.Year, filterModel.Month);
                string[] days = new string[daysMonth];
                for (int i = 1; i <= daysMonth; i++)
                    days[i - 1] = i.ToString();
                Model.LineChartLbl = days;
            }
            else
            {
                var AdmInfo = data.GroupBy(x => new { x.CourseName, x.AdmissionDate.Value.Year }).Select(items => new
                {
                    CourseName = items.Key.CourseName,
                    Year = items.Key.Year,
                    Count = items.Count()
                }).OrderBy(o => o.Year).ToList();
                var BBAinfo = AdmInfo.Where(a => a.CourseName == "BBA").ToList();
                var MBAinfo = AdmInfo.Where(a => a.CourseName == "MBA").ToList();
                var PHTinfo = AdmInfo.Where(a => a.CourseName == "PHT").ToList();
                int[] BBABarX = new int[6];
                int[] MBABarY = new int[6];
                int[] PHTBarZ = new int[6];

                Model.LineChartLbl = new string[6];
                decimal[] BarY = new decimal[6];
                int j = 1;
                for (int i = (DateTime.Now.Year - 5); i <= DateTime.Now.Year; i++)
                {
                    Model.LineChartLbl[j - 1] = i.ToString();
                    var a = BBAinfo.Where(n => n.Year == i).FirstOrDefault();
                    var b = MBAinfo.Where(n => n.Year == i).FirstOrDefault();
                    var c = PHTinfo.Where(n => n.Year == i).FirstOrDefault();
                    if (a != null)
                        BBABarX[j - 1] = a.Count;
                    else
                        BBABarX[j - 1] = 0;

                    if (b != null)
                        MBABarY[j - 1] = b.Count;
                    else
                        MBABarY[j - 1] = 0;

                    if (c != null)
                        PHTBarZ[j - 1] = c.Count;
                    else
                        PHTBarZ[j - 1] = 0;

                    j++;
                }
                Model.line = new List<Line>
                {
                    new Line{ Label="BBA",value=BBABarX },
                    new Line{Label="MBA",value=MBABarY},
                    new Line{Label="PHT",value=PHTBarZ}
                };
            }
            return Model;
        }
예제 #13
0
        // GET: Statistics
        public ActionResult Index()
        {
            int scale = 50;
            List <LineChartViewModel> stat      = new List <LineChartViewModel>();
            List <Gallery>            galleires = caller.ListOfAllGalleries().OrderByDescending(o => o.maxCapacity).ToList();

            if (scale < galleires.First().maxCapacity)
            {
                int sections = (int)galleires.First().maxCapacity / scale;
                int oldScale = 0;
                int tmpScale = scale;
                for (int i = 0; i < sections + 1; i++)
                {
                    //  if (galleires.Count(g => oldScale <= g.maxCapacity && g.maxCapacity < tmpScale)!=0)
                    // {
                    LineChartViewModel tmp = new LineChartViewModel();
                    tmp.x = tmpScale;
                    tmp.y = galleires.Count(g => oldScale <= g.maxCapacity && g.maxCapacity < tmpScale);
                    stat.Add(tmp);
                    // }//

                    oldScale = tmpScale;
                    tmpScale = tmpScale + scale;
                }
            }

            JavaScriptSerializer jss2 = new JavaScriptSerializer();

            string output3 = jss2.Serialize(stat);

            string demo3 = output3.Replace("\"", "");

            float somme  = 0;
            float somme2 = 0;
            float M      = 0;
            float V      = 0;
            float Ec     = 0;

            foreach (var item in galleires)
            {
                somme  = somme + (float)item.surface;
                somme2 = somme2 + (float)item.surface * (float)item.surface;
            }
            M            = somme / galleires.Count;
            V            = somme2 / galleires.Count - M * M;
            Ec           = (float)Math.Sqrt(V);
            ViewBag.M    = M;
            ViewBag.V    = V;
            ViewBag.Ec   = Ec;
            ViewBag.line = demo3;
            /******************************************/
            foreach (var item in galleires)
            {
                item.schedule = caller.ListOfAllSchedules(item.id);
            }
            Gallery gallery     = galleires.Find(g => g.id == 2);
            Gallery galleryBeta = galleires.Find(g => g.id == 3);
            int     count1_17   = 0;
            int     count1_18   = 0;
            int     count1_19   = 0;
            int     count2_17   = 0;
            int     count2_18   = 0;
            int     count2_19   = 0;

            //    int z = gallery.schedule.Count(e => { DateTime t = (DateTime)e.startDate} == 2017);
            foreach (var item in gallery.schedule)
            {
                DateTime t = (DateTime)item.startDate;
                if (t.Year == 2017)
                {
                    count1_17++;
                }
                if (t.Year == 2018)
                {
                    count1_18++;
                }
                if (t.Year == 2019)
                {
                    count1_19++;
                }
            }
            foreach (var item in galleryBeta.schedule)
            {
                DateTime t = (DateTime)item.startDate;
                if (t.Year == 2017)
                {
                    count2_17++;
                }
                if (t.Year == 2018)
                {
                    count2_18++;
                }
                if (t.Year == 2019)
                {
                    count2_19++;
                }
            }

            BarChartViewModel a = new BarChartViewModel();
            BarChartViewModel b = new BarChartViewModel();
            BarChartViewModel c = new BarChartViewModel();

            a.a = count1_17;
            a.b = count2_17;
            a.y = "2017";
            b.a = count1_18;
            b.b = count2_18;
            b.y = "2018";
            c.a = count1_19;
            c.b = count2_19;
            c.y = "2019";
            List <BarChartViewModel> bar = new List <BarChartViewModel>();

            bar.Add(a);
            bar.Add(b);
            bar.Add(c);
            var json = JsonConvert.SerializeObject(bar);

            JavaScriptSerializer jss = new JavaScriptSerializer();

            string output = jss.Serialize(bar);

            string demo = output.Replace("\"", "");

            ViewBag.jss = demo;

            /**********************/
            //  List<Gallery> galleires = caller.ListOfAllGalleries();

            List <schedule>   schedules = new List <schedule>();
            List <DonutChart> stat2     = new List <DonutChart>();
            DonutChart        donut     = new DonutChart();
            DonutChart        donut2    = new DonutChart();
            DonutChart        donut3    = new DonutChart();

            foreach (var item in galleires)
            {
                foreach (var tmp in item.schedule)
                {
                    schedules.Add(tmp);
                }
            }
            //Holiday,Event,Renovations,Other

            donut.value  = schedules.Count(s => s.type == "Holiday");
            donut.label  = "Holiday";
            donut2.value = schedules.Count(s => s.type == "Event");
            donut2.label = "Event";
            donut3.value = schedules.Count(s => s.type == "Renovations");
            donut3.label = "Renovations";
            donut3.value = schedules.Count(s => s.type == "Other");
            donut3.label = "Other";

            stat2.Add(donut);
            stat2.Add(donut2);
            stat2.Add(donut3);
            //JavaScriptSerializer jss = new JavaScriptSerializer();

            /*string output = jss.Serialize(stat);
             *
             * string demo = output.Replace("\"", "");*/

            ViewBag.dot = stat2;

            /*********************/
            return(View());
        }
예제 #14
0
        /// <summary>
        /// 按照指定日期取得資料庫中的舊資料,如果沒有指定日期,則向PWEB取得當日起一周預報
        /// </summary>
        /// <param name="location">區</param>
        /// <param name="date">日期</param>
        /// <returns></returns>
        public LineChartViewModel get(string location = null, DateTime?STdate = null, DateTime?EDdate = null)
        {
            List <TaipeiWeather> dataresult = new List <TaipeiWeather>();

            if ((STdate == null) || (EDdate == null))
            {
                if (!service.checkNew())
                {
                    //未指定日期且無新資料,向PWEB取一周預報資料
                    QueryPWEBTaipeiWeatherData data = service.Query();
                    //解析預報資料
                    dataresult = service.ParseData(data);
                }
                else
                {
                    //已有資料可從資料庫取得,避免頻繁向PWEB取資料拖慢效能
                    dataresult = service.getData(location, DateTime.Now, DateTime.Now.AddDays(7));
                }
            }
            else
            {
                //按照指定日期區間從資料庫取出資料
                dataresult = service.getData(location, STdate.Value, EDdate.Value);
            }

            if (string.IsNullOrEmpty(location))
            {
                //由於未指定地區,將從第一筆的地區做為預設
                dataresult = dataresult.Where(x => x.Location == dataresult.FirstOrDefault().Location).ToList();
            }
            else
            {
                dataresult = dataresult.Where(x => x.Location == location).ToList();
            }

            LineChartViewModel result = new LineChartViewModel();
            //取得歷史資料中的地區以及時間區間供前端選擇
            var HistoryArea = service.getHistoryRange();

            //轉換成Viewmodel
            result.Area = HistoryArea.Select(x => x.Location).Distinct().ToList();
            var range = HistoryArea.SelectMany(x => x.TimeRange).ToList();

            result.ListStartTime = range.Distinct().Select(x => x.StartTime.ToString("yyyy-MM-dd HH:mm:ss")).Distinct().ToList();
            result.ListEndTime   = range.Distinct().Select(x => x.EndTime.ToString("yyyy-MM-dd HH:mm:ss")).Distinct().ToList();

            result.series = new List <string>()
            {
                "降雨機率", "平均溫度", "平均相對濕度", "最小舒適度指數",
                "最大風速", "最高體感溫度", "最大舒適度指數", "最低溫度", "紫外線指數",
                "最低體感溫度", "最高溫度", "平均露點溫度"
            };

            List <List <string> > Labels = new List <List <string> >();

            foreach (var dt in dataresult)
            {
                List <string> datelabel = new List <string>();
                datelabel.Add(dt.StartTime.ToString("yyyy-MM-dd hh:mm:ss ~"));
                datelabel.Add(dt.EndTime.ToString("yyyy-MM-dd hh:mm:ss"));
                datelabel.Add(dt.Weather);
                //datelabel.Add(dt.WeatherDescription); //加這行會跑版
                datelabel.Add(dt.WindDirection);

                Labels.Add(datelabel);
            }
            result.Label = Labels;

            List <List <byte> > DataVals = new List <List <byte> >();

            DataVals.Add(dataresult.Select(x => x.RainChance).ToList());       //降雨機率
            DataVals.Add(dataresult.Select(x => x.Temperature).ToList());      //平均溫度
            DataVals.Add(dataresult.Select(x => x.RelativeHumidity).ToList()); //平均相對濕度
            DataVals.Add(dataresult.Select(x => x.MinCi).ToList());            //最小舒適度指數
            DataVals.Add(dataresult.Select(x => x.WindSpeed).ToList());        //最大風速
            DataVals.Add(dataresult.Select(x => x.MaxAt).ToList());            //最高體感溫度
            DataVals.Add(dataresult.Select(x => x.MaxCi).ToList());            //最大舒適度指數
            DataVals.Add(dataresult.Select(x => x.MinTemperature).ToList());   //最低溫度
            DataVals.Add(dataresult.Select(x => x.Uvi).ToList());              //紫外線指數
            DataVals.Add(dataresult.Select(x => x.MinAt).ToList());            //最低體感溫度
            DataVals.Add(dataresult.Select(x => x.MaxTemperature).ToList());   //最高溫度
            DataVals.Add(dataresult.Select(x => x.Td).ToList());               //平均露點溫度

            result.data = DataVals;

            return(result);
        }
예제 #15
0
        public ActionResult LayoutItem(DerLayoutItemViewModel viewModel)
        {
            if (viewModel.Id > 0)
            {
                #region edit
                var response      = _derService.GetDerLayoutItem(viewModel.Id);
                var editViewModel = response.MapTo <DerLayoutItemViewModel>();
                editViewModel.Types = _dropdownService.GetDerItemTypes().OrderBy(x => x.Text).MapTo <SelectListItem>();
                editViewModel.Type  = response.Type;
                switch (response.Type.ToLowerInvariant())
                {
                case "line":
                {
                    var lineChart = new LineChartViewModel();
                    editViewModel.LineChart = response.Artifact.MapPropertiesToInstance <LineChartViewModel>(lineChart);
                    var series = new LineChartViewModel.SeriesViewModel();
                    editViewModel.LineChart.Series.Insert(0, series);
                    editViewModel.Artifact.Measurements = _measurementService.GetMeasurements(new GetMeasurementsRequest
                        {
                            Take = -1,
                            SortingDictionary = new Dictionary <string, SortOrder> {
                                { "Name", SortOrder.Ascending }
                            }
                        }).Measurements
                                                          .Select(x => new SelectListItem {
                            Value = x.Id.ToString(), Text = x.Name
                        }).ToList();
                    break;
                }

                case "pie":
                {
                    var pie = new PieViewModel();
                    editViewModel.Pie = response.Artifact.MapPropertiesToInstance <PieViewModel>(pie);
                    var series = new PieViewModel.SeriesViewModel();
                    editViewModel.Pie.Series.Insert(0, series);
                    editViewModel.Artifact.Measurements = _measurementService.GetMeasurements(new GetMeasurementsRequest
                        {
                            Take = -1,
                            SortingDictionary = new Dictionary <string, SortOrder> {
                                { "Name", SortOrder.Ascending }
                            }
                        }).Measurements
                                                          .Select(x => new SelectListItem {
                            Value = x.Id.ToString(), Text = x.Name
                        }).ToList();
                    break;
                }

                case "tank":
                {
                    var tank = new TankViewModel();
                    editViewModel.Tank = response.Artifact.Tank.MapPropertiesToInstance <TankViewModel>(tank);
                    break;
                }

                case "multiaxis":
                {
                    var multiaxisChart = new MultiaxisChartViewModel();
                    editViewModel.MultiaxisChart = response.Artifact.MapPropertiesToInstance <MultiaxisChartViewModel>(multiaxisChart);
                    multiaxisChart.GraphicTypes.Add(new SelectListItem {
                            Value = "line", Text = "Line"
                        });
                    multiaxisChart.ValueAxes.Add(new SelectListItem {
                            Value = ValueAxis.KpiActual.ToString(), Text = "Kpi Actual"
                        });
                    multiaxisChart.Measurements = _measurementService.GetMeasurements(new GetMeasurementsRequest
                        {
                            Take = -1,
                            SortingDictionary = new Dictionary <string, SortOrder> {
                                { "Name", SortOrder.Ascending }
                            }
                        }).Measurements
                                                  .Select(x => new SelectListItem {
                            Value = x.Id.ToString(), Text = x.Name
                        }).ToList();
                    foreach (var chartRes in response.Artifact.Charts)
                    {
                        var chartViewModel = chartRes.MapTo <MultiaxisChartViewModel.ChartViewModel>();
                        switch (chartViewModel.GraphicType)
                        {
                        case "line":
                        {
                            chartViewModel.LineChart = chartRes.MapTo <LineChartViewModel>();
                            chartViewModel.LineChart.ValueAxes.Add(new SelectListItem {
                                        Value = ValueAxis.KpiActual.ToString(), Text = "Kpi Actual"
                                    });
                            var series = new LineChartViewModel.SeriesViewModel();
                            chartViewModel.LineChart.Series.Insert(0, series);
                        }
                        break;
                        }
                        multiaxisChart.Charts.Add(chartViewModel);
                    }
                    var chart = new MultiaxisChartViewModel.ChartViewModel();
                    editViewModel.MultiaxisChart.Charts.Insert(0, chart);

                    break;
                }

                case "speedometer":
                case "barmeter":
                {
                    var speedometerChart = new SpeedometerChartViewModel();
                    editViewModel.SpeedometerChart = response.Artifact.MapPropertiesToInstance <SpeedometerChartViewModel>(speedometerChart);
                    var plot = new SpeedometerChartViewModel.PlotBand();
                    editViewModel.SpeedometerChart.PlotBands.Insert(0, plot);
                    break;
                }

                case "highlight":
                {
                    var result = _selectService.GetHighlightTypesDropdown();
                    editViewModel.Highlights = result.Select(item => new SelectListItem()
                        {
                            Text = item.Text, Value = item.Value
                        }).ToList();
                    editViewModel.HighlightId = response.Highlight.SelectOptionId;
                    break;
                }

                case "key-equipment-status":
                {
                    var result = _selectService.GetHighlightTypesDropdown();
                    editViewModel.Highlights = result.Select(item => new SelectListItem()
                        {
                            Text = item.Text, Value = item.Value
                        }).ToList();
                    editViewModel.KpiInformations = AddEmptyKpiInformations(editViewModel.KpiInformations, 24);
                    for (int i = 0; i < response.KpiInformations.Count; i++)
                    {
                        if (response.KpiInformations[i].SelectOption != null)
                        {
                            editViewModel.KpiInformations[i].HighlightId = response.KpiInformations[i].SelectOption.Id;
                        }
                    }
                }
                break;

                case "termometer":
                case "person-on-board":
                {
                    editViewModel.KpiInformations = AddEmptyKpiInformations(editViewModel.KpiInformations, 1);
                    break;
                }

                case "hhv":
                case "procurement":
                {
                    editViewModel.KpiInformations = AddEmptyKpiInformations(editViewModel.KpiInformations, 2);
                    break;
                }

                case "mgdp":
                case "indicative-commercial-price":
                case "dafwc":
                case "job-pmts":
                {
                    editViewModel.KpiInformations = AddEmptyKpiInformations(editViewModel.KpiInformations, 3);
                    break;
                }

                case "total-feed-gas":
                case "weekly-maintenance":
                case "critical-pm":
                case "loading-duration":
                {
                    editViewModel.KpiInformations = AddEmptyKpiInformations(editViewModel.KpiInformations, 4);
                    break;
                }

                case "avg-ytd-key-statistic":
                {
                    editViewModel.KpiInformations = AddEmptyKpiInformations(editViewModel.KpiInformations, 5);
                    break;
                }

                case "security":
                {
                    editViewModel.KpiInformations = AddEmptyKpiInformations(editViewModel.KpiInformations, 6);
                    break;
                }

                case "lng-and-cds-production":
                {
                    editViewModel.KpiInformations = AddEmptyKpiInformations(editViewModel.KpiInformations, 9);
                    break;
                }

                case "plant-availability":
                {
                    editViewModel.KpiInformations = AddEmptyKpiInformations(editViewModel.KpiInformations, 10);
                    break;
                }

                case "safety":
                {
                    editViewModel.KpiInformations = AddEmptyKpiInformations(editViewModel.KpiInformations, 11);
                    break;
                }

                case "table-tank":
                case "global-stock-market":
                {
                    editViewModel.KpiInformations = AddEmptyKpiInformations(editViewModel.KpiInformations, 13);
                    var result = _selectService.GetHighlightTypesDropdown();
                    editViewModel.Highlights = result.Select(item => new SelectListItem()
                        {
                            Text = item.Text, Value = item.Value
                        }).ToList();
                    break;
                }

                case "economic-indicator":
                {
                    editViewModel.KpiInformations = AddEmptyKpiInformations(editViewModel.KpiInformations, 15);
                    break;
                }

                case "lng-and-cds":
                {
                    editViewModel.KpiInformations = AddEmptyKpiInformations(editViewModel.KpiInformations, 17);
                    break;
                }

                case "prepared-by":
                case "reviewed-by":
                {
                    editViewModel.SignedBy = response.SignedBy;
                    var result = _userService.GetUsers(new GetUsersRequest {
                            SortingDictionary = new Dictionary <string, SortOrder>(), Take = 1000
                        });
                    editViewModel.Users =
                        result.Users.Select(
                            item => new SelectListItem()
                        {
                            Text = item.Username, Value = item.Id.ToString()
                        }).ToList();
                    break;
                }
                }
                return(View("EditLayoutItem", editViewModel));

                #endregion
            }
            else
            {
                #region create
                viewModel.Types = _dropdownService.GetDerItemTypes().OrderBy(x => x.Text).MapTo <SelectListItem>();
                var rowCol = viewModel.Row.ToString() + "-and-" + viewModel.Column.ToString();
                switch (rowCol)
                {
                case "0-and-0":
                {
                    viewModel.Type = "avg-ytd-key-statistic";
                    break;
                };

                case "0-and-2":
                {
                    viewModel.Type = "speedometer";
                    break;
                }

                case "1-and-0":
                {
                    viewModel.Type = "multiaxis";
                    break;
                }

                case "1-and-1":
                case "1-and-2":
                case "1-and-3":
                {
                    viewModel.Type = "line";
                    break;
                }

                case "2-and-0":
                {
                    viewModel.Type = "dafwc";
                    break;
                }

                case "2-and-1":
                {
                    viewModel.Type = "weather";
                    break;
                }

                case "2-and-2":
                {
                    viewModel.Type = "wave";
                    break;
                }

                case "3-and-0":
                {
                    viewModel.Type = "safety";
                    break;
                }

                case "3-and-1":
                case "3-and-2":
                case "3-and-3":
                case "0-and-1":
                case "0-and-3":
                case "3-and-5":
                case "10-and-2":
                case "11-and-2":
                case "11-and-1":
                case "12-and-0":
                case "12-and-2":
                case "13-and-0":
                case "14-and-2":
                case "15-and-1":
                case "15-and-2":
                case "16-and-4":
                case "16-and-5":
                case "16-and-6":
                case "16-and-7":
                {
                    viewModel.Type = "highlight";
                    break;
                }

                case "3-and-4":
                {
                    viewModel.Type = "pie";
                    break;
                }

                case "4-and-0":
                {
                    viewModel.Type = "dafwc";
                    break;
                }

                case "4-and-1":
                {
                    viewModel.Type = "security";
                    break;
                }

                case "4-and-2":
                {
                    viewModel.Type = "alert";
                    break;
                }

                case "5-and-0":
                {
                    viewModel.Type = "job-pmts";
                    break;
                }

                case "5-and-1":
                {
                    viewModel.Type = "mgdp";
                    break;
                }

                case "5-and-2":
                {
                    viewModel.Type = "hhv";
                    break;
                }

                case "6-and-0":
                {
                    viewModel.Type = "total-feed-gas";
                    break;
                }

                case "6-and-2":
                {
                    viewModel.Type = "plant-availability";
                    break;
                }

                case "6-and-3":
                case "6-and-4":
                case "6-and-6":
                case "6-and-7":
                case "6-and-8":
                case "6-and-9":
                case "6-and-10":
                {
                    viewModel.Type = "barmeter";
                    break;
                }

                case "6-and-5":
                {
                    viewModel.Type = "termometer";
                    break;
                }

                case "7-and-0":
                {
                    viewModel.Type = "lng-and-cds-production";
                    break;
                }

                case "7-and-1":
                {
                    viewModel.Type = "lng-and-cds";
                    break;
                }

                case "8-and-0":
                case "8-and-1":
                case "8-and-2":
                case "8-and-3":
                {
                    viewModel.Type = "tank";
                    break;
                }

                case "8-and-4":
                {
                    viewModel.Type = "nls";
                    break;
                }

                case "9-and-0":
                {
                    viewModel.Type = "table-tank";
                    break;
                }

                case "10-and-0":
                {
                    viewModel.Type = "weekly-maintenance";
                    break;
                }

                case "10-and-1":
                {
                    viewModel.Type = "key-equipment-status";
                    break;
                }

                case "11-and-0":
                {
                    viewModel.Type = "critical-pm";
                    break;
                }

                case "12-and-1":
                {
                    viewModel.Type = "loading-duration";
                    break;
                }

                case "14-and-0":
                {
                    viewModel.Type = "procurement";
                    break;
                }

                case "15-and-0":
                {
                    viewModel.Type = "indicative-commercial-price";
                    break;
                }

                case "14-and-1":
                {
                    viewModel.Type = "economic-indicator";
                    break;
                }

                case "16-and-1":
                {
                    viewModel.Type = "global-stock-market";
                    break;
                }

                case "16-and-2":
                {
                    viewModel.Type = "prepared-by";
                    break;
                }

                case "16-and-3":
                {
                    viewModel.Type = "reviewed-by";
                    break;
                }

                case "15-and-3":
                {
                    viewModel.Type = "person-on-board";
                    break;
                }
                }
                return(View("LayoutItem", viewModel));

                #endregion
            }
        }