コード例 #1
0
        public async Task <LocationJerkModelExtended> GetLocationDetails(double?latitude, double?longitude)
        {
            IEnumerable <LocationJerkModel> fetchedData = await _locationJerkRepository.LoadLatestLocationJerkInfoAsync();

            if (latitude == null || longitude == null)
            {
                return(null);
            }

            if (fetchedData != null)
            {
                LocationJerkModel queriedData = fetchedData.FirstOrDefault(loc => loc.Latitude == latitude && loc.Longitude == longitude);

                if (queriedData != null)
                {
                    LocationJerkModelExtended location = new LocationJerkModelExtended
                    {
                        Latitude    = queriedData.Latitude,
                        Longitude   = queriedData.Longitude,
                        Status      = queriedData.Status,
                        Altitude    = queriedData.Altitude,
                        DeviceList  = queriedData.DeviceList,
                        NoOfDevices = queriedData.DeviceList.Count
                    };

                    return(location);
                }
            }

            return(null);
        }
コード例 #2
0
        public async Task <ActionResult> GetLocationProperties(double?latitude, double?longitude)
        {
            LocationJerkModelExtended location = await _locationJerkLogic.GetLocationDetails(latitude, longitude);

            LocationPropertiesModel locationModel = CreateViewModelFromLocationJerk(location);

            return(PartialView("_LocationProperties", locationModel));
        }
コード例 #3
0
        private LocationPropertiesModel CreateViewModelFromLocationJerk(LocationJerkModelExtended locationJerkModel)
        {
            LocationPropertiesModel model = new LocationPropertiesModel();

            model.JsonList    = JsonConvert.SerializeObject(locationJerkModel.DeviceList);
            model.NoOfDevices = locationJerkModel.NoOfDevices;
            model.Latitude    = locationJerkModel.Latitude;
            model.Longitude   = locationJerkModel.Longitude;
            model.Altitude    = locationJerkModel.Altitude;

            //if (locationJerkModel.Latitude != null)
            //{
            //    model.Latitude = locationJerkModel.Latitude.ToString();
            //}

            //if (locationJerkModel.Longitude != null)
            //{
            //    model.Longitude = locationJerkModel.Longitude.ToString();
            //}

            //if (locationJerkModel.Altitude != null)
            //{
            //    model.Altitude = locationJerkModel.Altitude.ToString();
            //}

            switch (locationJerkModel.Status)
            {
            case LocationStatus.Critical:
                model.Status = "Road Condition Critical.";
                break;

            case LocationStatus.Caution:
                model.Status = "Bad Road, proceed with Caution.";
                break;

            default:
                model.Status = "Road Fixed";
                break;
            }

            return(model);
        }
コード例 #4
0
        public async Task <HttpResponseMessage> GetJerkGraphData(string deviceId, string latitude, string longitude)
        {
            return(await GetServiceResponseAsync <LocationReportGraphPaneDataModel>(async() =>
            {
                double lat;
                double lng;
                LocationReportGraphPaneDataModel dataModel = null;
                if (Double.TryParse(latitude, out lat) && Double.TryParse(longitude, out lng) && !String.IsNullOrEmpty(deviceId))
                {
                    LocationJerkModelExtended locationJerkModel = await _locationJerkLogic.GetLocationDetails(lat as double?, lng as double?);
                    if (locationJerkModel.DeviceList != null)
                    {
                        DeviceJerkModel jerkModel = locationJerkModel.DeviceList.Where(d => d.DeviceId == deviceId).FirstOrDefault();

                        dataModel = new LocationReportGraphPaneDataModel()
                        {
                            DeviceId = jerkModel.DeviceId,
                            Speed = jerkModel.Speed,
                            Heading = jerkModel.Heading
                        };

                        IList <LocationJerkGraphFieldModel> graphFields = ExtractLocationJerkGraphFields();
                        dataModel.LocationJerkGraphFields = graphFields != null ? graphFields.ToArray() : null;

                        IEnumerable <LocationJerkGraphModel> graphModels = GetLocationJerkGraphModels(jerkModel.CapturedJerks);

                        if (graphModels == null)
                        {
                            dataModel.LocationJerkGraphModels = new LocationJerkGraphModel[0];
                        }
                        else
                        {
                            dataModel.LocationJerkGraphModels = graphModels.OrderBy(t => t.Timestamp).ToArray();
                        }
                    }
                }
                return dataModel;
            }, false));
        }