ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change
on this file since 3dcd11ba was
77f1265,
checked in by Thierry Delisle <tdelisle@…>, 3 years ago
|
Added stat array tools for processing
|
-
Property mode set to
100755
|
File size:
1.4 KB
|
Line | |
---|
1 | #!/usr/bin/python3 |
---|
2 | |
---|
3 | import argparse, os, sys, re |
---|
4 | |
---|
5 | def dir_path(string): |
---|
6 | if os.path.isdir(string): |
---|
7 | return string |
---|
8 | else: |
---|
9 | raise NotADirectoryError(string) |
---|
10 | |
---|
11 | parser = argparse.ArgumentParser() |
---|
12 | parser.add_argument('--path', type=dir_path, default=".cfadata", help= 'paste path to biog.txt file') |
---|
13 | |
---|
14 | try : |
---|
15 | args = parser.parse_args() |
---|
16 | except NotADirectoryError: |
---|
17 | print("Must use option --path to existing directory or have .cfadata in current directory", file=sys.stderr) |
---|
18 | sys.exit(1) |
---|
19 | |
---|
20 | root, _, filenames = next(os.walk(args.path)) |
---|
21 | |
---|
22 | merged = [] |
---|
23 | counters = {} |
---|
24 | |
---|
25 | #open the files |
---|
26 | for filename in filenames: |
---|
27 | try: |
---|
28 | m = re.search('[A-z]+0x([0-9a-f]+)\.data', filename) |
---|
29 | me = m.group(1) |
---|
30 | counters[me] = 0 |
---|
31 | with open(os.path.join(root, filename), 'r') as file: |
---|
32 | for line in file: |
---|
33 | data = [int(x.strip()) for x in line.split(',')] |
---|
34 | data = [me, *data] |
---|
35 | merged.append(data) |
---|
36 | |
---|
37 | except: |
---|
38 | pass |
---|
39 | |
---|
40 | |
---|
41 | # Sort by timestamp (the second element) |
---|
42 | # take second element for sort |
---|
43 | def takeSecond(elem): |
---|
44 | return elem[1] |
---|
45 | |
---|
46 | merged.sort(key=takeSecond) |
---|
47 | |
---|
48 | # for m in merged: |
---|
49 | # print(m) |
---|
50 | |
---|
51 | single = [] |
---|
52 | curr = 0 |
---|
53 | |
---|
54 | # merge the data |
---|
55 | for (me, time, value) in merged: |
---|
56 | # check now much this changes |
---|
57 | old = counters[me] |
---|
58 | change = value - old |
---|
59 | counters[me] = value |
---|
60 | |
---|
61 | # add change to the current |
---|
62 | curr = curr + change |
---|
63 | single.append( (time, curr) ) |
---|
64 | |
---|
65 | pass |
---|
66 | |
---|
67 | #print |
---|
68 | for t, v in single: |
---|
69 | print([t, v]) |
---|
Note: See
TracBrowser
for help on using the repository browser.