Commit 7410a315 authored by jaehyu's avatar jaehyu

clean sources

parent 37c85bdb
......@@ -3,6 +3,7 @@ package com.skt.ehs.mbs.db.maria.dao;
import java.util.HashMap;
import java.util.List;
import com.skt.ehs.mbs.db.maria.vo.FPElement;
import com.skt.ehs.mbs.fpbuilder._ble_indicator;
import org.apache.ibatis.annotations.Param;
......@@ -13,11 +14,14 @@ import org.apache.ibatis.annotations.Param;
*/
public interface FPBLEBuildDAO {
void updateScale(@Param("scale_pixel") double scale_pixel,@Param("map_id") int map_id);
public double selectScalePixel(HashMap<String, Integer> params);
// List<_ble_indicator> selectAPinCoordiwDir(@Param("lower_rssi_dir")int lower_rssi_dir, @Param("upper_rssi_dir")int upper_rssi_dir, @Param("position_x1")int position_x1 , @Param("position_y1")int position_y1, @Param("position_x2")int position_x2, @Param("position_y2")int position_y2);
// below is for binding-test
List<_ble_indicator> selectAPinCoordiwDir(@Param("lower_rssi_dir")int lower_rssi_dir, @Param("upper_rssi_dir")int upper_rssi_dir,
@Param("ble_cell_coordi_x1")int ble_cell_coordi_x1, @Param("ble_cell_coordi_y1")int ble_cell_coordi_y1,
@Param("ble_cell_coordi_x2")int ble_cell_coordi_x2, @Param("ble_cell_coordi_y2")int ble_cell_coordi_y2);
double selectScalePixel(HashMap<String, Integer> params);
List<_ble_indicator> selectAPinCoordiwDir(@Param("lower_rssi_dir")int lower_rssi_dir, @Param("upper_rssi_dir")int upper_rssi_dir,
@Param("ble_cell_coordi_x1")int ble_cell_coordi_x1, @Param("ble_cell_coordi_y1")int ble_cell_coordi_y1,
@Param("ble_cell_coordi_x2")int ble_cell_coordi_x2, @Param("ble_cell_coordi_y2")int ble_cell_coordi_y2);
/* Todo : MySQL Bulk insert
void insertFpBleData(FPElement fp_elem);
*/
}
\ No newline at end of file
......@@ -12,6 +12,8 @@ import java.util.ArrayList;
public interface RawDataAPDAO {
void insertRawDataAP(RawDataAP rawdata);
ArrayList<RawDataAP> getRawDataAP();
void deleteRawDataAP(String tag_id);
}
package com.skt.ehs.mbs.db.maria.vo;
/**
* Created by jaehyu on 2016-12-04.
*/
public class FPElement {
private int floor_id;
private int building_id;
private int campus_id;
private int ble_cell_id;
private int rssi_dir;
private String ap_id;
private int rssi_collect_cnt;
private double rssi_min;
private double rssi_max;
private double rssi_avg;
private double rssi_std_dev;
public FPElement(int floor, int building, int campus, int cell_id, int rssi_dir, String ap_id, int count, double min, double max, double average, double stddev) {
this.floor_id = floor;
this.building_id = building;
this.campus_id = campus;
this.ble_cell_id = cell_id;
this.rssi_dir = rssi_dir;
this.ap_id = ap_id;
this.rssi_collect_cnt = count;
this.rssi_min = min;
this.rssi_max = max;
this.rssi_avg = average;
this.rssi_std_dev = stddev;
}
@Override
public String toString() {
return "FPElement{" +
"floor_id=" + floor_id +
", building_id=" + building_id +
", campus_id=" + campus_id +
", ble_cell_id=" + ble_cell_id +
", rssi_dir=" + rssi_dir +
", ap_id='" + ap_id + '\'' +
", rssi_collect_cnt=" + rssi_collect_cnt +
", rssi_min=" + rssi_min +
", rssi_max=" + rssi_max +
", rssi_avg=" + rssi_avg +
", rssi_std_dev=" + rssi_std_dev +
'}';
}
}
package com.skt.ehs.mbs.fpbuilder;
/**
* Created by user on 2016-11-30.
*/
public class BLECell {
private int ble_cell_id;
private int location_x;
private int location_y; // 실거리 ??
BLECell(int id) {
ble_cell_id = id;
}
public int getBle_cell_id() {
return ble_cell_id;
}
public void setBle_cell_id(int ble_cell_id) {
this.ble_cell_id = ble_cell_id;
}
public int getLocation_x() {
return location_x;
}
public void setLocation_x(int location_x) {
this.location_x = location_x;
}
public int getLocation_y() {
return location_y;
}
public void setLocation_y(int location_y) {
this.location_y = location_y;
}
@Override
public String toString() {
return "BLECell{" +
"ble_cell_id=" + ble_cell_id +
", location_x=" + location_x +
", location_y=" + location_y +
'}';
}
}
......@@ -3,6 +3,7 @@ package com.skt.ehs.mbs.fpbuilder;
import com.skt.ehs.mbs.db.maria.DBManager;
import com.skt.ehs.mbs.db.maria.MariaConnectionManager;
import com.skt.ehs.mbs.db.maria.dao.FPBLEBuildDAO;
import com.skt.ehs.mbs.db.maria.vo.FPElement;
import org.apache.ibatis.session.SqlSession;
import java.util.*;
......@@ -10,10 +11,15 @@ import java.util.stream.Collectors;
public class BLEFPBuilder {
// Todo read from databse
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 SAMPLE_CAMPUS_ID = 1;
public static final int SAMPLE_BUILDING_ID = 1;
public static final int SAMPLE_FLOOR_ID = 1;
Floor mFloor;
public BLEFPBuilder(int M,int N) {
......@@ -27,7 +33,6 @@ public class BLEFPBuilder {
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;
// Todo calculate x,y
mFloor.setBLECellLocation(x-1,y-1,location_x,location_y);
}
}
......@@ -41,7 +46,7 @@ public class BLEFPBuilder {
int id_x = 1000 * x;
for (int y = 1; y <= mFloor.getN(); y++) {
id = id_x + y;
BLECell bleCell= new BLECell(id);
_ble_cell bleCell= new _ble_cell(id);
mFloor.setBLECell(x-1,y-1,bleCell);
}
}
......@@ -53,21 +58,26 @@ public class BLEFPBuilder {
return true;
}
private static double readMapScale() {
int iCampusID = 1; // Todo: Console 에서 받아옴
int iBuildingID = 1; // Todo: Console 에서 받아옴
int iFloorID = 1; // Todo: Console 에서 받아옴
double ret = 0;
private static double readMapScale(int campus_id, int building_id, int floor_id) {
double ret=0;
try {
ret = DBManager.getMapScale (iCampusID,iBuildingID,iFloorID);
ret = DBManager.getMapScale (campus_id,building_id,floor_id);
} catch (Throwable throwable) {
throwable.printStackTrace();
}
return ret;
}
private static boolean insertFPCellPerAP(List<FPElement> fp_cell_per_ap) {
MariaConnectionManager mngr = MariaConnectionManager.getInstance();
boolean ret = true;
try (SqlSession session = mngr.getSqlSessionFactory().openSession()) {
FPBLEBuildDAO mapper = session.getMapper(FPBLEBuildDAO.class);
// Todo : MySQL bulk insert
}
return ret;
}
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();
......@@ -76,46 +86,24 @@ public class BLEFPBuilder {
FPBLEBuildDAO mapper = session.getMapper(FPBLEBuildDAO.class);
ret = mapper.selectAPinCoordiwDir(d1,d2,x1,y1,x2, y2);
}
ret.forEach(System.out::println);
return ret;
}
private class _fp_elem {
String _ap_id;
int _rssi_collect_cnt;
double _rssi_min;
double _rssi_max;
double _rssi_avg;
double _rssi_std_dev;
public _fp_elem(String ap_id, int count, double min, double max, double average, double stddev) {
this._ap_id = ap_id;
this._rssi_collect_cnt = count;
this._rssi_min = min;
this._rssi_max = max;
this._rssi_avg = average;
this._rssi_std_dev = stddev;
}
public boolean build() {
@Override
public String toString() {
return "_fp_elem{" +
"_ap_id='" + _ap_id + '\'' +
", _rssi_collect_cnt=" + _rssi_collect_cnt +
", _rssi_min=" + _rssi_min +
", _rssi_max=" + _rssi_max +
", _rssi_avg=" + _rssi_avg +
", _rssi_std_dev=" + _rssi_std_dev +
'}';
}
}
// 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 ble_cell_id;
public boolean build() {
double scale_pixel = readMapScale();
double scale_pixel = readMapScale(campus_id, building_id, floor_id);
System.out.println("ble_fp_builder process started .................... ");
System.out.println("scale_pixel : "+scale_pixel);
mFloor.setMap_scale_pixel(scale_pixel);
/*********************** Loop of loop here ... *************************************/
/*********************** Todo Loop of loop here ... *************************************/
// 수집방향 맵 준비
int[] temp = mFloor.loadRSSIDir();
System.out.println(Arrays.toString(temp));
......@@ -126,18 +114,24 @@ public class BLEFPBuilder {
System.out.println("RSSI_DIR : "+rssi_dir);
// location coordinate 준비
BLECell bleCell = mFloor.getBLECell(3,5);
System.out.printf("Location : ("+bleCell.getLocation_x()+", "+bleCell.getLocation_y()+")");
int M=3;
int N=5;
ble_cell_id = mFloor.getBLECell(M,N).get_id();
System.out.printf("floor_id : %d, building_id : %d, campus_id : %d, ble_cell_id : %d, rssi_dir : %d,",
floor_id, building_id, campus_id, ble_cell_id, rssi_dir );
System.out.printf(" ble_cell_location : ("+mFloor.getBLECell(M,N).get_location_x()+", "+mFloor.getBLECell(M,N).get_location_y()+")");
System.out.println();
int coordinate_pixel_x1 = ( mFloor.getBLECell(3,5).getLocation_x() - CELL_SIZE_BLE/2 ) / (int)mFloor.getMap_scale_pixel();
int coordinate_pixel_y1 = ( mFloor.getBLECell(3,5).getLocation_y() - CELL_SIZE_BLE/2 ) / (int)mFloor.getMap_scale_pixel();
int coordinate_pixel_x2 = ( mFloor.getBLECell(3,5).getLocation_x() + CELL_SIZE_BLE/2 ) / (int)mFloor.getMap_scale_pixel();
int coordinate_pixel_y2 = ( mFloor.getBLECell(3,5).getLocation_y() + CELL_SIZE_BLE/2 ) / (int)mFloor.getMap_scale_pixel();
int coordinate_pixel_x1 = ( mFloor.getBLECell(3,5).get_location_x() - CELL_SIZE_BLE/2 ) / (int)mFloor.getMap_scale_pixel();
int coordinate_pixel_y1 = ( mFloor.getBLECell(3,5).get_location_y() - CELL_SIZE_BLE/2 ) / (int)mFloor.getMap_scale_pixel();
int coordinate_pixel_x2 = ( mFloor.getBLECell(3,5).get_location_x() + CELL_SIZE_BLE/2 ) / (int)mFloor.getMap_scale_pixel();
int coordinate_pixel_y2 = ( mFloor.getBLECell(3,5).get_location_y() + CELL_SIZE_BLE/2 ) / (int)mFloor.getMap_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, rssi_dir, coordinate_pixel_x1, coordinate_pixel_y1, coordinate_pixel_x2, coordinate_pixel_y2);
List<_ble_indicator> ble_list =
get_aplist_in_coordinate_per_rssidir(rssi_dir, rssi_dir, coordinate_pixel_x1, coordinate_pixel_y1, coordinate_pixel_x2, coordinate_pixel_y2);
ble_list.forEach(System.out::println);
// sample ble_list
......@@ -150,12 +144,12 @@ public class BLEFPBuilder {
new _ble_indicator("cccc", 6666),
new _ble_indicator("bbbb", 7777));
// transform list to map
// getting rssi_sub_list per ap_id by transform result-list to map<ap_id,rssi_sub_list>
Map<String,List<Integer>> transform = sample2.stream().collect(Collectors.groupingBy(_ble_indicator::get_ap_id,
Collectors.mapping(_ble_indicator::get_rssi,Collectors.toList())));
// prepare for insert value for storing
List<_fp_elem> fp_per_cell = new ArrayList<>();
List<FPElement> fp_cell_per_ap = new ArrayList<>();
// map traverse using set view
Set<Map.Entry<String, List<Integer>>> entries = transform.entrySet();
......@@ -171,19 +165,17 @@ public class BLEFPBuilder {
final double rssi_std_dev = Math.sqrt(sum_of_dev/(count-1)); // Bessel correction for sample stdev
// populate insert value
_fp_elem cell_elem = new _fp_elem(entry.getKey(),count,rssi_min,rssi_max,rssi_avg,rssi_std_dev);
fp_per_cell.add(cell_elem);
FPElement cell_elem = new FPElement(floor_id,building_id,campus_id,ble_cell_id,rssi_dir,entry.getKey(),count,rssi_min,rssi_max,rssi_avg,rssi_std_dev);
fp_cell_per_ap.add(cell_elem);
}
for (_fp_elem print_elem : fp_per_cell) {
for (FPElement print_elem : fp_cell_per_ap) {
System.out.println(print_elem);
}
// calculate mag_angle - 해당 cell의 각 수집방향에 대하여 수집된 지자기방향의 평균값으로 대표
// insert rows to db.
insertFPCellPerAP(fp_cell_per_ap);
// Loop here ..*********************************************************************/
......
package com.skt.ehs.mbs.fpbuilder;
/**
* Created by user on 2016-11-30.
*/
public class CellMatrix {
private final int M; // number of rows
private final int N; // number of columns
private int[][] cell_ids;
// create M-by-N matrix of 0's
public CellMatrix(int M, int N) {
this.M = M;
this.N = N;
cell_ids = new int[M][N];
}
// create Matrix using parameterized Matrix
public CellMatrix(int[][] data) {
M = data.length;
N = data[0].length;
this.cell_ids = new int[M][N];
for(int i = 0; i<M; i++)
for(int j = 0; j < N; j++)
this.cell_ids[i][j] = data[i][j];
}
public int getElement (int x, int y) {
return this.cell_ids[x][y];
}
// print matrix
public void show() {
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();
}
}
}
......@@ -4,30 +4,30 @@ import java.util.Arrays;
/**
* Created by user on 2016-12-01.
* 층을 가상 Matrix 로 구성하고,
* Matrix의 각 element는 값으로 BLECell 타입의 Object를 가지게 된다
*/
class Floor {
private int M;
private int N;
private BLECell[][] cm; // cell matrix
private _ble_cell[][] cm; // cell matrix
// 수집방향
// Todo 수집방향
private final int[] rssi_dir = new int[]{1000000, 2000000, 3000000, 4000000, 5000000, 6000000, 7000000, 8000000};
// FingerPrint
public Floor(int M, int N) {
this.M = M;
this.N = N;
cm = new BLECell[M][N];
cm = new _ble_cell[M][N];
}
public int getCellID(int M, int N) {
return cm[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].getBle_cell_id());
System.out.printf("%9d ", cm[i][j].get_id());
}
System.out.println();
}
......@@ -36,7 +36,7 @@ class Floor {
public void showCellLocation() {
for(int j=0;j< N;j++) {
for(int i=0;i< M; i++) {
System.out.printf("("+cm[i][j].getLocation_x()+","+cm[i][j].getLocation_y()+")");
System.out.printf("("+cm[i][j].get_location_x()+","+cm[i][j].get_location_y()+")");
}
System.out.println();
}
......@@ -58,17 +58,17 @@ class Floor {
N = n;
}
public BLECell getBLECell(int M, int N) {
public _ble_cell getBLECell(int M, int N) {
return cm[M][N];
}
public void setBLECell(int M, int N, BLECell bleCell) {
public void setBLECell(int M, int N, _ble_cell bleCell) {
cm[M][N] = bleCell;
}
public void setBLECellLocation(int M, int N, int x, int y) {
cm[M][N].setLocation_x(x);
cm[M][N].setLocation_y(y);
cm[M][N].set_location_x(x);
cm[M][N].set_location_y(y);
}
double map_scale_pixel;
......
package com.skt.ehs.mbs.fpbuilder;
/**
* Created by user on 2016-11-30.
*/
public class _ble_cell {
private int _id;
private int _location_x;
private int _location_y; // 실거리 ??
_ble_cell(int id) {
_id = id;
}
public int get_id() {
return _id;
}
public void set_id(int ble_cell_id) {
this._id = ble_cell_id;
}
public int get_location_x() {
return _location_x;
}
public void set_location_x(int location_x) {
this._location_x = location_x;
}
public int get_location_y() {
return _location_y;
}
public void set_location_y(int location_y) {
this._location_y = location_y;
}
@Override
public String toString() {
return "_ble_cell{" +
"_id=" + _id +
", _location_x=" + _location_x +
", _location_y=" + _location_y +
'}';
}
}
......@@ -35,5 +35,19 @@
AND t.collected_time = a.collected_time
AND t.sequence_num = a.sequence_num
</select>
<!--
Todo : MySQL Bulk insert
<insert id="insertRawDataAP" parameterType="RawDataAP" >
INSERT INTO raw_data_ap (tag_id, collected_time, sequence_num, ap_id, rssi, floor_id, building_id, campus_id) values(#{tag_id},#{collected_time},#{sequence_num},#{ap_id},#{rssi},#{floor_id},#{building_id},#{campus_id})
</insert>
<insert id="insertEmployeeList" parameterType="java.util.List">
INSERT ALL
<foreach collection="list" item="element" index="index" >
INTO EMPLOYEE (id,name) values (#{element.id},#{element.name})
</foreach>
SELECT * FROM dual
</insert>
-->
</mapper>
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