Skip to content

Commit

Permalink
Science filter (#113)
Browse files Browse the repository at this point in the history
allows for "dart run ./bin/science.dart" without breaking the dashboard

---------

Co-authored-by: Levi Lesches <[email protected]>
  • Loading branch information
aidanahram and Levi-Lesches authored Jun 2, 2023
1 parent 43985ca commit fa307c7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
38 changes: 32 additions & 6 deletions bin/science.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,37 @@
import "dart:convert";
import "dart:io";
import "dart:math";
//import "dart:math";

import "package:rover_dashboard/data.dart";
//import "package:rover_dashboard/data.dart";
import "package:protobuf/protobuf.dart" as proto;
//import "package:rover_dashboard/data.dart";
import "package:rover_dashboard/generated/google/protobuf/timestamp.pb.dart";
import "package:rover_dashboard/generated/science.pb.dart";
import "package:rover_dashboard/generated/wrapper.pb.dart";


//export "package:protobuf/protobuf.dart" show GeneratedMessageGenericExtensions;
//import "../lib/src/data/protobuf.dart";


/// A cleaner name for any message generated by Protobuf.
typedef Message = proto.GeneratedMessage;

extension MessageUtils on Message {
/// The name of the message as declared in the .proto file.
String get messageName => info_.messageName;

/// Returns a [WrappedMessage] representing this message with a timestamp
WrappedMessage wrap([DateTime? timestamp]) => WrappedMessage(
data: writeToBuffer(),
name: messageName,
timestamp: Timestamp.fromDateTime(timestamp ?? DateTime.now()),
);
}

/// Change these paths as needed
const oldPath = r"C:\Users\llesche1\Documents\Dashboard\logs\2023-5-5-1-7\ScienceData.log";
const newPath = r"C:\Users\llesche1\Documents\Dashboard\logs\2023-5-5-1-7\ScienceData2.log";
const oldPath = "/Users/aidanahram/Downloads/FakeData1.log";
const newPath = "/Users/aidanahram/Downloads/FakeData1New.log";

/// Return true to keep this data in the dataset, or false to remove it.
///
Expand Down Expand Up @@ -43,7 +68,7 @@ WrappedMessage modifyData(Timestamp timestamp, ScienceData data) {
// Wrap the data and return it. Do not delete.
return data.wrap(timestamp.toDateTime());
}

/*
/// Use this to add new data to your dataset.
List<WrappedMessage> newData = [
// Adds methane=1 for every second from t=1 to t=100 seconds
Expand All @@ -69,6 +94,7 @@ List<WrappedMessage> newData = [
// ==================== Do not edit unless you're Aidan or Levi ====================
final random = Random();
*/

extension on num {
bool isOutOfBounds({required num min, required num max}) => (this > max) || (this != 0 && this < min);
Expand All @@ -92,7 +118,7 @@ void main() async {
int pruned = 0;
if (File(newPath).existsSync()) await File(newPath).delete();
final List<WrappedMessage> oldData = await readLogs(File(oldPath));
for (final wrapper in oldData + newData) {
for (final wrapper in oldData) {
final data = ScienceData.fromBuffer(wrapper.data);
if (!shouldKeepData(data)) { pruned++; continue; }
else { await logData(modifyData(wrapper.timestamp, data)); }
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: rover_dashboard
description: Graphical application for remotely operating the rover.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 2023.6.2+1
version: 2023.6.2+3

environment:
sdk: "^3.0.0"
Expand Down Expand Up @@ -63,7 +63,7 @@ flutter_launcher_icons:
# Builds a Windows .msix App Installer file for the Dashboard.
# Run: flutter pub run msix:create
msix_config:
msix_version: 2023.6.2.1
msix_version: 2023.6.2.3
display_name: Dashboard
publisher_display_name: Binghamton University Rover Team
identity_name: edu.binghamton.rover
Expand Down

0 comments on commit fa307c7

Please sign in to comment.