Last active
April 26, 2022 08:19
-
-
Save tkreuder/f6ccda8e82f0796c952df695c932b0f8 to your computer and use it in GitHub Desktop.
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
abstract class FooBar {} | |
// 1. What is this? | |
// 2. How would you use this abstract class? | |
// 3. How can you inherit from it? | |
// 4. How can you get the actual instance, when the app is running? | |
// 5. Do you know other ways of sharing code? | |
class STMResult {} | |
class Database {} | |
class DataBaseHelper {} | |
class Logger {} | |
var logger = Logger(); | |
// 1. Explain what this code is doing | |
// 2. Would you change something about it? | |
// 3. How would you test this method? | |
// 4. What could happen, when you run this with thousands of entries | |
Future<STMResult?> getSTMResult({required String patientId, required String id}) async { | |
try { | |
final Database database = await DatabaseHelper.instance.database; | |
logger.d('querying all stm results'); | |
final List<Map<String, dynamic>> queryResult = await database.query(STMResult.table_name); | |
logger.d('received query result with ${queryResult.length} items'); | |
return queryResult | |
.map((Map<String, dynamic> singleEntryMap) => STMResult.fromMap(singleEntryMap)) | |
.toList() | |
.firstWhere((element) => element.patientId == patientId && element.id == id); | |
} catch (exception) { | |
logger.d('no stm result exists for patient-id: $patientId and id: $id'); | |
return null; | |
} | |
} | |
// What is happening here? | |
Stream<Map<String, String>> startScanSensors([int? maxCount]) { | |
int counter = 0; | |
final StreamController<Map<String, String>> controller = | |
StreamController<Map<String, String>>(onListen: null, onPause: null, onResume: null, onCancel: null); | |
sensorFoundCallback = (Map<dynamic, dynamic>? values) { | |
final Map<String, String> result = Map<String, String>.from(values!); | |
counter++; | |
controller.add(result); | |
if (counter == maxCount) { | |
controller.close(); | |
} | |
}; | |
unawaited(_getArguments()); | |
unawaited(_channel.invokeMethod<Map<String, String>>('startScanSensors')); | |
return controller.stream; | |
} | |
// What is happening here? | |
Future<Map<String, BleResponseCode>> get stopLongTermMeasurement async { | |
_stopLongTermMeasurementCompleter = Completer<Map<String, BleResponseCode>>(); | |
// ignore: unawaited_futures | |
_sensorWithResponseCode('stopLongTermMeasurement').then((Map<String, BleResponseCode> value) { | |
if (!_stopLongTermMeasurementCompleter.isCompleted) { | |
_stopLongTermMeasurementCompleter.complete(value); | |
} | |
}); | |
return _stopLongTermMeasurementCompleter.future; | |
} | |
// What is happening here? | |
Future<void> sensorsInitialized() async { | |
if (_isSensorInitialized) { | |
return; | |
} | |
await _mutex.protect(() async { | |
logger.i('awaiting sensors to be initialized'); | |
await databaseHelper.database; | |
final StudyParticipantInformation? studyParticipantInformation = await studyParticipantService | |
.currentStudyParticipant() | |
.firstWhere((StudyParticipantInformation? element) => element != null); | |
if (studyParticipantInformation == null) { | |
const String message = 'studyParticipantInformation cannot be null'; | |
logger.e(message); | |
throw Exception(message); | |
} | |
await SensorInitializationService.instance(plugin: blePluginInstance) | |
.initializeSensorIfNecessary(studyParticipantInformation.studyParticipant, pluginLocalization()); | |
logger.i('sensors are initialized'); | |
_isSensorInitialized = true; | |
}); | |
} | |
void main() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment