-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathax3_crunch.py
153 lines (127 loc) · 5.21 KB
/
ax3_crunch.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
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
#!/usr/bin/env python3
# coding=UTF-8
#
# BSD 2-Clause License
#
# Copyright (c) 2019, Jason Leake
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#
# Process one CWA file. The file is specified on the command line:
#
# python3 ax3_crunch.py ../myDataFile.CWA
# etc.
from pathlib import Path
import argparse
import ax3_plot_minutes
import ax3_seconds_stats
import ax3_split
import ax3_stats
import configparser
import cwa
import os
import sys
import time
def get(config, section, key):
if key in config[section]:
return config[section][key]
return None
def getb(config, section, key):
""" Get boolean value from config file """
value = get(config, section, key)
if value is None:
return False
return bool(value)
def process(file, configFile):
config = configparser.ConfigParser()
if configFile is not None:
if os.path.exists(configFile):
config.read(configFile)
else:
print(f"Control file {configFile} not found", file=sys.stderr)
return
# .cwa -> csv
outputFile, metadataFile = cwa.cwa(file, process=False)
# Generate output file if it doesn't exist
outputFilePath = Path(outputFile)
if not outputFilePath.is_file():
outputFile, metadataFile = cwa.cwa(file)
print(f"Output file is {outputFile}")
print(f"Metadata file is {metadataFile}")
else:
print(f"Not regenerating existing file {outputFile}")
print()
# Split the file
print(f"Splitting {outputFile}")
splitFiles = ax3_split.split(outputFile)
for splitFile in splitFiles:
datafile, nonBaselinedFile, baselinedFile = ax3_stats.stats(splitFile)
plotMinutes = ax3_plot_minutes.PlotMinutes()
for thisPlot in plotMinutes.fileTitles():
if len(thisPlot) == 0:
continue
if getb(config, thisPlot, "ax3_plot_minutes"):
bcontrolfile = get(config, thisPlot, "bcontrolfile")
nbcontrolfile = get(config, thisPlot, "nbcontrolfile")
showtime = getb(config, thisPlot, "showtime")
grid = getb(config, thisPlot, "grid")
ymin = get(config, thisPlot, "ymin")
if ymin is not None:
ymin = float(ymin)
ymax = get(config, thisPlot, "ymax")
if ymax is not None:
ymax = float(ymax)
# Only one config file for the baselined and nonbaselined
# files at the moment
plotMinutes(nonBaselinedFile, nbcontrolfile,
showtime, ymin, ymax, thisPlot, grid)
plotMinutes(baselinedFile, bcontrolfile,
showtime, ymin, ymax, thisPlot, grid)
if getb(config, thisPlot, "ax3_seconds_stat"):
limit = get(config, "seconds_stat", "limit")
if limit is not None:
limit = float(limit)
secondsMeansFile, secondsRmsFile, sweptFile = ax3_seconds_stats.process(splitFile,
limit=limit, axis=3)
def main():
parser = argparse.ArgumentParser(description=
"Processing chain for ax3_... scripts")
parser.add_argument("filename", help="Input filename")
parser.add_argument("--controlfile", nargs="?",
help="INI file to control plotting",
default="crunch_default.ini")
args = parser.parse_args()
filePath = args.filename
controlFile = args.controlfile
filePath = args.filename
name, extension = os.path.splitext(filePath)
if extension == ".csv":
print("You need the .CWA, not the .csv", file=stderr)
os.exit(0)
elapsed = time.time();
process(filePath, controlFile)
elapsed = time.time() - elapsed
print(f"Elapsed time {int(round(elapsed))} seconds")
if __name__ == "__main__":
main()