65 lines
2.2 KiB
Python
65 lines
2.2 KiB
Python
import java.sql.DriverManager as DriverManager
|
|
import java.sql.ResultSet as ResultSet
|
|
import java.util.Properties as Properties
|
|
|
|
Class.forName("org.relique.jdbc.csv.CsvDriver");
|
|
db = os.path.abspath(get_context().setup.expandPath("{home}/statistics"))
|
|
|
|
props = Properties()
|
|
props.put("fileExtension", ".csv")
|
|
props.put("separator", ";")
|
|
props.put("indexedFiles", "true");
|
|
props.put("fileTailPattern", "(\\d+)_(\\d+)"); #props.put("fileTailPattern", "-(\\d+)_(\\d+)");
|
|
props.put("fileTailParts", "Year,Month");
|
|
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()):
|
|
print("Command= " + results.getString("Command") + " Result= " + results.getString("Result"))
|
|
|
|
results = stmt.executeQuery("SELECT Command,Result,Start FROM . WHERE Result = 'success'")
|
|
while results.next():
|
|
print("Command= " + results.getString("Command") + " Result= " + results.getString("Result"))
|
|
"""
|
|
|
|
def _get_count(sql):
|
|
ret = 0
|
|
results = stmt.executeQuery("SELECT COUNT(*) AS count FROM . WHERE " + sql)
|
|
if results.first():
|
|
ret = results.getInt("count")
|
|
return ret
|
|
|
|
def get_count(command, result):
|
|
return _get_count("Command LIKE '"+ command +"' AND Result = '"+ result +"'")
|
|
|
|
|
|
def print_stats(command):
|
|
print "Statistics for: " + command
|
|
s = get_count(command, "success")
|
|
a = get_count(command, "abort")
|
|
e = get_count(command, "error")
|
|
t=s+a+e
|
|
if t==0:
|
|
print "No records"
|
|
else:
|
|
print "Success: ", ("%1.2f%% of %d" % ((float(s)/t) * 100, t))
|
|
print "Error: ", ("%1.2f%% of %d" % ((float(e)/t) * 100, t))
|
|
print "Abort: ", ("%1.2f%% of %d" % ((float(a)/t) * 100, t))
|
|
|
|
print_stats ("%test1.py")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#conn.close() |