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 '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 { class MeetingMineController extends GetxController {
final _controller = Get.find<MeetingHomeController>(); final profileCtrl = Get.find<ProfileController>();
Map statistics = {};
RxInt days = 0.obs; RxInt days = 0.obs;
RxInt numberFiles = 0.obs; RxInt numberFiles = 0.obs;
@ -12,15 +16,69 @@ class MeetingMineController extends GetxController {
RxInt maxNumberFiles = 0.obs; RxInt maxNumberFiles = 0.obs;
RxDouble maxHourage = 0.0.obs; RxDouble maxHourage = 0.0.obs;
int averageNumberFiles = 0;
@override @override
void onInit() { void onInit() {
super.onInit(); super.onInit();
_getStatistics(); _getStatistics();
} }
void _getStatistics() { void _getStatistics() async {
numberFiles.value = _controller.originalDataList.length; 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, itemCount: 364,
itemBuilder: (BuildContext context, int index) { 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( 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 'package:get/get.dart';
import 'dart:io'; import 'dart:io';
import '../../../routes/app_routes.dart'; import '../../../routes/app_routes.dart';
import '../../profile/controllers/profile_controller.dart';
import '../controllers/meeting_mine_controller.dart'; import '../controllers/meeting_mine_controller.dart';
import 'bottomSheet/statistics_bottom_sheet.dart'; import 'bottomSheet/statistics_bottom_sheet.dart';
@ -96,8 +95,6 @@ class MeetingMineView extends GetView<MeetingMineController> {
} }
Widget _head() { Widget _head() {
final ProfileController profileCtrl =
Get.find<ProfileController>(); // 从GetX中获取ProfileController实例
return Padding( return Padding(
padding: EdgeInsets.symmetric(vertical: 20.w), padding: EdgeInsets.symmetric(vertical: 20.w),
child: GestureDetector( child: GestureDetector(
@ -114,14 +111,19 @@ class MeetingMineView extends GetView<MeetingMineController> {
), ),
child: CircleAvatar( child: CircleAvatar(
radius: 25.w, radius: 25.w,
backgroundImage: profileCtrl.localAvatar.value.isNotEmpty backgroundImage: controller
? FileImage(File(profileCtrl.localAvatar.value)) .profileCtrl.localAvatar.value.isNotEmpty
: (profileCtrl.userInfo.value.avatar.isNotEmpty ? FileImage(
? NetworkImage(profileCtrl.userInfo.value.avatar) File(controller.profileCtrl.localAvatar.value))
: (controller
.profileCtrl.userInfo.value.avatar.isNotEmpty
? NetworkImage(
controller.profileCtrl.userInfo.value.avatar)
: null) as ImageProvider<Object>?, : null) as ImageProvider<Object>?,
backgroundColor: Colors.grey[200], backgroundColor: Colors.grey[200],
child: (profileCtrl.localAvatar.value.isEmpty && child: (controller.profileCtrl.localAvatar.value.isEmpty &&
profileCtrl.userInfo.value.avatar.isEmpty) controller
.profileCtrl.userInfo.value.avatar.isEmpty)
? Icon( ? Icon(
Icons.person, Icons.person,
size: 25.r, size: 25.r,
@ -133,7 +135,7 @@ class MeetingMineView extends GetView<MeetingMineController> {
Expanded( Expanded(
child: Obx( child: Obx(
() => Text( () => Text(
profileCtrl.userInfo.value.name, controller.profileCtrl.userInfo.value.name,
style: TextStyle( style: TextStyle(
color: Colors.black87, color: Colors.black87,
fontSize: 20.sp, fontSize: 20.sp,
@ -203,9 +205,22 @@ class MeetingMineView extends GetView<MeetingMineController> {
), ),
itemCount: 364, itemCount: 364,
itemBuilder: (BuildContext context, int index) { 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( return Container(
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.grey[200], color: type == 0
? Colors.grey[200]
: type == 1
? Colors.red[100]
: Colors.red,
borderRadius: BorderRadius.circular(2.w), borderRadius: BorderRadius.circular(2.w),
), ),
); );

Loading…
Cancel
Save