Commit 4b7aa107 authored by jaehyu's avatar jaehyu

read scale value & cell_size from not class but object

parent bdc2aec4
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<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.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" />
</component>
</module>
\ No newline at end of file
......@@ -22,40 +22,34 @@
</build>
<dependencies>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client -->
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>1.5.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.21</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client -->
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>1.5.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.21</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<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.21</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -4,8 +4,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.skt.ehs.mbs.db.maria.vo.FPElement;
import com.skt.ehs.mbs.fpbuilder._ble_indicator;
import com.skt.ehs.mbs.fpbuilder.blefpbuilder._ble_indicator;
import org.apache.ibatis.annotations.Param;
......
package com.skt.ehs.mbs.fpbuilder;
package com.skt.ehs.mbs.fpbuilder.blefpbuilder;
import com.skt.ehs.mbs.db.maria.DBManager;
import com.skt.ehs.mbs.db.maria.MariaConnectionManager;
......@@ -9,34 +9,22 @@ import org.apache.ibatis.session.SqlSession;
import java.util.*;
import java.util.stream.Collectors;
public class BLEFPBuilder {
public class BLEFpBuilder {
// Todo read from databse
// TODO read from databse. 플로어에 대한 정보 (가로 세로 길이)를 구한다. 셀크기는 conf 파일 통해..
public static final int CELL_SIZE_BLE = 300;
public static final int LENGTH_X = 8000;
public static final int WIDTH_Y = 4000;
public static final int FLOOR_LENGTH_X = 900;
public static final int FLOOR_LENGTH_Y = 900;
// TODO 빌딩과 FLOOR 에 대한 입력은 DB를 읽어 Console에서 선택할 수 있도록 console application 을 구현
public static final int SAMPLE_CAMPUS_ID = 1;
public static final int SAMPLE_BUILDING_ID = 1;
public static final int SAMPLE_FLOOR_ID = 1;
Floor mFloor;
BLE_Floor mFloor;
public BLEFPBuilder(int M,int N) {
mFloor = new Floor(M,N);
}
public void LoadCellLocation() {
int location_x = 0;
int location_y = 0;
for (int x = 1 ; x <= mFloor.getM(); x++) {
location_x = CELL_SIZE_BLE * x - CELL_SIZE_BLE / 2;
for (int y = 1; y <= mFloor.getN(); y++) {
location_y = CELL_SIZE_BLE * y - CELL_SIZE_BLE / 2;
mFloor.setBLECellLocation(x-1,y-1,location_x,location_y);
}
}
mFloor.showCellLocation();
public BLEFpBuilder(int M, int N, int sizeOfCell) {
mFloor = new BLE_Floor(M,N,sizeOfCell);
}
public void LoadCellID() {
......@@ -47,12 +35,27 @@ public class BLEFPBuilder {
for (int y = 1; y <= mFloor.getN(); y++) {
id = id_x + y;
_ble_cell bleCell= new _ble_cell(id);
mFloor.setBLECell(x-1,y-1,bleCell);
mFloor.setCell(x-1,y-1,bleCell);
}
}
mFloor.showCellID();
}
public void LoadCellLocation() {
int location_x = 0;
int location_y = 0;
int cell_size = mFloor.getBle_cell_size();
for (int x = 1 ; x <= mFloor.getM(); x++) {
location_x = (cell_size * x) - (cell_size / 2);
for (int y = 1; y <= mFloor.getN(); y++) {
location_y = (cell_size * y) - (cell_size / 2);
mFloor.setCellLocation(x-1,y-1,location_x,location_y);
}
}
mFloor.showCellLocation();
}
public boolean LoadDBConnectionPool() {
if (!MariaConnectionManager.getInstance().makeConnectionPool()) return false;
return true;
......@@ -96,10 +99,9 @@ public class BLEFPBuilder {
}
}
private List<_ble_indicator> get_aplist_in_coordinate_per_rssidir (int d1, int d2, int x1, int y1, int x2, int y2) {
MariaConnectionManager mngr = MariaConnectionManager.getInstance();
List<_ble_indicator> ret = Collections.emptyList();
List<_ble_indicator> ret;
try (SqlSession session = mngr.getSqlSessionFactory().openSession()) {
FPBLEBuildDAO mapper = session.getMapper(FPBLEBuildDAO.class);
......@@ -131,6 +133,7 @@ public class BLEFPBuilder {
return upper_rssi_dir;
}
}
private rssiDirBound normalizeRssiDir(int rssi_dir) {
rssiDirBound ret = null;
switch (rssi_dir) {
......@@ -164,47 +167,59 @@ public class BLEFPBuilder {
return ret;
}
public boolean build() {
public boolean build() throws Throwable {
// Todo read from Console or Database
int campus_id = SAMPLE_CAMPUS_ID;
int building_id = SAMPLE_BUILDING_ID;
int floor_id = SAMPLE_FLOOR_ID;
int object_cell_size = mFloor.getBle_cell_size();
int ble_cell_id;
double scale_pixel = readMapScale(campus_id, building_id, floor_id);
double scale_pixel = readMapScale(campus_id, building_id, floor_id); // 수집시 사용한 지도의 축척정보
mFloor.setMap_scale_pixel(scale_pixel);
double object_scale_pixel;
if((object_scale_pixel = mFloor.getMap_scale_pixel())==0) { }
System.out.println("object_scale_pixel : "+object_scale_pixel);
System.out.println("object_cell_size : "+object_cell_size);
System.out.println("ble_fp_builder process started .................... ");
System.out.println("scale_pixel : "+scale_pixel);
mFloor.setMap_scale_pixel(scale_pixel);
int[] rssi_dir_index = mFloor.loadRSSIDir();
rssiDirBound rssi_dir;
for (int i =0; i < rssi_dir_index.length ; i++ ) { // 수집방향별로 세트를 구성
for (int i =0; i < rssi_dir_index.length ; i++ ) { // 1.수집방향별로 세트를 구성
rssi_dir = normalizeRssiDir(rssi_dir_index[i]);
for (int m = 0; m < mFloor.getM(); m++) {
for (int n = 0; n < mFloor.getN(); n++) { // 격자별....
for (int n = 0; n < mFloor.getN(); n++) { // 2.격자별....
ble_cell_id = mFloor.getBLECell(m, n).get_id();
ble_cell_id = mFloor.getCell(m, n).get_id();
System.out.printf("floor_id : %d, building_id : %d, campus_id : %d, ble_cell_id : %d, lower_rssi_dir : %d, upper_rssi_dir : %d ",
floor_id, building_id, campus_id, ble_cell_id, rssi_dir.get_lower_rssi_dir(), rssi_dir.get_upper_rssi_dir() );
System.out.printf(" ble_cell_location : ("+mFloor.getBLECell(m,n).get_location_x()+", "+mFloor.getBLECell(m,n).get_location_y()+")");
System.out.printf(" ble_cell_location : ("+mFloor.getCell(m,n).get_location_x()+", "+mFloor.getCell(m,n).get_location_y()+")");
System.out.println();
int coordinate_pixel_x1 = (mFloor.getBLECell(m, n).get_location_x() - CELL_SIZE_BLE / 2) / (int) mFloor.getMap_scale_pixel();
int coordinate_pixel_y1 = (mFloor.getBLECell(m, n).get_location_y() - CELL_SIZE_BLE / 2) / (int) mFloor.getMap_scale_pixel();
int coordinate_pixel_x2 = (mFloor.getBLECell(m, n).get_location_x() + CELL_SIZE_BLE / 2) / (int) mFloor.getMap_scale_pixel();
int coordinate_pixel_y2 = (mFloor.getBLECell(m, n).get_location_y() + CELL_SIZE_BLE / 2) / (int) mFloor.getMap_scale_pixel();
int cell_location_x = mFloor.getCell(m, n).get_location_x();
int cell_location_y = mFloor.getCell(m, n).get_location_y();
int coordinate_pixel_x1 = (cell_location_x - object_cell_size / 2) / (int)object_scale_pixel;
int coordinate_pixel_y1 = (cell_location_y - object_cell_size / 2) / (int)object_scale_pixel;
int coordinate_pixel_x2 = (cell_location_x + object_cell_size / 2) / (int)object_scale_pixel;
int coordinate_pixel_y2 = (cell_location_y + object_cell_size / 2) / (int)object_scale_pixel;
System.out.printf("Pixel Coordinate : ("+coordinate_pixel_x1+", "+coordinate_pixel_y1+") ("+coordinate_pixel_x2+", "+coordinate_pixel_y2+")");
System.out.println();
List<_ble_indicator> ble_list =
get_aplist_in_coordinate_per_rssidir(rssi_dir.get_lower_rssi_dir(), rssi_dir.get_upper_rssi_dir(), coordinate_pixel_x1, coordinate_pixel_y1, coordinate_pixel_x2, coordinate_pixel_y2);
// getting rssi_sub_list per ap_id by transform result-list to map<ap_id,rssi_sub_list> // AP 별 ....
// Getting rssi_sub_list per ap_id by transform result-list to map<ap_id,rssi_sub_list>
Map<String, List<Integer>> transform = ble_list.stream().collect(Collectors.groupingBy(_ble_indicator::get_ap_id,
Collectors.mapping(_ble_indicator::get_rssi, Collectors.toList())));
......@@ -216,7 +231,7 @@ public class BLEFPBuilder {
// map traverse using set view
Set<Map.Entry<String, List<Integer>>> entries = transform.entrySet();
for (Map.Entry<String, List<Integer>> entry : entries) {
for (Map.Entry<String, List<Integer>> entry : entries) { // 3.AP 별 ....
List<Integer> rssi_list = entry.getValue();
// calculate statistics
......@@ -255,13 +270,22 @@ public class BLEFPBuilder {
public static void main(String[] args) {
BLEFPBuilder fp = new BLEFPBuilder((LENGTH_X % CELL_SIZE_BLE == 0)? LENGTH_X/CELL_SIZE_BLE : LENGTH_X/CELL_SIZE_BLE + 1,(WIDTH_Y % CELL_SIZE_BLE == 0)? WIDTH_Y/CELL_SIZE_BLE : WIDTH_Y/CELL_SIZE_BLE + 1); // mFloor
BLEFpBuilder fp = new BLEFpBuilder((FLOOR_LENGTH_X % CELL_SIZE_BLE == 0)? FLOOR_LENGTH_X/CELL_SIZE_BLE : FLOOR_LENGTH_X/CELL_SIZE_BLE + 1, (FLOOR_LENGTH_Y % CELL_SIZE_BLE == 0)? FLOOR_LENGTH_Y/CELL_SIZE_BLE : FLOOR_LENGTH_Y/CELL_SIZE_BLE + 1, CELL_SIZE_BLE); // mFloor
fp.LoadCellID();
fp.LoadCellLocation();
if (!fp.LoadDBConnectionPool()) {
//exit
}
fp.build();
try {
fp.build();
} catch (Throwable throwable) {
throwable.printStackTrace();
}
}
}
package com.skt.ehs.mbs.fpbuilder;
import java.util.Arrays;
package com.skt.ehs.mbs.fpbuilder.blefpbuilder;
/**
* Created by user on 2016-12-01.
*/
class Floor {
private int M;
private int N;
private _ble_cell[][] cm; // cell matrix
class BLE_Floor {
private int bcm_M; // M value of bcm
private int bcm_N; // N value of bcm
private _ble_cell[][] bcm; // ble cell matrix
// Todo 수집방향
private final int[] rssi_dir = new int[]{1000000, 2000000, 3000000, 4000000, 5000000, 6000000, 7000000, 8000000};
private double map_scale_pixel;
private int ble_cell_size;
public Floor(int M, int N) {
this.M = M;
this.N = N;
cm = new _ble_cell[M][N];
public BLE_Floor(int M, int N, int sizeOfCell) {
this.bcm_M = M;
this.bcm_N = N;
this.bcm = new _ble_cell[M][N];
this.ble_cell_size = sizeOfCell;
}
public int getCellID(int M, int N) {
return cm[M][N].get_id();
return bcm[M][N].get_id();
}
public void showCellID() {
for(int j=0;j< N;j++) {
for(int i=0;i< M; i++) {
System.out.printf("%9d ", cm[i][j].get_id());
for(int j=0;j< bcm_N;j++) {
for(int i=0;i< bcm_M; i++) {
System.out.printf("%9d ", bcm[i][j].get_id());
}
System.out.println();
}
}
public void showCellLocation() {
for(int j=0;j< N;j++) {
for(int i=0;i< M; i++) {
System.out.printf("("+cm[i][j].get_location_x()+","+cm[i][j].get_location_y()+")");
for(int j=0;j< bcm_N;j++) {
for(int i=0;i< bcm_M; i++) {
System.out.printf("("+bcm[i][j].get_location_x()+","+bcm[i][j].get_location_y()+")");
}
System.out.println();
}
}
public int getM() {
return M;
return bcm_M;
}
public void setM(int m) {
M = m;
bcm_M = m;
}
public int getN() {
return N;
return bcm_N;
}
public void setN(int n) {
N = n;
bcm_N = n;
}
public _ble_cell getBLECell(int M, int N) {
return cm[M][N];
public _ble_cell getCell(int M, int N) {
return bcm[M][N];
}
public void setBLECell(int M, int N, _ble_cell bleCell) {
cm[M][N] = bleCell;
public void setCell(int M, int N, _ble_cell bleCell) {
bcm[M][N] = bleCell;
}
public void setBLECellLocation(int M, int N, int x, int y) {
cm[M][N].set_location_x(x);
cm[M][N].set_location_y(y);
public void setCellLocation(int M, int N, int x, int y) {
bcm[M][N].set_location_x(x);
bcm[M][N].set_location_y(y);
}
double map_scale_pixel;
public int[] loadRSSIDir () {
return rssi_dir;
}
int ble_cell_size;
public double getMap_scale_pixel() {
return map_scale_pixel;
......@@ -87,11 +90,4 @@ class Floor {
return ble_cell_size;
}
public void setBle_cell_size(int ble_cell_size) {
this.ble_cell_size = ble_cell_size;
}
public int[] loadRSSIDir () {
return rssi_dir;
}
}
package com.skt.ehs.mbs.fpbuilder;
package com.skt.ehs.mbs.fpbuilder.blefpbuilder;
/**
* Created by user on 2016-11-30.
......
package com.skt.ehs.mbs.fpbuilder;
package com.skt.ehs.mbs.fpbuilder.blefpbuilder;
/**
* Created by user on 2016-12-02.
......
......@@ -7,7 +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="_ble_indicator" type="com.skt.ehs.mbs.fpbuilder._ble_indicator"/>
<typeAlias alias="_ble_indicator" type="com.skt.ehs.mbs.fpbuilder.blefpbuilder._ble_indicator"/>
</typeAliases>
<environments default="development">
......
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