Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion uniro_frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"build": "vite build",
"lint": "eslint . && prettier --write .",
"preview": "vite preview"
},
Expand Down
40 changes: 40 additions & 0 deletions uniro_frontend/src/data/converter/Converter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import type { CustomNode } from "../types/node";
import type { Path } from "../types/path";

export const convertToCoreNode = (data: { id: string; lat: number; lng: number }): CustomNode => {
return {
id: data.id,
lat: data.lat,
lng: data.lng,
isCore: true,
};
};

export const convertToSubNode = (data: { id: string; lat: number; lng: number }): CustomNode => {
return {
id: data.id,
lat: data.lat,
lng: data.lng,
isCore: false,
};
};
Comment on lines +4 to +20
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Converter를 만들어서 타입을 명시하고 자동 변환 시켜주는 접근이 좋습니다!


export const convertToPath = (pathKey: string, nodesData: { id: string; lat: number; lng: number }[]): Path => {
const nodeList = nodesData.map((node) => convertToSubNode(node));
const startNode = convertToCoreNode(nodesData[0]);
const endNode = convertToCoreNode(nodesData[nodesData.length - 1]);

nodeList[0] = startNode;
nodeList[nodeList.length - 1] = endNode;

return {
id: pathKey,
startNode,
endNode,
nodeList,
};
};

export const convertToPaths = (pathData: { [key: string]: { id: string; lat: number; lng: number }[] }): Path[] => {
return Object.keys(pathData).map((pathKey) => convertToPath(pathKey, pathData[pathKey]));
};
17 changes: 17 additions & 0 deletions uniro_frontend/src/data/factory/edgeFactory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { HazardEdge } from "../types/edge";
import { CautionFactor, DangerFactor } from "../types/factor";
import { CustomNode } from "../types/node";

export const createHazardEdge = (
id: string,
startNode: CustomNode,
endNode: CustomNode,
cautionFactors?: CautionFactor[],
dangerFactors?: DangerFactor[],
): HazardEdge => ({
id,
startNode,
endNode,
cautionFactors,
dangerFactors,
});
11 changes: 11 additions & 0 deletions uniro_frontend/src/data/factory/navigationFactory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { HazardEdge } from "../types/edge";
import { NavigationRoute } from "../types/route";

export const createNavigationRoute = (edges: HazardEdge[]): NavigationRoute => {
return {
route: edges,
hasCaution: edges.some((edge) => edge.cautionFactors !== undefined),
totalDistance: 1.5,
totalCost: 10,
};
};
8 changes: 8 additions & 0 deletions uniro_frontend/src/data/factory/nodeFactory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { CustomNode } from "../types/node";

export const createNode = (id: string, lat: number, lng: number, isCore: boolean = false): CustomNode => ({
id,
lat,
lng,
isCore,
});
54 changes: 54 additions & 0 deletions uniro_frontend/src/data/mock/hanyangBuildings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Building } from "../types/node";

export const buildings: Building[] = [
{
id: "101",
lng: 127.044755,
lat: 37.555994,
isCore: true,
buildingName: "역사관",
buildingImageUrl: "https://upload.wikimedia.org/wikipedia/commons/6/69/Hanyang_University_008.JPG",
phoneNumber: "02-2220-0114",
address: "서울특별시 성동구 왕십리로 222",
},
{
id: "102",
lng: 127.0455,
lat: 37.5565,
isCore: true,
buildingName: "본관",
buildingImageUrl: "https://upload.wikimedia.org/wikipedia/commons/6/69/Hanyang_University_008.JPG",
phoneNumber: "02-2220-0114",
address: "서울특별시 성동구 왕십리로 222",
},
{
id: "108",
lng: 127.0458,
lat: 37.557,
isCore: false,
buildingName: "국제관",
buildingImageUrl: "https://upload.wikimedia.org/wikipedia/commons/6/69/Hanyang_University_008.JPG",
phoneNumber: "02-2220-0114",
address: "서울특별시 성동구 왕십리로 222",
},
{
id: "701",
lng: 127.0452,
lat: 37.5548,
isCore: false,
buildingName: "백남학술정보관",
buildingImageUrl: "https://upload.wikimedia.org/wikipedia/commons/6/69/Hanyang_University_008.JPG",
phoneNumber: "02-2220-1363",
address: "서울특별시 성동구 왕십리로 222",
},
{
id: "201",
lng: 127.046,
lat: 37.5562,
isCore: false,
buildingName: "제1공학관",
buildingImageUrl: "https://upload.wikimedia.org/wikipedia/commons/6/69/Hanyang_University_008.JPG",
phoneNumber: "02-2220-0114",
address: "서울특별시 성동구 왕십리로 222",
},
];
27 changes: 27 additions & 0 deletions uniro_frontend/src/data/mock/hanyangHazardEdge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { createHazardEdge } from "../factory/edgeFactory";
import { createNode } from "../factory/nodeFactory";
import { HazardEdge } from "../types/edge";
import { CustomNode } from "../types/node";

const nodes: CustomNode[] = [
createNode("4", 37.557669, 127.042007),
createNode("5", 37.557695, 127.042002),
createNode("9", 37.557956, 127.04228),
createNode("10", 37.557956, 127.042314),
createNode("14", 37.557659, 127.042548),
createNode("15", 37.557637, 127.04253),
createNode("20", 37.559317, 127.045131),
createNode("21", 37.559296, 127.045152),
createNode("30", 37.559275, 127.043711),
createNode("31", 37.559301, 127.043705),
];

const edges: HazardEdge[] = [
createHazardEdge("path0", nodes[0], nodes[1], ["도로에 균열이 있어요"], []),
createHazardEdge("path1", nodes[2], nodes[3], [], ["계단이 있어요"]),
createHazardEdge("path2", nodes[4], nodes[5], ["낮은 턱이 있어요"], []),
createHazardEdge("path3", nodes[6], nodes[7], [], ["경사가 높아요"]),
createHazardEdge("path4", nodes[8], nodes[9], ["낮은 비탈길이 있어요"], []),
];

export const mockHazardEdges = edges;
Loading