Commit 8d33d5d1 authored by jaehyu's avatar jaehyu

for homework

parent 92239206
......@@ -13,8 +13,8 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.mybatis:mybatis:3.4.1" level="project" />
<orderEntry type="library" name="Maven: org.mariadb.jdbc:mariadb-java-client:1.5.4" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.7" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-log4j12:1.7.7" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.21" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-log4j12:1.7.21" level="project" />
<orderEntry type="library" name="Maven: log4j:log4j:1.2.17" level="project" />
<orderEntry type="library" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
......
......@@ -39,17 +39,16 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.7</version>
<version>1.7.21</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.7</version>
<version>1.7.21</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
......
......@@ -34,7 +34,9 @@ public class Configure {
public static final double CELL_SIZE_BLE = 300;
public static final double CELL_SIZE_MAG = 50;
public static final double LENGTH_X = 3500; // 층의 X축방향 길이
public static final double WIDTH_Y = 2000; // 폭
public static final double LENGTH_PIXEL_X = 350; // 층의 X축방향 길이
public static final double WIDTH_PIXEL_Y = 200; // 폭
}
......@@ -3,15 +3,13 @@ package com.skt.ehs.mbs.db.maria;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.skt.ehs.mbs.db.maria.dao.FPBLEBuildDAO;
import com.skt.ehs.mbs.db.maria.dao.RawDataAPDAO;
import com.skt.ehs.mbs.db.maria.dao.RawDataTagDAO;
import com.skt.ehs.mbs.db.maria.vo.*;
import org.apache.ibatis.session.SqlSession;
import com.skt.ehs.mbs.conf.Configure;
public class DBManager {
......@@ -19,9 +17,15 @@ public class DBManager {
public static final String COLUMN_NAME_BUILDING_ID = "building_id";
public static final String COLUMN_NAME_FLOOR_ID = "floor_id";
public static final String COLUMN_NAME_TAG_ID = "tag_id";
public static final String COLUMN_NAME_MAP_ID = "map_id";
public static final String COLUMN_NAME_SCALEPIXEL = "scale_pixel";
public static final String COMMAND_OPTION_GETPACKAGE = "getPackage";
public static final String COMMAND_OPTION_GETRAWDATATAG = "getRawDataTag";
public static final String COMMAND_OPTION_READSCALEPIXEL = "getScalePixel";
public static final String COMMAND_OPTION_UPDATESCALEPIXEL = "updateScalePixel";
// Todo needed to replace with try~resources stmts....
public static void deleteRawDataAP (String sid) {
MariaConnectionManager mngr = MariaConnectionManager.getInstance();
......@@ -42,8 +46,6 @@ public class DBManager {
public static <E> List<E> getRawDataTag (String cmd, int campus, int building, int floor) throws Throwable {
MariaConnectionManager mngr = MariaConnectionManager.getInstance();
SqlSession session = mngr.getSqlSessionFactory().openSession();
RawDataTagDAO mapper = session.getMapper(RawDataTagDAO.class);
HashMap<String, Integer> querry_params = new HashMap<>();
querry_params.put(COLUMN_NAME_CAMPUS_ID,campus);
......@@ -52,32 +54,59 @@ public class DBManager {
List<E> ret = Collections.emptyList();
try {
try (SqlSession session = mngr.getSqlSessionFactory().openSession()) {
RawDataTagDAO mapper = session.getMapper(RawDataTagDAO.class);
switch (cmd) {
case COMMAND_OPTION_GETPACKAGE:
// return type 을 List<String> 으로.....
//ret = (List<E>) mapper.hSelectPackage(querry_params);
break;
case COMMAND_OPTION_GETRAWDATATAG:
ret = (List<E>) mapper.hSelectAll(querry_params);
break;
}
return ret;
} catch (Exception e) {
throw e;
}
finally {
session.close();
}
}
public static double getMapScale (int campus, int building, int floor) throws Throwable {
MariaConnectionManager mngr = MariaConnectionManager.getInstance();
double scale= 0;
HashMap<String, Integer> querry_params = new HashMap<>();
querry_params.put(COLUMN_NAME_CAMPUS_ID,campus);
querry_params.put(COLUMN_NAME_BUILDING_ID,building);
querry_params.put(COLUMN_NAME_FLOOR_ID,floor);
try (SqlSession session = mngr.getSqlSessionFactory().openSession()) {
FPBLEBuildDAO mapper = session.getMapper(FPBLEBuildDAO.class);
scale = mapper.selectScalePixel(querry_params);
}
return scale;
}
public static void updateMapImage (String cmd, double scale_pixel, int map_id ) throws Throwable {
MariaConnectionManager mngr = MariaConnectionManager.getInstance();
try (SqlSession session = mngr.getSqlSessionFactory().openSession()) {
FPBLEBuildDAO mapper = session.getMapper(FPBLEBuildDAO.class);
switch (cmd) {
case COMMAND_OPTION_UPDATESCALEPIXEL:
mapper.updateScale(scale_pixel,map_id );
// added below codes for to prevent auto-rollback. which is what I see without a below statement now.
// jaehyu on 2016-11-23
session.commit();
break;
}
}
}
public static void storeRawDataAP(RawDataAP rawDataAP) throws Throwable {
MariaConnectionManager mngr = MariaConnectionManager.getInstance();
......
package com.skt.ehs.mbs.db.maria.dao;
import java.util.HashMap;
import org.apache.ibatis.annotations.Param;
/**
* Created by user on 2016-12-01.
*/
public interface FPBLEBuildDAO {
void updateScale(@Param("scale_pixel") double scale_pixel,@Param("map_id") int map_id);
public double selectScalePixel(HashMap<String, Integer> params);
}
\ No newline at end of file
......@@ -4,11 +4,17 @@ package com.skt.ehs.mbs.fpbuilder;
* Created by user on 2016-11-30.
*/
public class BLECell {
int ble_cell_id;
double location_x, location_y; // 실거리 ??
double rssi_min, rssi_max, rssi_avg, rssi_std_dev;
double location_x;
double location_y; // 실거리 ??
double rssi_min;
double rssi_max;
double rssi_avg;
double rssi_std_dev;
int rssi_dir;
double magnitude_angle; // 해당 cell의 각 수집방향에 대하여 수집된 지자기방향의 평균값으로 대표
double mag_angle; // 해당 cell의 각 수집방향에 대하여 수집된 지자기방향의 평균값으로 대표
public int getBle_cell_id() {
return ble_cell_id;
......@@ -75,11 +81,11 @@ public class BLECell {
}
public double getMagnitude_angle() {
return magnitude_angle;
return mag_angle;
}
public void setMagnitude_angle(double magnitude_angle) {
this.magnitude_angle = magnitude_angle;
this.mag_angle = magnitude_angle;
}
@Override
......@@ -93,7 +99,7 @@ public class BLECell {
", rssi_avg=" + rssi_avg +
", rssi_std_dev=" + rssi_std_dev +
", rssi_dir=" + rssi_dir +
", magnitude_angle=" + magnitude_angle +
", mag_angle=" + mag_angle +
'}';
}
}
......@@ -21,8 +21,8 @@ intellj 컴파일에 문제가 있으면 ,
by jaehyu 2016-11-28
*/
public class BLEFPBuilder {
Logger logger = LoggerFactory.getLogger(BLEFPBuilder.class);
private Floor mFloor;
boolean build_FP_BLE_CELL() {
int mag_per_ble = (int)(Configure.CELL_SIZE_BLE / Configure.CELL_SIZE_MAG);
......@@ -35,55 +35,14 @@ public class BLEFPBuilder {
*/
void genCells() {
// compose ble-cell-matrix
int M = (int) (Configure.LENGTH_X / Configure.CELL_SIZE_BLE);
int N = (int) (Configure.WIDTH_Y / Configure.CELL_SIZE_BLE);
System.out.println( "X : "+M+" Y : "+N);
if (((int)Configure.LENGTH_X % (int)Configure.CELL_SIZE_BLE) != 0 ) M++;
if (((int)Configure.WIDTH_Y % (int)Configure.CELL_SIZE_BLE) != 0 ) N++;
System.out.println( "M : "+M+" N : "+N);
int[][] ble_cell_ids = new int[M][N];
CellMatrix cells = new CellMatrix(ble_cell_ids);
cells.show();
List<BLECell> ble_cells = new ArrayList<>();
for (int x = 1; x <= M; x++) {
int idx = 0;
int id = 0;
int id_x = 1000 * x;
for (int y = 1; y <= N; y++) {
id = id_x + y;
BLECell next = new BLECell();
next.setBle_cell_id(id);
ble_cells.add(next);
}
}
Iterator<BLECell> iter = ble_cells.iterator();
//while (iter.hasNext()) System.out.println(iter.next().getCell_id());
System.out.println(ble_cells.size());
}
static boolean processor() {
System.out.println("Hello");
if (MariaConnectionManager.getInstance().makeConnectionPool() == false) {
//logger.error("Fail to connect IntegrationDB. Can't start MBSServer.");
return false;
}
System.out.println("Hello processor");
// package-only-list from raw_data_tag
List<RawDataTag> rawdata = Collections.emptyList();
List<RawDataTag> packNameList = Collections.emptyList();
......@@ -94,20 +53,23 @@ public class BLEFPBuilder {
throwable.printStackTrace();
}
System.out.println(rawdata.size());
//try {
// DBManager.deleteRawDataAP("bbbb");
//} catch (Throwable throwable) {
// throwable.printStackTrace();
//}
/*
try {
// 스케일값을 DB에 넣기 위한 임시코드
DBManager.updateMapImage(DBManager.COMMAND_OPTION_UPDATESCALEPIXEL,10.00,2);
} catch (Throwable throwable) {
throwable.printStackTrace();
}*/
return true;
}
public static void main(String[] args) {
BLEFPBuilder b = new BLEFPBuilder();
b.genCells();
processor();
Initializer.compose();
//processor();
}
}
......@@ -6,7 +6,7 @@ package com.skt.ehs.mbs.fpbuilder;
public class CellMatrix {
private final int M; // number of rows
private final int N; // number of columns
private int[][] cell_ids = null;
private int[][] cell_ids;
// create M-by-N matrix of 0's
public CellMatrix(int M, int N) {
......@@ -31,8 +31,8 @@ public class CellMatrix {
// print matrix
public void show() {
for(int i=0;i<M;i++) {
for(int j=0;j< N; j++) {
for(int j=0;j< N;j++) {
for(int i=0;i< M; i++) {
System.out.printf("%9d ", cell_ids[i][j]);
}
System.out.println();
......
......@@ -5,9 +5,39 @@ package com.skt.ehs.mbs.fpbuilder;
* 층을 가상 Matrix 로 구성하고,
* Matrix의 각 element는 값으로 BLECell 타입의 Object를 가지게 된다
*/
public class Floor extends CellMatrix {
class Floor {
BLECell[][] fp; // FingerPrint
public Floor(int M, int N) {
super(M, N);
fp = new BLECell[M][N];
}
public BLECell getBLECell(int M, int N) {
return fp[M][N];
}
public void setBLECell(int M, int N, BLECell bleCell) {
fp[M][N] = bleCell;
}
double map_scale_pixel;
int ble_cell_size;
public double getMap_scale_pixel() {
return map_scale_pixel;
}
public void setMap_scale_pixel(double map_scale_pixel) {
this.map_scale_pixel = map_scale_pixel;
}
public int getBle_cell_size() {
return ble_cell_size;
}
public void setBle_cell_size(int ble_cell_size) {
this.ble_cell_size = ble_cell_size;
}
}
package com.skt.ehs.mbs.fpbuilder;
import com.skt.ehs.mbs.conf.Configure;
import com.skt.ehs.mbs.db.maria.DBManager;
import com.skt.ehs.mbs.db.maria.MariaConnectionManager;
import com.skt.ehs.mbs.db.maria.dao.RawDataAPDAO;
import org.apache.ibatis.session.SqlSession;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* Created by user on 2016-12-01.
*/
public class Initializer {
// Todo BLECell 을 최소한의 필수 정보로 구성하여
// Floor Matrix 를 만든다
private static boolean generateCellid() {
// compose ble-cell-matrix
int M = (int) (Configure.LENGTH_PIXEL_X / Configure.CELL_SIZE_BLE);
int N = (int) (Configure.WIDTH_PIXEL_Y / Configure.CELL_SIZE_BLE);
System.out.println( "X : "+M+" Y : "+N);
if (((int)Configure.LENGTH_PIXEL_X % (int)Configure.CELL_SIZE_BLE) != 0 ) M++;
if (((int)Configure.WIDTH_PIXEL_Y % (int)Configure.CELL_SIZE_BLE) != 0 ) N++;
System.out.println( "M : "+M+" N : "+N);
// gen cell_id
int[][] ble_cell_ids = new int[M][N];
for (int x = 1; x <= M; x++) {
int idx = 0;
int id = 0;
int id_x = 1000 * x; // id는 6자리, 이 중 앞 3자리는 x(index) 성분 , 뒤 세자리는 y(index) 성분
// index 란 , ble cell 격자에서 좌상 element 에서 1 로 시작해서 오른쪽방향 그리고
// 아래방향(폭, y 방향) 으로 1씩 증가하는 수를 말한다
for (int y = 1; y <= N; y++) {
id = id_x + y;
ble_cell_ids[x-1][y-1] = id;
}
}
// assign Floor
CellMatrix ble_cells = new CellMatrix(ble_cell_ids);
ble_cells.show();
return true;
}
private static double readMapScale() {
int iCampusID = 1; // Todo console 에서 받아옴
int iBuildingID = 1; // Todo console 에서 받아옴
int iFloorID = 1; // Todo console 에서 받아옴
double ret = 0;
try {
ret = DBManager.getMapScale (iCampusID,iBuildingID,iFloorID);
} catch (Throwable throwable) {
throwable.printStackTrace();
}
return ret;
}
private static void initFloor() {
double scale = readMapScale();
System.out.printf("scale_pixel : %9.4f",scale);
//Floor floor = new Floor();
}
public static boolean compose() {
if (MariaConnectionManager.getInstance().makeConnectionPool() == false) {
return false;
}
initFloor();
//boolean t = generateCellid();
return false;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.skt.ehs.mbs.db.maria.dao.FPBLEBuildDAO">
<select id="selectScalePixel" parameterType="map" resultType="double">
select scale_pixel from map_image WHERE campus_id=#{campus_id} and BUILDING_ID = #{building_id} and floor_id=#{floor_id}
</select>
</mapper>
......@@ -7,16 +7,15 @@
<insert id="insertRawDataTag" parameterType="RawDataTag" >
<insert id="insertRawDataTag" parameterType="RawDataTag" >
INSERT INTO raw_data_tag (tag_id, collected_time, sequence_num, sub_seq_num, package_collect_key, revision_collect, position_x, position_y,
mag_bh, mag_bv, rssi_dir, north_dir, floor_id, building_id, campus_id, c_cell_id) values (#{tag_id},#{collected_time},#{sequence_num},#{sub_seq_num},#{package_collect_key},#{revision_collect},#{position_x},#{position_y},#{mag_bh},#{mag_bv},#{rssi_dir},#{north_dir},#{floor_id},#{building_id},#{campus_id},#{c_cell_id})
</insert>
</insert>
<select id="hSelectAll" parameterType="map" resultType="RawDataTag">
<select id="hSelectAll" parameterType="map" resultType="RawDataTag">
SELECT tag_id, collected_time, sequence_num, sub_seq_num, package_collect_key, revision_collect, position_x, position_y,
mag_bh, mag_bv, rssi_dir, north_dir, floor_id, building_id, campus_id, c_cell_id FROM raw_data_tag WHERE campus_id=#{campus_id} and BUILDING_ID = #{building_id} and floor_id=#{floor_id}
</select>
</select>
</mapper>
\ No newline at end of file
......@@ -7,6 +7,7 @@
<typeAliases>
<typeAlias alias="RawDataTag" type="com.skt.ehs.mbs.db.maria.vo.RawDataTag"/>
<typeAlias alias="RawDataAP" type="com.skt.ehs.mbs.db.maria.vo.RawDataAP"/>
<typeAlias alias="FPBLEBuildDAO" type="com.skt.ehs.mbs.db.maria.dao.FPBLEBuildDAO"/>
</typeAliases>
<environments default="development">
......@@ -25,6 +26,7 @@
<mappers>
<mapper resource="db/maria/mapper/RawDataTagMapper.xml" />
<mapper resource="db/maria/mapper/RawDataAPMapper.xml" />
<mapper resource="db/maria/mapper/FPBLEBuildMapper.xml" />
</mappers>
</configuration>
\ No newline at end of file
package com.skt.ehs.mbs.fpbuilder;
import static org.junit.Assert.*;
/**
* Created by user on 2016-12-01.
*/
public class CellMatrixTest {
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment