205 lines
7.8 KiB
Dart
205 lines
7.8 KiB
Dart
import 'package:flutter/material.dart';
|
||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||
import 'package:get/get.dart';
|
||
import 'package:school_asignment_app/common/job/homework_details.dart';
|
||
import 'package:school_asignment_app/page/home_page/children/quick_data_check/quick_data_check_state.dart';
|
||
|
||
class Utils{
|
||
Utils._internal();
|
||
|
||
/// 关闭键盘
|
||
static void hideKeyboard() {
|
||
FocusScopeNode? currentFocus = Get.focusScope?.nearestScope;
|
||
if (currentFocus == null) {
|
||
return;
|
||
}
|
||
if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) {
|
||
FocusManager.instance.primaryFocus?.unfocus();
|
||
}
|
||
}
|
||
|
||
// 是否是平板
|
||
static bool isPad([double mobilePhoneScale = 1.2]) {
|
||
return ScreenUtil().scaleWidth > mobilePhoneScale;
|
||
}
|
||
|
||
static String getDoubleRemoveZero(double? val, [String? defaultVal]) {
|
||
try {
|
||
if (val == null) throw Exception('数据为空');
|
||
List<String> _valArr = val.toString().split('.');
|
||
if (_valArr.length >= 2) {
|
||
if (int.parse(_valArr[1]) == 0) {
|
||
return val.toInt().toString();
|
||
}
|
||
return val.toString();
|
||
}
|
||
return val.toInt().toString();
|
||
} catch (e) {
|
||
return defaultVal ?? '';
|
||
}
|
||
}
|
||
|
||
/// 去除小数点
|
||
static String doubleToStringAsFixed(double val, {int fractionDigits = 2}) {
|
||
return val.toStringAsFixed(fractionDigits).replaceAll(RegExp(r'\.0*$'), '');
|
||
}
|
||
|
||
static calcRate (int divisor, int dividend) {
|
||
if(dividend != 0){
|
||
return ((100 * divisor) / dividend);
|
||
// return ((100 * divisor) / dividend).toStringAsFixed(0);
|
||
}else{
|
||
return 0.0;
|
||
}
|
||
|
||
}
|
||
|
||
/// 秒转时分秒
|
||
static String second2HMS(int sec, {bool isEasy = false}) {
|
||
String hms = "0";
|
||
if (!isEasy) hms = "0秒";
|
||
if (sec > 0) {
|
||
int h = sec ~/ 3600;
|
||
int m = (sec % 3600) ~/ 60;
|
||
int s = sec % 60;
|
||
if(h>0){
|
||
hms = "$h时$m分$s秒";
|
||
}else{
|
||
if(m>0){
|
||
hms = "$m分$s秒";
|
||
}else{
|
||
hms = "$s秒";
|
||
}
|
||
}
|
||
}
|
||
return hms;
|
||
}
|
||
|
||
static getHomeworkData(HomeworkDetails data){
|
||
|
||
CountData dataCount = CountData();
|
||
List<Dtls> kgt = data.dtls.where((w) => w.questionType == 1).toList();
|
||
dataCount.kgtAnswerCount = kgt.where((w) => w.state != 0).length;
|
||
dataCount.kgtOkCount = kgt.where((w) => w.state == 3).length;
|
||
dataCount.kgtDtlCount = kgt.length;
|
||
dataCount.kgtAnswerRate = Utils.calcRate(dataCount.kgtAnswerCount!, dataCount.kgtDtlCount!);
|
||
dataCount.kgtOkRate = Utils.calcRate(dataCount.kgtOkCount!, dataCount.kgtDtlCount!);
|
||
dataCount.kgtCount = data.questions.where((w) => w.questionType == 1).length;
|
||
|
||
List<Dtls> zgt = data.dtls.where((w) => w.questionType == 2).toList();
|
||
dataCount.zgtAnswerCount = zgt.where((w) => w.state != 0).length;
|
||
dataCount.zgtOkCount = zgt.where((w) => w.state == 3).length;
|
||
dataCount.zgtDtlCount = zgt.length;
|
||
dataCount.zgtAnswerRate = Utils.calcRate(dataCount.zgtAnswerCount!, dataCount.zgtDtlCount!);
|
||
dataCount.zgtOkRate = Utils.calcRate(dataCount.zgtOkCount!, dataCount.zgtDtlCount!);
|
||
dataCount.zgtCount = data.questions.where((w) => w.questionType == 2).length;
|
||
dataCount.studentCount = data.students.length;
|
||
dataCount.priorityStudents = data.students.where((w) => w.priorityAnnotate).toList();
|
||
|
||
|
||
for(var que in data.questions){
|
||
List<Dtls> ques = data.dtls.where((w) => w.templateId == que.templateId && w.questionNo == que.questionNo).toList();
|
||
que.answerCount = ques.where((w) => w.state != 0).length;
|
||
que.answerRate = Utils.calcRate(que.answerCount!, dataCount.studentCount!);
|
||
int okCount = ques.where((w) => w.state == 3).length;
|
||
que.okRate = Utils.calcRate(okCount, dataCount.studentCount!) ;
|
||
que.priorityInfo = ques.where((w) {
|
||
return dataCount.priorityStudents!.indexWhere((s) {
|
||
w.studentName = s.studentName;
|
||
return s.studentId == w.studentId;
|
||
}) > -1 && w.state != 3;
|
||
}).toList();
|
||
|
||
que.answerNgStudents = ques.where((w) {
|
||
w.studentName = data.students.firstWhere((s) => s.studentId == w.studentId).studentName;
|
||
return w.state == 2;
|
||
}).toList();
|
||
|
||
que.noAnswerStudents = ques.where((w) {
|
||
return w.state == 0;
|
||
}).toList();
|
||
que.answerOkStudents = ques.where((w) {
|
||
return w.state == 3;
|
||
}).toList();
|
||
|
||
}
|
||
|
||
dataCount.studentSubmitCount = data.students.where((s) => s.state != 0).length;
|
||
|
||
for(var stu in data.students){
|
||
stu.kgtStu = kgt.where((w) => w.studentId == stu.studentId).toList();
|
||
stu.kgtStu!.sort((a, b) => a.questionNo.compareTo(b.questionNo));
|
||
stu.kgtOkCount = stu.kgtStu!.where((w) => w.state == 3).length;
|
||
stu.kgtErrorCount = stu.kgtStu!.where((w) => w.state == 2).length;
|
||
stu.kgtAnswerCount = stu.kgtStu!.where((w) => w.state != 0).length;
|
||
|
||
stu.zgtStu = zgt.where((w) => w.studentId == stu.studentId).toList();
|
||
stu.zgtStu!.sort((a, b) => a.questionNo.compareTo(b.questionNo));
|
||
stu.zgtOkCount = stu.zgtStu!.where((w) => w.state == 3).length;
|
||
stu.zgtErrorCount = stu.zgtStu!.where((w) => w.state == 2).length;
|
||
stu.zgtUnrated = stu.zgtStu!.where((w) => w.state == 1).length;
|
||
stu.zgtAnswerCount = stu.zgtStu!.where((w) => w.state != 0).length;
|
||
stu.allOk = data.dtls.where((w) {
|
||
if(stu.studentId == w.studentId){
|
||
stu.useTime = w.useTime;
|
||
}
|
||
for(var que in data.questions){
|
||
if(w.templateId == que.templateId && w.questionNo == que.questionNo){
|
||
w.answer = que.answer;
|
||
w.questionPicture = que.questionPicture;
|
||
}
|
||
}
|
||
return w.studentId == stu.studentId && w.state != 3;
|
||
} ).length??0;
|
||
if( (stu.kgtStu!.length - stu.kgtAnswerCount!) + (stu.zgtStu!.length-stu.zgtAnswerCount!) == (stu.kgtStu!.length + stu.zgtStu!.length)){
|
||
stu.allNotDone = true;
|
||
}else{
|
||
stu.allNotDone = false;
|
||
}
|
||
stu.noAnswerCount = data.dtls.where((w) => w.state == 0 && stu.studentId == w.studentId).length;
|
||
|
||
List<Questions> ques = data.questions;
|
||
stu.queDtls =data.dtls.where((w) => w.studentId == stu.studentId && ques.indexWhere((q) => w.templateId == q.templateId && w.questionNo == q.questionNo) > -1).toList();
|
||
int okCount = stu.queDtls!.where((w) => w.state == 3).length;
|
||
int ttlCount = stu.queDtls!.length;
|
||
stu.okRate = Utils.calcRate(okCount, ttlCount);
|
||
|
||
}
|
||
|
||
data.students.sort((a, b) {
|
||
int num1 = a.state;
|
||
int num2 = b.state;
|
||
return num2.compareTo(num1);
|
||
});
|
||
|
||
for(var know in data.knows){
|
||
List<Questions> ques = data.questions.where((w) => w.knows.indexWhere((k) => k.knowledgeId == know.knowledgeId) > -1).toList();
|
||
List<Dtls> queDtls = data.dtls.where((w) => ques.indexWhere((q) => w.templateId == q.templateId && w.questionNo == q.questionNo) > -1).toList();
|
||
know.okCount = queDtls.where((w) => w.state == 3).length;
|
||
know.ttlCount = queDtls.length;
|
||
know.okRate = Utils.calcRate(know.okCount!, know.ttlCount!);
|
||
}
|
||
|
||
return dataCount;
|
||
}
|
||
|
||
static DateTime getWeekStartDate() {
|
||
DateTime now = DateTime.now();
|
||
int dayOfWeek = now.weekday; // 获取今天是周几(1代表周一,7代表周日)
|
||
int diff = dayOfWeek - 1; // 计算今天距离周一的天数差
|
||
if (diff < 0) {
|
||
diff += 7; // 如果是周日,则需要加上一周的天数
|
||
}
|
||
return now.subtract(Duration(days: diff)); // 减去天数差,得到本周一的时间
|
||
}
|
||
|
||
static DateTime getWeekEndDate() {
|
||
DateTime now = DateTime.now();
|
||
int dayOfWeek = now.weekday; // 获取今天是周几
|
||
int diff = 7 - dayOfWeek; // 计算今天距离周日的天数差
|
||
if (diff == 0) {
|
||
diff = 7; // 如果是周日,则加上一周的天数
|
||
}
|
||
return now.add(Duration(days: diff)); // 加上天数差减一,得到本周日的时间
|
||
}
|
||
} |