LCOV - code coverage report
Current view: top level - Users/yeradis/Projects/Garage/dart/stay_points.dart/lib/src/identification/offline - offline_identification.dart (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 18 18 100.0 %
Date: 2017-10-10 20:17:03 Functions: 0 0 -

          Line data    Source code
       1             : import '../model/location.dart';
       2             : import '../model/stay_point.dart';
       3             : import '../model/threshold.dart';
       4             : 
       5             : abstract class OfflineRepository {
       6             :     List<StayPoint> process({Threshold threshold, List<Location> locations});
       7             : }
       8             : 
       9             : class OfflineIdentification implements OfflineRepository {
      10             : 
      11             :     List<StayPoint> process({Threshold threshold, List<Location> locations}) {
      12           1 :         List<StayPoint> result = [];
      13             :         Location locationStart, locationEnd;
      14             :         double distance;
      15             : 
      16             :         int pStart = 0;
      17             :         int pEnd = 0;
      18             : 
      19           1 :         int pCount = locations != null ? locations.length : 0;
      20             : 
      21           1 :         if (pCount <= 1) {
      22           1 :             print("Provided location path is not enough");
      23             :             return result;
      24             :         }
      25             : 
      26           1 :         while (pStart < pCount) {
      27           1 :             pEnd = pStart + 1;
      28             : 
      29           1 :             while (pEnd < pCount) {
      30           1 :                 locationStart = locations[pStart];
      31           1 :                 locationEnd = locations[pEnd];
      32             : 
      33           1 :                 distance = locationStart.distanceTo(locationEnd);
      34           3 :                 bool validated = continueWithCurrent(current: locationEnd, previous: locations[pEnd - 1]);
      35             : 
      36           3 :                 if (validated && distance > threshold.minimumDistance.inMeters) {
      37           1 :                     Duration timespan = locationStart.timeDifference(location: locationEnd);
      38             : 
      39           6 :                     if (timespan.inSeconds.abs() > threshold.minimumTime.inSeconds.abs()) {
      40           2 :                         StayPoint stayPoint = new StayPoint.fromLocations(locationsInvolved:locations.sublist(pStart,pEnd));
      41           1 :                         result.add(stayPoint);
      42             :                     }
      43             : 
      44             :                     pStart = pEnd;
      45             :                     break;
      46             :                 }
      47           1 :                 pEnd += 1;
      48             :             }
      49           1 :             pStart += 1;
      50             :         }
      51             :         return result;
      52             :     }
      53             : 
      54             :     /// used to avoid noise like having the previous location with a a low accuracy
      55             :     /// and the current location with a cell tower accuracy > 1400 meters
      56             :     /// making the process fail because will pass threshold validation when it should not
      57             :     bool continueWithCurrent({Location current,previous}) {
      58             :         // TODO add the accuracy value and find a better way to avoid noise
      59             :         // example: user entered a tunnel and at exit the locations will have some values that
      60             :         // can affect the identification creating a new cluster path
      61             :         // this is a very simple approach, a better one can be:
      62             :         // distance(newLocation,lastLocation) > location accuracy
      63             :         // but this depends on the distance threshold
      64             :         //return lastLocation.horizontalAccuracy + newLocation.horizontalAccuracy < 200
      65             :         return true;
      66             :     }
      67             : }

Generated by: LCOV version 1.13