-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqep_stats.py
64 lines (54 loc) · 2.42 KB
/
qep_stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from tree_node import TreeNode
def markLargestNode(all_nodes):
row_switch = 'Plan Rows'
if 'Actual Rows' in all_nodes[0].description_dict:
row_switch = 'Actual Rows'
all_nodes_rows = [n.description_dict[row_switch] for n in all_nodes]
largest = max(all_nodes_rows)
label = '*Largest Node (by rows)'
for n in all_nodes:
n.description_dict[label] = False
if n.description_dict[row_switch] == largest:
n.description_dict[label] = True
return largest
def calculateActualCost(all_nodes):
for n in all_nodes:
children_cost = sum([c.description_dict['Total Cost'] for c in n.children])
n.description_dict['*Actual Cost'] = n.description_dict['Total Cost'] - children_cost
def markCostliestNode(all_nodes):
all_nodes_cost = [n.description_dict['*Actual Cost'] for n in all_nodes]
largest = max(all_nodes_cost)
label = '*Costiest Node (by cost)'
for n in all_nodes:
n.description_dict[label] = False
if n.description_dict['*Actual Cost'] == largest:
n.description_dict[label] = True
return largest
def calculateActualDuration(all_nodes):
if 'Actual Total Time' not in all_nodes[0].description_dict:
for n in all_nodes:
n.description_dict['*Actual Duration'] = 0
return
for n in all_nodes:
children_cost = sum([c.description_dict['Actual Total Time'] for c in n.children])
n.description_dict['*Actual Duration'] = n.description_dict['Actual Total Time'] - children_cost
def markSlowestNode(all_nodes):
if 'Actual Total Time' not in all_nodes[0].description_dict:
for n in all_nodes:
n.description_dict['*Slowest Node (by duration)'] = False
return
all_nodes_cost = [n.description_dict['*Actual Duration'] for n in all_nodes]
largest = max(all_nodes_cost)
label = '*Slowest Node (by duration)'
for n in all_nodes:
n.description_dict[label] = False
if n.description_dict['*Actual Duration'] == largest:
n.description_dict[label] = True
return largest
def calculatePercentDuration(all_nodes, total_duration):
if total_duration is None:
for n in all_nodes:
n.description_dict['*Percent Duration'] = None
return
for n in all_nodes:
n.description_dict['*Percent Duration'] = round(n.description_dict['*Actual Duration'] / total_duration * 100)