-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpylog_visualizer.py
62 lines (48 loc) · 1.55 KB
/
pylog_visualizer.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
import sys
import csv
import matplotlib.pyplot as plt
from os import listdir, makedirs
from os.path import isfile, isdir, join, exists, dirname, split
def check_output(output_path):
dir_path = dirname(output_path)
if not exists(dir_path):
makedirs(dir_path)
elif not isdir(dir_path):
raise Exception("The given output %s was not a directory" % dir_path)
def get_files(input_path):
files = []
if isfile(input):
files = [input]
elif isdir(input):
for f in listdir(input):
path = join(input, f)
if isfile(path) and path.endswith('.csv'):
files.append(path)
else:
raise Exception("Could not locate input: %s" % input)
return files
def csv_reader(paths):
offsets = []
times = []
for f in paths:
with open(f) as csvfile:
reader = csv.reader(csvfile)
for row in reader:
offsets.append(row[2])
times.append(row[0])
return (offsets, times)
def plot_offset_time(offsets, times, output):
plt.plot(offsets, times)
plt.xlabel('Offset (Bytes)')
plt.ylabel('Time (Miliseconds)')
plt.title('The Time it Takes to Read a GeoTiff at a\nGiven Byte Offset'
'in Miliseconds')
(dir_path, file_name) = split(output)
plt.savefig(join(dir_path, file_name))
if __name__ == "__main__":
input = sys.argv[1]
output = sys.argv[2]
check_output(output)
files = get_files(input)
(offsets, times) = csv_reader(files)
plot_offset_time(offsets, times, output)