Exemple #1
0
        public JsonResult GetPathway(string numbers, DateTime timeIntervalsBegin, DateTime timeIntervalsEnd)
        {
            var res = new List <PathwayModel>();

            string[] nums  = numbers.Trim().Split(',');
            int      count = nums.Length;

            var pathData    = PathDataModel.GetAllPathData();
            var gatewayData = GatewayModel.GetAllDevice();

            for (int i = 0; i < count; i++)
            {
                var pathway = new PathwayModel();
                pathway.Number   = nums[i];
                pathway.Gateways = new List <GatewayPathModel>();

                var pData = pathData.Where(x => x.Number == nums[i] && x.Time >= timeIntervalsBegin && x.Time <= timeIntervalsEnd).OrderBy(x => x.Time).ToList();
                foreach (var item in pData)
                {
                    var gateway = GatewayController.Get(item.DeviceId);
                    GatewayPathModel gatewayPath = new GatewayPathModel(gateway.DeviceId, gateway.LAT, gateway.LON, gateway.Address, item.Time);
                    pathway.Gateways.Add(gatewayPath);
                }
                if (pathway.Gateways.Count > 0)
                {
                    res.Add(pathway);
                }
            }

            return(Json(res, JsonRequestBehavior.AllowGet));
        }
Exemple #2
0
        public JsonResult GetNearbyGateways(string deviceId, double radius = 200)
        {
            GatewayModel        gateway = Get(deviceId);
            List <GatewayModel> devices = GatewayModel.GetAllDevice();
            List <GatewayModel> res     = new List <GatewayModel>();

            double xx1, yy1;

            double.TryParse(gateway.LON, out xx1);
            double.TryParse(gateway.LAT, out yy1);

            foreach (var device in devices)
            {
                double xx2, yy2;
                if (double.TryParse(device.LON, out xx2) && double.TryParse(device.LAT, out yy2))
                {
                    if (Distance.GetDistance("baidu", yy2, xx2, yy1, xx1) <= radius && device.DeviceId.ToLower() != deviceId.ToLower())
                    {
                        res.Add(device);
                    }
                }
            }

            return(Json(new { Center = gateway, Nearby = res }, JsonRequestBehavior.AllowGet));
        }
Exemple #3
0
        public JsonResult GetDrawGateway(decimal x1, decimal y1, decimal x2, decimal y2)
        {
            //所有网关
            List <GatewayModel> devices = GatewayModel.GetAllDevice();

            //在矩形区域内的网关
            List <GatewayModel> innerDevices = new List <GatewayModel>();

            for (int i = 0; i < devices.Count; i++)
            {
                decimal xx1, xx2, yy1, yy2;
                if (decimal.TryParse(devices[i].LON, out xx1) && decimal.TryParse(devices[i].LON, out xx2) && decimal.TryParse(devices[i].LAT, out yy1) && decimal.TryParse(devices[i].LAT, out yy2))
                {
                    if (xx1 >= x1 && xx2 <= x2 && yy1 >= y1 && yy2 <= y2)
                    {
                        innerDevices.Add(devices[i]);
                    }
                }
            }

            return(Json(innerDevices, JsonRequestBehavior.AllowGet));
        }
Exemple #4
0
 public static GatewayModel Get(string id)
 {
     return(GatewayModel.GetAllDevice().Where(x => x.DeviceId == id).FirstOrDefault());
 }
Exemple #5
0
        public JsonResult GetAllGateway()
        {
            List <GatewayModel> list = GatewayModel.GetAllDevice();

            return(Json(list, JsonRequestBehavior.AllowGet));
        }