mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 22:57:21 +00:00
connect generate reports model and api to view
This commit is contained in:
@ -1,31 +0,0 @@
|
||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_reports.dart';
|
||||
|
||||
class FakeDeviceReport {
|
||||
static DeviceReport generateFakeReport() {
|
||||
return DeviceReport(
|
||||
deviceUuid: 'fake-uuid-12345',
|
||||
startTime: DateTime.now().millisecondsSinceEpoch,
|
||||
endTime: DateTime.now().add(Duration(hours: 1)).millisecondsSinceEpoch,
|
||||
data: [
|
||||
{
|
||||
'date': '13/08/2024',
|
||||
'time': '13:05',
|
||||
'status': 'Presence',
|
||||
'description': 'Description for Presence at 13:05 on 13/08/2024',
|
||||
},
|
||||
{
|
||||
'date': '13/08/2024',
|
||||
'time': '14:10',
|
||||
'status': 'No Presence',
|
||||
'description': 'Description for No Presence at 14:10 on 13/08/2024',
|
||||
},
|
||||
{
|
||||
'date': '14/08/2024',
|
||||
'time': '15:30',
|
||||
'status': 'Presence',
|
||||
'description': 'Description for Presence at 15:30 on 14/08/2024',
|
||||
},
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@ class DeviceReport {
|
||||
final String? deviceUuid;
|
||||
final int? startTime;
|
||||
final int? endTime;
|
||||
final List<dynamic>? data;
|
||||
final List<DeviceEvent>? data;
|
||||
|
||||
DeviceReport({
|
||||
this.deviceUuid,
|
||||
@ -15,12 +15,37 @@ class DeviceReport {
|
||||
: deviceUuid = json['deviceUuid'] as String?,
|
||||
startTime = json['startTime'] as int?,
|
||||
endTime = json['endTime'] as int?,
|
||||
data = json['data'] as List?;
|
||||
data = (json['data'] as List<dynamic>?)
|
||||
?.map((e) => DeviceEvent.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'deviceUuid': deviceUuid,
|
||||
'startTime': startTime,
|
||||
'endTime': endTime,
|
||||
'data': data
|
||||
'data': data?.map((e) => e.toJson()).toList(),
|
||||
};
|
||||
}
|
||||
|
||||
class DeviceEvent {
|
||||
final String? code;
|
||||
final int? eventTime;
|
||||
final String? value;
|
||||
|
||||
DeviceEvent({
|
||||
this.code,
|
||||
this.eventTime,
|
||||
this.value,
|
||||
});
|
||||
|
||||
DeviceEvent.fromJson(Map<String, dynamic> json)
|
||||
: code = json['code'] as String?,
|
||||
eventTime = json['eventTime'] as int?,
|
||||
value = json['value'] as String?;
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'code': code,
|
||||
'eventTime': eventTime,
|
||||
'value': value,
|
||||
};
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/all_devices/helper/fake_report_data.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/bloc/event.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/bloc/state.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/model/ceiling_sensor_model.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/model/help_description.dart';
|
||||
import 'package:syncrow_web/services/devices_mang_api.dart';
|
||||
|
||||
class CeilingSensorBloc extends Bloc<CeilingSensorEvent, CeilingSensorState> {
|
||||
@ -93,17 +93,21 @@ class CeilingSensorBloc extends Bloc<CeilingSensorEvent, CeilingSensorState> {
|
||||
|
||||
FutureOr<void> _getDeviceReports(GetCeilingDeviceReportsEvent event,
|
||||
Emitter<CeilingSensorState> emit) async {
|
||||
emit(CeilingReportsLoadingState());
|
||||
|
||||
try {
|
||||
//await DevicesManagementApi.getDeviceReports(deviceId, event.code)
|
||||
// .then((value) {
|
||||
final fakeReport = FakeDeviceReport.generateFakeReport();
|
||||
emit(CeilingReportsState(deviceReport: fakeReport));
|
||||
// });
|
||||
} catch (e) {
|
||||
emit(CeilingReportsFailedState(error: e.toString()));
|
||||
if (event.code.isEmpty) {
|
||||
emit(ShowCeilingDescriptionState(description: reportString));
|
||||
return;
|
||||
} else {
|
||||
emit(CeilingReportsLoadingState());
|
||||
|
||||
try {
|
||||
await DevicesManagementApi.getDeviceReports(deviceId, event.code)
|
||||
.then((value) {
|
||||
emit(CeilingReportsState(deviceReport: value));
|
||||
});
|
||||
} catch (e) {
|
||||
emit(CeilingReportsFailedState(error: e.toString()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,17 @@
|
||||
String reportString = '''
|
||||
1. Nobody, the report to someone
|
||||
Instruction: The propagation and processing of electromagnetic waves are complicated. There will be false alarms in the actual use of radar, and there will be some influencing factors in the environment, including:
|
||||
|
||||
A. Physical disturbance: including air conditioning, fan, motor and other facilities vibration, cats, dogs, mice, birds and other animals passing through, may cause radar misjudgement of the environment.
|
||||
|
||||
B. Space electromagnetic wave disturbance, including the possible existence of high-power electrical equipment around the radar, electromagnetic wave intensive places, the simultaneous coexistence of multiple radars and other environmental factors, may also cause radar misjudgement. Such interference items are few in home and office scenes, but more in factories and industrial environments.
|
||||
|
||||
C. Power supply disturbance is mainly caused by power supply radar crosstalk caused by associated facilities and equipment in the mains environment, resulting in unstable power supply of radar and resulting in output misjudgement.
|
||||
|
||||
2. In the case of human misreporting no one:
|
||||
A. The presence of a human body beyond the radar test range.
|
||||
|
||||
B. The human body is covered by metal, or by extremely thick office desks and chairs.
|
||||
|
||||
C. When sleeping, the body cannot detect breathing micro-movements on the side, and may misjudge as nobody for a short time.
|
||||
''';
|
@ -30,7 +30,8 @@ class CeilingSensorControls extends StatelessWidget
|
||||
..add(CeilingInitialEvent()),
|
||||
child: BlocBuilder<CeilingSensorBloc, CeilingSensorState>(
|
||||
builder: (context, state) {
|
||||
if (state is CeilingLoadingInitialState) {
|
||||
if (state is CeilingLoadingInitialState ||
|
||||
state is CeilingReportsLoadingState) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else if (state is CeilingUpdateState) {
|
||||
return _buildGridView(
|
||||
@ -39,11 +40,11 @@ class CeilingSensorControls extends StatelessWidget
|
||||
return ReportsTable(
|
||||
report: state.deviceReport,
|
||||
onRowTap: (index) {
|
||||
final entry = state.deviceReport.data![index];
|
||||
context.read<CeilingSensorBloc>().add(
|
||||
ShowCeilingDescriptionEvent(
|
||||
description: entry['description']),
|
||||
);
|
||||
// final entry = state.deviceReport.data![index];
|
||||
// context.read<CeilingSensorBloc>().add(
|
||||
// ShowCeilingDescriptionEvent(
|
||||
// description: entry['description']),
|
||||
// );
|
||||
},
|
||||
onClose: () {
|
||||
context
|
||||
@ -154,7 +155,7 @@ class CeilingSensorControls extends StatelessWidget
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
context.read<CeilingSensorBloc>().add(GetCeilingDeviceReportsEvent(
|
||||
code: 'illuminance_record', deviceUuid: device.uuid!));
|
||||
code: 'presence_state', deviceUuid: device.uuid!));
|
||||
},
|
||||
child: const PresenceStaticWidget(
|
||||
icon: Assets.illuminanceRecordIcon,
|
||||
|
@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_reports.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/shared/table/table_cell_widget.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/shared/table/table_header.dart';
|
||||
@ -39,13 +40,20 @@ class ReportsTable extends StatelessWidget {
|
||||
),
|
||||
...report.data!.asMap().entries.map((entry) {
|
||||
int index = entry.key;
|
||||
var data = entry.value;
|
||||
DeviceEvent data = entry.value;
|
||||
|
||||
// Parse eventTime into Date and Time
|
||||
DateTime eventDateTime =
|
||||
DateTime.fromMillisecondsSinceEpoch(data.eventTime!);
|
||||
String date = DateFormat('dd/MM/yyyy').format(eventDateTime);
|
||||
String time = DateFormat('HH:mm').format(eventDateTime);
|
||||
|
||||
return TableRow(
|
||||
children: [
|
||||
TableCellWidget(value: data['date']),
|
||||
TableCellWidget(value: data['time']),
|
||||
TableCellWidget(value: date),
|
||||
TableCellWidget(value: time),
|
||||
TableCellWidget(
|
||||
value: data['status'],
|
||||
value: data.value!,
|
||||
onTap: () => onRowTap(index),
|
||||
),
|
||||
],
|
||||
|
@ -1,6 +1,5 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/all_devices/helper/fake_report_data.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/wall_sensor/bloc/event.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/wall_sensor/bloc/state.dart';
|
||||
@ -98,11 +97,10 @@ class WallSensorBloc extends Bloc<WallSensorEvent, WallSensorState> {
|
||||
emit(DeviceReportsLoadingState());
|
||||
|
||||
try {
|
||||
//await DevicesManagementApi.getDeviceReports(deviceId, event.code)
|
||||
// .then((value) {
|
||||
final fakeReport = FakeDeviceReport.generateFakeReport();
|
||||
emit(DeviceReportsState(deviceReport: fakeReport));
|
||||
// });
|
||||
await DevicesManagementApi.getDeviceReports(deviceId, event.code)
|
||||
.then((value) {
|
||||
emit(DeviceReportsState(deviceReport: value));
|
||||
});
|
||||
} catch (e) {
|
||||
emit(DeviceReportsFailedState(error: e.toString()));
|
||||
return;
|
||||
|
@ -28,7 +28,8 @@ class WallSensorControls extends StatelessWidget with HelperResponsiveLayout {
|
||||
WallSensorBloc(deviceId: device.uuid!)..add(WallSensorInitialEvent()),
|
||||
child: BlocBuilder<WallSensorBloc, WallSensorState>(
|
||||
builder: (context, state) {
|
||||
if (state is WallSensorLoadingInitialState) {
|
||||
if (state is WallSensorLoadingInitialState ||
|
||||
state is DeviceReportsLoadingState) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else if (state is WallSensorUpdateState) {
|
||||
return _buildGridView(
|
||||
@ -36,12 +37,7 @@ class WallSensorControls extends StatelessWidget with HelperResponsiveLayout {
|
||||
} else if (state is DeviceReportsState) {
|
||||
return ReportsTable(
|
||||
report: state.deviceReport,
|
||||
onRowTap: (index) {
|
||||
final entry = state.deviceReport.data![index];
|
||||
context.read<WallSensorBloc>().add(
|
||||
ShowDescriptionEvent(description: entry['description']),
|
||||
);
|
||||
},
|
||||
onRowTap: (index) {},
|
||||
onClose: () {
|
||||
context.read<WallSensorBloc>().add(BackToGridViewEvent());
|
||||
},
|
||||
@ -155,7 +151,7 @@ class WallSensorControls extends StatelessWidget with HelperResponsiveLayout {
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
context.read<WallSensorBloc>().add(GetDeviceReportsEvent(
|
||||
code: 'illuminance_record', deviceUuid: device.uuid!));
|
||||
code: 'illuminance_value', deviceUuid: device.uuid!));
|
||||
},
|
||||
child: const PresenceStaticWidget(
|
||||
icon: Assets.illuminanceRecordIcon,
|
||||
@ -165,7 +161,7 @@ class WallSensorControls extends StatelessWidget with HelperResponsiveLayout {
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
context.read<WallSensorBloc>().add(GetDeviceReportsEvent(
|
||||
code: 'presence_record', deviceUuid: device.uuid!));
|
||||
code: 'presence_state', deviceUuid: device.uuid!));
|
||||
},
|
||||
child: const PresenceStaticWidget(
|
||||
icon: Assets.presenceRecordIcon,
|
||||
|
Reference in New Issue
Block a user