Exemplo n.º 1
0
        //[HttpGet]
        public JsonResult GetLocations(string type, string value)
        {
            DataAccess.hackathon2019Entities hackathon2019Entities = new DataAccess.hackathon2019Entities();

            IEnumerable <string> locations;

            switch (type)
            {
            case "All":
                locations = hackathon2019Entities.cnf_locations.Select(x => x.region).Distinct().OrderBy(x => x).ToList();
                break;

            case "Region":
                locations = hackathon2019Entities.cnf_locations.Where(x => x.region == value).Select(x => x.country).Distinct().OrderBy(x => x).ToList();
                break;

            case "Country":
                locations = hackathon2019Entities.cnf_locations.Where(x => x.country == value).Select(x => x.city).Distinct().OrderBy(x => x).ToList();
                break;

            case "City":
                locations = hackathon2019Entities.cnf_locations.Where(x => x.city == value).Select(x => x.location_code).Distinct().OrderBy(x => x).ToList();
                break;

            default:
                locations = new List <string>();
                break;
            }

            return(Json(locations, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        public JsonResult ChartsData(string region, string country, string city, string office, string graphType, string Period, string StartDate, string EndDate)
        {
            DateTime start = new DateTime(2019, 8, 1);
            DateTime end   = new DateTime(2019, 10, 1);

            try
            {
                start = DateTime.ParseExact(StartDate, "yyyy-MM-dd", null);
                end   = DateTime.ParseExact(EndDate, "yyyy-MM-dd", null);
            }
            catch (Exception)
            {
            }

            DataAccess.hackathon2019Entities db = new DataAccess.hackathon2019Entities();

            decimal[] array  = new decimal[] { 1, 3, 3 };
            string[]  lables = new string[] { "1-10-2019", "2-10-2019", "3-10-2019" };

            if (graphType == "Waste")
            {
                if (office != "All")
                {
                    var query = db.item_utilisation.Join(db.cnf_locations, x => x.location_id, y => y.id, (x, y) => new { ItemData = x, LocationData = y })
                                .Where(x => x.LocationData.location_code == office && (x.ItemData.asof_date >= start && x.ItemData.asof_date <= end))
                                .Select(x => new { X = x.ItemData.asof_date, Y = x.ItemData.wasted.Value }).ToList();
                    array  = query.Select(x => x.Y).ToArray();
                    lables = query.Select(x => x.X.ToString("dd-MM-yyyy")).ToArray();
                }
            }

            var dataFirst = new
            {
                label       = "Food Waste",
                data        = array,
                lineTension = 0,
                fill        = false,
                borderColor = $"rgb({GetRandomNumber()},{GetRandomNumber()},{GetRandomNumber()})"
            };

            var data = new
            {
                labels   = lables,
                datasets = new[] { dataFirst }
            };

            return(Json(data, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 3
0
        public ViewResult Charts()
        {
            ChartData chartData = new ChartData();

            DataAccess.hackathon2019Entities hackathon2019Entities = new DataAccess.hackathon2019Entities();
            var rawData = hackathon2019Entities.item_utilisation.Join(hackathon2019Entities.cnf_locations, x => x.category_id, y => y.id, (x, y) => new { x.wasted, y.location_code, x.asof_date }).ToList();


            var dataFirst = new
            {
                label = rawData[0].location_code,
                data  = rawData.Select(x => x.wasted),

                lineTension = 0,
                fill        = false,
                borderColor = $"rgb({GetRandomNumber()},{GetRandomNumber()},{GetRandomNumber()})"
            };

            //var dataSecond = new
            //{
            //    label = "Car B - Speed (mph)",
            //    data = new int[] { 20, 15, 60, 60, 65, 30, 70 },
            //    lineTension = 0,
            //    fill = false,
            //    borderColor = $"rgb({GetRandomNumber()},{GetRandomNumber()},{GetRandomNumber()})"
            //};

            var data = new
            {
                //labels = new string[] { "0s", "10s", "20s", "30s", "40s", "50s", "60s" },
                labels = rawData.Select(x => x.asof_date.ToString("dd-MM-yyyy")),
                //datasets = new[] { dataFirst, dataSecond }
                datasets = new[] { dataFirst }
            };

            chartData.Data = data;

            chartData.Locations.AddRange(hackathon2019Entities.cnf_locations.Select(x => x.location_code));


            return(View(chartData));
        }
Exemplo n.º 4
0
        public ViewResult DataPoints(int count = 10, string type = "json")
        {
            DataAccess.hackathon2019Entities hackathon2019Entities = new DataAccess.hackathon2019Entities();

            var data = hackathon2019Entities.item_utilisation.Where(x => x.location_id == 2 && x.category_id == 1).ToList().Select(x => new DataPoint()
            {
                Y = x.wasted.Value, Label = x.asof_date.ToString("dd-MM-yyyy")
            });

            string str = JsonConvert.SerializeObject(data);

            return(View((object)str));

            //switch (type)
            //{
            //    case "json": return Content(JsonConvert.SerializeObject(DataService.GetRandomDataForNumericAxis(count), _jsonSetting), "application/json");


            //    default: return Content(JsonConvert.SerializeObject(DataService.GetRandomDataForNumericAxis(count), _jsonSetting), "application/json"); ;
            //}
        }