diff --git a/app/lib/consts.dart b/app/lib/consts.dart index d1c7751a71c5564ccd46cbcae484bfc4e276be05..b3f948567476401e91e837cb80e12693e5477c4a 100644 --- a/app/lib/consts.dart +++ b/app/lib/consts.dart @@ -8,15 +8,15 @@ import 'package:google_fonts/google_fonts.dart'; const String port = "8443"; const String serverURI = "https://127.0.0.1:$port/"; const String mapEndpoint = "update_map"; -const int fetchInterval = 60; // Fetch marker data every n minutes // Map variables String selectedLake = 'Mjøsa'; // Init to Mjøsa, NB should be initialised to last selected lake Uint8List selectedRelation = Uint8List(0); List<Measurement> selectedMarkerList = []; + LatLng mapCenter = LatLng(60.8000, 10.8471); DateTime ?lastUpdate; // Last time data was fetched from server -List<String> lakeSearchOptions = []; // Init empty +List<String> lakeSearchOptions = []; bool internetConnection = true; // Font settings @@ -35,11 +35,3 @@ final regTextStyle = GoogleFonts.chakraPetch(fontSize: 16, color: textColor); final regTextStyleBig = GoogleFonts.chakraPetch(fontSize: 18, color: textColor); final chartTextStyle = GoogleFonts.chakraPetch(fontSize: 12, color: textColor); final subHeadingStyle = GoogleFonts.chakraPetch(fontSize: 18, color: textColor, fontWeight: FontWeight.bold); - -// Colors -const darkBlue = Color(0xFF015E8F); -const teal = Color(0xFF00B4D8); -const darkestBlue = Color(0xFF03045E); -const lightBlue = Color(0xFFCAF0F8); -const superLightBlue = Color(0xFFCAF0F8); -const barBlue = Color(0xFF0077B6); \ No newline at end of file diff --git a/app/lib/data_classes.dart b/app/lib/data_classes.dart index 8de99433b443b8ddcb9f3ed213c34e6496ffa034..45188019b24a6f73392b2d7fdc56d0c092549fa5 100644 --- a/app/lib/data_classes.dart +++ b/app/lib/data_classes.dart @@ -9,6 +9,7 @@ class Measurement { String bodyOfWater; LatLng center; List <SubDiv> subDivs; + IceStats iceStats; Measurement({ required this.measurementID, @@ -17,6 +18,7 @@ class Measurement { required this.bodyOfWater, required this.center, required this.subDivs, + required this.iceStats, }); factory Measurement.fromJson(Map<String, dynamic> json) { @@ -27,6 +29,7 @@ class Measurement { bodyOfWater: json['BodyOfWater'] ?? 'nil', center: LatLng(json['CenterLat'], json['CenterLon']), subDivs: (json['Subdivisions'] as List<dynamic>).map((data) => SubDiv.fromJson(data)).toList(), + iceStats: IceStats.fromJson(json['IceStats']), ); } } @@ -67,6 +70,54 @@ class SubDiv { } } +class IceStats { + DateTime dateTime; + double slushIce; + double blackIce; + double totalIce; + double snowDepth; + double totalSnow; + double cloudCover; + double temperature; + + IceStats({ + required this.dateTime, + required this.slushIce, + required this.blackIce, + required this.totalIce, + required this.snowDepth, + required this.totalSnow, + required this.cloudCover, + required this.temperature, + }); + + factory IceStats.fromJson(Map<String, dynamic>? json) { + if (json == null) { // Return empty json + return IceStats( + dateTime: DateTime.now(), + slushIce: 0.0, + blackIce: 0.0, + totalIce: 0.0, + snowDepth: 0.0, + totalSnow: 0.0, + cloudCover: 0.0, + temperature: 0.0, + ); + } + + return IceStats( + dateTime: DateTime.parse(json['Date'] ?? DateTime.now().toString()), + slushIce: json['Slush ice'] != null ? json['Slush ice'].toDouble() : 0.0, + blackIce: json['Black ice'] != null ? json['Black ice'].toDouble() : 0.0, + totalIce: json['Total ice'] != null ? json['Total ice'].toDouble() : 0.0, + snowDepth: json['Snow depth'] != null ? json['Snow depth'].toDouble() : 0.0, + totalSnow: json['Total snow'] != null ? json['Total snow'].toDouble() : 0.0, + cloudCover: json['Cloud cover'] != null ? json['Cloud cover'].toDouble() : 0.0, + temperature: json['Temperature'] != null ? json['Temperature'].toDouble() : 0.0, + ); + } +} + class Sensor { int sensorID; String sensorType; diff --git a/app/lib/server_requests/fetch_markers.dart b/app/lib/server_requests/fetch_markers.dart index 80cbc1726d1dc265c8c97da753c1b44c1efeabd6..7cd1b5c4e1d437a7cfa8d39948d570a055b94c35 100644 --- a/app/lib/server_requests/fetch_markers.dart +++ b/app/lib/server_requests/fetch_markers.dart @@ -70,6 +70,9 @@ Future<FetchResult> loadSavedData() async { // Read file contents File file = File(filePath); if (await file.exists()) { + + print('Reading marker data from file'); + String contents = await file.readAsString(); List<dynamic> jsonData = json.decode(contents); // Parse JSON string from file List<Measurement> measurements = jsonData.map((data) => Measurement.fromJson(data)).toList(); diff --git a/app/lib/widgets/bar_graph/bar_data.dart b/app/lib/widgets/bar_graph/bar_data.dart index db2c2599e619c6d367834e719972fda637164495..779be9ba11facef3956b7ecb64b7c9bde795fe41 100644 --- a/app/lib/widgets/bar_graph/bar_data.dart +++ b/app/lib/widgets/bar_graph/bar_data.dart @@ -119,20 +119,20 @@ class _BarDataState extends State<BarData> { show: true, bottomTitles: SideTitles( showTitles: true, - reservedSize: 5, + reservedSize: 20, getTextStyles: (value) => const TextStyle(color: Colors.white60), ), leftTitles: SideTitles( showTitles: true, getTextStyles: (value) => const TextStyle(color: Colors.white60), - margin: 10, + margin: 5, reservedSize: 30, interval: 2, ), rightTitles: SideTitles( showTitles: true, getTextStyles: (value) => const TextStyle(color: Colors.white60), - margin: 10, + margin: 5, reservedSize: 30, interval: 2, ), @@ -163,10 +163,10 @@ class _BarDataState extends State<BarData> { child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - _buildLegendItem(Colors.white60, "Snow"), - _buildLegendItem(const Color(0xFF3766E0), "Slush ice"), - _buildLegendItem(const Color(0xFF000085), "Black ice"), _buildLegendItem(const Color(0xFF13dbff), "Steel ice"), + _buildLegendItem(const Color(0xFF000085), "Black ice"), + _buildLegendItem(const Color(0xFF3766E0), "Slush ice"), + _buildLegendItem(Colors.white60, "Snow"), ], ), ), diff --git a/server/map_handler/__pycache__/get_measurements.cpython-311.pyc b/server/map_handler/__pycache__/get_measurements.cpython-311.pyc index 738499b30b843de2743516c74543ef6dacca696a..05ef1c7e71b422c77e6e0540aa3e05eb6b2979b2 100644 Binary files a/server/map_handler/__pycache__/get_measurements.cpython-311.pyc and b/server/map_handler/__pycache__/get_measurements.cpython-311.pyc differ