use of org.apache.poi.xssf.usermodel.XSSFRow in project dom5utils by larzm42.
the class EventStatIndexer method run.
public static void run() {
effectToUnitSet.addAll(Arrays.asList(effectToUnit));
requirementToUnitSet.addAll(Arrays.asList(requirementToUnit));
effectToGemSet.addAll(Arrays.asList(effectToGem));
effectToScaleSet.addAll(Arrays.asList(effectToScale));
FileInputStream stream = null;
try {
File file = new File("units.txt");
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader);
String line;
while ((line = bufferedReader.readLine()) != null) {
StringTokenizer tok = new StringTokenizer(line, "\t");
Integer key = Integer.parseInt(tok.nextToken());
String value = tok.nextToken();
if (key != 1) {
unitMap.put(key, value);
}
}
fileReader.close();
gemMap.put(0, "F");
gemMap.put(1, "A");
gemMap.put(2, "W");
gemMap.put(3, "E");
gemMap.put(4, "S");
gemMap.put(5, "D");
gemMap.put(6, "N");
gemMap.put(7, "B");
gemMap.put(50, "Random");
gemMap.put(51, "Elemental");
gemMap.put(52, "Sorcery");
gemMap.put(56, "All");
scaleMap.put(0, "Turmoil");
scaleMap.put(1, "Sloth");
scaleMap.put(2, "Cold");
scaleMap.put(3, "Death");
scaleMap.put(4, "Misfortune");
scaleMap.put(5, "Drain");
List<Event> events = new ArrayList<Event>();
stream = new FileInputStream("Dominions5.exe");
stream.skip(Starts.EVENT);
long startIndex = Starts.EVENT;
// Name
InputStreamReader isr = new InputStreamReader(stream, "ISO-8859-1");
Reader in = new BufferedReader(isr);
int ch;
while ((ch = in.read()) > -1) {
StringBuffer name = new StringBuffer();
while (ch != 0) {
name.append((char) ch);
ch = in.read();
}
if (name.length() == 0) {
continue;
}
if (name.toString().equals("end")) {
break;
}
Event event = new Event();
event.description = name.toString();
event.requirements = new ArrayList<Pair>();
event.effects = new ArrayList<Pair>();
events.add(event);
stream = new FileInputStream("Dominions5.exe");
startIndex = startIndex + Starts.EVENT_SIZE;
stream.skip(startIndex);
isr = new InputStreamReader(stream, "ISO-8859-1");
in = new BufferedReader(isr);
}
in.close();
stream.close();
stream = new FileInputStream("Dominions5.exe");
stream.skip(Starts.EVENT);
stream.skip(1400l);
// rarity
int i = 0;
byte[] c = new byte[2];
while ((stream.read(c, 0, 2)) != -1) {
String high = String.format("%02X", c[1]);
String low = String.format("%02X", c[0]);
int tmp = new BigInteger(high + low, 16).intValue();
if (tmp > 100) {
tmp = new BigInteger("FFFFFF" + low, 16).intValue();
}
events.get(i).rarity = tmp;
stream.skip(Starts.EVENT_SIZE - 2l);
i++;
if (i >= events.size()) {
break;
}
}
stream.close();
requirements(events);
effects(events);
XSSFWorkbook wb = new XSSFWorkbook();
FileOutputStream fos = new FileOutputStream("events.xlsx");
XSSFSheet sheet = wb.createSheet();
int rowNum = 0;
for (Event event : events) {
// Event
if (rowNum == 0) {
XSSFRow row = sheet.createRow(rowNum);
for (i = 0; i < event_columns.length; i++) {
row.getCell(i, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue(event_columns[i]);
}
rowNum++;
}
XSSFRow row = sheet.createRow(rowNum);
row.getCell(0, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue(rowNum);
row.getCell(1, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue(event.description.substring(0, Math.min(event.description.length(), 30)));
row.getCell(2, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue(event.rarity);
row.getCell(3, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue(event.description);
boolean first = true;
StringBuffer req = new StringBuffer();
for (Pair pair : event.requirements) {
req.append((first ? "" : "|") + pair.name + " " + pair.value);
first = false;
}
row.getCell(4, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue(req.toString());
StringBuffer eff = new StringBuffer();
first = true;
for (Pair pair : event.effects) {
eff.append((first ? "" : "|") + pair.name + " " + pair.value);
first = false;
}
row.getCell(5, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue(eff.toString());
rowNum++;
}
wb.write(fos);
fos.close();
wb.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
use of org.apache.poi.xssf.usermodel.XSSFRow in project dom5utils by larzm42.
the class MercenaryStatIndexer method run.
public static void run() {
FileInputStream stream = null;
List<Mercenary> mercenaryList = new ArrayList<Mercenary>();
try {
long startIndex = Starts.MERCENARY;
int ch;
stream = new FileInputStream(EXE_NAME);
stream.skip(startIndex);
// name
InputStreamReader isr = new InputStreamReader(stream, "ISO-8859-1");
Reader in = new BufferedReader(isr);
int rowNumber = 1;
while ((ch = in.read()) > -1) {
StringBuffer name = new StringBuffer();
while (ch != 0) {
name.append((char) ch);
ch = in.read();
}
if (name.length() == 0) {
continue;
}
if (name.toString().equals("end")) {
break;
}
in.close();
Mercenary merc = new Mercenary();
merc.parameters = new HashMap<String, Object>();
merc.parameters.put("id", rowNumber);
merc.parameters.put("name", name.toString());
merc.parameters.put("bossname", getString(startIndex + 36l));
merc.parameters.put("com", getBytes2(startIndex + 74));
merc.parameters.put("unit", getBytes2(startIndex + 78));
merc.parameters.put("nrunits", getBytes2(startIndex + 82));
merc.parameters.put("minmen", getBytes2(startIndex + 86));
merc.parameters.put("minpay", getBytes2(startIndex + 90));
merc.parameters.put("xp", getBytes2(startIndex + 94));
merc.parameters.put("randequip", getBytes2(startIndex + 158));
merc.parameters.put("recrate", getBytes2(startIndex + 306));
merc.parameters.put("item1", getString(startIndex + 162l));
merc.parameters.put("item2", getString(startIndex + 198l));
merc.parameters.put("eramask", getBytes1(startIndex - 2));
merc.parameters.put("level", getBytes1(startIndex - 1));
mercenaryList.add(merc);
stream = new FileInputStream(EXE_NAME);
startIndex = startIndex + 312l;
stream.skip(startIndex);
isr = new InputStreamReader(stream, "ISO-8859-1");
in = new BufferedReader(isr);
rowNumber++;
}
in.close();
stream.close();
XSSFWorkbook wb = new XSSFWorkbook();
FileOutputStream fos = new FileOutputStream("Mercenary.xlsx");
XSSFSheet sheet = wb.createSheet();
int rowNum = 0;
for (Mercenary merc : mercenaryList) {
// Mercenary
if (rowNum == 0) {
XSSFRow row = sheet.createRow(rowNum);
for (int i = 0; i < mercenary_columns.length; i++) {
row.getCell(i, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue(mercenary_columns[i]);
}
rowNum++;
}
XSSFRow row = sheet.createRow(rowNum);
for (int i = 0; i < mercenary_columns.length; i++) {
Object object = merc.parameters.get(mercenary_columns[i]);
if (object != null) {
row.getCell(i, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue(object.toString());
}
}
rowNum++;
}
wb.write(fos);
fos.close();
wb.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
use of org.apache.poi.xssf.usermodel.XSSFRow in project dom5utils by larzm42.
the class SiteStatIndexer method run.
public static void run() {
FileInputStream stream = null;
List<Site> siteList = new ArrayList<Site>();
try {
BufferedWriter writer = new BufferedWriter(new FileWriter("sites.txt"));
BufferedWriter writerUnknown = new BufferedWriter(new FileWriter("sitesUnknown.txt"));
long startIndex = Starts.SITE;
int ch;
stream = new FileInputStream(EXE_NAME);
stream.skip(Starts.SITE);
Set<String> unknown = new TreeSet<String>();
// Name
InputStreamReader isr = new InputStreamReader(stream, "ISO-8859-1");
Reader in = new BufferedReader(isr);
int rowNumber = 1;
while ((ch = in.read()) > -1) {
StringBuffer name = new StringBuffer();
while (ch != 0) {
name.append((char) ch);
ch = in.read();
}
if (name.length() == 0) {
continue;
}
if (name.toString().equals("end")) {
break;
}
in.close();
Site site = new Site();
site.parameters = new TreeMap<String, Object>();
site.parameters.put("id", rowNumber);
site.parameters.put("name", name.toString());
short rarity = getBytes1(startIndex + 42);
site.parameters.put("rarity", rarity == -1 ? "0" : rarity);
site.parameters.put("loc", getBytes4(startIndex + 208));
site.parameters.put("level", getBytes2(startIndex + 40));
String[] paths = { "Fire", "Air", "Water", "Earth", "Astral", "Death", "Nature", "Blood", "Holy" };
int[] spriteOffset = { 1, 9, 18, 26, 35, 42, 50, 59, 68 };
short path = getBytes1(startIndex + 38);
short sprite = getBytes1(startIndex + 36);
site.parameters.put("path", path == -1 ? "" : paths[path]);
site.parameters.put("sprite", path == -1 ? "" : spriteOffset[path] + sprite);
List<AttributeValue> attributes = getAttributes(startIndex + Starts.SITE_ATTRIBUTE_OFFSET, Starts.SITE_ATTRIBUTE_GAP, 8);
for (AttributeValue attr : attributes) {
boolean found = false;
for (int x = 0; x < KNOWN_SITE_ATTRS.length; x++) {
if (KNOWN_SITE_ATTRS[x][0].equals(attr.attribute)) {
found = true;
if (KNOWN_SITE_ATTRS[x][1].endsWith("#")) {
int i = 1;
for (String value : attr.values) {
site.parameters.put(KNOWN_SITE_ATTRS[x][1].replace("#", i + ""), Integer.parseInt(value));
i++;
}
} else {
switch(KNOWN_SITE_ATTRS[x][1]) {
case ("conj"):
case ("alter"):
case ("evo"):
case ("const"):
case ("ench"):
case ("thau"):
case ("blood"):
case ("heal"):
case ("disease"):
case ("curse"):
case ("horror"):
case ("holyfire"):
case ("holypow"):
case ("voidgate"):
site.parameters.put(KNOWN_SITE_ATTRS[x][1], attr.values.get(0) + "%");
break;
case ("lab"):
site.parameters.put(KNOWN_SITE_ATTRS[x][1], "lab");
break;
case ("unr"):
site.parameters.put(KNOWN_SITE_ATTRS[x][1], -Integer.parseInt(attr.values.get(0)));
break;
default:
site.parameters.put(KNOWN_SITE_ATTRS[x][1], attr.values.get(0));
}
}
}
}
if (!found) {
site.parameters.put("\tUnknown Attribute<" + attr.attribute + ">", attr.values.get(0));
unknown.add(attr.attribute);
}
}
// scales
String[] scales = { "Turmoil", "Sloth", "Cold", "Death", "Misfortune", "Drain" };
String[] opposite = { "Order", "Productivity", "Heat", "Growth", "Luck", "Magic" };
String[] scalesValue = { "", "" };
int index = 0;
if (attributes.contains(new AttributeValue("1F00"))) {
AttributeValue attributeValue = attributes.get(attributes.indexOf(new AttributeValue("1F00")));
for (String vals : attributeValue.values) {
scalesValue[index++] = opposite[Integer.parseInt(vals)];
}
}
if (attributes.contains(new AttributeValue("2000"))) {
AttributeValue attributeValue = attributes.get(attributes.indexOf(new AttributeValue("2000")));
for (String vals : attributeValue.values) {
scalesValue[index++] = scales[Integer.parseInt(vals)];
}
}
site.parameters.put("scale1", scalesValue[0]);
site.parameters.put("scale2", scalesValue[1]);
// rit/ritrng
boolean[] boolPaths = { false, false, false, false, false, false, false, false };
String[] boolPathsStr = { "F", "A", "W", "E", "S", "D", "N", "B" };
String value = "";
if (attributes.contains(new AttributeValue("FA00"))) {
AttributeValue attributeValue = attributes.get(attributes.indexOf(new AttributeValue("FA00")));
value = attributeValue.values.get(0);
boolPaths[0] = true;
}
if (attributes.contains(new AttributeValue("FB00"))) {
AttributeValue attributeValue = attributes.get(attributes.indexOf(new AttributeValue("FB00")));
value = attributeValue.values.get(0);
boolPaths[1] = true;
}
if (attributes.contains(new AttributeValue("FC00"))) {
AttributeValue attributeValue = attributes.get(attributes.indexOf(new AttributeValue("FC00")));
value = attributeValue.values.get(0);
boolPaths[2] = true;
}
if (attributes.contains(new AttributeValue("FD00"))) {
AttributeValue attributeValue = attributes.get(attributes.indexOf(new AttributeValue("FD00")));
value = attributeValue.values.get(0);
boolPaths[3] = true;
}
if (attributes.contains(new AttributeValue("FE00"))) {
AttributeValue attributeValue = attributes.get(attributes.indexOf(new AttributeValue("FE00")));
value = attributeValue.values.get(0);
boolPaths[4] = true;
}
if (attributes.contains(new AttributeValue("FF00"))) {
AttributeValue attributeValue = attributes.get(attributes.indexOf(new AttributeValue("FF00")));
value = attributeValue.values.get(0);
boolPaths[5] = true;
}
if (attributes.contains(new AttributeValue("0001"))) {
AttributeValue attributeValue = attributes.get(attributes.indexOf(new AttributeValue("0001")));
value = attributeValue.values.get(0);
boolPaths[6] = true;
}
if (attributes.contains(new AttributeValue("0101"))) {
AttributeValue attributeValue = attributes.get(attributes.indexOf(new AttributeValue("0101")));
value = attributeValue.values.get(0);
boolPaths[7] = true;
}
if (attributes.contains(new AttributeValue("0201"))) {
AttributeValue attributeValue = attributes.get(attributes.indexOf(new AttributeValue("0201")));
value = attributeValue.values.get(0);
boolPaths = new boolean[] { true, true, true, true, false, false, false, false };
}
if (attributes.contains(new AttributeValue("0301"))) {
AttributeValue attributeValue = attributes.get(attributes.indexOf(new AttributeValue("0301")));
value = attributeValue.values.get(0);
boolPaths = new boolean[] { false, false, false, false, true, true, true, true };
}
if (attributes.contains(new AttributeValue("0401"))) {
AttributeValue attributeValue = attributes.get(attributes.indexOf(new AttributeValue("0401")));
value = attributeValue.values.get(0);
boolPaths = new boolean[] { true, true, true, true, true, true, true, true };
}
StringBuffer rit = new StringBuffer();
for (int x = 0; x < boolPaths.length; x++) {
if (boolPaths[x]) {
rit.append(boolPathsStr[x]);
}
}
site.parameters.put("rit", rit.toString());
site.parameters.put("ritrng", value);
// summoning
String sum1 = null;
int sum1count = 0;
String sum2 = null;
int sum2count = 0;
String sum3 = null;
int sum3count = 0;
String sum4 = null;
int sum4count = 0;
if (attributes.contains(new AttributeValue("1200"))) {
AttributeValue attributeValue = attributes.get(attributes.indexOf(new AttributeValue("1200")));
for (String val : attributeValue.values) {
if (sum1 == null || sum1.equals(val)) {
sum1 = val;
sum1count++;
} else if (sum2 == null || sum2.equals(val)) {
sum2 = val;
sum2count++;
} else if (sum3 == null || sum3.equals(val)) {
sum3 = val;
sum3count++;
} else if (sum4 == null || sum4.equals(val)) {
sum4 = val;
sum4count++;
}
}
}
if (sum1 != null) {
site.parameters.put("sum1", sum1);
site.parameters.put("n_sum1", sum1count);
}
if (sum2 != null) {
site.parameters.put("sum2", sum2);
site.parameters.put("n_sum2", sum2count);
}
if (sum3 != null) {
site.parameters.put("sum3", sum3);
site.parameters.put("n_sum3", sum3count);
}
if (sum4 != null) {
site.parameters.put("sum4", sum4);
site.parameters.put("n_sum4", sum4count);
}
siteList.add(site);
stream = new FileInputStream(EXE_NAME);
startIndex = startIndex + Starts.SITE_SIZE;
stream.skip(startIndex);
isr = new InputStreamReader(stream, "ISO-8859-1");
in = new BufferedReader(isr);
rowNumber++;
}
in.close();
stream.close();
XSSFWorkbook wb = new XSSFWorkbook();
FileOutputStream fos = new FileOutputStream("MagicSites.xlsx");
XSSFSheet sheet = wb.createSheet();
int rowNum = 0;
for (Site site : siteList) {
if (rowNum == 0) {
XSSFRow row = sheet.createRow(rowNum);
for (int i = 0; i < site_columns.length; i++) {
row.getCell(i, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue(site_columns[i]);
}
rowNum++;
}
XSSFRow row = sheet.createRow(rowNum);
for (int i = 0; i < site_columns.length; i++) {
Object object = site.parameters.get(site_columns[i]);
if (object != null) {
row.getCell(i, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue(object.toString());
}
}
dumpTextFile(site, writer);
rowNum++;
}
dumpUnknown(unknown, writerUnknown);
writer.close();
writerUnknown.close();
wb.write(fos);
fos.close();
wb.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
use of org.apache.poi.xssf.usermodel.XSSFRow in project ImmunogeneticDataTools by nmdp-bioinformatics.
the class DetectedFindingsWriter method reportDetectedFindings.
/**
* @param linkagesFound
* @throws IOException
* @throws SecurityException
*/
public synchronized void reportDetectedFindings(DetectedLinkageFindings findings) {
XSSFRow row = spreadsheet.createRow(rowId++);
int cellId = 0;
XSSFCell cell = row.createCell(cellId++);
cell.setCellValue(findings.getGLId());
cell = row.createCell(cellId++);
cell.setCellValue(findings.getAlleleCount(Locus.HLA_A));
cell = row.createCell(cellId++);
cell.setCellValue(findings.getAlleleCount(Locus.HLA_B));
cell = row.createCell(cellId++);
cell.setCellValue(findings.getAlleleCount(Locus.HLA_C));
cell = row.createCell(cellId++);
cell.setCellValue(findings.getAlleleCount(Locus.HLA_DRB1));
cell = row.createCell(cellId++);
cell.setCellValue(findings.getAlleleCount(Locus.HLA_DRB345));
cell = row.createCell(cellId++);
cell.setCellValue(findings.getAlleleCount(Locus.HLA_DQB1));
for (Linkages linkage : LinkagesLoader.getInstance().getLinkages()) {
cell = row.createCell(cellId++);
cell.setCellValue(findings.getLinkageCount(linkage.getLoci()));
cell = row.createCell(cellId++);
cell.setCellValue(findings.getMinimumDifference(linkage.getLoci()) + "");
}
String detectedFindings = formatDetectedFindings(findings);
printWriter.write(detectedFindings);
}
Aggregations