Skip to content

Commit

Permalink
Merge pull request #646 from hpi-studyu/feat/monitoring-check-list-merge
Browse files Browse the repository at this point in the history
feat(designer): Monitoring section
  • Loading branch information
johannesvedder authored Jul 15, 2024
2 parents c537426 + 190db38 commit 58f006e
Show file tree
Hide file tree
Showing 23 changed files with 1,332 additions and 166 deletions.
18 changes: 17 additions & 1 deletion core/lib/src/models/study_schedule/study_schedule.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:studyu_core/core.dart';

part 'study_schedule.g.dart';

Expand All @@ -21,10 +22,18 @@ class StudySchedule {
Map<String, dynamic> toJson() => _$StudyScheduleToJson(this);

int getNumberOfPhases() =>
numberOfCycles * numberOfInterventions + (includeBaseline ? 1 : 0);
numberOfCycles *
(sequence == PhaseSequence.customized
? sequenceCustom.length
: StudySchedule.numberOfInterventions) +
(includeBaseline ? 1 : 0);

int get numberOfPhases => getNumberOfPhases();

int get length => getNumberOfPhases() * phaseDuration;

int get baselineLength => includeBaseline ? phaseDuration : 0;

List<int> generateWith(int firstIntervention) {
final cycles = Iterable<int>.generate(numberOfCycles);
final phases = cycles
Expand All @@ -33,6 +42,13 @@ class StudySchedule {
return phases;
}

List<String> generateInterventionIdsInOrder(List<String> interventionsIds) {
return [
if (includeBaseline) Study.baselineID,
...generateWith(0).map<String>((int index) => interventionsIds[index]),
];
}

int _nextIntervention(int index) => (index + 1) % numberOfInterventions;

List<int> _generateCycle(int first, int cycle) {
Expand Down
8 changes: 2 additions & 6 deletions core/lib/src/models/tables/study_subject.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,8 @@ class StudySubject extends SupabaseObjectFunctions<StudySubject> {
) : id = const Uuid().v4(),
studyId = study.id;

List<String> get interventionOrder => [
if (study.schedule.includeBaseline) Study.baselineID,
...study.schedule
.generateWith(0)
.map<String>((int index) => selectedInterventionIds[index]),
];
List<String> get interventionOrder =>
study.schedule.generateInterventionIdsInOrder(selectedInterventionIds);

List<Intervention> get selectedInterventions {
final selectedInterventions = selectedInterventionIds
Expand Down
50 changes: 1 addition & 49 deletions designer_v2/l10n-missing.txt
Original file line number Diff line number Diff line change
@@ -1,49 +1 @@
{
"de": [
"report_status_primary",
"report_status_secondary",
"report_status_primary_description",
"report_status_secondary_description",
"form_report_create",
"form_report_edit",
"form_report_readonly",
"form_field_report_title_required",
"form_field_report_text_required",
"form_array_reports_empty_title",
"form_array_report_items_title",
"form_array_report_items_description",
"form_array_report_items_test",
"form_array_reports_empty_description",
"form_array_reports_new",
"form_field_report_title",
"form_field_report_title_tooltip",
"form_field_report_title_hint",
"form_field_report_text",
"form_field_report_text_tooltip",
"form_field_report_text_hint",
"form_field_report_section_type",
"form_field_report_section_type_tooltip",
"form_field_report_section_type_description",
"form_field_report_improvementDirection_title",
"form_field_report_improvementDirection_tooltip",
"reportSection_type_average",
"form_field_report_average_temporalAggregation_title",
"form_field_report_average_temporalAggregation_tooltip",
"reportSection_type_temporalAggregation_day",
"reportSection_type_temporalAggregation_phase",
"reportSection_type_temporalAggregation_intervention",
"form_field_report_temporalAggregation_required",
"reportSection_type_linearRegression",
"reportSection_type_improvementDirection_positive",
"reportSection_type_improvementDirection_negative",
"form_field_report_improvementDirection_required",
"form_field_report_linearRegression_alpha_title",
"form_field_report_linearRegression_alpha_tooltip",
"form_field_report_linearRegression_alpha_hint",
"form_field_report_alphaConfidence_required",
"form_field_report_alphaConfidence_number",
"form_field_report_data_source_title",
"form_field_report_data_source_tooltip",
"form_field_report_data_source_required"
]
}
{}
73 changes: 16 additions & 57 deletions designer_v2/lib/common_views/standard_table.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class StandardTable<T> extends StatefulWidget {
required List<StandardTableColumn>? columns,
required this.onSelectItem,
required this.buildCellsAt,
this.pinnedPredicates,
this.sortColumnPredicates,
this.trailingActionsAt,
StandardTableColumn? trailingActionsColumn,
Expand All @@ -59,6 +58,8 @@ class StandardTable<T> extends StatefulWidget {
this.cellSpacing = 10.0,
this.rowSpacing = 9.0,
this.minRowHeight = 60.0,
this.headerMaxLines = 1,
this.softWrapHeader = false,
this.showTableHeader = true,
this.tableWrapper,
this.leadingWidget,
Expand Down Expand Up @@ -97,7 +98,6 @@ class StandardTable<T> extends StatefulWidget {

final StandardTableCellsBuilder<T> buildCellsAt;
final List<int Function(T a, T b)?>? sortColumnPredicates;
final int Function(T a, T b)? pinnedPredicates;
final StandardTableRowBuilder? headerRowBuilder;
final StandardTableRowBuilder? dataRowBuilder;
late final StandardTableColumn inputTrailingActionsColumn;
Expand All @@ -108,6 +108,8 @@ class StandardTable<T> extends StatefulWidget {
final double rowSpacing;
final double? minRowHeight;

final int headerMaxLines;
final bool softWrapHeader;
final bool showTableHeader;
final bool hideLeadingTrailingWhenEmpty;

Expand Down Expand Up @@ -254,70 +256,25 @@ class _StandardTableState<T> extends State<StandardTable<T>> {
sortAscending: sortAscending,
);
});
_sortPinnedStudies(
widget.items,
columnIndex: columnIndex,
sortAscending: sortAscending,
);
} else {
widget.items.clear();
widget.items.addAll(sortDefaultOrder!);
_sortPinnedStudies(widget.items, columnIndex: columnIndex);
}
_cachedRows.clear();
}

void _sortPinnedStudies(
List<T> items, {
required int columnIndex,
bool? sortAscending,
}) {
// Extract and insert pinned items at the top
if (widget.pinnedPredicates != null) {
items.sort((a, b) {
final int ret = widget.pinnedPredicates!(a, b);
// Fallback to default sorting algorithm
return ret == 0
? _sortLogic(
a,
b,
columnIndex: columnIndex,
sortAscending: sortAscending,
)
: ret;
});
}
}

int _sortLogic(
T a,
T b, {
required int columnIndex,
required bool? sortAscending,
bool? useSortPredicate,
}) {
final sortPredicate = widget.sortColumnPredicates;
if (useSortPredicate != null &&
useSortPredicate &&
sortPredicate != null &&
sortPredicate[columnIndex] != null) {
final int res;
if (sortPredicate != null && sortPredicate[columnIndex] != null) {
if (sortAscending ?? true) {
res = sortPredicate[columnIndex]!(a, b);
} else {
res = sortPredicate[columnIndex]!(b, a);
}
if (res == 0) {
// Fallback to default sorting algorithm
return _sortLogic(
a,
b,
columnIndex: columnIndex,
sortAscending: sortAscending,
useSortPredicate: false,
);
return sortPredicate[columnIndex]!(a, b);
}
return res;
return sortPredicate[columnIndex]!(b, a);
} else if (a is Comparable && b is Comparable) {
// If sortPredicate is not provided, use default comparison logic
return sortAscending ?? true
Expand Down Expand Up @@ -400,13 +357,15 @@ class _StandardTableState<T> extends State<StandardTable<T>> {
),
child: Row(
children: [
Text(
columns[i].label,
overflow: TextOverflow.visible,
maxLines: 1,
softWrap: false,
style: theme.textTheme.bodySmall!.copyWith(
color: theme.colorScheme.onSurface.withOpacity(0.8),
Flexible(
child: Text(
columns[i].label,
overflow: TextOverflow.visible,
maxLines: widget.headerMaxLines,
softWrap: widget.softWrapHeader,
style: theme.textTheme.bodySmall!.copyWith(
color: theme.colorScheme.onSurface.withOpacity(0.8),
),
),
),
if (widget.inputColumns[i].sortable)
Expand Down
19 changes: 19 additions & 0 deletions designer_v2/lib/common_views/striped_gradient.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'package:flutter/material.dart';

class StripedGradient {
StripedGradient({
required this.colors,
});

final List<Color> colors;

LinearGradient get gradient {
return LinearGradient(
begin: Alignment.topRight,
end: const Alignment(0.5, -0.4),
stops: const [0.0, 0.5, 0.5, 1],
colors: colors,
tileMode: TileMode.repeated,
);
}
}
18 changes: 17 additions & 1 deletion designer_v2/lib/common_views/utils.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:flutter/widgets.dart';
import 'package:flutter/material.dart';
import 'package:studyu_designer_v2/theme.dart';
import 'package:studyu_designer_v2/utils/extensions.dart';

typedef WidgetDecorator = Widget Function(Widget widget);

Expand Down Expand Up @@ -43,3 +45,17 @@ extension ColorX on Color {
return withAlpha((alphaScaleFactor * alpha).round());
}
}

Widget interventionPrefix(int rowIdx, ThemeData theme) {
return Row(
children: [
Text(
''.alphabetLetterFrom(rowIdx).toUpperCase(),
style: TextStyle(
color: ThemeConfig.dropdownMenuItemTheme(theme).iconTheme!.color,
),
),
const SizedBox(width: 16.0),
],
);
}
3 changes: 3 additions & 0 deletions designer_v2/lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class Config {
static const minSplashTime = 0;

static const formAutosaveDebounce = 1000;

static const participantDropoutDuration = 5;
static const participantInactiveDuration = 3;
}

const kPathSeparator = ' / ';
Expand Down
Loading

0 comments on commit 58f006e

Please sign in to comment.