Startup
This commit is contained in:
@@ -1,9 +1,18 @@
|
||||
###################################################################################################
|
||||
# Utilities for generating reports from command statistics files
|
||||
###################################################################################################
|
||||
|
||||
#CsvJdbc JAR file must be downloaded to extensions folder:
|
||||
#http://central.maven.org/maven2/net/sourceforge/csvjdbc/csvjdbc/1.0.34/csvjdbc-1.0.34.jar
|
||||
|
||||
|
||||
import java.sql.DriverManager as DriverManager
|
||||
import java.sql.ResultSet as ResultSet
|
||||
import java.util.Properties as Properties
|
||||
import java.lang.Class as Class
|
||||
import os
|
||||
from startup import get_context
|
||||
import ch.psi.pshell.core.CommandManager.CommandStatisticsFileRange as CommandStatisticsFileRange
|
||||
|
||||
stmt = None
|
||||
STAT_COLUMN_NAMES = ["Command","Args","Source","Start","End","Background","Result","Return"]
|
||||
@@ -15,16 +24,22 @@ def get_stats_connection():
|
||||
props.put("fileExtension", ".csv")
|
||||
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");
|
||||
|
||||
fileRange = get_context().commandManager.commandStatisticsConfig.fileRange
|
||||
if fileRange==CommandStatisticsFileRange.Daily:
|
||||
props.put("fileTailPattern", "(\\d+)_(\\d+)_(\\d+)");
|
||||
props.put("fileTailParts", "Year,Month,Day");
|
||||
elif fileRange==CommandStatisticsFileRange.Monthly:
|
||||
props.put("fileTailPattern", "(\\d+)_(\\d+)"); #props.put("fileTailPattern", "-(\\d+)_(\\d+)");
|
||||
props.put("fileTailParts", "Year,Month");
|
||||
elif fileRange==CommandStatisticsFileRange.Yearly:
|
||||
props.put("fileTailPattern", "(\\d+)");
|
||||
props.put("fileTailParts", "Year");
|
||||
|
||||
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");
|
||||
return conn
|
||||
|
||||
def _get_count(sql):
|
||||
@@ -89,14 +104,6 @@ def get_commands(commands =None, start = None, end = None):
|
||||
if (commands is None) or (len(commands)==0):
|
||||
sql = "SELECT * FROM . WHERE Command != ''"
|
||||
sql = _add_sql_time(sql, start, end)
|
||||
#if (commands is not None) and (len(commands)>0):
|
||||
# sql = sql + " AND ("
|
||||
# first = True
|
||||
# for c in commands:
|
||||
# sql = sql + ("" if first else " OR")
|
||||
# sql = sql + "(Command LIKE '" + c + "')"
|
||||
# first = False
|
||||
# sql = sql + " )"
|
||||
sql = sql + " GROUP BY Command"
|
||||
results = stmt.executeQuery(sql)
|
||||
while results.next():
|
||||
|
||||
17
script/test/TestStats.py
Normal file
17
script/test/TestStats.py
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
from statistics import *
|
||||
|
||||
cmds = ["mount%", "unmount%", "dry%", "recover%", "trash%", "robot_recover%", "scan%", "homing%"]
|
||||
conn = get_stats_connection()
|
||||
|
||||
start= "01/03/19"
|
||||
end= "01/04/19"
|
||||
|
||||
print_stats(cmds, start, end)
|
||||
|
||||
for cmd in cmds:
|
||||
print_cmd_stats (cmd, start, end)
|
||||
|
||||
print_cmd_records("recover%", start, end, "error")
|
||||
conn.close()
|
||||
|
||||
Reference in New Issue
Block a user