Index: src/mapservice/openapi.yaml
===================================================================
--- src/mapservice/openapi.yaml	(revision 72cc33989269bc2dab1ffc2e448c54534722aa15)
+++ src/mapservice/openapi.yaml	(revision ac11efee71d43906e5e8823aee644605721af468)
@@ -377,23 +377,135 @@
         '404':
           $ref: '#/components/responses/NotFound'
+  /devices:
+    get:
+      description: Returns all devices of user
+      tags:
+        - devices
+      summary: Find devices by id
+      operationId: devicesGet
+      security:
+        - basicAuth: []
+        - apiKeyAuth: []
+      parameters:
+        - name: name
+          in: query
+          schema:
+            $ref: '#/components/schemas/itemName'
+          example: Love
+        - $ref: '#/components/parameters/orderBy'
+        - $ref: '#/components/parameters/offset'
+        - $ref: '#/components/parameters/limit'
+      responses:
+        '200':
+          description: OK
+          content:
+            application/json:
+              schema:
+                $ref: '#/components/schemas/devices'
+              examples:
+                Devices:
+                  $ref: '#/components/examples/devices'
+        '404':
+          $ref: '#/components/responses/NotFound'
+    post:
+      description: Adds a new device to the database
+      tags:
+        - devices
+      summary: Add a new device
+      operationId: devicesCreate
+      security:
+        - basicAuth: []
+        - apiKeyAuth: []
+      requestBody:
+        content:
+          application/json:
+            schema:
+              $ref: '#/components/schemas/DeviceCreation'
+            example:
+              name: Lovely Boat
+              sensorDepth: 2
+      responses:
+        '201':
+          description: Device created
+          content:
+            application/json:
+              schema:
+                $ref: '#/components/schemas/Device'
+              examples:
+                Device:
+                  $ref: '#/components/examples/Device'
+        '400':
+          $ref: '#/components/responses/BadRequest'
+        '401':
+          $ref: '#/components/responses/Unauthorized'
+  '/devices/{id}':
+    get:
+      description: Returns the device identified by id
+      tags:
+        - devices
+      summary: Represents a device
+      operationId: devicesGetById
+      security:
+        - basicAuth: []
+        - apiKeyAuth: []
+      parameters:
+        - name: id
+          in: path
+          description: Item ID
+          required: true
+          schema:
+            $ref: '#/components/schemas/itemId'
+      responses:
+        '200':
+          description: OK
+          content:
+            application/json:
+              schema:
+                $ref: '#/components/schemas/Device'
+              examples:
+                Water:
+                  $ref: '#/components/examples/Device'
+        '404':
+          $ref: '#/components/responses/NotFound'
+    delete:
+      description: Deletes given device and returns remaining devices of the user
+      tags:
+        - devices
+      summary: Deletes device
+      operationId: devicesDeviceDelete
+      security:
+        - basicAuth: []
+        - apiKeyAuth: []
+      parameters:
+        - name: id
+          in: path
+          description: Item id
+          required: true
+          schema:
+            $ref: '#/components/schemas/itemId'
+          example: 1
+      responses:
+        '200':
+          description: OK
+          content:
+            application/json:
+              schema:
+                $ref: '#/components/schemas/devices'
+              example:
+                Devices:
+                  $ref: '#/components/examples/devices'
+        '400':
+          $ref: '#/components/responses/BadRequest'
+        '401':
+          $ref: '#/components/responses/Unauthorized'
+        '404':
+          $ref: '#/components/responses/NotFound'
+  '/logs':
     post:
       description: Adds a new log to the database
       tags:
-        - waters
+        - logs
       summary: Add a new log
-      operationId: watersCreateLog
-      parameters:
-        - name: water_id
-          in: path
-          description: Water ID
-          required: true
-          schema:
-            $ref: '#/components/schemas/itemId'
-        - name: gauge_id
-          in: path
-          description: Gauge ID
-          required: true
-          schema:
-            $ref: '#/components/schemas/itemId'
+      operationId: logsLogCreate
       security:
         - basicAuth: []
@@ -424,24 +536,12 @@
         '401':
           $ref: '#/components/responses/Unauthorized'
-  '/waters/{water_id}/gauges/{gauge_id}/{log_id}':
+  '/logs/{log_id}':
     get:
       description: Returns the log identified by id
       tags:
-        - waters
+        - logs
       summary: Represents a log
-      operationId: watersLogGetById
+      operationId: logsLogGetById
       parameters:
-        - name: water_id
-          in: path
-          description: Water ID
-          required: true
-          schema:
-            $ref: '#/components/schemas/itemId'
-        - name: gauge_id
-          in: path
-          description: Gauge ID
-          required: true
-          schema:
-            $ref: '#/components/schemas/itemId'
         - name: log_id
           in: path
@@ -473,23 +573,11 @@
       description: Deletes given log and returns remaining logs of the gauge
       tags:
-        - waters
+        - logs
       summary: Deletes log
-      operationId: watersLogDelete
+      operationId: logsLogDelete
       security:
         - basicAuth: []
         - apiKeyAuth: []
       parameters:
-        - name: water_id
-          in: path
-          description: Water ID
-          required: true
-          schema:
-            $ref: '#/components/schemas/itemId'
-        - name: gauge_id
-          in: path
-          description: Gauge ID
-          required: true
-          schema:
-            $ref: '#/components/schemas/itemId'
         - name: log_id
           in: path
@@ -508,128 +596,4 @@
                 Devices:
                   $ref: '#/components/examples/logs'
-        '400':
-          $ref: '#/components/responses/BadRequest'
-        '401':
-          $ref: '#/components/responses/Unauthorized'
-        '404':
-          $ref: '#/components/responses/NotFound'
-  /devices:
-    get:
-      description: Returns all devices of user
-      tags:
-        - devices
-      summary: Find devices by id
-      operationId: devicesGet
-      security:
-        - basicAuth: []
-        - apiKeyAuth: []
-      parameters:
-        - name: name
-          in: query
-          schema:
-            $ref: '#/components/schemas/itemName'
-          example: Love
-        - $ref: '#/components/parameters/orderBy'
-        - $ref: '#/components/parameters/offset'
-        - $ref: '#/components/parameters/limit'
-      responses:
-        '200':
-          description: OK
-          content:
-            application/json:
-              schema:
-                $ref: '#/components/schemas/devices'
-              examples:
-                Devices:
-                  $ref: '#/components/examples/devices'
-        '404':
-          $ref: '#/components/responses/NotFound'
-    post:
-      description: Adds a new device to the database
-      tags:
-        - devices
-      summary: Add a new device
-      operationId: devicesCreate
-      security:
-        - basicAuth: []
-        - apiKeyAuth: []
-      requestBody:
-        content:
-          application/json:
-            schema:
-              $ref: '#/components/schemas/DeviceCreation'
-            example:
-              name: Lovely Boat
-              sensorDepth: 2
-      responses:
-        '201':
-          description: Device created
-          content:
-            application/json:
-              schema:
-                $ref: '#/components/schemas/Device'
-              examples:
-                Device:
-                  $ref: '#/components/examples/Device'
-        '400':
-          $ref: '#/components/responses/BadRequest'
-        '401':
-          $ref: '#/components/responses/Unauthorized'
-  '/devices/{id}':
-    get:
-      description: Returns the device identified by id
-      tags:
-        - devices
-      summary: Represents a device
-      operationId: devicesGetById
-      security:
-        - basicAuth: []
-        - apiKeyAuth: []
-      parameters:
-        - name: id
-          in: path
-          description: Item ID
-          required: true
-          schema:
-            $ref: '#/components/schemas/itemId'
-      responses:
-        '200':
-          description: OK
-          content:
-            application/json:
-              schema:
-                $ref: '#/components/schemas/Device'
-              examples:
-                Water:
-                  $ref: '#/components/examples/Device'
-        '404':
-          $ref: '#/components/responses/NotFound'
-    delete:
-      description: Deletes given device and returns remaining devices of the user
-      tags:
-        - devices
-      summary: Deletes device
-      operationId: devicesDeviceDelete
-      security:
-        - basicAuth: []
-        - apiKeyAuth: []
-      parameters:
-        - name: id
-          in: path
-          description: Item id
-          required: true
-          schema:
-            $ref: '#/components/schemas/itemId'
-          example: 1
-      responses:
-        '200':
-          description: OK
-          content:
-            application/json:
-              schema:
-                $ref: '#/components/schemas/devices'
-              example:
-                Devices:
-                  $ref: '#/components/examples/devices'
         '400':
           $ref: '#/components/responses/BadRequest'
@@ -786,5 +750,5 @@
           $ref: '#/components/schemas/Gauges'
         logs:
-          $ref: '#/components/schemas/LogMetaData'
+          $ref: '#/components/schemas/logs'
       required:
         - waterId
@@ -820,5 +784,5 @@
           $ref: '#/components/schemas/point'
         logs:
-          $ref: '#/components/schemas/LogMetaData'
+          $ref: '#/components/schemas/logs'
         comment:
           $ref: '#/components/schemas/comment'
@@ -883,4 +847,6 @@
         sensorDepth:
           $ref: '#/components/schemas/sensorDepth'
+        logs:
+          $ref: '#/components/schemas/logs'
         comment:
           $ref: '#/components/schemas/comment'
@@ -924,4 +890,7 @@
           type: number
           format: float
+      required:
+        - datetime
+        - location
     LogMetaData:
       title: 'Metadata of a log, without log entries'
@@ -931,5 +900,5 @@
           $ref: '#/components/schemas/itemId'
         submitter:
-          $ref: '#/components/schemas/User'
+          $ref: '#/components/schemas/username'
         water:
           $ref: '#/components/schemas/itemId'
@@ -941,9 +910,9 @@
           $ref: '#/components/schemas/GaugeLevel'
         start:
-          title: Date and Time of the first log entry
+          title: Date and Time of the first log entry in UTC timezone
           type: string
           format: date-time
         end:
-          title: Date and Time of the last log entry
+          title: Date and Time of the last log entry in UTC timezone
           type: string
           format: date-time
@@ -978,9 +947,9 @@
       properties:
         water:
-          $ref: '#/components/schemas/Water'
+          $ref: '#/components/schemas/itemId'
         device:
-          $ref: '#/components/schemas/Device'
+          $ref: '#/components/schemas/itemId'
         gauge:
-          $ref: '#/components/schemas/Gauge'
+          $ref: '#/components/schemas/itemId'
         gaugeLevel:
           $ref: '#/components/schemas/GaugeLevel'
@@ -996,5 +965,5 @@
       type: array
       items:
-        $ref: '#/components/schemas/Log'
+        $ref: '#/components/schemas/LogMetaData'
     LogGeoJson:
       title: Log in GeoJson format
@@ -1312,2 +1281,4 @@
   - name: devices
     description: All actions used to manage devices of an user
+  - name: logs
+    description: All actions used to manage logs of an water, device, gauge or user
Index: src/mapservice/src/server_impl/controllers/DevicesController.py
===================================================================
--- src/mapservice/src/server_impl/controllers/DevicesController.py	(revision 72cc33989269bc2dab1ffc2e448c54534722aa15)
+++ src/mapservice/src/server_impl/controllers/DevicesController.py	(revision ac11efee71d43906e5e8823aee644605721af468)
@@ -61,5 +61,4 @@
 		raise MapserviceUnauthorized
 	
-	print(id)
 	if not Device.query.filter_by(owner = user).filter_by(id=id).delete():
 		raise MapserviceBadRequest(detail="Could not delete device with id {}".format(id))
Index: src/mapservice/src/server_impl/controllers/LogsController.py
===================================================================
--- src/mapservice/src/server_impl/controllers/LogsController.py	(revision ac11efee71d43906e5e8823aee644605721af468)
+++ src/mapservice/src/server_impl/controllers/LogsController.py	(revision ac11efee71d43906e5e8823aee644605721af468)
@@ -0,0 +1,69 @@
+'''
+    Copyright (C) 2019 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+'''
+import connexion
+
+from ..database.Model import User, Log, Water, Device, Gauge, db
+from ..HttpErrors import MapserviceBadRequest, MapserviceUnauthorized, MapserviceNotFound
+
+def logs_log_get_by_id(id):
+	log = Log.query.filter_by(id=id).all()
+	if len(log) != 1:
+		raise MapserviceNotFound
+	return log[0].log()
+
+def logs_log_create(log_creation, log_file):
+	user = User.loggedin_user()
+	if user is None:
+		raise MapserviceUnauthorized
+	
+	water = Water.query.filter_by(id=log_creation.water).all()
+	if len(water) != 1:
+		raise MapserviceBadRequest
+	device = Device.query.filter_by(id=log_creation.device).all()
+	if len(device) != 1:
+		raise MapserviceBadRequest
+	gauge = Gauge.query.filter_by(id=log_creation.gauge).all()
+	if len(gauge) != 1:
+		raise MapserviceBadRequest
+	
+	comment = ""
+	if log_creation.comment:
+		comment = log_creation.comment
+	
+	# handling / parsing of the log file is not implemented!
+	return MapserviceBadRequest
+	
+	log = Log(submitter=user, water=water, device=device, gauge=gauge, gauge_level=log_creation.gauge_level, comment=comment)
+	db.session.add(log)
+	db.session.commit()
+	return log.meta_data()
+
+def logs_log_delete(id):
+	user = User.loggedin_user()
+	if user is None:
+		raise MapserviceUnauthorized
+	
+	if not Log.query.filter_by(submitter = user).filter_by(id=id).delete():
+		raise MapserviceBadRequest(detail="Could not delete log with id {}".format(id))
+	db.session.commit()
+	
+	query = Log.query.filter_by(submitter = user)
+	result = []
+	for log in query:
+		result.append(log.meta_data())
+	return result
+
Index: src/mapservice/src/server_impl/controllers/WatersController.py
===================================================================
--- src/mapservice/src/server_impl/controllers/WatersController.py	(revision 72cc33989269bc2dab1ffc2e448c54534722aa15)
+++ src/mapservice/src/server_impl/controllers/WatersController.py	(revision ac11efee71d43906e5e8823aee644605721af468)
@@ -17,5 +17,5 @@
 import connexion
 
-from ..database.Model import User, Water, Gauge, db
+from ..database.Model import User, Water, Gauge, Log, db
 from ..HttpErrors import MapserviceBadRequest, MapserviceUnauthorized, MapserviceNotFound
 
Index: src/mapservice/src/server_impl/database/Model.py
===================================================================
--- src/mapservice/src/server_impl/database/Model.py	(revision 72cc33989269bc2dab1ffc2e448c54534722aa15)
+++ src/mapservice/src/server_impl/database/Model.py	(revision ac11efee71d43906e5e8823aee644605721af468)
@@ -21,4 +21,5 @@
 from geoalchemy2 import Geometry
 from geoalchemy2.shape import to_shape
+from sqlalchemy_utc import UtcDateTime
 from shapely import wkb
 import hashlib
@@ -123,4 +124,9 @@
 			for gauge in obj.gauges:
 				result['gauges'].append(gauge.to_dict())
+		if obj.logs:
+			logs = []
+			for log in obj.logs:
+				logs.append(log.meta_data())
+			result['logs'] = logs
 		return result
 	
@@ -147,4 +153,9 @@
 		location = Gauge.wkb_to_dict(obj.location)
 		result['location'] = [location['longitude'], location['latitude']]
+		if obj.logs:
+			logs = []
+			for log in obj.logs:
+				logs.append(log.meta_data())
+			result['logs'] = logs
 		if obj.comment:
 			result['comment'] = obj.comment
@@ -186,7 +197,79 @@
 	def to_dict(obj):
 		result = { 'deviceId': obj.id, 'name': obj.name, 'sensorDepth': obj.sensor_depth }
+		if obj.logs:
+			logs = []
+			for log in obj.logs:
+				logs.append(log.meta_data())
+			result['logs'] = logs
 		if obj.comment:
 			result['comment'] = obj.comment
 		return result
+	
+class Log(db.Model):
+	__tablename__ = "logs"
+	
+	id = db.Column(db.Integer, primary_key=True, autoincrement=True)
+	submitter_id = db.Column(db.Integer, db.ForeignKey('users.id'))
+	water_id = db.Column(db.Integer, db.ForeignKey('waters.id'))
+	device_id = db.Column(db.Integer, db.ForeignKey('devices.id'))
+	gauge_id = db.Column(db.Integer, db.ForeignKey('gauges.id'))
+	gauge_level = db.Column(db.Float, nullable=False)
+	start = db.Column(UtcDateTime, nullable=False)
+	end = db.Column(UtcDateTime, nullable=False)
+	comment = db.Column(db.String(255))
+	
+	submitter = db.relationship("User", backref=db.backref("logs"), lazy=True)
+	water = db.relationship("Water", backref=db.backref("logs"), lazy=True)
+	device = db.relationship("Device", backref=db.backref("logs"), lazy=True)
+	gauge = db.relationship("Gauge", backref=db.backref("logs"), lazy=True)
+	
+	def meta_data(obj):
+		result = {
+			'logId': obj.id,
+			'submitter': obj.submitter.username,
+			'water': obj.water.id,
+			'device': obj.device.id,
+			'gauge': obj.gauge.id,
+			'gaugeLevel': obj.gauge_level,
+			'start': obj.start.isoformat('T'),
+			'end': obj.end.isoformat('T')
+		}
+		entries_count = 0
+		if obj.log_entries:
+			entries_count = len(obj.log_entries)
+		result['entriesCount'] = entries_count
+		if obj.comment:
+			result['comment'] = obj.comment
+		return result
+	
+	def log(obj):
+		result = { 'metaData': obj.meta_data() }
+		entries = []
+		if obj.log_entries:
+			for log in obj.log_entries:
+				entries.append(log.to_dict())
+		result['entries'] = entries
+		return result
+
+class LogEntry(db.Model):
+	__tablename__ = "logentries"
+	
+	id = db.Column(db.Integer, primary_key=True, autoincrement=True)
+	log_id = db.Column(db.Integer, db.ForeignKey('logs.id'))
+	datetime = db.Column(UtcDateTime, nullable=False)
+	# POINT(Lon Lat)
+	location = db.Column(Geometry(geometry_type='POINT', srid=4326, management=True))
+	water_depth = db.Column(db.Float)
+	
+	log = db.relationship("Log", backref=db.backref("log_entries"), lazy=True)
+	
+	def to_dict(obj):
+		result = {'datetime': obj.datetime.isoformat('T') }
+		location = Gauge.wkb_to_dict(obj.location)
+		result['location'] = [location['longitude'], location['latitude']]
+		if obj.water_depth:
+			result['waterDepth'] = obj.water_depth
+		return result
+	
 
 def db_setup():
@@ -200,5 +283,5 @@
 	db_setup()
 	
-	print("CREATING DATABASE TEST CONTENT")
+	print("CREATING DATABASE TEST CONTENT...")
 	with db.session.no_autoflush:
 		test_user_john = None
@@ -223,13 +306,14 @@
 			db.session.commit()
 		
-		test_key_del = ApiKey(user=test_user_jane, key='DelApiKey4711')
 		if len(ApiKey.query.filter_by(key='DelApiKey4711').all()) < 1:
-			db.session.add(test_key_del)
+			db.session.add(ApiKey(user=test_user_jane, key='DelApiKey4711'))
+			db.session.commit()
 		if len(ApiKey.query.filter_by(key='test_key').all()) < 1:
-			test_key = ApiKey(user=test_user_jane, key='test_key')
-			db.session.add(test_key)
+			db.session.add(ApiKey(user=test_user_jane, key='test_key'))
+			db.session.commit()
 		if len(ApiKey.query.filter_by(key='ApiKey4712').all()) < 1:
-			test_key = ApiKey(user=test_user_jane, key='ApiKey4712')
-			db.session.add(test_key)
+			db.session.add(ApiKey(user=test_user_jane, key='ApiKey4712'))
+			db.session.commit()
+		
 		mississippi = None
 		query = Water.query.filter_by(name='Mississippi').all()
@@ -244,13 +328,41 @@
 			forggensee = Water(name='Forggensee', manager=test_user_john, osm_id=897899, osm_type=OsmType.Relation)
 			db.session.add(forggensee)
-							
-		if len(Gauge.query.filter_by(name='New Orleans').all()) < 1:
+			db.session.commit()
+		
+		new_orleans = None
+		query = Gauge.query.filter_by(name='New Orleans').all()
+		if len(query) == 1:
+			new_orleans = query[0]
+		else:
 			new_orleans = Gauge(name='New Orleans', manager=test_user_jane, water=mississippi, location='SRID=4326;POINT(-90.136111 29.934722)')
 			db.session.add(new_orleans)
-			
-		
-		if len(Device.query.filter_by(name='GnuBoat 1').all()) < 1:
+			db.session.commit()
+		
+		gnuboat_one = None
+		query = Device.query.filter_by(name='GnuBoat 1').all()
+		if len(query) == 1:
+			gnuboat_one = query[0]
+		else:
 			gnuboat_one = Device(name='GnuBoat 1', owner=test_user_jane, sensor_depth=0.2, comment='SUP attachment')
 			db.session.add(gnuboat_one)
-		db.session.commit()
-
+			db.session.commit()
+			
+		if len(Log.query.filter_by(submitter=test_user_jane).all()) < 1:
+			import pandas as pd
+			import random
+			import pytz
+			
+			end = datetime.datetime.now(pytz.timezone('Europe/Berlin'))
+			start = end - datetime.timedelta(hours=1)
+			log = Log(submitter=test_user_jane, water=mississippi, device=gnuboat_one, gauge=new_orleans, gauge_level=2.2, start=start, end=end, comment='Test log for {}'.format(mississippi.name))
+			db.session.add(log)
+			
+			i = 0
+			for entrie_datetime in pd.date_range(start=start, end=end, freq='S'):
+				db.session.add(LogEntry(log=log, datetime=entrie_datetime, location='SRID=4326;POINT(-90.1361{} 29.934722)'.format(i), water_depth=random.random() * 10.0))
+				i += 1
+			
+			
+			db.session.commit()
+		print("...Finished")
+
