64 lines
1.7 KiB
Dart
64 lines
1.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:lamiter/Class/Form/stress_index_form.dart';
|
|
import 'package:lamiter/Class/Question/scq.dart';
|
|
|
|
class StressIndexResult {
|
|
int score;
|
|
|
|
StressIndexResult({
|
|
required this.score,
|
|
});
|
|
|
|
StressIndexResult.fromJson(Map<String, dynamic> json)
|
|
: score = json["score"] as int;
|
|
|
|
Map<String, dynamic> toJson() => {'score': score};
|
|
|
|
StressIndexResult.fromForm(StressIndexForm form)
|
|
: score = _calculateScore(form);
|
|
|
|
static int _calculateScore(StressIndexForm form) {
|
|
int score = 0;
|
|
form.scores.forEach((String qid, SCQAnswer answer) {
|
|
score += answer.score;
|
|
});
|
|
return score;
|
|
}
|
|
|
|
final int max_score = 34;
|
|
final int status_length = 3;
|
|
final List<int> status_thresh = <int>[10, 5, 19];
|
|
final List<Color> status_colors = [Colors.green, Colors.amber, Colors.red];
|
|
final List<String> status_labels = ['低', '中等', '高'];
|
|
final List<String> status_infos = [
|
|
'精神壓力程度低,但可能顯示生活缺乏刺激,較為單調沉悶,做事的動力不高。',
|
|
'精神壓力程度中等,雖然有時會感到壓力較大,但仍能應付。',
|
|
'精神壓力偏高,應反省壓力來源並尋求解決方法。',
|
|
];
|
|
|
|
int _status() {
|
|
int temp = score;
|
|
for (int i = 0; i < status_length; i++) {
|
|
if (temp <= status_thresh[i]) return i;
|
|
temp -= status_thresh[i];
|
|
}
|
|
return status_length - 1;
|
|
}
|
|
|
|
double factor() {
|
|
return score.toDouble() / max_score.toDouble();
|
|
}
|
|
|
|
Color color() {
|
|
return status_colors[_status()];
|
|
}
|
|
|
|
String label() {
|
|
return status_labels[_status()];
|
|
}
|
|
|
|
String info() {
|
|
return status_infos[_status()];
|
|
}
|
|
}
|