Skip to content
Snippets Groups Projects
Commit 329d5bc4 authored by Sara Savanovic Djordjevic's avatar Sara Savanovic Djordjevic
Browse files

update: working dynamic allocation

parent bb1410cf
No related branches found
No related tags found
1 merge request!12Clhp map
...@@ -13,7 +13,7 @@ const String mapEndpoint = "update_map"; ...@@ -13,7 +13,7 @@ const String mapEndpoint = "update_map";
String selectedLake = 'Mjøsa'; // Init to Mjøsa, NB should be initialised to last selected lake String selectedLake = 'Mjøsa'; // Init to Mjøsa, NB should be initialised to last selected lake
Uint8List selectedRelation = Uint8List(0); Uint8List selectedRelation = Uint8List(0);
List<Measurement> selectedMarkerList = []; List<Measurement> selectedMarkerList = [];
Measurement? selectedSubDiv; SubDiv? selectedSubDiv;
LatLng mapCenter = LatLng(60.8000, 10.8471); // NB may not be necessary LatLng mapCenter = LatLng(60.8000, 10.8471); // NB may not be necessary
DateTime ?lastUpdate; // Last time data was fetched from server DateTime ?lastUpdate; // Last time data was fetched from server
......
...@@ -9,7 +9,6 @@ class Measurement { ...@@ -9,7 +9,6 @@ class Measurement {
String bodyOfWater; String bodyOfWater;
LatLng center; LatLng center;
List <SubDiv> subDivs; List <SubDiv> subDivs;
List<IceStats> iceStats;
Measurement({ Measurement({
required this.measurementID, required this.measurementID,
...@@ -18,7 +17,6 @@ class Measurement { ...@@ -18,7 +17,6 @@ class Measurement {
required this.bodyOfWater, required this.bodyOfWater,
required this.center, required this.center,
required this.subDivs, required this.subDivs,
required this.iceStats,
}); });
factory Measurement.fromJson(Map<String, dynamic> json) { factory Measurement.fromJson(Map<String, dynamic> json) {
...@@ -29,9 +27,6 @@ class Measurement { ...@@ -29,9 +27,6 @@ class Measurement {
bodyOfWater: json['BodyOfWater'] ?? 'nil', bodyOfWater: json['BodyOfWater'] ?? 'nil',
center: LatLng(json['CenterLat'], json['CenterLon']), center: LatLng(json['CenterLat'], json['CenterLon']),
subDivs: (json['Subdivisions'] as List<dynamic>).map((data) => SubDiv.fromJson(data)).toList(), subDivs: (json['Subdivisions'] as List<dynamic>).map((data) => SubDiv.fromJson(data)).toList(),
iceStats: (json['IceStats'] as List<dynamic>?)
?.map((data) => IceStats.fromJson(data))
.toList() ?? [],
); );
} }
} }
...@@ -44,7 +39,7 @@ class SubDiv { ...@@ -44,7 +39,7 @@ class SubDiv {
LatLng center; LatLng center;
double accuracy; double accuracy;
Color color; Color color;
Color savedColor; List<IceStats> iceStats;
SubDiv({ SubDiv({
required this.sub_div_id, required this.sub_div_id,
...@@ -54,7 +49,7 @@ class SubDiv { ...@@ -54,7 +49,7 @@ class SubDiv {
required this.center, required this.center,
required this.accuracy, required this.accuracy,
required this.color, required this.color,
required this.savedColor required this.iceStats,
}); });
factory SubDiv.fromJson(Map<String, dynamic> json) { factory SubDiv.fromJson(Map<String, dynamic> json) {
...@@ -67,7 +62,9 @@ class SubDiv { ...@@ -67,7 +62,9 @@ class SubDiv {
accuracy: json['Accuracy'], accuracy: json['Accuracy'],
// Set grey as default color // Set grey as default color
color: json['Color'] != null ? Color(json['Color']) : Colors.grey, color: json['Color'] != null ? Color(json['Color']) : Colors.grey,
savedColor: json['Color'] != null ? Color(json['Color']) : Colors.grey, iceStats: (json['IceStats'] as List<dynamic>?)
?.map((data) => IceStats.fromJson(data))
.toList() ?? [],
); );
} }
} }
...@@ -108,14 +105,14 @@ class IceStats { ...@@ -108,14 +105,14 @@ class IceStats {
} }
return IceStats( return IceStats(
dateTime: DateTime.parse(json['Date'] ?? DateTime.now().toString()), dateTime: DateTime.parse(json['Date']),
slushIce: json['Slush ice'] != null ? json['Slush ice'].toDouble() : 0.0, slushIce: json['Slush ice (m)'] != null ? json['Slush ice (m)'].toDouble() : 0.0,
blackIce: json['Black ice'] != null ? json['Black ice'].toDouble() : 0.0, blackIce: json['Black ice (m)'] != null ? json['Black ice (m)'].toDouble() : 0.0,
totalIce: json['Total ice'] != null ? json['Total ice'].toDouble() : 0.0, totalIce: json['Total ice (m)'] != null ? json['Total ice (m)'].toDouble() : 0.0,
snowDepth: json['Snow depth'] != null ? json['Snow depth'].toDouble() : 0.0, snowDepth: json['Snow depth (m)'] != null ? json['Snow depth (m)'].toDouble() : 0.0,
totalSnow: json['Total snow'] != null ? json['Total snow'].toDouble() : 0.0, totalSnow: json['Total snow (m)'] != null ? json['Total snow (m)'].toDouble() : 0.0,
cloudCover: json['Cloud cover'] != null ? json['Cloud cover'].toDouble() : 0.0, cloudCover: json['Cloud cover'] != null ? json['Cloud cover'].toDouble() : 0.0,
temperature: json['Temperature'] != null ? json['Temperature'].toDouble() : 0.0, temperature: json['Temperature (t)'] != null ? json['Temperature (t)'].toDouble() : 0.0,
); );
} }
} }
......
...@@ -16,15 +16,29 @@ class _BarDataState extends State<BarData> { ...@@ -16,15 +16,29 @@ class _BarDataState extends State<BarData> {
static const double barWidth = 30; static const double barWidth = 30;
// Allocate bar data dynamically from selected subdivision // Allocate bar data dynamically from selected subdivision
var barData = Map<int, List<double>>.from(selectedSubDiv!.iceStats.asMap().map((index, iceStats) { var barData = <int, List<double>>{};
return MapEntry(index, [iceStats.slushIce, iceStats.blackIce, iceStats.snowDepth]);
})); // NB should not be index, should be the date, fix
int touchedIndex = -1; int touchedIndex = -1;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
print("SelectedSubDiv.icestats: ${selectedSubDiv?.iceStats[0].slushIce}");
// Allocate bar data dynamically based from the selected subdivision
for (int i = 0; i < selectedSubDiv!.iceStats.length; i++) {
var entry = selectedSubDiv?.iceStats[i];
if (entry != null) {
barData[i] = [
entry.slushIce,
entry.blackIce,
entry.snowDepth,
];
} else {
barData[i] = [0.0, 0.0, 0.0];
}
}
} }
BarChartGroupData generateGroup( BarChartGroupData generateGroup(
...@@ -178,8 +192,7 @@ class _BarDataState extends State<BarData> { ...@@ -178,8 +192,7 @@ class _BarDataState extends State<BarData> {
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [ children: [
_buildLegendItem(const Color(0xFF13dbff), "Steel ice"), _buildLegendItem(const Color(0xFF13dbff), "Black ice"),
_buildLegendItem(const Color(0xFF000085), "Black ice"),
_buildLegendItem(const Color(0xFF3766E0), "Slush ice"), _buildLegendItem(const Color(0xFF3766E0), "Slush ice"),
_buildLegendItem(Colors.white60, "Snow"), _buildLegendItem(Colors.white60, "Snow"),
], ],
......
...@@ -39,6 +39,8 @@ class _MapContainerWidgetState extends State<MapContainerWidget> { ...@@ -39,6 +39,8 @@ class _MapContainerWidgetState extends State<MapContainerWidget> {
bool isSatTapped = false; // Satellite button tap state tracker bool isSatTapped = false; // Satellite button tap state tracker
bool isMapTapped = false; // OSM button tap state tracker bool isMapTapped = false; // OSM button tap state tracker
Measurement? selectedMeasurement = selectedMarkerList[0];
// Initialise lastUpdate variable from persistent storage if server fetch fails // Initialise lastUpdate variable from persistent storage if server fetch fails
Future<void> checkAndSetLastUpdate() async { Future<void> checkAndSetLastUpdate() async {
if (lastUpdate == null) { if (lastUpdate == null) {
...@@ -61,7 +63,8 @@ class _MapContainerWidgetState extends State<MapContainerWidget> { ...@@ -61,7 +63,8 @@ class _MapContainerWidgetState extends State<MapContainerWidget> {
for (Measurement measurement in widget.measurements) { for (Measurement measurement in widget.measurements) {
for (SubDiv subdivision in measurement.subDivs) { for (SubDiv subdivision in measurement.subDivs) {
if (subdivision.sub_div_id == indexString) { if (subdivision.sub_div_id == indexString) {
selectedSubDiv= widget.measurements[index]; selectedSubDiv = subdivision;
selectedMeasurement = measurement;
break; break;
} }
} }
...@@ -72,7 +75,7 @@ class _MapContainerWidgetState extends State<MapContainerWidget> { ...@@ -72,7 +75,7 @@ class _MapContainerWidgetState extends State<MapContainerWidget> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// Initialise selectedMarker to first element in markerList // Initialise selectedMarker to first element in markerList
selectedSubDiv ??= widget.measurements[0]; selectedSubDiv ??= widget.measurements[0].subDivs[0];
checkAndSetLastUpdate(); checkAndSetLastUpdate();
...@@ -237,16 +240,16 @@ class _MapContainerWidgetState extends State<MapContainerWidget> { ...@@ -237,16 +240,16 @@ class _MapContainerWidgetState extends State<MapContainerWidget> {
style: subHeadingStyle, style: subHeadingStyle,
), ),
Text( Text(
'Date: ${(selectedSubDiv?.timeMeasured.day ?? '-')}/${(selectedSubDiv?.timeMeasured.month ?? '-')}/${(selectedSubDiv?.timeMeasured.year ?? '-')}', 'Date: ${(selectedMeasurement?.timeMeasured.day ?? '-')}/${(selectedMeasurement?.timeMeasured.month ?? '-')}/${(selectedMeasurement?.timeMeasured.year ?? '-')}',
style: regTextStyle, style: regTextStyle,
), ),
Text( Text(
'Time: ${selectedSubDiv?.timeMeasured.hour}:00', 'Time: ${selectedMeasurement?.timeMeasured.hour}:00',
style: regTextStyle, style: regTextStyle,
), ),
const SizedBox(height: contPadding), const SizedBox(height: contPadding),
Text( Text(
'Measuring point: (${selectedSubDiv?.measurementID}, ${selectedSubDiv?.measurementID})', 'Measuring point: (${selectedMeasurement?.measurementID}, ${selectedMeasurement?.measurementID})',
style: regTextStyle, style: regTextStyle,
), ),
], ],
......
This diff is collapsed.
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment