comparison runner/JAMSFeatureWriter.cpp @ 169:859d8ec60e06 jams

Add setNofM logic which the JSON writer can use to write a list when sending multiple files' worth to a single target
author Chris Cannam
date Wed, 15 Oct 2014 16:05:15 +0100
parents 3e30dbb68ca2
children 3536342ac088
comparison
equal deleted inserted replaced
168:3e30dbb68ca2 169:859d8ec60e06
31 SupportOneFilePerTrack | 31 SupportOneFilePerTrack |
32 SupportOneFileTotal | 32 SupportOneFileTotal |
33 SupportStdOut, 33 SupportStdOut,
34 "json"), 34 "json"),
35 m_network(false), 35 m_network(false),
36 m_networkRetrieved(false) 36 m_networkRetrieved(false),
37 m_n(1),
38 m_m(1)
37 { 39 {
38 } 40 }
39 41
40 JAMSFeatureWriter::~JAMSFeatureWriter() 42 JAMSFeatureWriter::~JAMSFeatureWriter()
41 { 43 {
140 } 142 }
141 143
142 if (f.values.size() > 0) { 144 if (f.values.size() > 0) {
143 d += QString(", \"value\": [ "); 145 d += QString(", \"value\": [ ");
144 for (int j = 0; j < int(f.values.size()); ++j) { 146 for (int j = 0; j < int(f.values.size()); ++j) {
145 d += QString("%1 ").arg(f.values[i]); 147 if (isnan(f.values[j])) {
148 d += "\"NaN\" ";
149 } else if (isinf(f.values[j])) {
150 d += "\"Inf\" ";
151 } else {
152 d += QString("%1 ").arg(f.values[j]);
153 }
146 } 154 }
147 d += "]"; 155 d += "]";
148 } 156 }
149 157
150 d += " }"; 158 d += " }";
152 160
153 m_data[did] = d; 161 m_data[did] = d;
154 } 162 }
155 163
156 void 164 void
165 JAMSFeatureWriter::setNofM(int n, int m)
166 {
167 if (m_singleFileName != "" || m_stdout) {
168 m_n = n;
169 m_m = m;
170 } else {
171 m_n = 1;
172 m_m = 1;
173 }
174 }
175
176 void
157 JAMSFeatureWriter::finish() 177 JAMSFeatureWriter::finish()
158 { 178 {
159 for (FileStreamMap::const_iterator stri = m_streams.begin(); 179 for (FileStreamMap::const_iterator stri = m_streams.begin();
160 stri != m_streams.end(); ++stri) { 180 stri != m_streams.end(); ++stri) {
161 181
162 QTextStream *sptr = stri->second; 182 QTextStream *sptr = stri->second;
163 QTextStream &stream = *sptr; 183 QTextStream &stream = *sptr;
164 184
165 if (m_streamTracks[sptr].size() > 1) {
166 stream << "[\n";
167 }
168
169 bool firstInStream = true; 185 bool firstInStream = true;
170 186
171 for (TrackIds::const_iterator tri = m_streamTracks[sptr].begin(); 187 for (TrackIds::const_iterator tri = m_streamTracks[sptr].begin();
172 tri != m_streamTracks[sptr].end(); ++tri) { 188 tri != m_streamTracks[sptr].end(); ++tri) {
173 189
174 TrackId trackId = *tri; 190 TrackId trackId = *tri;
175 191
176 if (!firstInStream) { 192 if (firstInStream) {
193 if (m_streamTracks[sptr].size() > 1 || (m_m > 1 && m_n == 1)) {
194 stream << "[\n";
195 }
196 }
197
198 if (!firstInStream || (m_m > 1 && m_n > 1)) {
177 stream << ",\n"; 199 stream << ",\n";
178 } 200 }
179 201
180 stream << "{\n" 202 stream << "{\n"
181 << QString("\"file_metadata\": {\n" 203 << QString("\"file_metadata\": {\n"
251 273
252 stream << "\n}"; 274 stream << "\n}";
253 firstInStream = false; 275 firstInStream = false;
254 } 276 }
255 277
256 if (m_streamTracks[sptr].size() > 1) { 278 if (!firstInStream) {
257 stream << "\n]"; 279 if (m_streamTracks[sptr].size() > 1 || (m_m > 1 && m_n == m_m)) {
258 } 280 stream << "\n]";
259 stream << "\n"; 281 }
282 stream << "\n";
283 }
260 } 284 }
261 285
262 m_streamTracks.clear(); 286 m_streamTracks.clear();
263 m_streamTasks.clear(); 287 m_streamTasks.clear();
264 m_streamData.clear(); 288 m_streamData.clear();