-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cc13e18
commit cdc679d
Showing
15 changed files
with
541 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_blue","path":"C:\\\\Users\\\\maxim\\\\Programming\\\\SDKs\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_blue-0.7.2\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\Users\\\\maxim\\\\Programming\\\\SDKs\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-2.0.1\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\Users\\\\maxim\\\\Programming\\\\SDKs\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-2.0.0+3\\\\","dependencies":[]}],"android":[{"name":"flutter_blue","path":"C:\\\\Users\\\\maxim\\\\Programming\\\\SDKs\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_blue-0.7.2\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\Users\\\\maxim\\\\Programming\\\\SDKs\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-2.0.1\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\Users\\\\maxim\\\\Programming\\\\SDKs\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-2.0.0+3\\\\","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"C:\\\\Users\\\\maxim\\\\Programming\\\\SDKs\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_macos-2.0.0\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\Users\\\\maxim\\\\Programming\\\\SDKs\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-2.0.0+3\\\\","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"C:\\\\Users\\\\maxim\\\\Programming\\\\SDKs\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_linux-2.0.0\\\\","dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"C:\\\\Users\\\\maxim\\\\Programming\\\\SDKs\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_windows-2.0.0\\\\","dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"flutter_blue","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos","path_provider_linux","path_provider_windows"]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2021-03-24 17:32:08.890493","version":"2.0.3"} | ||
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_blue","path":"C:\\\\Users\\\\maxim\\\\Programming\\\\SDKs\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_blue-0.7.2\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\Users\\\\maxim\\\\Programming\\\\SDKs\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-2.0.1\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\Users\\\\maxim\\\\Programming\\\\SDKs\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-2.0.0+3\\\\","dependencies":[]}],"android":[{"name":"flutter_blue","path":"C:\\\\Users\\\\maxim\\\\Programming\\\\SDKs\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_blue-0.7.2\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\Users\\\\maxim\\\\Programming\\\\SDKs\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-2.0.1\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\Users\\\\maxim\\\\Programming\\\\SDKs\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-2.0.0+3\\\\","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"C:\\\\Users\\\\maxim\\\\Programming\\\\SDKs\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_macos-2.0.0\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\Users\\\\maxim\\\\Programming\\\\SDKs\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-2.0.0+3\\\\","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"C:\\\\Users\\\\maxim\\\\Programming\\\\SDKs\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_linux-2.0.0\\\\","dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"C:\\\\Users\\\\maxim\\\\Programming\\\\SDKs\\\\Flutter\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_windows-2.0.0\\\\","dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"flutter_blue","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos","path_provider_linux","path_provider_windows"]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2021-03-29 17:49:15.960154","version":"2.0.3"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
173 changes: 173 additions & 0 deletions
173
Mobile_app/smart_mask/lib/src/logic/blocs/analytics/analytics_bloc.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
// Sensor Data Business Logic (BLoc) provider | ||
// | ||
// Description: | ||
// | ||
|
||
import 'dart:async'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:rxdart/rxdart.dart'; | ||
import 'package:smart_mask/src/logic/database/models/sensor_model.dart'; | ||
import 'package:smart_mask/src/logic/repositories/sensor_data_repo.dart'; | ||
|
||
class AnalyticsBloc { | ||
final _sensorDataRepo = SensorDataRepository(); | ||
Sensor _selectedSensor = Sensor.sensor_1; | ||
AnalyticsState _analyticsState = AnalyticsState(); | ||
|
||
BehaviorSubject<Sensor> _selectedSensorSubject; | ||
BehaviorSubject<TimeInterval> _timeRangeSubject; | ||
BehaviorSubject<List<SensorData>> _sensorDataProcessedSubject; | ||
BehaviorSubject<bool> _analyticsRefresh; | ||
|
||
AnalyticsBloc() { | ||
_selectedSensorSubject = BehaviorSubject<Sensor>(); | ||
_timeRangeSubject = BehaviorSubject<TimeInterval>(); | ||
_sensorDataProcessedSubject = BehaviorSubject<List<SensorData>>(); | ||
_analyticsRefresh = BehaviorSubject<bool>(); | ||
_analyticsRefresh.stream.listen((event) => processAnalytics()); | ||
setSelectedSensor(_selectedSensor); | ||
} | ||
|
||
processAnalytics() { | ||
print(_analyticsState.toString()); | ||
} | ||
|
||
Future<TimeInterval> getAvailableInterval() async { | ||
var start = await _sensorDataRepo.getEarliestSensorData(_selectedSensor); | ||
var end = await _sensorDataRepo.getLatestSensorData(_selectedSensor); | ||
var startDate = DateTime.fromMillisecondsSinceEpoch(start.timeStamp); | ||
var endDate = DateTime.fromMillisecondsSinceEpoch(end.timeStamp); | ||
return TimeInterval(startDate, endDate); | ||
} | ||
|
||
getSensorData(TimeInterval interval) async { | ||
List<SensorData> sensorData = await _sensorDataRepo.getSensorData( | ||
_selectedSensor, | ||
interval: [interval.start, interval.end], | ||
); | ||
_sensorDataProcessedSubject.sink.add(sensorData); | ||
} | ||
|
||
Stream<List<SensorData>> getSensorDataStream() { | ||
return _sensorDataProcessedSubject.stream; | ||
} | ||
|
||
Stream<TimeInterval> get timeRangeStream => _timeRangeSubject.stream; | ||
|
||
set timeRange(TimeInterval interval) { | ||
_timeRangeSubject.add(interval); | ||
getSensorData(interval); | ||
} | ||
|
||
void setSelectedSensor(Sensor sensor) { | ||
_selectedSensorSubject.add(sensor); | ||
} | ||
|
||
Stream<Sensor> getSelectedSensorStream() { | ||
return _selectedSensorSubject.stream; | ||
} | ||
|
||
Stream<bool> getAnalyticsRefreshStream() { | ||
return _analyticsRefresh.stream; | ||
} | ||
|
||
triggerAnalyticsRefresh() { | ||
_analyticsRefresh.add(true); | ||
} | ||
|
||
setLowPassFilter(double value) { | ||
_analyticsState.lowPassFilter = value; | ||
triggerAnalyticsRefresh(); | ||
} | ||
|
||
setHighPassFilter(double value) { | ||
_analyticsState.highPassFilter = value; | ||
triggerAnalyticsRefresh(); | ||
} | ||
|
||
setTime(int value) { | ||
_analyticsState.time = value; | ||
triggerAnalyticsRefresh(); | ||
} | ||
|
||
increaseZoomLevel() { | ||
_analyticsState.zoomLevel += 1; | ||
triggerAnalyticsRefresh(); | ||
} | ||
|
||
decreaseZoomLevel() { | ||
_analyticsState.zoomLevel -= 1; | ||
triggerAnalyticsRefresh(); | ||
} | ||
|
||
dispose() { | ||
_sensorDataProcessedSubject.close(); | ||
_selectedSensorSubject.close(); | ||
_timeRangeSubject.close(); | ||
} | ||
} | ||
|
||
class TimeInterval { | ||
DateTime start; | ||
DateTime end; | ||
|
||
TimeInterval(this.start, this.end); | ||
|
||
factory TimeInterval.fromMsSinceEpoch(RangeValues range) { | ||
DateTime dateStart = | ||
DateTime.fromMicrosecondsSinceEpoch(range.start.toInt()); | ||
DateTime dateEnd = DateTime.fromMicrosecondsSinceEpoch(range.end.toInt()); | ||
return TimeInterval(dateStart, dateEnd); | ||
} | ||
} | ||
|
||
class AnalyticsState { | ||
int _time; | ||
int _zoomLevel; | ||
double _lowPassFilter; | ||
double _highPassFilter; | ||
|
||
AnalyticsState() { | ||
_time = DateTime.now().millisecondsSinceEpoch; | ||
_zoomLevel = 0; | ||
_lowPassFilter = 100.0; | ||
_highPassFilter = 0.2; | ||
} | ||
|
||
double get lowPassFilter => _lowPassFilter; | ||
|
||
set lowPassFilter(double value) { | ||
if (value < 0 || value <= _highPassFilter || value > 10000) return; | ||
_lowPassFilter = value; | ||
} | ||
|
||
double get highPassFilter => _highPassFilter; | ||
|
||
set highPassFilter(double value) { | ||
if (value < 0 || value >= _lowPassFilter || value > 10000) return; | ||
_highPassFilter = value; | ||
} | ||
|
||
int get time => _time; | ||
|
||
set time(int value) { | ||
int nowMs = DateTime.now().millisecondsSinceEpoch; | ||
int nowMinus1monthMs = | ||
DateTime.now().subtract(Duration(days: 30)).millisecondsSinceEpoch; | ||
if (value > nowMs || value < nowMinus1monthMs) return; | ||
_time = value; | ||
} | ||
|
||
int get zoomLevel => _zoomLevel; | ||
|
||
set zoomLevel(int value) { | ||
if (value < 0 || value > 15) return; | ||
_zoomLevel = value; | ||
} | ||
|
||
@override | ||
String toString() { | ||
return "Analytics State ${DateTime.fromMillisecondsSinceEpoch(_time)}, " | ||
"Zoom level : $_zoomLevel, Low pass $_lowPassFilter, High pass $_highPassFilter"; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
Mobile_app/smart_mask/lib/src/logic/blocs/analytics/analytics_provider.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Sensor Data Business Logic (BLoc) provider | ||
// | ||
// Description: | ||
// Enable the Sensor Data bloc to be accessible (provided) | ||
// throughout the app with contex.inherit.. | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:smart_mask/src/logic/blocs/analytics/analytics_bloc.dart'; | ||
|
||
class AnalyticsProvider extends InheritedWidget { | ||
final AnalyticsBloc bloc; | ||
|
||
AnalyticsProvider({Key key, Widget child, this.bloc}) | ||
: super(key: key, child: child); | ||
|
||
bool updateShouldNotify(_) => true; | ||
|
||
static AnalyticsBloc of(BuildContext context) { | ||
return context.dependOnInheritedWidgetOfExactType<AnalyticsProvider>().bloc; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
Mobile_app/smart_mask/lib/src/logic/blocs/sensor_data/sensor_mock.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:smart_mask/src/logic/database/models/sensor_model.dart'; | ||
import 'dart:math'; | ||
|
||
import 'package:smart_mask/src/logic/repositories/sensor_data_repo.dart'; | ||
|
||
class SensorsMock { | ||
final _sensorDataRepo = SensorDataRepository(); | ||
Map<Sensor, int> sensorMockData = Map(); | ||
Random rng; | ||
|
||
Duration addInterval = Duration(milliseconds: 200); | ||
Timer mockTimer; | ||
|
||
SensorsMock() { | ||
rng = Random(); | ||
for (var s in Sensor.values) { | ||
sensorMockData[s] = 0; | ||
} | ||
mockTimer = Timer.periodic(addInterval, (Timer t) => addMockData()); | ||
} | ||
|
||
addMockData() { | ||
for (var s in Sensor.values) { | ||
var rand = rng.nextInt(10); | ||
|
||
if (rng.nextBool()) | ||
sensorMockData[s] += rand; | ||
else | ||
sensorMockData[s] -= rand; | ||
|
||
if (sensorMockData[s] < -3000) sensorMockData[s] = -3000; | ||
if (sensorMockData[s] > 3000) sensorMockData[s] = 3000; | ||
|
||
var sensorData = SensorData.fromSensorAndValue( | ||
s, sensorMockData[s], DateTime.now().millisecondsSinceEpoch); | ||
|
||
_sensorDataRepo.insertSensorData(sensorData); | ||
} | ||
} | ||
|
||
dispose() { | ||
mockTimer.cancel(); | ||
} | ||
} |
Oops, something went wrong.