diff options
Diffstat (limited to 'Metrics/Metrics-Calculation/metrics_plot/utils/readCSV.py')
-rw-r--r-- | Metrics/Metrics-Calculation/metrics_plot/utils/readCSV.py | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/Metrics/Metrics-Calculation/metrics_plot/utils/readCSV.py b/Metrics/Metrics-Calculation/metrics_plot/utils/readCSV.py index 33378ce5..1cec2f0c 100644 --- a/Metrics/Metrics-Calculation/metrics_plot/utils/readCSV.py +++ b/Metrics/Metrics-Calculation/metrics_plot/utils/readCSV.py | |||
@@ -13,8 +13,10 @@ def readcsvfile(filename): | |||
13 | 13 | ||
14 | contents = {} | 14 | contents = {} |
15 | with open(filename) as f: | 15 | with open(filename) as f: |
16 | for i, line in enumerate(f): | 16 | data = list(f) |
17 | arr = line.split(',') | 17 | f.close() |
18 | for i, line in enumerate(data): | ||
19 | arr = line.replace('\n', '').split(',') | ||
18 | # if there is no element in the line, continue | 20 | # if there is no element in the line, continue |
19 | if len(line) < 0: continue | 21 | if len(line) < 0: continue |
20 | # else check for contents | 22 | # else check for contents |
@@ -24,14 +26,17 @@ def readcsvfile(filename): | |||
24 | # meta models are string | 26 | # meta models are string |
25 | elif(arr[0] == constants.METAMODEL): | 27 | elif(arr[0] == constants.METAMODEL): |
26 | contents[constants.METAMODEL] = arr[1:] | 28 | contents[constants.METAMODEL] = arr[1:] |
27 | # NA and OD are integers | 29 | # Node types |
30 | elif(arr[0] == constants.NODE_TYPE): | ||
31 | types = data[i+1].replace('\n', '').split(',') | ||
32 | numbers = data[i+2].replace('\n', '').split(',') | ||
33 | contents[constants.Node_TYPE_KEY] = {t : n for t, n in zip(types, numbers)} | ||
34 | # NA and OD are integers, and store other information as string | ||
28 | else: | 35 | else: |
29 | try: | 36 | try: |
30 | contents[arr[0]] = list(map(int, arr[1:])) | 37 | contents[arr[0]] = list(map(int, arr[1:])) |
31 | except: | 38 | except: |
32 | message = arr[0], ' is not integer' | 39 | contents[arr[0]] = arr[1:] |
33 | #print(message) | ||
34 | f.close() | ||
35 | return contents | 40 | return contents |
36 | 41 | ||
37 | def checkAndReshape(arr): | 42 | def checkAndReshape(arr): |