-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.cpp
139 lines (116 loc) · 3.11 KB
/
parser.cpp
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
#include <stdio.h>
#include <string>
#include <fstream>
#include <sstream>
struct package{
int array1[22];
int array2[22];
int array3[12];
int array4[12];
double power[10];
};
int bin1(std::string word); //capacity
int bin2(std::string word); //feedwater temp
int bin3(std::string word); //outlet temp
int bin4(std::string word); //pressure
package parser(std::string filename){
// File pointer
std::fstream fin;
// Open the file containing the records
fin.open(filename, std::ios::in);
// Get the roll number
// of which the data is required
// Read the Data from the file as string
std::string line, word, temp;
int count = 0;
int array1[22];
int array2[22];
int array3[12];
int array4[12];
double power[10];
while (fin >> temp) {
// read an entire row and
// store it in a string variable 'line'
std::getline(fin, line);
// used for breaking words
std::stringstream s(line);
// read every column data of a row and update value of the arrays
//update static arrays depend on sensor type
if (0 <= count < 8) {
while (getline(s, word, ','))
array1[bin1(word)]++;
}
else if(8 <= count < 16) {
while (getline(s, word, ','))
array2[bin2(word)]++;
}
else if(16 <= count < 24) {
while (getline(s, word, ','))
array3[bin3(word)]++;
}
else if(24 <= count < 32) {
while (getline(s, word, ','))
array4[bin4(word)]++;
}
else if (count == 32) {
int size = 0;
while (getline(s, word, ','))
power[size++] = std::stod(word);
}
else
break;
count ++;
}
package output;
for (int i = 0; i < 22; i++) {
output.array1[i] = array1[i];
output.array2[i] = array2[i];
}
for (int j = 0; j < 12; j++) {
output.array3[j] = array3[j];
output.array4[j] = array4[j];
}
for (int k = 0; k < 10; k++)
output.power[k] = power[k];
return output;
}
int bin1(std::string word){
int value;
double raw = std::stod(word);
if (raw < 6500.0) value = 0;
else if (raw >= 10000.0) value = 21;
else {
value = ((int)raw - 6500)/175 + 1;
}
return value;
}
int bin2(std::string word){
int value;
double raw = std::stod(word);
if (raw < 270.0) value = 0;
else if (raw >= 650.0) value = 21;
else {
value = ((int)raw - 270)/19 + 1;
}
return value;
}
int bin3(std::string word){
int value;
double raw = std::stod(word);
if (raw < 234.0) value = 0;
else if (raw >= 334.0) value = 11;
else {
value = ((int)raw - 234)/10 + 1;
}
return value;
}
int bin4(std::string word){
int value;
double raw = std::stod(word);
if (raw < 6.4) value = 0;
else if (raw >= 7.4) value = 11;
else {
value = (int)((raw - 6.4)/0.1) + 1;
}
return value;
}