Skip to content

Commit 9b1dae2

Browse files
author
Maxim Moinat
committed
Number of records logged, small fixes
1 parent 7fbfa0d commit 9b1dae2

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/main/java/org/radarcns/restructureAvroRecords.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ public class restructureAvroRecords {
3131
private final static SimpleDateFormat dateFormatFileName = new SimpleDateFormat("yyyyMMdd_HH");
3232

3333
private int processedFileCount;
34+
private int processedRecordsCount;
3435

3536
public static void main(String [] args) throws Exception {
36-
3737
restructureAvroRecords restr = new restructureAvroRecords(args[0], args[2]);
3838
long time1 = System.currentTimeMillis();
3939
restr.start(args[1]);
40+
System.out.printf("Processed %d files and %,d records\n", restr.getProcessedFileCount(), restr.getProcessedRecordsCount());
4041
System.out.printf("Time taken: %.2f seconds\n",(System.currentTimeMillis() - time1)/1000d);
4142

42-
4343
// restructureAvroRecords restr = new restructureAvroRecords("webhdfs://radar-test.thehyve.net:50070", "output4/");
4444
// restr.start("/topicE4/");
4545

@@ -63,6 +63,14 @@ public void setOutputPath(String path) {
6363
offsetsPath = outputPath + "/" + OFFSETS_FILE_NAME;
6464
}
6565

66+
public int getProcessedFileCount() {
67+
return processedFileCount;
68+
}
69+
70+
public int getProcessedRecordsCount() {
71+
return processedRecordsCount;
72+
}
73+
6674
public void start(String directoryName) throws IOException {
6775
// Get files and directories
6876
Path path = new Path(directoryName);
@@ -86,8 +94,6 @@ public void start(String directoryName) throws IOException {
8694
processTopic(filePath);
8795
}
8896
}
89-
90-
System.out.printf("%d files processed\n", processedFileCount);
9197
}
9298

9399
private void processTopic(Path topicPath) throws IOException {
@@ -133,6 +139,7 @@ record = dataFileReader.next(record);
133139
this.writeRecord(record, topicName);
134140
}
135141

142+
// Write which file has been processed and update bins
136143
this.writeSeenOffsets(fileName);
137144
bins.writeBins();
138145
processedFileCount++;
@@ -154,8 +161,9 @@ private void writeRecord(GenericRecord record, String topicName) throws IOExcept
154161
String data = record.toString(); // TODO: check whether this indeed always creates valid JSON
155162
this.appendToFile(dirName, outputFileName, data);
156163

157-
// Count data
164+
// Count data (binned and total)
158165
bins.addToBin(topicName, keyField.get("sourceId").toString(), (Double) valueField.get("time"));
166+
processedRecordsCount++;
159167
}
160168

161169
public static String createHourTimestamp(Double time) {
@@ -230,8 +238,7 @@ private void readSeenOffsets() {
230238
}
231239

232240
} catch (IOException e) {
233-
// TODO
234-
e.printStackTrace();
241+
System.out.println("No files processed yet.");
235242
}
236243
}
237244
}

0 commit comments

Comments
 (0)