public async Task <IHttpActionResult> GetLocation(int id) { SpacesHandler SH = new SpacesHandler(db); TrackerLocationsHandler TLH = new TrackerLocationsHandler(db); StoreysHandler StH = new StoreysHandler(db); TrackerLocation loc = TLH.GetTrackerLocation(id); Dictionary <string, double> Options = new Dictionary <string, double>(); Stream stream = new MemoryStream(loc.Options); BinaryFormatter binfor = new BinaryFormatter(); Options = (Dictionary <string, double>)binfor.Deserialize(stream); List <Option> options = new List <Option>(); foreach (KeyValuePair <string, double> kv in Options) { Space space = SH.GetSpace(Guid.Parse(kv.Key)); Guid spaceID = space.ID; Guid storeyID = space.Storey.ID; Guid buildingID = space.Storey.Building.ID; Option option = new Option(spaceID, storeyID, buildingID, kv.Value); options.Add(option); } KeyValuePair <DateTime, List <Option> > result = new KeyValuePair <DateTime, List <Option> >(loc.TimeStamp, options); return(Json(result)); }
public TrackerLocation GetTrackerLocation(int id) { var trackerLoc = from b in db.TrackerLocations where b.Tracker.ID == id select b; var trackerLocation = trackerLoc.OrderByDescending(x => x.TimeStamp).First(); TrackerLocation result = new TrackerLocation(trackerLocation.TimeStamp, trackerLocation.Options, trackerLocation.Tracker); return(result); }
public async Task <IHttpActionResult> PostLocation() { DateTime time = DateTime.Now; TrackersHandler TH = new TrackersHandler(db); TrackerLocationsHandler TLH = new TrackerLocationsHandler(db); SpacesHandler SH = new SpacesHandler(db); KnnsHandler KH = new KnnsHandler(db); string resultString = Request.Content.ReadAsStringAsync().Result.Trim(); KeyValuePair <int, KeyValuePair <Guid, List <double> > > coordinates = LocationParser(resultString); Knn Knn = KH.GetKnn(coordinates.Value.Key); byte[] options = Classify.ClassifyTemplate(coordinates.Value.Value, Knn); Tracker tracker = TH.GetTracker(coordinates.Key); TrackerLocation loc = new TrackerLocation(time, options, tracker); TLH.PostTrackerLocation(loc); return(Ok(Classify.ClassifyTemplate(coordinates.Value.Value, Knn))); }
public void PostTrackerLocation(TrackerLocation loc) { db.TrackerLocations.Add(loc); db.SaveChangesAsync(); }