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

add: IceStats class

parent f5237bc0
No related branches found
No related tags found
1 merge request!12Clhp map
......@@ -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
......@@ -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;
......
......@@ -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();
......
......@@ -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"),
],
),
),
......
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