private static int DataPointSorter(DataPoint d1, DataPoint d2) { if (d1.Time > d2.Time) return 1; if (d1.Time < d2.Time) return -1; return 0; }
public static List<DataPoint> GenerateDataInBetweenPoints(DataPoint p1, DataPoint p2) { int randomStay1 = Random.Next(3600 / 5, 36000 / 5); int randomStay2 = Random.Next(3600 / 5, 36000 / 5); double distance = GetDistanceInKm(p1.Location, p2.Location); double speed = 6; if (distance < 2) { speed = new Random(Seed).Next(2, 10); } else if (distance > 10) { speed = Random.Next(30, 80); } else { speed = Random.Next(20, 50); } int time = (int)(distance / speed) * (3600 / 5); double latDelta = (p1.Location.Lat - p2.Location.Lat) / (double)time; double longDelta = (p1.Location.Lng - p2.Location.Lng) / (double)time; List<DataPoint> dataPoints = new List<DataPoint>(); for (int i = 0; i < randomStay1; i++) { DataPoint dataPoint = new DataPoint() { UserId = p1.UserId, Location = new Location(p1.Location.Lat, p1.Location.Lng), DataType = DataType.FakeStay, MoveHint = 0 }; dataPoint.WifiLocation = PerturbDataPointForWifi(p1.Location); dataPoint.GSMLocation = PerturbDataPointForGSM(p1.Location); dataPoints.Add(dataPoint); } /* Interpolation */ for (int i = 1; i <= time; i += 10) { double lat = p1.Location.Lat + (i * latDelta); double lng = p1.Location.Lng + (i * longDelta); DataPoint dataPoint = new DataPoint() { UserId = p1.UserId, Location = new Location(lat, lng), DataType = DataType.FakeMove, MoveHint = 1 }; dataPoint.WifiLocation = PerturbDataPointForWifi(p1.Location); dataPoint.GSMLocation = PerturbDataPointForGSM(p1.Location); dataPoints.Add(dataPoint); } for (int i = 0; i < randomStay2; i++) { DataPoint dataPoint = new DataPoint() { UserId = p2.UserId, Location = new Location(p2.Location.Lat, p2.Location.Lng), DataType = DataType.FakeStay, MoveHint = (i == 0) ? 1 : 0 }; dataPoint.WifiLocation = PerturbDataPointForWifi(p2.Location); dataPoint.GSMLocation = PerturbDataPointForGSM(p2.Location); dataPoints.Add(dataPoint); } return dataPoints; }
/* File IO routines */ public static List<List<DataPoint>> ReadData(int userIndex) { List<List<DataPoint>> data = new List<List<DataPoint>>(); string[] userDirs = Directory.GetDirectories(BaseDir); string user = userDirs[userIndex]; string trajectoryDir = Path.Combine(userDirs[userIndex], "Trajectory"); string[] trajectories = Directory.GetFiles(trajectoryDir); for (int j = 0; j < trajectories.Length; j++) { List<DataPoint> dataPoints = new List<DataPoint>(); StreamReader sr = new StreamReader(trajectories[j]); for (int k = 0; k < 6; k++) sr.ReadLine(); while (true) { string line = sr.ReadLine(); if (line == null) break; string[] splits = line.Split(new char[] { ',' }); DataPoint dataPoint = new DataPoint() { UserId = user, Location = new Location(Convert.ToDouble(splits[0]), Convert.ToDouble(splits[1])), DataType = DataType.Original, MoveHint = 1 }; dataPoint.WifiLocation = PerturbDataPointForWifi(dataPoint.Location); dataPoint.GSMLocation = PerturbDataPointForGSM(dataPoint.Location); dataPoints.Add(dataPoint); } sr.Close(); data.Add(dataPoints); } return data; }