Skip to content

Commit d66b5cd

Browse files
authored
Merge pull request #21 from UteSpiske/database-recording
Database recording
2 parents 550dc32 + aa6e041 commit d66b5cd

File tree

8 files changed

+582
-124
lines changed

8 files changed

+582
-124
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[![GitHub Downloads](https://img.shields.io/github/downloads/andreped/DSS/total?label=GitHub%20downloads&logo=github)](https://github.com/andreped/DSS/releases)
1010
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.7603053.svg)](https://doi.org/10.5281/zenodo.7603053)
1111
[![codecov](https://codecov.io/gh/andreped/DSS/branch/main/graph/badge.svg?token=Nf2GKXXYXE)](https://codecov.io/gh/andreped/DSS)
12-
12+
1313
**DSS** was developed by SINTEF Health with aim to integrate AIs into smart sensor systems.
1414
</div>
1515

@@ -20,7 +20,7 @@ Below there are described some of the key features of this project, but to see w
2020
| Build Type | Status |
2121
| - | - |
2222
| **Test Training** | ![CI](https://github.com/andreped/DSS/workflows/Test%20Training/badge.svg) |
23-
| **Test Flutter** | ![CI](https://github.com/andreped/DSS/workflows/Test%20Flutter/badge.svg)|
23+
| **Test Flutter** | ![CI](https://github.com/andreped/DSS/workflows/Test%20Flutter/badge.svg)|
2424
| **Build APK** | ![CI](https://github.com/andreped/DSS/workflows/Build%20APK/badge.svg) |
2525

2626

@@ -114,12 +114,12 @@ FeaturesDict({
114114
The training framework was mainly developed using [Keras](https://github.com/keras-team/keras) with [TensorFlow](https://github.com/tensorflow/tensorflow) backend.
115115

116116
The mobile app was developed using [Flutter](https://github.com/flutter/flutter), which is a framework developed by Google.
117-
For the app, the following _open_ packages were used (either MIT or BSD-2 licensed):
117+
For the app, the following _open_ packages were used (either MIT, BSD-2, or BSD-3 licensed):
118118
* [flutter_sensors](https://pub.dev/packages/flutter_sensors)
119119
* [tflite_flutter](https://pub.dev/packages/tflite_flutter)
120120
* [wakelock](https://pub.dev/packages/wakelock)
121121
* [sqflite](https://pub.dev/packages/sqflite)
122-
* [provider](https://pub.dev/packages/provider)
122+
* [intl](https://pub.dev/packages/intl)
123123

124124
## How to cite
125125

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:sw_app/widgets/recording_database.dart';
3+
import 'package:sw_app/widgets/recording_model.dart';
4+
import 'package:intl/intl.dart';
5+
6+
class RecordingStoragePage extends StatefulWidget {
7+
@override
8+
_RecordingStoragePageState createState() => _RecordingStoragePageState();
9+
}
10+
11+
class _RecordingStoragePageState extends State<RecordingStoragePage> {
12+
late List<RecordingList> recordingList;
13+
bool isLoading = false;
14+
15+
@override
16+
void initState() {
17+
super.initState();
18+
19+
refreshNotes();
20+
}
21+
22+
@override
23+
void dispose() {
24+
super.dispose();
25+
}
26+
27+
Future refreshNotes() async {
28+
setState(() => isLoading = true);
29+
30+
this.recordingList =
31+
(await RecordingDatabase.instance.readRecordingList())!;
32+
33+
setState(() => isLoading = false);
34+
}
35+
36+
@override
37+
Widget build(BuildContext context) {
38+
var theme = Theme.of(context);
39+
var style = theme.textTheme.displaySmall!.copyWith(fontSize: 30);
40+
41+
return SingleChildScrollView(
42+
//physics: AlwaysScrollableScrollPhysics(),
43+
primary: false,
44+
child: Column(
45+
children: [
46+
const SizedBox(
47+
height: 20,
48+
width: 20,
49+
),
50+
Container(
51+
//alignment: Alignment.center,
52+
//padding: const EdgeInsets.all(30),
53+
width: 380,
54+
decoration: BoxDecoration(
55+
borderRadius: BorderRadius.circular(10),
56+
),
57+
child: Row(
58+
mainAxisAlignment: MainAxisAlignment.spaceAround,
59+
children: [
60+
Text('Recorded Data', textAlign: TextAlign.center, style: style),
61+
ElevatedButton.icon(
62+
onPressed: () async {
63+
await RecordingDatabase.instance.deleteDatabase();
64+
setState(() {});
65+
},
66+
label: Text('Delete all'),
67+
icon: Icon(Icons.delete),
68+
style: ElevatedButton.styleFrom(backgroundColor: Colors.red),
69+
),
70+
],
71+
),
72+
),
73+
const SizedBox(
74+
height: 20,
75+
width: 20,
76+
),
77+
FutureBuilder<List<RecordingList>?>(
78+
future: RecordingDatabase.instance.readRecordingList(),
79+
builder: (context, AsyncSnapshot<List<RecordingList>?> snapshot) {
80+
if (snapshot.hasError) {
81+
return Center(child: Text(snapshot.error.toString()));
82+
}
83+
if (snapshot.data != null) {
84+
return ListView.builder(
85+
physics: NeverScrollableScrollPhysics(),
86+
shrinkWrap: true,
87+
itemCount: snapshot.data?.length,
88+
itemBuilder: (context, index) {
89+
final item = snapshot.data![index];
90+
return ListTile(
91+
leading: Icon(Icons.edgesensor_high),
92+
title: Text(
93+
'''Start time: ${DateFormat('dd-MM-yyyy- – kk:mm').format(item.timeStamp)}
94+
Duration: ${item.duration} sec'''),
95+
trailing: IconButton(
96+
onPressed: () {
97+
RecordingDatabase.instance.delete(item.id);
98+
setState(() {});
99+
},
100+
icon: Icon(Icons.delete)),
101+
);
102+
},
103+
);
104+
} else {
105+
return Container(
106+
height: 300,
107+
child: const Center(
108+
child: Text(
109+
'No recordings yet',
110+
style: TextStyle(fontSize: 20),
111+
),
112+
));
113+
}
114+
},
115+
),
116+
],
117+
),
118+
);
119+
}
120+
}

sw_app/lib/widgets/datarecording.dart

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_sensors/flutter_sensors.dart';
33
import 'package:fl_chart/fl_chart.dart';
4-
import 'package:sqflite/sqflite.dart';
4+
import 'package:sw_app/widgets/recording_database.dart';
5+
import 'package:sw_app/widgets/recording_model.dart';
56
import 'dart:math';
67
import '../utils/datatypes.dart';
78
import '../utils/constants.dart' as _constants;
@@ -25,8 +26,9 @@ class _DataRecordingPageState extends State<DataRecordingPage> {
2526

2627
var accelSubscription;
2728
var isStarted = false;
29+
var recordingList;
2830

29-
void stream_accelerometer_data() async {
31+
void stream_accelerometer_data(listId) async {
3032
final _stream = await SensorManager().sensorUpdates(
3133
sensorId: Sensors.ACCELEROMETER,
3234
interval: Sensors.SENSOR_DELAY_GAME,
@@ -54,9 +56,15 @@ class _DataRecordingPageState extends State<DataRecordingPage> {
5456
zPoints.removeAt(0);
5557
}
5658

57-
setState(() {
58-
//this.isStarted = true;
59-
});
59+
setState(() {});
60+
61+
var recording = Recording(
62+
listId: listId ,
63+
timeStamp: DateTime.now(),
64+
xAccel: x,
65+
yAccel: y,
66+
zAccel: z);
67+
RecordingDatabase.instance.create(recording);
6068
});
6169
}
6270

@@ -147,11 +155,21 @@ class _DataRecordingPageState extends State<DataRecordingPage> {
147155
makeLineChart(yPoints, _constants.yColor),
148156
makeLineChart(zPoints, _constants.zColor),
149157
ElevatedButton(
150-
onPressed: () {
158+
onPressed: () async {
151159
this.isStarted = !this.isStarted;
152-
this.isStarted
153-
? stream_accelerometer_data()
154-
: reset_variables();
160+
if (this.isStarted) {
161+
recordingList = RecordingList(
162+
timeStamp: DateTime.now(), duration: 0);
163+
RecordingDatabase.instance.createList(recordingList);
164+
165+
int latestListId = await RecordingDatabase.instance.getLatestListId();
166+
167+
stream_accelerometer_data(latestListId);
168+
} else {
169+
170+
RecordingDatabase.instance.update();
171+
reset_variables();
172+
}
155173

156174
setState(() {});
157175
},

0 commit comments

Comments
 (0)