package com.fgkj.fbo;
|
|
import static com.fgkj.dao.BattTestData.BATT_MON_COUNT_MAX;
|
|
import java.io.BufferedReader;
|
import java.io.File;
|
import java.io.FileInputStream;
|
import java.io.FileReader;
|
import java.io.IOException;
|
import java.util.Date;
|
import java.util.GregorianCalendar;
|
import java.util.List;
|
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
import org.dom4j.Document;
|
import org.dom4j.Element;
|
import org.dom4j.io.SAXReader;
|
import org.dom4j.DocumentException;
|
import com.fgkj.dao.BattTestData;
|
import com.fgkj.dto.Com;
|
|
|
public class CsvData {
|
public static final int DevType_Csv = 0x45;
|
public static final int DevType_FBR = 0x46;
|
|
public boolean m_DataOk = true;
|
public String m_BattGroupNameFull = "";
|
public int m_STDAH; //±ê³ÆÈÝÁ¿¡£
|
public int m_BattSum; //µç³Ø¸öÊý¡£
|
public float m_MonomerVol = 2;
|
public int m_DevType = 0;
|
public int m_TestType = 0;
|
public Date m_TestTime = new Date();
|
public float m_GroupVol;
|
public float m_TestCurr;
|
|
public int m_MinNum = 0;
|
public float m_MinValue = 0;
|
|
public float[] MonomerVol = new float[BATT_MON_COUNT_MAX];
|
public float[] MonomerRes = new float[BattTestData.BATT_MON_COUNT_MAX];
|
public float[] MonomerSer = new float[BattTestData.BATT_MON_COUNT_MAX];
|
public float[] MonomerTmp = new float[BattTestData.BATT_MON_COUNT_MAX];
|
public float[] MonomerConn = new float[BattTestData.BATT_MON_COUNT_MAX];
|
|
public void setData(File file)
|
{
|
//System.out.println(111111111);
|
m_DataOk = true;
|
BufferedReader reader = null;
|
try {
|
m_TestType = BattTestData.BATTDATA_SER;
|
m_DevType = DevType_Csv;
|
|
reader = new BufferedReader(new FileReader(file));
|
//-------------------------------------------------------------------//
|
//-------------------------------------------------------------------//
|
String tmpstr = reader.readLine();
|
//-------------------------------------------------------------------//
|
//-------------------------------------------------------------------//
|
tmpstr = reader.readLine();
|
for(int n=0; n<4; n++) {
|
tmpstr = tmpstr.substring(tmpstr.indexOf(",")+1, tmpstr.length());
|
}
|
if(tmpstr.contains(",")) {
|
tmpstr = tmpstr.substring(0, tmpstr.indexOf(","));
|
} else if(tmpstr.contains("\r\n")) {
|
tmpstr = tmpstr.substring(0, tmpstr.indexOf("\r\n"));
|
}
|
//System.out.println(tmpstr);
|
m_BattSum = Integer.parseInt(tmpstr.trim());
|
//-------------------------------------------------------------------//
|
//-------------------------------------------------------------------//
|
tmpstr = reader.readLine();
|
for(int n=0; n<4; n++) {
|
tmpstr = tmpstr.substring(tmpstr.indexOf(",")+1, tmpstr.length());
|
}
|
tmpstr = tmpstr.substring(0, tmpstr.indexOf(","));
|
m_MonomerVol = Float.parseFloat(tmpstr.trim());
|
if((m_MonomerVol>10.1) && (m_MonomerVol<20)) {
|
m_MonomerVol = 12;
|
} else if((m_MonomerVol>5.4) && (m_MonomerVol<7.8)) {
|
m_MonomerVol = 6;
|
} else if((m_MonomerVol>2.7) && (m_MonomerVol<4.0)) {
|
m_MonomerVol = 4;
|
} else {
|
m_MonomerVol = 2;
|
}
|
//-------------------------------------------------------------------//
|
//-------------------------------------------------------------------//
|
tmpstr = reader.readLine();
|
for(int n=0; n<4; n++) {
|
tmpstr = tmpstr.substring(tmpstr.indexOf(",")+1, tmpstr.length());
|
}
|
int month = Integer.parseInt(tmpstr.substring(0, tmpstr.indexOf("/")).trim());
|
tmpstr = tmpstr.substring(tmpstr.indexOf("/")+1, tmpstr.length());
|
|
int day = Integer.parseInt(tmpstr.substring(0, tmpstr.indexOf("/")).trim());
|
tmpstr = tmpstr.substring(tmpstr.indexOf("/")+1, tmpstr.length());
|
|
int year = Integer.parseInt(tmpstr.substring(0, tmpstr.indexOf(",")).trim());
|
tmpstr = tmpstr.substring(tmpstr.indexOf(",")+1, tmpstr.length());
|
|
int hour = Integer.parseInt(tmpstr.substring(0, tmpstr.indexOf(":")).trim());
|
tmpstr = tmpstr.substring(tmpstr.indexOf(":")+1, tmpstr.length());
|
|
int minute = Integer.parseInt(tmpstr.substring(0, 2).trim());
|
tmpstr = tmpstr.substring(3, tmpstr.length());
|
if(tmpstr.substring(0, tmpstr.indexOf(",")).trim().equals("PM"))
|
{
|
hour += 12;
|
}
|
GregorianCalendar gc = (GregorianCalendar) GregorianCalendar.getInstance();
|
gc.set(GregorianCalendar.YEAR, year);
|
gc.set(GregorianCalendar.MONTH, month-1);
|
gc.set(GregorianCalendar.DATE, day);
|
gc.set(GregorianCalendar.HOUR_OF_DAY, hour);
|
gc.set(GregorianCalendar.MINUTE, minute);
|
gc.set(GregorianCalendar.SECOND, 0);
|
m_TestTime = gc.getTime();
|
//-------------------------------------------------------------------//
|
//-------------------------------------------------------------------//
|
tmpstr = reader.readLine();
|
reader.mark(0);
|
//-------------------------------------------------------------------//
|
//-------------------------------------------------------------------//
|
tmpstr = reader.readLine() + reader.readLine() + reader.readLine() + reader.readLine();
|
int sub_con_count = 1;
|
if (tmpstr.contains("J1D")) {
|
sub_con_count = 4;
|
} else if (tmpstr.contains("J1C")) {
|
sub_con_count = 3;
|
} else if (tmpstr.contains("J1B")) {
|
sub_con_count = 2;
|
}
|
m_BattSum /= sub_con_count;
|
//-------------------------------------------------------------------//
|
reader.reset();
|
//-------------------------------------------------------------------//
|
m_MinValue = 900000;
|
for(int n=0; n<m_BattSum; n++) {
|
float tmpser = 0;
|
float tmpvol = 0;
|
for(int cnt=0; cnt<sub_con_count; cnt++) {
|
tmpstr = reader.readLine();
|
if(null != tmpstr) {
|
tmpstr = tmpstr.substring(tmpstr.indexOf(",")+1, tmpstr.length());
|
tmpser += Float.parseFloat(tmpstr.substring(0, tmpstr.indexOf(",")));
|
|
tmpstr = tmpstr.substring(tmpstr.indexOf(",")+1, tmpstr.length());
|
tmpvol += Float.parseFloat(tmpstr.substring(0, tmpstr.indexOf(",")));
|
} else {
|
m_DataOk = false;
|
break;
|
}
|
}
|
|
if(false == m_DataOk) {
|
break;
|
}
|
|
MonomerSer[n] = tmpser / sub_con_count;
|
MonomerVol[n] = tmpvol / sub_con_count ;
|
|
MonomerRes[n] = 0;
|
if(MonomerSer[n] > 1) {
|
MonomerRes[n] = 1000 / (MonomerSer[n] / (m_MonomerVol/2));
|
}
|
|
if(MonomerSer[n] < m_MinValue) {
|
m_MinValue = MonomerSer[n];
|
m_MinNum = n+1;
|
}
|
}
|
//-------------------------------------------------------------------//
|
} catch (Exception e) {
|
m_DataOk = false;
|
System.err.println("Class 'CsvData' function setData(): " + e.getMessage());
|
} finally {
|
try {
|
reader.close();
|
} catch (IOException e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
}
|
}
|
|
public void checkCsvFile(File file)
|
{
|
setData(file);
|
}
|
|
private String getNodeTextEx(Object ob, Element rootnode, String node_name) {
|
String text = String.valueOf(ob);
|
try
|
{
|
Element node = rootnode.element(node_name);
|
text = node.getTextTrim();
|
} catch (NullPointerException e) {
|
e.printStackTrace();
|
}
|
|
return text;
|
}
|
|
public void checkXmlFile(File file)
|
{
|
m_DataOk = false;
|
try {
|
SAXReader reader = new SAXReader();
|
Document document = reader.read(file);
|
Element rootnode = document.getRootElement();
|
|
m_TestType = BattTestData.BATTDATA_RES;
|
m_DevType = DevType_FBR;
|
|
String test_time = getNodeTextEx("1990-01-01_00:00:00", rootnode, "TEST_TIME");
|
if(test_time.contains("1990-01-01")) {
|
m_DataOk = false;
|
return;
|
}
|
|
m_TestTime = Com.get_DT_FromStr(test_time.replace("_", " ").trim(), Com.DTF_YMDhms);
|
|
//String data_version = Config.getNodeTextEx("V1.0", rootnode, "VERSION");
|
|
Element sub_node = rootnode.element("BATT_PARAM");
|
m_BattSum = Integer.parseInt(getNodeTextEx("0", sub_node, "batt_count"));
|
m_MonomerVol = Float.parseFloat(getNodeTextEx("0.0", sub_node, "batt_vol"));
|
m_STDAH = Integer.parseInt(getNodeTextEx("0", sub_node, "batt_cap"));
|
int concount_pb = Integer.parseInt(getNodeTextEx("1", sub_node, "concount_pb"));
|
|
|
m_MinValue = 900000;
|
for(int n=0; n<m_BattSum; n++) {
|
@SuppressWarnings("unchecked")
|
List<Element> childElements = rootnode.elements();
|
int cnt = 0;
|
for(cnt=0; cnt<childElements.size(); cnt++) {
|
Element child = childElements.get(cnt);
|
if(null == child.attributeValue("batt_num")) {
|
continue;
|
}
|
if(Integer.parseInt(child.attributeValue("batt_num").trim()) == (n+1)) {
|
float tmp_var_res = 0;
|
float tmp_var_vol = 0;
|
float tmp_var_ser = 0;
|
float tmp_var_con = 0;
|
for(int c=0; c<concount_pb; c++) {
|
tmp_var_res += Float.parseFloat(getNodeTextEx("0.0", child, "br_" + (c+1)));
|
tmp_var_vol += Float.parseFloat(getNodeTextEx("0.0", child, "bv_" + (c+1)));
|
tmp_var_ser += Float.parseFloat(getNodeTextEx("0.0", child, "bs_" + (c+1)));
|
tmp_var_con += Float.parseFloat(getNodeTextEx("0.0", child, "cr_" + (c+1)));
|
}
|
tmp_var_res /= concount_pb;
|
tmp_var_vol /= concount_pb;
|
tmp_var_ser /= concount_pb;
|
tmp_var_con /= concount_pb;
|
MonomerRes[n] = tmp_var_res;
|
MonomerVol[n] = tmp_var_vol;
|
MonomerSer[n] = tmp_var_ser;
|
MonomerConn[n] = tmp_var_con;
|
break;
|
}
|
}
|
|
if(cnt < childElements.size()) {
|
m_DataOk = true;
|
}
|
|
if(MonomerSer[n] < m_MinValue) {
|
m_MinValue = MonomerSer[n];
|
m_MinNum = n+1;
|
}
|
}
|
} catch (NumberFormatException e) {
|
m_DataOk = false;
|
e.printStackTrace();
|
} catch (DocumentException e) {
|
m_DataOk = false;
|
e.printStackTrace();
|
}
|
}
|
|
|
|
public void checkFgxlsFile(File file)
|
{
|
FileInputStream fis = null;
|
try {
|
fis = new FileInputStream(file);
|
HSSFWorkbook workbook = new HSSFWorkbook(fis);
|
HSSFSheet rs = workbook.getSheetAt(0);
|
m_BattGroupNameFull=rs.getRow(0).getCell(0).getStringCellValue().trim().replace("---", "-");
|
String bg_inf = rs.getRow(0).getCell(1).getStringCellValue().trim().replace("---", "-");
|
//m_BattGroupNameFull = rs.getCell(0, 0).getContents().trim().replace("---", "-");
|
//System.out.println(m_BattGroupNameFull);
|
//String bg_inf = rs.getCell(0, 1).getContents().trim();
|
//System.out.println(bg_inf);
|
m_TestType = DevType_Csv;
|
m_DevType = DevType_Csv;
|
m_MonomerVol = Float.parseFloat(bg_inf.substring(bg_inf.indexOf("µ¥Ìåµçѹ:")+5,
|
bg_inf.indexOf("²Î¿¼µçµ¼Öµ")-1).trim());
|
m_BattSum = Integer.parseInt(bg_inf.substring(bg_inf.indexOf("µ¥ÌåÊý:")+4,
|
bg_inf.indexOf("²âÊÔʱ¼ä:")-1).trim());
|
m_TestTime = Com.get_DT_FromStr(bg_inf.substring(bg_inf.indexOf("²âÊÔʱ¼ä:")+5,
|
bg_inf.length()).trim(), Com.DTF_YMDhms);
|
|
if(m_BattSum > 500) {
|
m_BattSum = 500;
|
}
|
|
m_MinValue = 900000;
|
for(int n=0; n<m_BattSum; n++) {
|
MonomerSer[n] = Float.parseFloat(rs.getRow(1).getCell(n+3).getStringCellValue().trim());
|
MonomerSer[n] = Float.parseFloat(rs.getRow(2).getCell(n+3).getStringCellValue().trim());
|
//MonomerSer[n] = Float.parseFloat(rs.getCell(1, n+3).getContents().trim());
|
//MonomerVol[n] = Float.parseFloat(rs.getCell(2, n+3).getContents().trim());
|
MonomerRes[n] = 0;
|
if(MonomerSer[n] > 1) {
|
MonomerRes[n] = 1000 / (MonomerSer[n] / (m_MonomerVol/2));
|
}
|
|
if(MonomerSer[n] < m_MinValue) {
|
m_MinValue = MonomerSer[n];
|
m_MinNum = n+1;
|
}
|
}
|
} catch (IOException e) {
|
e.printStackTrace();
|
} finally {
|
if(null != fis)
|
{
|
try {
|
fis.close();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
}
|
}
|