-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathcsv_processor.py
More file actions
executable file
·160 lines (101 loc) · 4.26 KB
/
csv_processor.py
File metadata and controls
executable file
·160 lines (101 loc) · 4.26 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/env python3
import sys
import os
import argparse
import pandas as pd
# https://pandas.pydata.org/pandas-docs/stable/user_guide/visualization.html
# https://queirozf.com/entries/pandas-dataframe-plot-examples-with-matplotlib-pyplot
if sys.version_info[0] != 3:
print("This script requires Python 3")
exit(1)
sys.path.append(os.path.join(os.path.abspath(__file__ + "../../../")))
class L3CSVParcer():
def __init__(self, csv_file):
# left this in for testing
'''csv_obj = open(csv_file, 'r')
csv_reader = csv.reader(csv_obj)
print(csv_reader)
for row in csv_reader:
if row[1] == 'rx':
print(row)'''
include_summary = ['Time epoch', 'Time', 'Monitor', 'least', 'most', 'average']
self.csv_file = csv_file
df_s = pd.read_csv(self.csv_file, header=0, usecols=lambda column: any(substr in column for substr in include_summary))
print('{}'.format(csv_file))
csv_file_summary = self.csv_file.replace('results_', 'results_summary_')
df_s.to_csv(csv_file_summary, index=False, header=True)
include_raw = ['Time epoch', 'Time', 'Monitor', 'LT', 'MT']
self.csv_file = csv_file
df_r = pd.read_csv(self.csv_file, header=0, usecols=lambda column: any(substr in column for substr in include_raw))
csv_file_raw = self.csv_file.replace('results_', 'results_raw_')
df_r.to_csv(csv_file_raw, index=False, header=True)
'''df_rx_delta = df_r.loc[df['Monitor'] == 'rx_delta']
df_rx_delta.plot(x='Time epoch', y='average_rx_data')
plt.show()
total_cols = len(df.axes[0])
print(df.columns)
print(df.loc[df['Monitor'] == 'rx_delta'])
print(df.loc[df['Monitor'] == 'rx'])
print(df.loc[df['Monitor'] == 'rx_delta', df.columns != 'Time'])
df_rx_delta = df.loc[df['Monitor'] == 'rx_delta']
print(df_rx_delta.describe())
df_rx_delta.plot(x='Time epoch', y='average_rx_data')
plt.show()
df_rx_delta.plot(x='Time', y='average_rx_data')
plt.show()
df_rx_drop_pct = df.loc[df['Monitor'] == 'rx_drop_percent']
print(df_rx_drop_pct)
df_rx_delta.plot(x='Time epoch', y='rx_drop_percent')
plt.show()
df2 = df.filter(regex='LT-s')
print(df2)
#plt.plot(df2[0], df2[1]
#plt.show()
df2_mean = df2.mean().sort_values(ascending=False)
print(df2_mean)
df2_mean_no_outliers = df2_mean[df2_mean(df2_mean.quantile(.10), df2_mean.quantile(.90))]
print("no outliers")
print(df2_mean_no_outliers)
print("Top 10")
print(df2_mean.head(10))
print("Bottom 10")
print(df2_mean.tail(10))
print("mean others")
# set display format otherwise get scientific notation
pd.set_option('display.float_format', lambda x: '%.3f' % x)
df_mean = df_rx_delta.mean().sort_values()
#print(df_mean)
print(df_mean[0])
#df_uni_cast = [col for col in df_rx_delta if 'LT' in col]
#df_LT_rx_delta_mean = df_uni_cast.mean().sort_values()
#print(df_LT_rx_delta_mean)
x = np.linspace(0, 20, 100)
plt.plot(x, np.sin(x))
plt.show()'''
def main():
# debug_on = False
parser = argparse.ArgumentParser(
prog='csv_processor.py',
formatter_class=argparse.RawTextHelpFormatter,
epilog='''\
This script is an simple example on how to process data from a csv file.
''',
description='''csv_processor.py:
''')
parser.add_argument('-i', '--infile', help="file of csv data", default='longevity_results_08_14_2020_14_37.csv')
parser.add_argument('--debug', help='--debug: Enable debugging', default=True)
parser.add_argument('--help_summary', action="store_true", help='Show summary of what this script does')
args = parser.parse_args()
help_summary = '''\
This script is an simple example on how to process data from a csv file.
This script is no longer supported.
'''
if args.help_summary:
print(help_summary)
exit(0)
# debug_on = args.debug
if args.infile:
csv_file_name = args.infile
L3CSVParcer(csv_file_name)
if __name__ == "__main__":
main()