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

update: maybe fix loadRelation()

parent 7946b488
No related branches found
No related tags found
1 merge request!11Clhp map
...@@ -45,25 +45,23 @@ Future<Uint8List> fetchRelation() async { ...@@ -45,25 +45,23 @@ Future<Uint8List> fetchRelation() async {
} }
} }
/// Load last saved relation data form last_relation.json
Future<Uint8List> loadSavedRelation() async { Future<Uint8List> loadSavedRelation() async {
try { try {
// Get latest saved relation from file if the server does not respond // Get latest saved relation from file if the server does not respond
Directory appDocumentsDirectory = await getApplicationDocumentsDirectory(); Directory appDocumentsDirectory = await getApplicationDocumentsDirectory();
String filePath = '${appDocumentsDirectory.path}/last_relation.json'; String filePath = '${appDocumentsDirectory.path}/last_relation.json';
// Read file contents // Read file contents as bytes
File file = File(filePath); File file = File(filePath);
if (await file.exists()) { if (await file.exists()) {
String contents = await file.readAsString(); Uint8List bytes = await file.readAsBytes();
List<dynamic> jsonData = json.decode(contents); // Parse JSON string from file return bytes;
Uint8List relation = Uint8List.fromList(utf8.encode(jsonData.toString()));
return relation;
} else { } else {
throw Exception('File does not exist'); throw Exception('Relation file does not exist');
} }
} catch (error) { } catch (error) {
print('Error in reading relation from file: $error'); print('Error in reading relation from file: $error');
return Uint8List(0); return Uint8List(0);
} }
} }
...@@ -20,10 +20,8 @@ Future<void> initialiseState() async { ...@@ -20,10 +20,8 @@ Future<void> initialiseState() async {
late Future<Uint8List> relationFuture; late Future<Uint8List> relationFuture;
try { try {
if (!internetConnection) { // Read data from files if no internet connection
// Read data from files if no internet connection selectedRelation = await loadSavedRelation();
if (!internetConnection) {
selectedRelation = Uint8List(0); // NB update once fixed
FetchResult fetchResult = await loadSavedData(); FetchResult fetchResult = await loadSavedData();
List<Measurement> measurements = fetchResult.measurements; List<Measurement> measurements = fetchResult.measurements;
......
...@@ -13,6 +13,7 @@ import sqlite3 ...@@ -13,6 +13,7 @@ import sqlite3
app = Flask(__name__) app = Flask(__name__)
terminate_server = 0 terminate_server = 0
class IceHTTPServer(HTTPServer): class IceHTTPServer(HTTPServer):
def __init__(self, server_address, handler_class, cursor): def __init__(self, server_address, handler_class, cursor):
super().__init__(server_address, handler_class) super().__init__(server_address, handler_class)
...@@ -65,7 +66,8 @@ class IceHTTP(BaseHTTPRequestHandler): ...@@ -65,7 +66,8 @@ class IceHTTP(BaseHTTPRequestHandler):
def do_POST(self): def do_POST(self):
if self.path == '/new_lidar_data': if self.path == '/new_lidar_data':
input_new_Lidar_data(self,self.cursor, 1, 'Mjosa') # hardcoded body of water must change later input_new_Lidar_data(self, self.cursor, 1, 'Mjosa') # hardcoded body of water must change later
# Start a server on port 8443 using self defined HTTP class # Start a server on port 8443 using self defined HTTP class
if __name__ == "__main__": if __name__ == "__main__":
......
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