Skip to content

Commit

Permalink
fix telemetrySaver
Browse files Browse the repository at this point in the history
  • Loading branch information
paulo authored and paulo committed May 4, 2024
1 parent 6c080c7 commit 1e2d01d
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 118 deletions.
42 changes: 26 additions & 16 deletions lib/providers/telemetry/telemetry_saver.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import 'dart:async';
import 'dart:convert';
import 'dart:typed_data';

import 'package:csv/csv.dart';
import 'package:file_saver/file_saver.dart';
import 'package:intl/intl.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:to_csv/to_csv.dart';

import '../../extensions.dart';
import '../radio_config/radio_config_service.dart';
import '../repository/telemetry_repository.dart';

part 'telemetry_saver.g.dart';

@Riverpod(keepAlive: true)
@riverpod
Raw<Future<void>> telemetrySaver(TelemetrySaverRef ref, int nodeNum) async {
final telemetryRepository = ref.watch(telemetryRepositoryProvider);
final myNodeNum =
Expand All @@ -20,7 +26,7 @@ Raw<Future<void>> telemetrySaver(TelemetrySaverRef ref, int nodeNum) async {
final data =
await telemetryRepository.get(fromNode: nodeNum, owner: myNodeNum);

final parsedData = data.map((it) {
final csvBodyData = data.map((it) {
final telemetry = it.telemetry;
final environmentalMetrics = it.telemetry.environmentMetrics;
final recordedTime =
Expand All @@ -46,18 +52,22 @@ Raw<Future<void>> telemetrySaver(TelemetrySaverRef ref, int nodeNum) async {
final nodeNumHexLastFour = nodeNumHex.substring(nodeNumHex.length - 4);
final formattedDate =
DateFormat('MM-dd-yyyy-HH-mm-ss').format(DateTime.now());
final filename = 'Telemetry-$nodeNumHexLastFour-$formattedDate';

await myCSV(
[
'Time received',
'Time recorded',
'Temperature ${displayFahrenheit ? 'F' : 'C'}',
'Relative Humidity',
'Barometric Pressure',
'Gas Resistance',
'IAQ',
],
parsedData,
fileName: 'Telemetry-$nodeNumHexLastFour-$formattedDate',
);
final headerRow = [
'Time received',
'Time recorded',
'Temperature ${displayFahrenheit ? 'F' : 'C'}',
'Relative Humidity',
'Barometric Pressure',
'Gas Resistance',
'IAQ',
];

final csvData =
const ListToCsvConverter().convert([headerRow, ...csvBodyData]);
final bytes = Uint8List.fromList(utf8.encode(csvData));
const type = MimeType.csv;
await FileSaver.instance
.saveAs(name: filename, bytes: bytes, ext: 'csv', mimeType: type);
}
11 changes: 6 additions & 5 deletions lib/providers/telemetry/telemetry_saver.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import flutter_local_notifications
import mobile_scanner
import package_info_plus
import path_provider_foundation
import share_plus
import shared_preferences_foundation
import sqflite

Expand All @@ -28,7 +27,6 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
MobileScannerPlugin.register(with: registry.registrar(forPlugin: "MobileScannerPlugin"))
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
}
84 changes: 2 additions & 82 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.0"
charcode:
dependency: transitive
description:
name: charcode
sha256: fb98c0f6d12c920a02ee2d998da788bca066ca5f148492b7085ee23372b12306
url: "https://pub.dev"
source: hosted
version: "1.3.1"
chat_bubbles:
dependency: "direct main"
description:
Expand Down Expand Up @@ -225,14 +217,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.7.2"
cross_file:
dependency: transitive
description:
name: cross_file
sha256: "55d7b444feb71301ef6b8838dbc1ae02e63dd48c8773f3810ff53bb1e2945b32"
url: "https://pub.dev"
source: hosted
version: "0.3.4+1"
crypto:
dependency: "direct main"
description:
Expand All @@ -250,7 +234,7 @@ packages:
source: hosted
version: "1.0.0"
csv:
dependency: transitive
dependency: "direct main"
description:
name: csv
sha256: "63ed2871dd6471193dffc52c0e6c76fb86269c00244d244297abbb355c84a86e"
Expand Down Expand Up @@ -338,7 +322,7 @@ packages:
source: hosted
version: "7.0.0"
file_saver:
dependency: transitive
dependency: "direct main"
description:
name: file_saver
sha256: bdebc720e17b3e01aba59da69b6d47020a7e5ba7d5c75bd9194f9618d5f16ef4
Expand Down Expand Up @@ -1024,22 +1008,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.19.1"
share_plus:
dependency: transitive
description:
name: share_plus
sha256: "3ef39599b00059db0990ca2e30fca0a29d8b37aae924d60063f8e0184cf20900"
url: "https://pub.dev"
source: hosted
version: "7.2.2"
share_plus_platform_interface:
dependency: transitive
description:
name: share_plus_platform_interface
sha256: "251eb156a8b5fa9ce033747d73535bf53911071f8d3b6f4f0b578505ce0d4496"
url: "https://pub.dev"
source: hosted
version: "3.4.0"
shared_preferences:
dependency: "direct main"
description:
Expand Down Expand Up @@ -1317,14 +1285,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.1"
to_csv:
dependency: "direct main"
description:
name: to_csv
sha256: "52b31fa320c5d83b900cb8b73f4438c4cc851b154ab8ec06cadfd88cd2962dba"
url: "https://pub.dev"
source: hosted
version: "2.2.1"
tuple:
dependency: "direct main"
description:
Expand All @@ -1341,14 +1301,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.2"
universal_html:
dependency: transitive
description:
name: universal_html
sha256: "56536254004e24d9d8cfdb7dbbf09b74cf8df96729f38a2f5c238163e3d58971"
url: "https://pub.dev"
source: hosted
version: "2.2.4"
universal_io:
dependency: transitive
description:
Expand All @@ -1357,38 +1309,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.2.2"
url_launcher_linux:
dependency: transitive
description:
name: url_launcher_linux
sha256: ab360eb661f8879369acac07b6bb3ff09d9471155357da8443fd5d3cf7363811
url: "https://pub.dev"
source: hosted
version: "3.1.1"
url_launcher_platform_interface:
dependency: transitive
description:
name: url_launcher_platform_interface
sha256: "552f8a1e663569be95a8190206a38187b531910283c3e982193e4f2733f01029"
url: "https://pub.dev"
source: hosted
version: "2.3.2"
url_launcher_web:
dependency: transitive
description:
name: url_launcher_web
sha256: "8d9e750d8c9338601e709cd0885f95825086bd8b642547f26bda435aade95d8a"
url: "https://pub.dev"
source: hosted
version: "2.3.1"
url_launcher_windows:
dependency: transitive
description:
name: url_launcher_windows
sha256: ecf9725510600aa2bb6d7ddabe16357691b6d2805f66216a97d1b881e21beff7
url: "https://pub.dev"
source: hosted
version: "3.1.1"
uuid:
dependency: transitive
description:
Expand Down
7 changes: 2 additions & 5 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ dependencies:
chat_bubbles: ^1.6.0
convert: ^3.1.1
crypto: ^3.0.3
csv: ^5.1.1
easy_debounce: ^2.0.3
file_saver: ^0.2.12
firebase_analytics: ^10.10.1
firebase_core: ^2.29.0
firebase_crashlytics: ^3.5.1
Expand Down Expand Up @@ -44,7 +46,6 @@ dependencies:
shimmer: ^3.0.0
sqflite: ^2.3.2
sqflite_common_ffi: ^2.3.3
to_csv: ^2.2.1
tuple: ^2.0.2

dev_dependencies:
Expand All @@ -60,10 +61,6 @@ dev_dependencies:
riverpod_lint: ^2.3.8
test: ^1.24.9

dependency_overrides:
flutter_lints: ^3.0.1
intl: ^0.19.0

flutter:
uses-material-design: true
assets:
Expand Down
6 changes: 0 additions & 6 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#include <file_saver/file_saver_plugin.h>
#include <firebase_core/firebase_core_plugin_c_api.h>
#include <permission_handler_windows/permission_handler_windows_plugin.h>
#include <share_plus/share_plus_windows_plugin_c_api.h>
#include <url_launcher_windows/url_launcher_windows.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
FileSaverPluginRegisterWithRegistrar(
Expand All @@ -19,8 +17,4 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("FirebaseCorePluginCApi"));
PermissionHandlerWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin"));
SharePlusWindowsPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("SharePlusWindowsPluginCApi"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
}
2 changes: 0 additions & 2 deletions windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ list(APPEND FLUTTER_PLUGIN_LIST
file_saver
firebase_core
permission_handler_windows
share_plus
url_launcher_windows
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down

0 comments on commit 1e2d01d

Please sign in to comment.