From 40aa2528b7650feaa7dbd20e37d32190eaf4b8cb Mon Sep 17 00:00:00 2001
From: Sara <sarasdj@stud.ntnu.no>
Date: Tue, 7 May 2024 11:31:49 +0200
Subject: [PATCH] update: subdiv list in init

---
 app/lib/consts.dart                           |   4 ++--
 app/lib/pages/default_page.dart               |   1 +
 app/lib/server_requests/init_state.dart       |  21 +++++++++++++++++-
 app/lib/widgets/choropleth_map.dart           |  21 +++++-------------
 app/lib/widgets/main_layout.dart              |   3 +++
 server/__pycache__/scheduler.cpython-311.pyc  | Bin 0 -> 1734 bytes
 .../get_measurements.cpython-311.pyc          | Bin 7443 -> 6476 bytes
 7 files changed, 31 insertions(+), 19 deletions(-)
 create mode 100644 server/__pycache__/scheduler.cpython-311.pyc

diff --git a/app/lib/consts.dart b/app/lib/consts.dart
index d3163031..dae3e59a 100644
--- a/app/lib/consts.dart
+++ b/app/lib/consts.dart
@@ -11,12 +11,12 @@ const String mapEndpoint = "update_map";
 
 // Map variables
 String selectedLake = 'Mjøsa'; // NB should be initialised to last selected lake
-Uint8List selectedRelation = Uint8List(0);
+
+Uint8List selectedRelation = Uint8List(0); // Initialised in init_state.dart
 List<Measurement> selectedMeasurements = [];
 List<SubDiv> selectedSubdivisions = [];
 SubDiv? selectedSubDiv;
 
-LatLng mapCenter = LatLng(60.8000, 10.8471); // NB may not be necessary
 DateTime ?lastUpdate; // Last time data was fetched from server
 List<String> lakeSearchOptions = [];
 bool internetConnection = true;
diff --git a/app/lib/pages/default_page.dart b/app/lib/pages/default_page.dart
index e57dd7be..3d9459e3 100644
--- a/app/lib/pages/default_page.dart
+++ b/app/lib/pages/default_page.dart
@@ -86,6 +86,7 @@ class _DefaultPageState extends State<DefaultPage> {
             child: ListView(
               children: [
                 MapContainerWidget(
+                  subdivisions: selectedSubdivisions,
                   measurements: selectedMeasurements,
                   relation: selectedRelation,
                   serverConnection: serverConnection,
diff --git a/app/lib/server_requests/init_state.dart b/app/lib/server_requests/init_state.dart
index f9ad01fe..a30d0fd5 100644
--- a/app/lib/server_requests/init_state.dart
+++ b/app/lib/server_requests/init_state.dart
@@ -26,13 +26,32 @@ Future<void> initialiseState(bool fetchSearchOptions) async {
       List<Measurement> measurements = fetchResult.measurements;
       selectedMeasurements = measurements;
 
+      // Extract all _subdivisions from list of measurements
+      for (Measurement measurement in measurements) {
+        for (SubDiv subdivision in measurement.subDivs) {
+          selectedSubdivisions.add(subdivision);
+        }
+      }
+
+      // Sort the list of SubDiv objects based on each subdivision id
+      selectedSubdivisions.sort((a, b) => a.sub_div_id.compareTo(b.sub_div_id));
+
       print("Loaded from files: Meas.len: ${selectedMeasurements.length}, rel.len: ${selectedRelation.length}");
 
     } else { // Try to fetch measurement data from server
       markerListFuture = fetchMeasurements().then((fetchResult) {
         List<Measurement> measurements = fetchResult.measurements;
+        selectedMeasurements = measurements;
+
+        // Extract all _subdivisions from list of measurements
+        for (Measurement measurement in measurements) {
+          for (SubDiv subdivision in measurement.subDivs) {
+            selectedSubdivisions.add(subdivision);
+          }
+        }
+
         serverConnection = fetchResult.connected;
-        setLastLake();
+        setLastLake(); // Update persistent value for latest fetched lake
 
         // Return measurements
         return measurements;
diff --git a/app/lib/widgets/choropleth_map.dart b/app/lib/widgets/choropleth_map.dart
index fdfd07ca..b4869d90 100644
--- a/app/lib/widgets/choropleth_map.dart
+++ b/app/lib/widgets/choropleth_map.dart
@@ -13,11 +13,13 @@ class ChoroplethMap extends StatefulWidget {
     Key? key,
     required this.relation,
     required this.measurements,
+    required this.subdivisions,
     required this.onSelectionChanged,
   }) : super(key: key);
 
   final Uint8List relation;
   final List<Measurement> measurements;
+  final List<SubDiv> subdivisions;
   final void Function(int selectedIndex) onSelectionChanged;
 
   @override
@@ -28,7 +30,6 @@ class ChoroplethMapState extends State<ChoroplethMap> {
   int selectedIndex = -1;            // Subdivision/map tile index
   late MapShapeSource dataSource;
   late final MapZoomPanBehavior _zoomPanBehavior = MapZoomPanBehavior();
-  final List<SubDiv> _subdivisions = <SubDiv>[];
 
   void updateDataSource() {
     _initDataSource();
@@ -41,24 +42,12 @@ class ChoroplethMapState extends State<ChoroplethMap> {
     }
 
     void _initDataSource() {
-      _subdivisions.clear();
-
-      // Extract all _subdivisions from list of measurements
-      for (Measurement measurement in widget.measurements) {
-        for (SubDiv subdivision in measurement.subDivs) {
-          _subdivisions.add(subdivision);
-        }
-      }
-
-      // Sort the list of SubDiv objects based on each subdivision id
-      _subdivisions.sort((a, b) => a.sub_div_id.compareTo(b.sub_div_id));
-
       dataSource = MapShapeSource.memory(
         widget.relation,
         shapeDataField: 'sub_div_id',
-        dataCount: _subdivisions.length,
-        primaryValueMapper: (int index) => _subdivisions[index].sub_div_id,
-        shapeColorValueMapper: (int index) => _subdivisions[index].avgThickness, // NB will later be minThickness
+        dataCount: widget.subdivisions.length,
+        primaryValueMapper: (int index) => widget.subdivisions[index].sub_div_id,
+        shapeColorValueMapper: (int index) => widget.subdivisions[index].avgThickness, // NB will later be minThickness
         shapeColorMappers: const [
           MapColorMapper(
               from: -2,
diff --git a/app/lib/widgets/main_layout.dart b/app/lib/widgets/main_layout.dart
index 652c8b4b..49687cc4 100644
--- a/app/lib/widgets/main_layout.dart
+++ b/app/lib/widgets/main_layout.dart
@@ -14,11 +14,13 @@ import '../utils/format_month.dart';
 /// MapContainerWidget is the main widget that contains the map with all
 /// its layers, polygons and markers.
 class MapContainerWidget extends StatefulWidget {
+  final List<SubDiv> subdivisions;
   final List<Measurement> measurements;
   final  Uint8List relation;
   final bool serverConnection;
 
   const MapContainerWidget({Key? key,
+    required this.subdivisions,
     required this.measurements,
     required this.relation,
     required this.serverConnection,
@@ -105,6 +107,7 @@ class _MapContainerWidgetState extends State<MapContainerWidget> {
                       child: ChoroplethMap(
                         relation: widget.relation,
                         measurements: widget.measurements,
+                        subdivisions: widget.subdivisions,
                         onSelectionChanged: handleSelection,
                       ),
                     ),
diff --git a/server/__pycache__/scheduler.cpython-311.pyc b/server/__pycache__/scheduler.cpython-311.pyc
new file mode 100644
index 0000000000000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_h44bInt
z^NrxV=$Fgx((=L3TMw3Zo$oUbGFu_hESKepB+rG;zk-~|UdJ6DAHPogLPP54?q_u}
z-XP;H8HZ@p$Y%2XWStB(#2opPjQv5zo<y(zTC7JCjcB4yW*cPIC9_SxqFy}E`WxD4
zr<)J7p6$^6$!{auk*!Em1qD6;fBo}NBJ6t<CW*elqYD^lEW`#u&PD_o0^*GVSTcFI
z%EaYz_8w!RExpLAODLYTE$;AEHA@BV$U4eAKSWIQoh-#m?W3|SE~^{t9gqn?@OwZY
vgBU+W;SKqmV){1Z^9)V9-Sa8B;&#ub--j>#M4AYev!rJLUu>fDL`L=>F?5!p

literal 0
HcmV?d00001

diff --git a/server/map_handler/__pycache__/get_measurements.cpython-311.pyc b/server/map_handler/__pycache__/get_measurements.cpython-311.pyc
index 37cda1166d0176caae3f53b92b227f7f3618f8a8..acfeae94592fa21a28438ff18d170d9215bff394 100644
GIT binary patch
delta 1247
zcmZuwO=whC6u$S}_cMQQ=FLneLo$huCfE$ACE7%cKMC5HGFSqlE>aXb^^SHlnHk=^
z5Rv<;NLQ_k>e-a4U@6!|HbS6uQ&A~216?Sz3kTc^VizeQ1i{jCo{2M-o_Y7X-*@gg
z_uRjMUB7RS|7hD0hPLh5*r_KySK^PdoaCA%u@~5$uj*I+nb^oAKac8`#@HgZ*XHxn
z%-669IL5bf4qx$&87{TAqehvp!yTSY>bJ1K;+rDA0d?bjM;Vjs8-6_Jn>dlBOc>A(
z_L<V?Ua!KGDa}p=m$mMkDXq3ohT9xxxU2P_4Plnu_D-_nSN*UG%Xr)8M^Gm^bQHDI
zp<^l{ljuveeW=nMDym{C4AY|92%_NobQfGg6;U_>H$}e)D-Bk}pr$PBvanZA#xH}i
zR7l!;aED5en}=Xr-;`nMKS$@=G7H1nxFZGqlr3Y|O+UVt6o-~x5bUM{o2)dPuo5t6
z^yLzs{pRG@8M?;6lu!xy)Yzg+ahSoORM#;g{mdI!k6>(oxqZIlz1#N49_3tPH?+5J
zj<Xpih3|Z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