Skip to content

Commit

Permalink
Merge pull request #125 from COS301-SE-2024/NonFuncTesting
Browse files Browse the repository at this point in the history
Audio Integration
  • Loading branch information
PineCone85 authored Sep 29, 2024
2 parents 6fc6039 + bc6ff6e commit b782c45
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 0 deletions.
46 changes: 46 additions & 0 deletions frontend/lib/NonFuncTesting/NonFuncTestingPage.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import 'package:flutter/material.dart';
import 'neural_net_service.dart'; // Import the service

class ImageProcessingPage extends StatelessWidget {
const ImageProcessingPage({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Image Processing Page'),
),
body: Center(
child: ElevatedButton(
onPressed: () async {
NeuralNetService neuralNetService = NeuralNetService();
double avgResponseTime = await neuralNetService.processImagesAndGetAverageResponseTime();
_showAverageResponseTime(context, avgResponseTime);
},
child: const Text('Select Images and Get Avg Response Time'),
),
),
);
}

// Function to show average response time in a dialog
void _showAverageResponseTime(BuildContext context, double avgResponseTime) {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('Average Response Time'),
content: Text('Average Response Time: $avgResponseTime ms'),
actions: <Widget>[
TextButton(
child: const Text('OK'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
}
52 changes: 52 additions & 0 deletions frontend/lib/NonFuncTesting/neural_net_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import 'package:flutter/services.dart';
import 'package:file_picker/file_picker.dart';
import 'dart:async';
import 'dart:io';

class NeuralNetService {
static const MethodChannel _channel = MethodChannel('neural_net_method_channel');


Future<double> processImagesAndGetAverageResponseTime() async {
List<File> selectedFiles = [];
int totalResponseTime = 0;
try {
FilePickerResult? result = await FilePicker.platform.pickFiles(
type: FileType.image,
allowMultiple: true,
);
if (result != null) {
selectedFiles = result.paths
.where((path) => path != null)
.map((path) => File(path!))
.toList()
.take(10)
.toList();
} else {
print('No files selected');
return 0.0;
}
} on PlatformException catch (e) {
print('Error: ${e.message}');
return 0.0;
}

// Step 2: Calculate the average response time
for (var file in selectedFiles) {
final stopwatch = Stopwatch()..start();

try {
final imageBytes = await file.readAsBytes();
await _channel.invokeMethod('get_mood', {'image': imageBytes});
} on PlatformException catch (e) {
print('Error: ${e.message}');
continue;
}

stopwatch.stop();
totalResponseTime += stopwatch.elapsedMilliseconds;
}

return selectedFiles.isNotEmpty ? totalResponseTime / selectedFiles.length : 0.0;
}
}
4 changes: 4 additions & 0 deletions frontend/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import 'package:frontend/pages/camera.dart';
import 'package:camera/camera.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:frontend/pages/audio_player_page.dart';
import 'package:frontend/NonFuncTesting/NonFuncTestingPage.dart';


List<CameraDescription> cameras = <CameraDescription>[];

Expand Down Expand Up @@ -74,6 +76,8 @@ class MyApp extends StatelessWidget {
'/camerahelp': (context) => CameraVoiceHelpPage(),
'/settings': (context) => SettingsPage(),
'/audio': (context) => AudioPlayerPage(),
'/NonFunc': (context) => ImageProcessingPage()

},
theme: Provider.of<ThemeProvider>(context).themeData,
),
Expand Down
2 changes: 2 additions & 0 deletions frontend/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ environment:
dependencies:
flutter:
sdk: flutter

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.6
Expand Down Expand Up @@ -59,6 +60,7 @@ dependencies:
permission_handler: ^10.3.0
sentiment_dart:
sqflite_common_ffi:
file_picker: ^8.1.2



Expand Down

0 comments on commit b782c45

Please sign in to comment.