first commit
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
from flask import Blueprint, jsonify, request, current_app
|
||||
from ..utils import get_db_connection
|
||||
|
||||
max_time_diff_bp = Blueprint('max_time_diff', __name__, url_prefix='/max_time_diff')
|
||||
|
||||
@max_time_diff_bp.route('/', strict_slashes=False)
|
||||
def max_time_diff():
|
||||
start_date = request.args.get('start_date')
|
||||
end_date = request.args.get('end_date')
|
||||
start_time = request.args.get('start_time', '00:00')
|
||||
end_time = request.args.get('end_time', '23:59')
|
||||
|
||||
if not start_date or not end_date:
|
||||
return jsonify({'error': 'Bitte sowohl Start- als auch End-Datum auswählen.'})
|
||||
|
||||
conn = get_db_connection()
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Angepasste SQL-Abfrage
|
||||
query = """
|
||||
WITH time_differences AS (
|
||||
SELECT
|
||||
create_time AS start_time,
|
||||
LEAD(create_time) OVER (ORDER BY create_time) AS end_time,
|
||||
TIMESTAMPDIFF(SECOND, create_time, LEAD(create_time) OVER (ORDER BY create_time)) AS time_diff
|
||||
FROM gi_debugger_entry
|
||||
WHERE webservice_id = %s
|
||||
AND create_time BETWEEN %s AND %s
|
||||
)
|
||||
SELECT start_time, end_time, time_diff
|
||||
FROM time_differences
|
||||
WHERE time_diff = (
|
||||
SELECT MAX(time_diff)
|
||||
FROM time_differences
|
||||
);
|
||||
"""
|
||||
start_datetime = f"{start_date} {start_time}"
|
||||
end_datetime = f"{end_date} {end_time}"
|
||||
|
||||
try:
|
||||
cursor.execute(query, (current_app.config['WEB_SERVICE_ID'], start_datetime, end_datetime))
|
||||
result = cursor.fetchone()
|
||||
conn.close()
|
||||
|
||||
# Ergebnis zurückgeben
|
||||
if result and result[2] is not None:
|
||||
return jsonify({
|
||||
'max_time_diff_seconds': result[2],
|
||||
'start_time': result[0],
|
||||
'end_time': result[1]
|
||||
})
|
||||
else:
|
||||
return jsonify({
|
||||
'max_time_diff_seconds': 0,
|
||||
'start_time': None,
|
||||
'end_time': None
|
||||
})
|
||||
except Exception as e:
|
||||
conn.close()
|
||||
return jsonify({'error': str(e)})
|
||||
Reference in New Issue
Block a user