Пример #1
0
        /// <summary>
        /// Get Parking Lots.
        /// Route: '/api/parking-lots'
        /// </summary>
        /// <returns>Array of parking lots</returns>
        public static async Task <List <ParkingLot> > GetParkingLots()
        {
            try {
                string parkingLots = await http.Get("/api/parking-lots");

                return(Factories.CreateCollection <ParkingLot>(parkingLots));
            } catch {
                Console.WriteLine("Couldn't get Parking Lots");
                throw;
            }
        }
Пример #2
0
        public async Task <JsonResult> OnPostAsync(string UserInput)
        {
            try
            {
                HttpAsync httpAsync = new HttpAsync();
                string    response  = await httpAsync.Get(CrtShUrl.Replace("#URL#", UserInput));

                return(new JsonResult(response));
            }
            catch (Exception ex)
            {
                return(new JsonResult(ex.Message));
            }
        }
Пример #3
0
        /// <summary>
        /// Get logs for the given sensor withing the time interval.
        /// </summary>
        /// <param name="start">Starting date-time.</param>
        /// <param name="end">Ending date-time.</param>
        /// <param name="id">Id of the sensor.</param>
        public async Task <ICollection <SensorLog> > GetSensorLogs(string start, string end, string id)
        {
            try {
                string response = await HttpAsync.Get($"/{Path}/{id}/{SensorLogApi.Path}/{start}/{end}");

                try {
                    return(JsonConvert.DeserializeObject <ICollection <SensorLog> >(response));
                } catch (Exception ex) {
                    Console.WriteLine($"Couldn't create sensor log objects: " + ex);
                    return(new List <SensorLog>());
                }
            } catch {
                Console.WriteLine($"Couldn't get sensor logs.");
                throw;
            }
        }
        /// <summary>
        /// Get all driveways that belong to the parking lot.
        /// </summary>
        /// <param name="id">Id of the parking lot.</param>
        public async Task <ICollection <Driveway> > GetDriveways(string id)
        {
            try {
                string response = await HttpAsync.Get($"/{Path}/{id}/{DrivewayApi.Path}");

                try {
                    return(JsonConvert.DeserializeObject <ICollection <Driveway> >(response));
                } catch (Exception ex) {
                    Console.WriteLine($"Couldn't create driveway objects: " + ex);
                    return(new List <Driveway>());
                }
            } catch {
                Console.WriteLine($"Couldn't get driveways.");
                throw;
            }
        }
Пример #5
0
        public async Task <ContentResult> OnPostRawDataAsync(string binid)
        {
            if (!string.IsNullOrEmpty(binid))
            {
                try
                {
                    HttpAsync httpAsync = new HttpAsync();
                    string    response  = await httpAsync.Get(PastBinUrl.Replace("#bin#", binid));

                    return(Content(response));
                }
                catch (Exception ex)
                {
                    return(Content(ex.Message));
                }
            }
            else
            {
                return(Content("No data not found"));
            }
        }
Пример #6
0
        public async Task <JsonResult> OnPostAsync(string UserInput)
        {
            if (!string.IsNullOrEmpty(UserInput))
            {
                List <BinResult> binResults = new List <BinResult>();
                string[]         keywords   = UserInput.Split(" ").Take(5).ToArray();
                List <string>    jReturns   = new List <string>();
                foreach (string keyword in keywords)
                {
                    //    data.Labels.Add(keyword);
                    //todo add link to pastbin raw data based on binID
                    try
                    {
                        HttpAsync httpAsync = new HttpAsync();
                        string    response  = await httpAsync.Get(PsDumpUrl.Replace("#keyword#", keyword));

                        if (!string.IsNullOrEmpty(response))
                        {
                            try
                            {
                                binResults.Add(JsonConvert.DeserializeObject <BinResult>(response));
                                jReturns.Add(response);
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
                //Create chart
                Chart chart = new Chart();
                chart.Type = Enums.ChartType.Line;
                LineDataset lineDataset = new LineDataset();
                Data        data        = new Data();
                data.Labels   = new List <string>();
                data.Datasets = new List <Dataset>();
                foreach (BinResult binResult in binResults)
                {
                    LineDataset    dataset = new LineDataset();
                    List <double?> c       = new List <double?>();
                    foreach (var line in binResult.data.GroupBy(f => DateTime.Parse(f.Time).ToUniversalTime()
                                                                .ToString("Y", System.Globalization.CultureInfo.CreateSpecificCulture("en-US")))
                             .Select(group => new
                    {
                        xAxis = group.Key,
                        yAxis = group.Count()
                    })
                             .OrderBy(x => x.xAxis))
                    {
                        Debug.WriteLine(line.xAxis);
                        if (!data.Labels.Contains(line.xAxis))
                        {
                            data.Labels.Add(line.xAxis);
                        }

                        if (c.Count() < data.Labels.IndexOf(line.xAxis))
                        {
                            for (int i = c.Count(); i < data.Labels.IndexOf(line.xAxis); i++)
                            {
                                c.Add(0);
                            }
                        }
                        c.Insert(data.Labels.IndexOf(line.xAxis), (line.yAxis));
                        Debug.WriteLine("{0} {1} {2}", binResult.Search, line.xAxis, line.yAxis);
                    }
                    lineDataset = CreateChartDataSet(binResult.Search, c);
                    data.Datasets.Add(lineDataset);
                }
                Options options = new Options()
                {
                    Scales              = new Scales(),
                    Responsive          = true,
                    MaintainAspectRatio = true
                };

                Scales scales = new Scales()
                {
                    YAxes = new List <Scale>()
                    {
                        new CartesianScale()
                    },
                    XAxes = new List <Scale>()
                    {
                        new CartesianScale()
                        {
                            Type     = "category",
                            Position = "bottom",
                            Ticks    = new CartesianLinearTick()
                            {
                                BeginAtZero = false
                            }
                        }
                    }
                };

                CartesianScale yAxes = new CartesianScale()
                {
                    Ticks = new Tick()
                };

                Tick tick = new Tick()
                {
                    Callback = "function(value, index, values) {return '#of bins' + value;}"
                };

                yAxes.Ticks  = tick;
                scales.YAxes = new List <Scale>()
                {
                    yAxes
                };
                options.Scales = scales;
                chart.Options  = options;
                chart.Data     = data;
                return(new JsonResult(new { table = jReturns, chart = chart.CreateChartCode("lineChart") }));
            }
            return(null);
        }