healthrian_visualization_support 2.4.2
healthrian_visualization_support: ^2.4.2 copied to clipboard
Healthrian visualization support library
example/lib/main.dart
import 'dart:convert';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
// import 'package:healthrian_ble_support_for_cardio_em_cdc/healthrian_ble_support_for_cardio_em_cdc.dart';
import 'package:healthrian_ble_support_for_cardio_em/healthrian_ble_support_for_cardio_em.dart';
import 'package:healthrian_visualization_support/healthrian_visualization_support.dart';
import 'package:rxdart/rxdart.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
void initState() {
super.initState();
// BLEManager().samplingRate = SamplingRate.freq4000hz;
// final file = File('20s/30hz.json');
// BLEManager().ecg?.callbacks.add(
// (
// (a, b) {
// final map = {
// 'l1' : a.l1,
// 'l2' : a.l2,
// 'l3' : a.l3,
// 'aVR' : a.aVR,
// 'aVL' : a.aVL,
// 'aVF' : a.aVF,
// 'v1' : a.v1,
// 'v2' : a.v2,
// 'v3' : a.v3,
// 'v4' : a.v4,
// 'v5' : a.v5,
// 'v6' : a.v6,
// };
// final mapAsJson = jsonEncode(map);
// file.writeAsString(mapAsJson);
// print(DateTime.now());
// },
// 500 * 20,
// ),
// );
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
ConnectionMonitor(module: BLEManager().module),
HeartRateMonitor(module: BLEManager().module, isUsingMean: false),
LeadstateMonitor(module: BLEManager().module),
Observer(
builder: (context) {
return StreamBuilder(
stream: BLEManager()
.module
.ble
.streams
.ecg
.meta
.value
?.expand((e) => e.first)
.bufferTime(Duration(seconds: 1))
.map((e) => e.length),
builder: (context, snapshot) => Text('${snapshot.data} Samples/sec.'),
);
},
),
// Expanded(
// child: SingleChildScrollView(
// child: Observer(
// builder: (context) {
// return StreamBuilder(
// stream: module.ble.streams.ecg.filter.buffer,
// builder: (context, snapshot) => Text('${snapshot.data?.l2.length}'),
// );
// },
// ),
// ),
// ),
// Expanded(
// child: Observer(
// builder: (context) {
// return StreamBuilder(
// stream: module.ble.streams.ecg.meta.raw,
// builder: (context, snapshot) {
// if (!snapshot.hasData) return const SizedBox();
// final spots = List.generate(
// snapshot.data!.length,
// (i) => FlSpot(i.toDouble(), snapshot.data![i].toDouble()),
// );
// return LineChart(
// duration: Duration.zero,
// LineChartData(
// lineBarsData: [
// LineChartBarData(
// spots: spots,
// ),
// ],
// ),
// );
// },
// );
// },
// ),
// ),
// Observer(
// builder: (context) => StreamBuilder(
// stream: module.ble.streams.ecg.meta.raw?.scan(
// (acc, v, i) {
// if ((acc.$2 + 1) % 0x100 != v[2]) print((acc.$2, v[2], DateTime.now()));
// return ((acc.$2 + 1) % 0x100 == v[2], v[2]);
// },
// (false, -1),
// ),
// builder: (context, snapshot) {
// return Text(snapshot.data.toString());
// },
// ),
// ),
Expanded(
child: SingleChildScrollView(
child: EcgMonitor(
module: BLEManager().module,
// isFiltered: false,
),
),
),
],
),
floatingActionButton: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ControlPanel(module: BLEManager().module),
FloatingActionButton(
onPressed: () {
BLEManager().module.ecg?.dataFilter?.dcBlock = DcBlock.off;
BLEManager().module.ecg?.dataFilter?.lowPass = LowPass.off;
BLEManager().module.ecg?.dataFilter?.highPass = HighPass.off;
BLEManager().module.ecg?.dataFilter?.bandStop = BandStop.off;
},
),
FloatingActionButton(
onPressed: () {
BLEManager().module.ecg?.resetPlot();
},
),
FloatingActionButton(
onPressed: () {
final dir = Directory('20s_250sps');
for (final file in dir.listSync()) {
if (file is! File) continue;
// if(!file.path.contains('260hz')) continue;
print(file.path);
final dataAsString = file.readAsStringSync();
final dataJson = jsonDecode(dataAsString);
final hr = AdaptiveFilterRT();
final l2 = dataJson['l2'] as List;
final hrList = [];
for (final d in l2) {
final d2 = hr.applyFilter(d)[1];
if (d2 <= 0) continue;
hrList.add(d2);
}
print(hrList);
}
},
),
// FloatingActionButton(
// onPressed: () async {
// final inDir = Directory('20s');
// final outDir = Directory('20s_250sps');
// for (final inFile in inDir.listSync()) {
// if (inFile is! File) continue;
// final outFile = File('${outDir.path}/${inFile.path.split('\\').last}');
// final dataAsString = inFile.readAsStringSync();
// final dataJson = jsonDecode(dataAsString);
// final newMap = <String, dynamic>{};
// final keys = ['l1', 'l2', 'l3', 'aVR', 'aVL', 'aVF', 'v1', 'v2', 'v3', 'v4', 'v5', 'v6'];
// for (final key in keys) {
// newMap[key] =
// await Stream.fromIterable(dataJson[key] as List).bufferCount(2).map((e) => e.first).toList();
// }
// final newMapAsString = jsonEncode(newMap);
// outFile.writeAsStringSync(newMapAsString);
// }
// },
// ),
],
),
);
}
}