0

I have this log file (log.txt):

omer| (stmt : 0) | adminT|  Connection id - 0
omer| (stmt : 0) | adminT|  Start Time - 2018-11-06 16:52:01
omer| (stmt : 0) | adminT|  Statement create or replace table amit (x date);
omer| (stmt : 0)| adminT|  Connection id - 0 - Executing - create or replace table amit (x date);
omer| (stmt : 0) | adminT|  Connection id - 0
omer| (stmt : 0) | adminT|  End Time - 2018-11-06 16:52:01
omer| (stmt : 0) | adminT|  SQL - create or replace table amit (x date);
omer| (stmt : 0) | adminT|  Success
admin| (stmt : 1) | adminT|  Connection id - 0
admin| (stmt : 1) | adminT|  Start Time - 2018-11-06 16:52:14
admin| (stmt : 1) | adminT|  Statement create or replace table amit (x int, y int);
admin| (stmt : 1)| adminT|  Connection id - 0 - Executing - create or replace table amit (x int, y int);
admin| (stmt : 1) | adminT|  Connection id - 0
admin| (stmt : 1) | adminT|  End Time - 2018-11-06 16:52:15
admin| (stmt : 2) | adminT|  Connection id - 0
admin| (stmt : 2) | adminT|  Start Time - 2018-11-06 16:52:19
admin| (stmt : 2) | adminT|  Statement create table amit (x int, y int);
admin| (stmt : 2) | adminT|  Connection id - 0
admin| (stmt : 2) | adminT|  End Time - 2018-11-06 16:52:22
admin| (stmt : 2) | adminT|  SQL - Can't create table 'public.amit' - a table with the same name already exists
admin| (stmt : 2) | adminT|  Failed

and I want to calculate the statement that was the slowest successful statement for example:

start time - 2018-11-06 16:52:01 End Time - 2018-11-06 16:52:01 the result is zero time and the statement at the end was Success

even though the last statement took 3 seconds it does not matter due to the fact that the statement failed in the end: Start Time - 2018-11-06 16:52:19 End Time - 2018-11-06 16:52:22 and Failed so it does not matter. so it comes that the middle statement took 1 second and was a success so this is the slowest statement.

I wish to implement this code using python that will produce the result.

tupac shakur
  • 658
  • 1
  • 12
  • 29

1 Answers1

0

You could save the dates in date variables (you have to import 'datetime')

For example if you want to save 19.05.2020 9:00 then you need to code:

date = datetime.datetime(year=YOUR YEAR, month=YOUR Month, day=YOUR DAY, hour=YOUR HOUR {And so on})

and with the python function min() you can pass in multiple values and the function will return the smalest. For example:

print(min(date - date1, date2 - date3, date4 - date5))
Leon
  • 13
  • 3