Skip to content

Commit

Permalink
mobility_features 6.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bardram committed Sep 26, 2024
1 parent d586552 commit e51bcab
Show file tree
Hide file tree
Showing 32 changed files with 723 additions and 785 deletions.
116 changes: 61 additions & 55 deletions packages/mobility_features/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,120 +1,126 @@
## 6.0.0

* using carp_serialization for JSON serialization resulting in a new JSON schema for serialization
* upgrade of example app to use new Flutter Android Gradle build setup
* improvements of code structure and documentation

## 5.0.0

- upgrade to Dart 3.2 and Flutter 3.16
- improvements to API docs
- improvements to example apps (permissions - PR [#971](https://github.com/cph-cachet/flutter-plugins/pull/971)).
* upgrade to Dart 3.2 and Flutter 3.16
* improvements to API docs
* improvements to example apps (permissions - PR [#971](https://github.com/cph-cachet/flutter-plugins/pull/971)).

## 4.0.1

- Fixed formatting
- Lowered minSdk
* Fixed formatting
* Lowered minSdk

## 4.0.0

- Updated kotlin and AGP
- Upgraded example app to `carp_background_location` 4.0.0
- Implemented minor fixes
* Updated kotlin and AGP
* Upgraded example app to `carp_background_location` 4.0.0
* Implemented minor fixes

## 3.1.0

- improvement to `MobilityContext` API.
- misc updates to documentation.
* improvement to `MobilityContext` API.
* misc updates to documentation.

## 3.0.0+2

- update to null-safety
- rename of `MobilityFactory` to `MobilityFeatures`and using the standard Dart singleton syntax for `MobilityFeatures()`.
- misc updates to documentation
* update to null-safety
* rename of `MobilityFactory` to `MobilityFeatures`and using the standard Dart singleton syntax for `MobilityFeatures()`.
* misc updates to documentation

## 2.0.6+1

- removal of exception
- update to use `carp_background_location`
* removal of exception
* update to use `carp_background_location`

## 2.0.5

- Documentation
- Added images and changed documentation somewhat
* Documentation
* Added images and changed documentation somewhat

## 2.0.4

- Move Consolidation
- Moves are now recomputed each time a stop is computed
- This means that the number of moves is always one less that the number of stops
* Move Consolidation
* Moves are now recomputed each time a stop is computed
* This means that the number of moves is always one less that the number of stops

## 2.0.3

- Move Calculation
- Fixed a bug when creating moves between two stops belonging to the same place
- To avoid inaccuracy distance as a resulting of noisy readings when inside buildings, this path should be computed as a straight line, rather than from a list of points
* Move Calculation
* Fixed a bug when creating moves between two stops belonging to the same place
* To avoid inaccuracy distance as a resulting of noisy readings when inside buildings, this path should be computed as a straight line, rather than from a list of points

## 2.0.2

- Stop merging
- Implemented stop merging to prevent gaps in the data
- This was especially a problem on iOS devices during the night, where location sampling is automatically limited by the OS
- Gaps in the data during the night would cause the home stay feature to be very unreliable
* Stop merging
* Implemented stop merging to prevent gaps in the data
* This was especially a problem on iOS devices during the night, where location sampling is automatically limited by the OS
* Gaps in the data during the night would cause the home stay feature to be very unreliable

## 2.0.1

- Stream-based API
- Removed Routine Index temporarily
* Stream-based API
* Removed Routine Index temporarily

## 2.0.0

- Stream-based API
- The API is now fully streaming-based.
* Stream-based API
* The API is now fully streaming-based.

## 1.3.4

- Flushing data
- Fixed an error where location samples were being flushed when they shouldn't
* Flushing data
* Fixed an error where location samples were being flushed when they shouldn't

## 1.3.3

- Dependencies
- Updated dependencies
* Dependencies
* Updated dependencies

## 1.3.2

- Streaming based API
- Renamed GeoPosition to GeoLocation due to naming conflicts with another package.
* Streaming based API
* Renamed GeoPosition to GeoLocation due to naming conflicts with another package.

## 1.3.0

- Streaming based API
- Refactored API to support streaming
- An example app is now included
* Streaming based API
* Refactored API to support streaming
* An example app is now included

## 1.2.0

- Restructuring
- MobilitySerializer is now private.
* Restructuring
* MobilitySerializer is now private.

## 1.1.5

- Major refactoring
- Renamed and refactored classes such as Location and SingleLocationPoint to GeoPosition and LocationSample respectively.
* Major refactoring
* Renamed and refactored classes such as Location and SingleLocationPoint to GeoPosition and LocationSample respectively.

## 1.1.0

- Private classes
- Made a series of classes private such that they cannot be instantiated from outside the package
* Private classes
* Made a series of classes private such that they cannot be instantiated from outside the package

## 1.0.0

- Formatting
- Fixed a series of formatting issues which caused the package to score lower on pub.dev
- Upgraded the release number to 1.x.x to increase the package score on pub.dev
* Formatting
* Fixed a series of formatting issues which caused the package to score lower on pub.dev
* Upgraded the release number to 1.x.x to increase the package score on pub.dev

## 0.1.5

- Private constructor.
- The Mobility Context constructor is now private
- A Mobility Context should always be instantiated via the ContextGenerator class.
* Private constructor.
* The Mobility Context constructor is now private
* A Mobility Context should always be instantiated via the ContextGenerator class.

## 0.1.0

- First release.
- The first official release with working unit tests
- Includes a minimalistic API which allows the application programmer to generate features with very few lines of code.
* First release.
* The first official release with working unit tests
* Includes a minimalistic API which allows the application programmer to generate features with very few lines of code.
57 changes: 23 additions & 34 deletions packages/mobility_features/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Read more on the [theoretical background](#theoretical-background) on these mobi

The Mobility Features package is designed to work independent of the location plugin. You may choose you own location plugin, since you may already use this in your app.

In the example app we use our own plugin [`carp_background_location`](https://pub.dev/packages/carp_background_location) which works on both Android and iOS as of August 2020. However, the [location](https://pub.dev/packages/location) plugin will also work. The important thing, however, is to make sure that the app runs in the background. On Android this is tied to running the app as a foreground service.
In the example app we use our own plugin [carp_background_location](https://pub.dev/packages/carp_background_location) which works on both Android and iOS as of August 2020. However, the [location](https://pub.dev/packages/location) plugin will also work. The important thing, however, is to make sure that the app runs in the background. On Android this is tied to running the app as a foreground service.

Add the package to your `pubspec.yaml` file and import the package

Expand Down Expand Up @@ -62,22 +62,18 @@ For example, given a low stop duration, stopping for a red light in traffic will

### Step 2 - Set up location streaming

Collection of location data is not directly supported by this package, for this you have to use a location plugin such as [`carp_background_location`](https://pub.dev/packages/carp_background_location). You can to convert from whichever location object is used by the location plugin to a `LocationSample` object.
Next, you can start listening to location updates and subscribe to the `MobilityFeatures()`'s `contextStream` to be be notified each time a new set of features has been computed.
Collection of location data is not directly supported by this package, for this you have to use a location plugin such as [carp_background_location](https://pub.dev/packages/carp_background_location). You can to convert from whichever location object is used by the location plugin to a `LocationSample` object.
Next, you can start listening to location updates and subscribe to the `contextStream` to be be notified each time a new set of features has been computed.

Below is shown an example using the [`carp_background_location`](https://pub.dev/packages/carp_background_location) plugin, where a `LocationDto` stream is converted into a `LocationSample` stream by using a map-function.
Below is shown an example using the [carp_background_location](https://pub.dev/packages/carp_background_location) plugin, where a `LocationDto` stream is converted into a `LocationSample` stream by using a map-function.

```dart
/// Set up streams:
/// * Location streaming to MobilityContext
/// * Subscribe to MobilityContext updates
/// * Location streaming to MobilityContext
/// * Subscribe to MobilityContext updates
void streamInit() async {
locationStream = LocationManager().locationStream;
// subscribe to location stream - in case this is needed in the app
if (locationSubscription != null) locationSubscription.cancel();
locationSubscription = locationStream.listen(onLocationUpdate);
// start the location service (specific to carp_background_location)
await LocationManager().start();
Expand All @@ -94,14 +90,9 @@ Below is shown an example using the [`carp_background_location`](https://pub.dev
mobilitySubscription =
MobilityFeatures().contextStream.listen(onMobilityContext);
}
/// Called whenever location changes.
void onLocationUpdate(LocationDto dto) {
print(dtoToString(dto));
}
```

> **Note** that access to location data needs permissions from the OS. This is **not** handled by the plugin but should be handled on an app-level. See the example app for this. Note also, that permissions for access location "ALWAYS" needs to be granted by the user in order to collect location information in the background.
> **NOTE** that access to location data needs permissions from the OS. This is **NOT** handled by the plugin but should be handled on an app-level. See the example app for this. Note also, that permissions for access location "ALWAYS" needs to be granted by the user in order to collect location information in the background.
### Step 3 - Listen to mobility features

Expand All @@ -115,20 +106,21 @@ void onMobilityContext(MobilityContext context) {
}
```

All the mobility features are accessible in the `MobilityContext` object:

```dart
/// Location features
context.places;
context.stops;
context.moves;
/// Derived features
context.numberOfSignificantPlaces;
context.homeStay;
context.entropy;
context.normalizedEntropy;
context.distanceTraveled;
Mobility features are accessible in the `MobilityContext` object which can be serialized to JSON using the `toJson()` method:

```json
{
"timestamp": "2024-09-26T10:56:21.397768",
"date": "2020-01-01T00:00:00.000",
"numberOfStops": 2,
"numberOfMoves": 1,
"numberOfSignificantPlaces": 2,
"locationVariance": 0.00011097661986704458,
"entropy": 0.6365141682948128,
"normalizedEntropy": 0.9182958340544894,
"homeStay": 0.64,
"distanceTraveled": 0.0
}
```

## Feature errors
Expand All @@ -145,10 +137,7 @@ For example:
The example application included in the package shows the feature values, including separate pages for stops, moves and places.
It also illustrates how to ask the user for permissions to access location data, also when the app is in the background.

![mobility_app_1](https://raw.githubusercontent.com/cph-cachet/flutter-plugins/master/packages/mobility_features/images/features.jpeg)
![mobility_app_2](https://raw.githubusercontent.com/cph-cachet/flutter-plugins/master/packages/mobility_features/images/stops.jpeg)
![mobility_app_3](https://raw.githubusercontent.com/cph-cachet/flutter-plugins/master/packages/mobility_features/images/places.jpeg)
![mobility_app_4](https://raw.githubusercontent.com/cph-cachet/flutter-plugins/master/packages/mobility_features/images/moves.jpeg)
![mobility_app_1](https://raw.githubusercontent.com/cph-cachet/flutter-plugins/master/packages/mobility_features/images/app.jpeg)

## Theoretical Background

Expand Down
63 changes: 22 additions & 41 deletions packages/mobility_features/example/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,63 +1,44 @@
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
plugins {
id "com.android.application"
id "kotlin-android"
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
id "dev.flutter.flutter-gradle-plugin"
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 33
namespace = "com.example.example"
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

lintOptions {
disable 'InvalidPackage'
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.example"
minSdkVersion 23
targetSdkVersion 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
applicationId = "com.example.example"
// You can update the following values to match your application needs.
// For more information, see: https://flutter.dev/to/review-gradle-config.
minSdk = 23
targetSdk = flutter.targetSdkVersion
versionCode = flutter.versionCode
versionName = flutter.versionName
}

buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
signingConfig = signingConfigs.debug
}
}
}

flutter {
source '../..'
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
source = "../.."
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
FlutterApplication and put your custom class here. -->

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
Expand Down
13 changes: 0 additions & 13 deletions packages/mobility_features/example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
buildscript {
ext.kotlin_version = '1.7.10'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.3.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

allprojects {
repositories {
google()
Expand Down
Loading

0 comments on commit e51bcab

Please sign in to comment.