Browse Source

添加热力图

weicu
tanlongsheng 1 year ago
parent
commit
ecec8ceb4a
  1. 68
      lib/modules/meeting/controllers/meeting_mine_controller.dart
  2. 20
      lib/modules/meeting/views/bottomSheet/statistics_bottom_sheet.dart
  3. 37
      lib/modules/meeting/views/meeting_mine_view.dart

68
lib/modules/meeting/controllers/meeting_mine_controller.dart

@ -1,9 +1,13 @@
import 'package:common_utils/common_utils.dart';
import 'package:get/get.dart';
import 'meeting_home_controller.dart';
import '../../../data/services/db/sqflite_api.dart';
import '../../profile/controllers/profile_controller.dart';
class MeetingMineController extends GetxController {
final _controller = Get.find<MeetingHomeController>();
final profileCtrl = Get.find<ProfileController>();
Map statistics = {};
RxInt days = 0.obs;
RxInt numberFiles = 0.obs;
@ -12,15 +16,69 @@ class MeetingMineController extends GetxController {
RxInt maxNumberFiles = 0.obs;
RxDouble maxHourage = 0.0.obs;
int averageNumberFiles = 0;
@override
void onInit() {
super.onInit();
_getStatistics();
}
void _getStatistics() {
numberFiles.value = _controller.originalDataList.length;
void _getStatistics() async {
List dataList = await SqfliteApi.getMeetingList();
numberFiles.value = dataList.length;
statistics = {};
for (var element in dataList) {
DateTime creationtime =
DateTime.fromMillisecondsSinceEpoch(element['creationtime']);
int dayOfYear = DateUtil.getDayOfYear(creationtime);
if (!statistics.containsKey(dayOfYear)) {
statistics[dayOfYear] = {
'creationtime': creationtime,
'count': 0,
'seconds': 0,
};
}
statistics[dayOfYear]['count']++;
statistics[dayOfYear]['seconds'] += element['seconds'];
}
int currentD = 1;
int maxD = 1;
int previous = 0;
int h = 0;
int maxH = 0;
int maxN = 0;
int minN = 0;
statistics.forEach((key, value) {
h += value['seconds'] as int;
if (key + 1 == previous) {
currentD++;
if (currentD > maxD) {
maxD = currentD;
}
} else {
currentD = 1;
}
previous = key;
if (value['count'] > maxN) {
maxN = value['count'];
}
if (value['count'] < minN || minN == 0) {
minN = value['count'];
}
if (value['seconds'] > maxH) {
maxH = value['seconds'];
}
});
for (var element in _controller.originalDataList) {}
days.value = statistics.length;
hourage.value = double.parse((h / 60 / 60).toStringAsFixed(2));
continuousDays.value = maxD;
maxNumberFiles.value = maxN;
maxHourage.value = double.parse((maxH / 60 / 60).toStringAsFixed(2));
averageNumberFiles = (maxN + minN) ~/ 2;
}
}

20
lib/modules/meeting/views/bottomSheet/statistics_bottom_sheet.dart

@ -171,8 +171,26 @@ class _StatisticsBottomSheetState extends State<StatisticsBottomSheet> {
),
itemCount: 364,
itemBuilder: (BuildContext context, int index) {
final col = index % 52;
final row = index ~/ 52;
final vIndex = row + col * 7;
int type = 0;
if (_mineController.statistics
.containsKey(vIndex + 1)) {
if (_mineController.statistics[vIndex + 1]['count'] <=
_mineController.averageNumberFiles) {
type = 1;
} else {
type = 2;
}
}
return Container(
color: Colors.grey[200],
color: type == 0
? Colors.grey[200]
: type == 1
? Colors.red[100]
: Colors.red,
);
},
),

37
lib/modules/meeting/views/meeting_mine_view.dart

@ -3,7 +3,6 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'dart:io';
import '../../../routes/app_routes.dart';
import '../../profile/controllers/profile_controller.dart';
import '../controllers/meeting_mine_controller.dart';
import 'bottomSheet/statistics_bottom_sheet.dart';
@ -96,8 +95,6 @@ class MeetingMineView extends GetView<MeetingMineController> {
}
Widget _head() {
final ProfileController profileCtrl =
Get.find<ProfileController>(); // 从GetX中获取ProfileController实例
return Padding(
padding: EdgeInsets.symmetric(vertical: 20.w),
child: GestureDetector(
@ -114,14 +111,19 @@ class MeetingMineView extends GetView<MeetingMineController> {
),
child: CircleAvatar(
radius: 25.w,
backgroundImage: profileCtrl.localAvatar.value.isNotEmpty
? FileImage(File(profileCtrl.localAvatar.value))
: (profileCtrl.userInfo.value.avatar.isNotEmpty
? NetworkImage(profileCtrl.userInfo.value.avatar)
backgroundImage: controller
.profileCtrl.localAvatar.value.isNotEmpty
? FileImage(
File(controller.profileCtrl.localAvatar.value))
: (controller
.profileCtrl.userInfo.value.avatar.isNotEmpty
? NetworkImage(
controller.profileCtrl.userInfo.value.avatar)
: null) as ImageProvider<Object>?,
backgroundColor: Colors.grey[200],
child: (profileCtrl.localAvatar.value.isEmpty &&
profileCtrl.userInfo.value.avatar.isEmpty)
child: (controller.profileCtrl.localAvatar.value.isEmpty &&
controller
.profileCtrl.userInfo.value.avatar.isEmpty)
? Icon(
Icons.person,
size: 25.r,
@ -133,7 +135,7 @@ class MeetingMineView extends GetView<MeetingMineController> {
Expanded(
child: Obx(
() => Text(
profileCtrl.userInfo.value.name,
controller.profileCtrl.userInfo.value.name,
style: TextStyle(
color: Colors.black87,
fontSize: 20.sp,
@ -203,9 +205,22 @@ class MeetingMineView extends GetView<MeetingMineController> {
),
itemCount: 364,
itemBuilder: (BuildContext context, int index) {
int type = 0;
if (controller.statistics.containsKey(index + 1)) {
if (controller.statistics[index + 1]['count'] <=
controller.averageNumberFiles) {
type = 1;
} else {
type = 2;
}
}
return Container(
decoration: BoxDecoration(
color: Colors.grey[200],
color: type == 0
? Colors.grey[200]
: type == 1
? Colors.red[100]
: Colors.red,
borderRadius: BorderRadius.circular(2.w),
),
);

Loading…
Cancel
Save