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 {
}
}
/// Load last saved relation data form last_relation.json
Future<Uint8List> loadSavedRelation() async {
try {
// Get latest saved relation from file if the server does not respond
Directory appDocumentsDirectory = await getApplicationDocumentsDirectory();
String filePath = '${appDocumentsDirectory.path}/last_relation.json';
// Read file contents
// Read file contents as bytes
File file = File(filePath);
if (await file.exists()) {
String contents = await file.readAsString();
List<dynamic> jsonData = json.decode(contents); // Parse JSON string from file
Uint8List relation = Uint8List.fromList(utf8.encode(jsonData.toString()));
return relation;
Uint8List bytes = await file.readAsBytes();
return bytes;
} else {
throw Exception('File does not exist');
throw Exception('Relation file does not exist');
}
} catch (error) {
print('Error in reading relation from file: $error');
return Uint8List(0);
print('Error in reading relation from file: $error');
return Uint8List(0);
}
}
......@@ -20,10 +20,8 @@ Future<void> initialiseState() async {
late Future<Uint8List> relationFuture;
try {
// Read data from files if no internet connection
if (!internetConnection) {
selectedRelation = Uint8List(0); // NB update once fixed
if (!internetConnection) { // Read data from files if no internet connection
selectedRelation = await loadSavedRelation();
FetchResult fetchResult = await loadSavedData();
List<Measurement> measurements = fetchResult.measurements;
......
......@@ -13,6 +13,7 @@ import sqlite3
app = Flask(__name__)
terminate_server = 0
class IceHTTPServer(HTTPServer):
def __init__(self, server_address, handler_class, cursor):
super().__init__(server_address, handler_class)
......@@ -65,7 +66,8 @@ class IceHTTP(BaseHTTPRequestHandler):
def do_POST(self):
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
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