Skip to content

Commit bd5408f

Browse files
committed
Added lab class to generate synthetic data.
1 parent 4a040e3 commit bd5408f

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ dependencies {
2525
compile 'org.tukaani:xz:1.5'
2626
testCompile 'junit:junit:4.12'
2727
testCompile 'au.com.bytecode:opencsv:2.4'
28+
testCompile 'com.imsweb:data-generator:0.3'
2829
}
2930

3031
// enforce UTF-8 for all compilation tasks
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (C) 2016 Information Management Services, Inc.
3+
*/
4+
package lab;
5+
6+
import java.io.File;
7+
import java.io.FileInputStream;
8+
import java.io.FileOutputStream;
9+
import java.io.IOException;
10+
import java.nio.file.Files;
11+
import java.nio.file.Path;
12+
import java.nio.file.Paths;
13+
import java.util.Arrays;
14+
import java.util.Collections;
15+
import java.util.List;
16+
import java.util.zip.ZipEntry;
17+
import java.util.zip.ZipOutputStream;
18+
19+
import org.apache.commons.io.IOUtils;
20+
21+
import com.imsweb.datagenerator.naaccr.NaaccrDataGenerator;
22+
import com.imsweb.datagenerator.naaccr.NaaccrDataGeneratorOptions;
23+
import com.imsweb.layout.LayoutFactory;
24+
import com.imsweb.layout.record.fixed.naaccr.NaaccrLayout;
25+
26+
public class SyntheticDataLab {
27+
28+
private static final Path _TARGET_DIR = Paths.get(System.getProperty("user.dir"), "build");
29+
30+
private static final String _NAACCR_VERSION = LayoutFactory.LAYOUT_ID_NAACCR_16_ABSTRACT;
31+
32+
private static final List<Integer> _NUM_RECORDS = Arrays.asList(2, 5, 25, 250, 2500, 25000);
33+
34+
public static void main(String[] args) throws IOException {
35+
if (!Files.exists(_TARGET_DIR))
36+
Files.createDirectory(_TARGET_DIR);
37+
38+
// set the options
39+
NaaccrDataGeneratorOptions options = new NaaccrDataGeneratorOptions();
40+
options.setConstantValuesPostProcessing(Collections.singletonMap("registryId", "0000000000"));
41+
options.setState("MD");
42+
43+
// create the generator
44+
NaaccrDataGenerator generator = new NaaccrDataGenerator((NaaccrLayout)LayoutFactory.getLayout(_NAACCR_VERSION));
45+
46+
// create the files
47+
try (ZipOutputStream os = new ZipOutputStream(new FileOutputStream(new File(_TARGET_DIR.toFile(), _NAACCR_VERSION + ".zip")))) {
48+
for (Integer numRecords : _NUM_RECORDS) {
49+
File file = new File(_TARGET_DIR.toFile(), _NAACCR_VERSION + "_" + numRecords + ".txt");
50+
generator.generateFile(file, numRecords, options);
51+
try (FileInputStream is = new FileInputStream(file)) {
52+
os.putNextEntry(new ZipEntry(file.getName()));
53+
IOUtils.copy(is, os);
54+
}
55+
if (!file.delete())
56+
System.err.println("Unable to delete " + file.getPath());
57+
else
58+
System.out.println("Created " + file.getPath());
59+
}
60+
}
61+
62+
}
63+
64+
}

0 commit comments

Comments
 (0)