From ddb42cb639269aeda43df92195a7d2571247428a Mon Sep 17 00:00:00 2001 From: Alexandre Gobbo Date: Tue, 2 Apr 2019 11:01:21 +0200 Subject: [PATCH] Script execution --- script/statistics.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/script/statistics.py b/script/statistics.py index b46af15..a8f2a97 100644 --- a/script/statistics.py +++ b/script/statistics.py @@ -7,18 +7,23 @@ db = os.path.abspath(get_context().setup.expandPath("{home}/statistics")) props = Properties() props.put("fileExtension", ".csv") -props.put("separator", ";") +props.put("separator", ";") +props.put("timestampFormat", "dd/MM/yy HH:mm:ss.SSS") +#timestampFormat, timeFormat, dateFormat props.put("indexedFiles", "true"); props.put("fileTailPattern", "(\\d+)_(\\d+)"); #props.put("fileTailPattern", "-(\\d+)_(\\d+)"); props.put("fileTailParts", "Year,Month"); +#Command,Args,Source,Start,End,Background,Result,Return +props.put("columnTypes", "String,String,String,Timestamp,Timestamp,Boolean,String,String"); conn = DriverManager.getConnection("jdbc:relique:csv:" + db, props); stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY); #results = stmt.executeQuery("SELECT Command,Result FROM 2019_03"); #results = stmt.executeQuery("SELECT Command,Result,Year,Month FROM Test"); +""" results = stmt.executeQuery("SELECT Command,Result,Year,Month, Start FROM ."); #Command,Args,Source,Start,End,Background,Result,Return -""" + if results.last(): print("Command= " + results.getString("Command") + " Result= " + results.getString("Result")) if (results.first()): @@ -38,11 +43,15 @@ def _get_count(sql): def get_count(command= "%%", start = None, end = None, result= "%%"): sql = "Command LIKE '"+ command +"' AND Result LIKE '"+ result +"'" + if start: + sql = sql + " AND Start>='" + start + "'" + if end: + sql = sql + " AND (\"End\"<'" + end + "')" return _get_count(sql) def print_stats(command = "%", start = None, end = None): - print "Statistics for: " + command + print "Statistics for: " , command , " from ", start , " to ", end s = get_count(command, start, end, "success") a = get_count(command, start, end, "abort") e = get_count(command, start, end, "error") @@ -55,8 +64,11 @@ def print_stats(command = "%", start = None, end = None): print "Abort: ", ("%1.2f%% of %d" % ((float(a)/t) * 100, t)) cmd = "%test1.py" -start= "" -end= "" +start= "06/02/19 13:27:56.124" +end= "29/04/19 13:27:56.124" + +print _get_count("Result LIKE 'success' AND \"End\">='06/02/19 13:27:56.124'") + print_stats ("%test1.py", start, end) @@ -64,6 +76,10 @@ print_stats ("%test1.py", start, end) +results = stmt.executeQuery("SELECT Command,Start FROM ."); + +if (results.first()): + print("Command= " + results.getString("Command") + " Start= " + str(results.getTimestamp("Start"))) -#conn.close() \ No newline at end of file +conn.close() \ No newline at end of file