1 | #include "binary_arithmetic_filter.hpp" |
---|
2 | #include "workflow_graph.hpp" |
---|
3 | |
---|
4 | namespace xios |
---|
5 | { |
---|
6 | CScalarFieldArithmeticFilter::CScalarFieldArithmeticFilter(CGarbageCollector& gc, const std::string& op, double value) |
---|
7 | : CFilter(gc, 1, this) |
---|
8 | , op(operatorExpr.getOpScalarField(op)) |
---|
9 | , value(value) |
---|
10 | { |
---|
11 | StdString input_op_expression=op; |
---|
12 | if(input_op_expression == "add") |
---|
13 | op_expression = "+"; |
---|
14 | else if(input_op_expression == "minus") |
---|
15 | op_expression = "-"; |
---|
16 | else if(input_op_expression == "mult") |
---|
17 | op_expression = "x"; |
---|
18 | else if(input_op_expression == "div") |
---|
19 | op_expression = "/"; |
---|
20 | else if(input_op_expression == "eq") |
---|
21 | op_expression = "="; |
---|
22 | else if(input_op_expression == "lt") |
---|
23 | op_expression = "<"; |
---|
24 | else if(input_op_expression == "gt") |
---|
25 | op_expression = ">"; |
---|
26 | else if(input_op_expression == "le") |
---|
27 | op_expression = "<="; |
---|
28 | else if(input_op_expression == "ge") |
---|
29 | op_expression = ">="; |
---|
30 | else if(input_op_expression == "ne") |
---|
31 | op_expression = "!="; |
---|
32 | else |
---|
33 | op_expression = " "; |
---|
34 | }; |
---|
35 | |
---|
36 | CDataPacketPtr CScalarFieldArithmeticFilter::apply(std::vector<CDataPacketPtr> data) |
---|
37 | { |
---|
38 | if(this->tag) |
---|
39 | { |
---|
40 | this->filterID = InvalidableObject::filterIdGenerator++; |
---|
41 | |
---|
42 | if(CWorkflowGraph::mapFieldToFilters_ptr==0) CWorkflowGraph::mapFieldToFilters_ptr = new std::unordered_map <StdString, vector <int> >; |
---|
43 | if(CWorkflowGraph::mapFilters_ptr==0) CWorkflowGraph::mapFilters_ptr = new std::unordered_map <int, StdString>; |
---|
44 | |
---|
45 | (*CWorkflowGraph::mapFilters_ptr)[this->filterID] = "S "+op_expression +" F Filter" ; |
---|
46 | std::cout<<"CScalarFieldArithmeticFilter::apply filter tag = "<<this->tag<<std::endl; |
---|
47 | |
---|
48 | StdString str = data[0]->fieldID +" ts=" + to_string(data[0]->timestamp); |
---|
49 | (*CWorkflowGraph::mapFieldToFilters_ptr)[str].push_back(data[0]->src_filterID); |
---|
50 | (*CWorkflowGraph::mapFieldToFilters_ptr)[str].push_back(this->filterID); |
---|
51 | } |
---|
52 | |
---|
53 | CDataPacketPtr packet(new CDataPacket); |
---|
54 | packet->date = data[0]->date; |
---|
55 | packet->timestamp = data[0]->timestamp; |
---|
56 | packet->status = data[0]->status; |
---|
57 | if(this->tag) packet->src_filterID = this->filterID; |
---|
58 | packet->fieldID = this->output_field_id; |
---|
59 | |
---|
60 | if (packet->status == CDataPacket::NO_ERROR) |
---|
61 | packet->data.reference(op(value, data[0]->data)); |
---|
62 | |
---|
63 | return packet; |
---|
64 | } |
---|
65 | |
---|
66 | CFieldScalarArithmeticFilter::CFieldScalarArithmeticFilter(CGarbageCollector& gc, const std::string& op, double value) |
---|
67 | : CFilter(gc, 1, this) |
---|
68 | , op(operatorExpr.getOpFieldScalar(op)) |
---|
69 | , value(value) |
---|
70 | { |
---|
71 | StdString input_op_expression=op; |
---|
72 | if(input_op_expression == "add") |
---|
73 | op_expression = "+"; |
---|
74 | else if(input_op_expression == "minus") |
---|
75 | op_expression = "-"; |
---|
76 | else if(input_op_expression == "mult") |
---|
77 | op_expression = "x"; |
---|
78 | else if(input_op_expression == "div") |
---|
79 | op_expression = "/"; |
---|
80 | else if(input_op_expression == "pow") |
---|
81 | op_expression = "^"; |
---|
82 | else if(input_op_expression == "eq") |
---|
83 | op_expression = "="; |
---|
84 | else if(input_op_expression == "lt") |
---|
85 | op_expression = "<"; |
---|
86 | else if(input_op_expression == "gt") |
---|
87 | op_expression = ">"; |
---|
88 | else if(input_op_expression == "le") |
---|
89 | op_expression = "<="; |
---|
90 | else if(input_op_expression == "ge") |
---|
91 | op_expression = ">="; |
---|
92 | else if(input_op_expression == "ne") |
---|
93 | op_expression = "!="; |
---|
94 | else |
---|
95 | op_expression = " "; |
---|
96 | }; |
---|
97 | |
---|
98 | CDataPacketPtr CFieldScalarArithmeticFilter::apply(std::vector<CDataPacketPtr> data) |
---|
99 | { |
---|
100 | if(this->tag) |
---|
101 | { |
---|
102 | this->filterID = InvalidableObject::filterIdGenerator++; |
---|
103 | |
---|
104 | if(CWorkflowGraph::mapFieldToFilters_ptr==0) CWorkflowGraph::mapFieldToFilters_ptr = new std::unordered_map <StdString, vector <int> >; |
---|
105 | if(CWorkflowGraph::mapFilters_ptr==0) CWorkflowGraph::mapFilters_ptr = new std::unordered_map <int, StdString>; |
---|
106 | |
---|
107 | (*CWorkflowGraph::mapFilters_ptr)[this->filterID] = "F "+op_expression +" S Filter" ; |
---|
108 | std::cout<<"CFieldScalarArithmeticFilter::apply filter tag = "<<this->tag<<std::endl; |
---|
109 | |
---|
110 | StdString str = data[0]->fieldID +" ts=" + to_string(data[0]->timestamp); |
---|
111 | (*CWorkflowGraph::mapFieldToFilters_ptr)[str].push_back(data[0]->src_filterID); |
---|
112 | (*CWorkflowGraph::mapFieldToFilters_ptr)[str].push_back(this->filterID); |
---|
113 | } |
---|
114 | |
---|
115 | CDataPacketPtr packet(new CDataPacket); |
---|
116 | packet->date = data[0]->date; |
---|
117 | packet->timestamp = data[0]->timestamp; |
---|
118 | packet->status = data[0]->status; |
---|
119 | if(this->tag) packet->src_filterID = this->filterID; |
---|
120 | packet->fieldID = this->output_field_id; |
---|
121 | |
---|
122 | |
---|
123 | if (packet->status == CDataPacket::NO_ERROR) |
---|
124 | packet->data.reference(op(data[0]->data, value)); |
---|
125 | |
---|
126 | return packet; |
---|
127 | } |
---|
128 | |
---|
129 | CFieldFieldArithmeticFilter::CFieldFieldArithmeticFilter(CGarbageCollector& gc, const std::string& op) |
---|
130 | : CFilter(gc, 2, this) |
---|
131 | , op(operatorExpr.getOpFieldField(op)) |
---|
132 | { |
---|
133 | StdString input_op_expression=op; |
---|
134 | if(input_op_expression == "add") |
---|
135 | op_expression = "+"; |
---|
136 | else if(input_op_expression == "minus") |
---|
137 | op_expression = "-"; |
---|
138 | else if(input_op_expression == "mult") |
---|
139 | op_expression = "x"; |
---|
140 | else if(input_op_expression == "div") |
---|
141 | op_expression = "/"; |
---|
142 | else if(input_op_expression == "pow") |
---|
143 | op_expression = "^"; |
---|
144 | else if(input_op_expression == "eq") |
---|
145 | op_expression = "="; |
---|
146 | else if(input_op_expression == "lt") |
---|
147 | op_expression = "<"; |
---|
148 | else if(input_op_expression == "gt") |
---|
149 | op_expression = ">"; |
---|
150 | else if(input_op_expression == "le") |
---|
151 | op_expression = "<="; |
---|
152 | else if(input_op_expression == "ge") |
---|
153 | op_expression = ">="; |
---|
154 | else if(input_op_expression == "ne") |
---|
155 | op_expression = "!="; |
---|
156 | else |
---|
157 | op_expression = " "; |
---|
158 | }; |
---|
159 | |
---|
160 | CDataPacketPtr CFieldFieldArithmeticFilter::apply(std::vector<CDataPacketPtr> data) |
---|
161 | { |
---|
162 | if(this->tag) |
---|
163 | { |
---|
164 | |
---|
165 | this->filterID = InvalidableObject::filterIdGenerator++; |
---|
166 | |
---|
167 | if(CWorkflowGraph::mapFieldToFilters_ptr==0) CWorkflowGraph::mapFieldToFilters_ptr = new std::unordered_map <StdString, vector <int> >; |
---|
168 | if(CWorkflowGraph::mapFilters_ptr==0) CWorkflowGraph::mapFilters_ptr = new std::unordered_map <int, StdString>; |
---|
169 | |
---|
170 | (*CWorkflowGraph::mapFilters_ptr)[this->filterID] = "F "+op_expression +" F Filter" ; |
---|
171 | std::cout<<"CFieldFieldArithmeticFilter::apply filter tag = "<<this->tag<<std::endl; |
---|
172 | |
---|
173 | StdString str = data[0]->fieldID +" ts=" + to_string(data[0]->timestamp); |
---|
174 | (*CWorkflowGraph::mapFieldToFilters_ptr)[str].push_back(data[0]->src_filterID); |
---|
175 | (*CWorkflowGraph::mapFieldToFilters_ptr)[str].push_back(this->filterID); |
---|
176 | |
---|
177 | str = data[1]->fieldID +" ts=" + to_string(data[0]->timestamp); |
---|
178 | |
---|
179 | (*CWorkflowGraph::mapFieldToFilters_ptr)[str].push_back(data[1]->src_filterID); |
---|
180 | (*CWorkflowGraph::mapFieldToFilters_ptr)[str].push_back(this->filterID); |
---|
181 | } |
---|
182 | |
---|
183 | |
---|
184 | CDataPacketPtr packet(new CDataPacket); |
---|
185 | packet->date = data[0]->date; |
---|
186 | packet->timestamp = data[0]->timestamp; |
---|
187 | if(this->tag) packet->src_filterID = this->filterID; |
---|
188 | packet->fieldID = this->output_field_id; |
---|
189 | |
---|
190 | |
---|
191 | if (data[0]->status != CDataPacket::NO_ERROR) |
---|
192 | packet->status = data[0]->status; |
---|
193 | else if (data[1]->status != CDataPacket::NO_ERROR) |
---|
194 | packet->status = data[1]->status; |
---|
195 | else |
---|
196 | { |
---|
197 | packet->status = CDataPacket::NO_ERROR; |
---|
198 | packet->data.reference(op(data[0]->data, data[1]->data)); |
---|
199 | } |
---|
200 | |
---|
201 | return packet; |
---|
202 | } |
---|
203 | |
---|
204 | StdString CScalarFieldArithmeticFilter::GetName(void) { return StdString("CScalarFieldArithmeticFilter"); } |
---|
205 | StdString CFieldScalarArithmeticFilter::GetName(void) { return StdString("CFieldScalarArithmeticFilter"); } |
---|
206 | StdString CFieldFieldArithmeticFilter::GetName(void) { return StdString("CFieldFieldArithmeticFilter"); } |
---|
207 | |
---|
208 | |
---|
209 | } // namespace xios |
---|