Skip to content

Commit

Permalink
fix of bug in data viz #204
Browse files Browse the repository at this point in the history
  • Loading branch information
bardram committed Jan 11, 2024
1 parent 7d5524e commit 39228cc
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 102 deletions.
3 changes: 2 additions & 1 deletion android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
android.useAndroidX=true
android.enableR8=true
12 changes: 7 additions & 5 deletions lib/blocs/app_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ enum StudyAppState {
class StudyAppBLoC {
StudyAppState _state = StudyAppState.created;
final CarpBackend _backend = CarpBackend();
final CarpStudyAppViewModel _data = CarpStudyAppViewModel();
final CarpStudyAppViewModel _appViewModel = CarpStudyAppViewModel();
StudyDeploymentStatus? _status;
final StreamController<StudiesAppState> _stateStream =
StreamController.broadcast();
Expand Down Expand Up @@ -102,7 +102,7 @@ class StudyAppBLoC {
DateTime? get studyStartTimestamp => deployment?.deployed;

/// The overall data model for this app
CarpStudyAppViewModel get data => _data;
CarpStudyAppViewModel get appViewModel => _appViewModel;
// Future<void>? dataPageInitialization;

/// Initialize this BLOC. Called before being used for anything.
Expand Down Expand Up @@ -149,7 +149,6 @@ class StudyAppBLoC {
if (isConfiguring) return;

stateStream.sink.add(StudiesAppState.configuring);
info('$runtimeType configuring...');

// set up and initialize sensing
await Sensing().initialize();
Expand All @@ -158,7 +157,9 @@ class StudyAppBLoC {
await Sensing().addStudy();

// initialize the UI data models
await data.init(Sensing().controller!);
appViewModel.init(Sensing().controller!);

debug('$runtimeType - done init() of view model');

// set up the messaging part
messageManager.initialize().then(
Expand Down Expand Up @@ -241,7 +242,8 @@ class StudyAppBLoC {
? user!.username
: Sensing().controller!.deployment!.userId!;

/// The name used for friendly greeting - '' if no user logged in.
/// The name used for friendly greeting.
/// Returns an empty string if no user logged in.
String? get friendlyUsername => (user != null) ? user!.firstName : '';

/// Does this [deployment] have any measures?
Expand Down
12 changes: 6 additions & 6 deletions lib/carp_study_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class CarpStudyAppState extends State<CarpStudyApp> {
parentNavigatorKey: _shellNavigatorKey,
pageBuilder: (context, state) => CustomTransitionPage(
child: TaskListPage(
bloc.data.taskListPageViewModel,
bloc.appViewModel.taskListPageViewModel,
),
transitionsBuilder: bottomNavigationBarAnimation,
),
Expand All @@ -58,7 +58,7 @@ class CarpStudyAppState extends State<CarpStudyApp> {
parentNavigatorKey: _shellNavigatorKey,
pageBuilder: (context, state) => CustomTransitionPage(
child: StudyPage(
bloc.data.studyPageViewModel,
bloc.appViewModel.studyPageViewModel,
),
transitionsBuilder: bottomNavigationBarAnimation,
),
Expand All @@ -68,7 +68,7 @@ class CarpStudyAppState extends State<CarpStudyApp> {
parentNavigatorKey: _shellNavigatorKey,
pageBuilder: (context, state) => CustomTransitionPage(
child: DataVisualizationPage(
bloc.data.dataVisualizationPageViewModel),
bloc.appViewModel.dataVisualizationPageViewModel),
transitionsBuilder: bottomNavigationBarAnimation,
),
),
Expand All @@ -84,7 +84,7 @@ class CarpStudyAppState extends State<CarpStudyApp> {
path: '/profile',
parentNavigatorKey: _shellNavigatorKey,
pageBuilder: (context, state) => CustomTransitionPage(
child: ProfilePage(bloc.data.profilePageViewModel),
child: ProfilePage(bloc.appViewModel.profilePageViewModel),
transitionsBuilder: bottomNavigationBarAnimation,
),
),
Expand All @@ -111,7 +111,7 @@ class CarpStudyAppState extends State<CarpStudyApp> {
? firstRoute
: (bloc.studyId == null ? '/invitations' : null),
builder: (context, state) => InformedConsentPage(
bloc.data.informedConsentViewModel,
bloc.appViewModel.informedConsentViewModel,
),
),
GoRoute(
Expand Down Expand Up @@ -139,7 +139,7 @@ class CarpStudyAppState extends State<CarpStudyApp> {
? '/consent'
: (bloc.user == null ? '/login' : null),
builder: (context, state) =>
InvitationListPage(bloc.data.invitationsListViewModel),
InvitationListPage(bloc.appViewModel.invitationsListViewModel),
),
],
debugLogDiagnostics: true,
Expand Down
99 changes: 41 additions & 58 deletions lib/ui/pages/data_visualization_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,61 +14,49 @@ class _DataVisualizationPageState extends State<DataVisualizationPage> {
Widget build(BuildContext context) {
RPLocalizations locale = RPLocalizations.of(context)!;
return Scaffold(
backgroundColor: Theme.of(context).colorScheme.secondary,
body: SafeArea(
child: FutureBuilder(
future: bloc.data._dataVisualizationPageViewModel
.init(Sensing().controller!),
builder: (context, data) {
if (data.connectionState == ConnectionState.waiting) {
return const Center(child: CircularProgressIndicator());
} else {
return Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const CarpAppBar(),
Container(
color: Theme.of(context).colorScheme.secondary,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 15),
child: Align(
alignment: Alignment.centerLeft,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'${locale.translate('pages.data_viz.hello')} ${bloc.friendlyUsername}'
.toUpperCase(),
style: dataCardTitleStyle.copyWith(
color: Theme.of(context).primaryColor),
),
Text(locale.translate('pages.data_viz.thanks'),
style: aboutCardSubtitleStyle),
const SizedBox(height: 15),
],
),
backgroundColor: Theme.of(context).colorScheme.secondary,
body: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const CarpAppBar(),
Container(
color: Theme.of(context).colorScheme.secondary,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 15),
child: Align(
alignment: Alignment.centerLeft,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'${locale.translate('pages.data_viz.hello')} ${bloc.friendlyUsername}'
.toUpperCase(),
style: dataCardTitleStyle.copyWith(
color: Theme.of(context).primaryColor),
),
),
Text(locale.translate('pages.data_viz.thanks'),
style: aboutCardSubtitleStyle),
const SizedBox(height: 15),
],
),
Expanded(
flex: 4,
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: _dataVizCards,
),
),
)
],
);
}
},
),
),
);
),
),
),
Expanded(
flex: 4,
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: _dataVizCards,
),
),
)
],
)));
}

// The list of cards, depending on what measures are defined in the study.
Expand Down Expand Up @@ -109,11 +97,6 @@ class _DataVisualizationPageState extends State<DataVisualizationPage> {
widgets.add(MediaCardWidget(mediaModelsList));
}

// check to show device data visualizations
if (bloc.hasDevices()) {
//TODO ADD DEVICES VIZ?
}

if (bloc.hasMeasure(SensorSamplingPackage.STEP_COUNT)) {
widgets.add(StepsCardWidget(widget.model.stepsCardDataModel));
}
Expand Down
3 changes: 2 additions & 1 deletion lib/ui/widgets/details_banner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class DetailsBanner extends StatelessWidget {
if (imagePath != null && imagePath!.isNotEmpty)
SizedBox(
height: 300,
child: bloc.data.studyPageViewModel.getMessageImage(imagePath),
child:
bloc.appViewModel.studyPageViewModel.getMessageImage(imagePath),
),
Padding(
padding: const EdgeInsets.all(16),
Expand Down
4 changes: 2 additions & 2 deletions lib/view_models/cards/activity_data_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class ActivityCardViewModel extends SerializableViewModel<WeeklyActivities> {
.where((measurement) => measurement.data is Activity);

@override
Future<void> init(SmartphoneDeploymentController ctrl) async {
await super.init(ctrl);
void init(SmartphoneDeploymentController ctrl) {
super.init(ctrl);

// listen for activity events and count the minutes
activityEvents?.listen((measurement) {
Expand Down
4 changes: 2 additions & 2 deletions lib/view_models/cards/heart_rate_data_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class HeartRateCardViewModel extends SerializableViewModel<HourlyHeartRate> {
.where((measurement) => measurement.data is PolarHR);

@override
Future<void> init(SmartphoneDeploymentController ctrl) async {
await super.init(ctrl);
void init(SmartphoneDeploymentController ctrl) {
super.init(ctrl);

heartRateEvents?.listen(
(heartRateDataPoint) {
Expand Down
4 changes: 2 additions & 2 deletions lib/view_models/cards/mobility_data_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class MobilityCardViewModel extends SerializableViewModel<WeeklyMobility> {

MobilityCardViewModel();
@override
Future<void> init(SmartphoneDeploymentController ctrl) async {
await super.init(ctrl);
void init(SmartphoneDeploymentController ctrl) {
super.init(ctrl);

// listen for mobility events and update the features
mobilityEvents?.listen((measurement) {
Expand Down
4 changes: 2 additions & 2 deletions lib/view_models/cards/steps_data_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class StepsCardViewModel extends SerializableViewModel<WeeklySteps> {
.where((dataPoint) => dataPoint.data is StepCount);

@override
Future<void> init(SmartphoneDeploymentController ctrl) async {
await super.init(ctrl);
void init(SmartphoneDeploymentController ctrl) {
super.init(ctrl);

// listen for pedometer events and count them
pedometerEvents?.listen((pedometerDataPoint) {
Expand Down
23 changes: 11 additions & 12 deletions lib/view_models/data_visualization_page_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,18 @@ class DataVisualizationPageViewModel extends ViewModel {
DataVisualizationPageViewModel();

@override
Future<int> init(SmartphoneDeploymentController ctrl) async {
void init(SmartphoneDeploymentController ctrl) {
super.init(ctrl);
await _activityCardDataModel.init(ctrl);
await _stepsCardDataModel.init(ctrl);
await _heartRateCardDataModel.init(ctrl);
await _mobilityCardDataModel.init(ctrl);
await _measuresCardDataModel.init(ctrl);
await _surveysCardDataModel.init(ctrl);
await _audioCardDataModel.init(ctrl);
await _videoCardDataModel.init(ctrl);
await _imageCardDataModel.init(ctrl);
await _studyProgressCardDataModel.init(ctrl);
return 1;
_activityCardDataModel.init(ctrl);
_stepsCardDataModel.init(ctrl);
_heartRateCardDataModel.init(ctrl);
_mobilityCardDataModel.init(ctrl);
_measuresCardDataModel.init(ctrl);
_surveysCardDataModel.init(ctrl);
_audioCardDataModel.init(ctrl);
_videoCardDataModel.init(ctrl);
_imageCardDataModel.init(ctrl);
_studyProgressCardDataModel.init(ctrl);
}

/// Delete all persistent view models.
Expand Down
26 changes: 15 additions & 11 deletions lib/view_models/view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ abstract class ViewModel {

/// Initialize this view model before use.
@mustCallSuper
Future<void> init(SmartphoneDeploymentController ctrl) async {
void init(SmartphoneDeploymentController ctrl) {
debug('$runtimeType - init()');

_controller = ctrl;
}
}
Expand Down Expand Up @@ -43,12 +45,12 @@ abstract class SerializableViewModel<D extends DataModel> extends ViewModel {

@override
@mustCallSuper
Future<void> init(SmartphoneDeploymentController ctrl) async {
void init(SmartphoneDeploymentController ctrl) {
super.init(ctrl);
_model = createModel();

// restore the data model (if any saved)
await restore().then((savedModel) => _model = savedModel ?? _model);
restore().then((savedModel) => _model = savedModel ?? _model);

// save the data model on a regular basis.
Timer.periodic(const Duration(minutes: 3), (_) => save(model.toJson()));
Expand Down Expand Up @@ -170,13 +172,15 @@ class CarpStudyAppViewModel extends ViewModel {
_informedConsentViewModel;

@override
Future<void> init(SmartphoneDeploymentController ctrl) async {
await super.init(ctrl);
await _studyPageViewModel.init(ctrl);
await _taskListPageViewModel.init(ctrl);
await _profilePageViewModel.init(ctrl);
await _devicesPageViewModel.init(ctrl);
await _invitationsListViewModel.init(ctrl);
await _informedConsentViewModel.init(ctrl);
// Future<void> init(SmartphoneDeploymentController ctrl) async {
void init(SmartphoneDeploymentController ctrl) {
super.init(ctrl);
_studyPageViewModel.init(ctrl);
_taskListPageViewModel.init(ctrl);
_profilePageViewModel.init(ctrl);
_devicesPageViewModel.init(ctrl);
_invitationsListViewModel.init(ctrl);
_informedConsentViewModel.init(ctrl);
_dataVisualizationPageViewModel.init(ctrl);
}
}

0 comments on commit 39228cc

Please sign in to comment.