Administrator
2022-10-19 bec9d52048d24f89ac665aa4b5abb726e212df63
BattFBS9600_ForFG/src/com/dev/fg/FBS9600_State_SQL.java
@@ -434,21 +434,58 @@
      }
   }
   public static float queryAvgBattMonResAlmPama(MysqlConnPool pool,int dev_id) {
      String sql_str_sel = " SELECT * FROM " + Sql_Mysql.Tb_Dev_Param_Table + " WHERE dev_Id = " + dev_id + " AND alm_id = 119007 LIMIT 1";
      Sql_Mysql sql = new Sql_Mysql(pool.getConn());
      ResultSet res = null;
      float avg_param = 0;
      try {
         res = sql.sqlMysqlQuery(sql_str_sel);
         if(res.next()) {
            float alm_high_coe = res.getFloat("alm_high_coe");
            float alm_low_coe = res.getFloat("alm_low_coe");
            avg_param = (alm_high_coe + alm_low_coe)/2;
         }
      } catch (Exception e) {
         e.printStackTrace();
      } finally {
         if(null != res) {
            try {
               res.close();
            } catch (SQLException e) {
               e.printStackTrace();
            }
         }
         sql.close_con();
      }
      return avg_param;
   }
   /**
    * 启动是模拟每个电池组的内阻数据值
    * @param gB_MysqlConnPool
    */
   public static void MakeMonResDataRandom(MysqlConnPool pool) {      
      String sql_str_sel = "SELECT * FROM " + Sql_Mysql.BattRtData_Table;
      String sql_str_sel = "SELECT * FROM " + Sql_Mysql.BattInf_Table;
      //String sql_str_sel = "SELECT * FROM " + Sql_Mysql.BattRtData_Table;
      ResultSet res = null;
      Sql_Mysql sql = new Sql_Mysql(pool.getConn());
      try {
         res = sql.sqlMysqlQuery(sql_str_sel);
         while(res.next()) {
            int battgroupid = res.getInt("BattGroupId");
            int mon_num = res.getInt("mon_num");
            int BattGroupId = res.getInt("BattGroupId");
            int MonCount    = res.getInt("MonCount");
            int MonVolStd   = res.getInt("MonVolStd");
            int MonCapStd   = res.getInt("MonCapStd");
            
            sql.sqlMysqlExecute("UPDATE " + Sql_Mysql.BattRtData_Table + " SET mon_res = " + String.format("%1.3f", (float)(0.101+Math.random()*0.298)) + " WHERE BattGroupId = " + battgroupid + " AND mon_num = " + mon_num);
            int FBSDeviceId = res.getInt("FBSDeviceId");
            float avg_param = queryAvgBattMonResAlmPama(pool,FBSDeviceId);
            float jiaozhun = (float)(1*((float)MonVolStd/2)/((float)MonCapStd/100));
            //System.out.println("校准值为:"+jiaozhun + "\t MonVolStd"+MonVolStd+"\t MonCapStd"+MonCapStd);
            for(int cnt = 1 ;cnt <= MonCount;cnt++) {
               sql.sqlMysqlExecute("UPDATE " + Sql_Mysql.BattRtData_Table + " SET mon_res = " + String.format("%1.3f", (float)(jiaozhun*avg_param +Math.random()*0.01)) + " WHERE BattGroupId = " + BattGroupId + " AND mon_num = " + cnt);
            }
         }
      } catch (SQLException e) {
         e.printStackTrace();
@@ -466,14 +503,16 @@
   
   public static void main(String[] args) {
      MysqlConnPool pool = new MysqlConnPool("127.0.0.1", 3360, 5);
      MakeMonResDataRandom(pool);
      //MakeMonResDataRandom(pool);
      
//      for(int i = 0;i< 100000;i++) {
//         float ran = (float)(0.101+Math.random()*0.298);
//         if(ran < 0.101 || ran > 0.4 ) {
//            System.err.println(ran);
//         }
//         System.out.println(String.format("%1.3f", ran));
//      }
      System.out.println(queryAvgBattMonResAlmPama(pool, 401600012));
      for(int i = 0;i< 100000;i++) {
         float ran = (float)(0.11+Math.random()*0.019);
         if(ran < 0.101 || ran > 0.4 ) {
            System.err.println(ran);
         }
         System.out.println(String.format("%1.3f", ran));
      }
   }
}