Skip to content

Commit

Permalink
refactor: access to the updated tool API
Browse files Browse the repository at this point in the history
  • Loading branch information
martsimq committed Jul 6, 2024
1 parent 1a07c43 commit c37dd21
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 53 deletions.
4 changes: 2 additions & 2 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/

// 手动修改 Mock 接口
// export * from "./job.ts"
export * from "./mock.ts";
export * from "./job.ts";
// export * from "./mock.ts";
export * from "./qgis.ts";

// TODO: interface definition of api
8 changes: 6 additions & 2 deletions src/api/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
import { AxiosInstanceConfig, createAxiosInstance } from "@/api/axios.ts";

const BASE_URL = "http://121.196.198.27:32580/";
const BASE_URL = "http://47.237.25.20:32580/";

const axiosConfig: AxiosInstanceConfig = {
baseURL: BASE_URL,
Expand All @@ -19,7 +19,11 @@ const axiosInstance = createAxiosInstance(axiosConfig);
* @param data
*/
export function fetchJob(data: string) {
return axiosInstance.post("gis_agent_backend/simple/task_plan/", data);
return axiosInstance.post("gis_agent_backend/simple/task_plan/", data, {
headers: {
"Content-Type": "application/json",
},
});
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/api/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const fetchJob = (task: string) =>
resolve({
data: JSON.parse(
MOCK_JOB.replace(
/"task":"Extract water body from Landsat-8 images/,
/"task":"Extract elevation data of Sri Lanka from multiple TIF files using the shape of the island from a vector file/,
'"task":"' + task,
),
),
Expand Down
24 changes: 15 additions & 9 deletions src/components/Case.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
import { useSessionStore } from "../store/session.ts";
import { onMounted } from "vue";
const props = defineProps<{
name: string;
}>();
const sessionStore = useSessionStore();
function handleClick() {
sessionStore.session.question = "Calculation of Flood Affected Area";
sessionStore.session.question =
"Extract elevation data of Sri Lanka from multiple TIF files using the shape of the island from a vector file";
sessionStore.chatted();
}
Expand All @@ -18,11 +16,19 @@ onMounted(() => {
</script>

<template>
<el-button @click="handleClick"
><div>
{{ props.name }}
</div></el-button
<el-button
class="case-button"
@click="handleClick"
v-if="sessionStore.questionShow"
>Elevation of Sri Lanka</el-button
>
<div></div>
</template>

<style scoped lang="less"></style>
<style scoped lang="less">
.case-button {
position: absolute;
bottom: 20px;
left: 20px;
}
</style>
2 changes: 1 addition & 1 deletion src/constant/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ export const TOOL_EXAMPLE = {
},
],
};
export const MOCK_JOB = `{"task":"Extract water body from Landsat-8 images","subtasks":[{"task":"Import Landsat-8 imagery into QGIS","toolId":"gdal:translate","subtasks":[],"toolName":"gdal:translate"},{"task":"Assign projection to the imported raster if it does not already have one","toolId":"gdal:assignprojection","subtasks":[],"toolName":"gdal:assignprojection"},{"task":"Select an appropriate spectral band combination for water body extraction","toolId":"gdal:rearrange_bands","subtasks":[],"toolName":"gdal:rearrange_bands"},{"task":"Apply threshold to identify water bodies","toolId":"gdal:rastercalculator","subtasks":[],"toolName":"gdal:rastercalculator"},{"task":"Convert the raster of threshold values to vector format for precise delineation","toolId":"gdal:polygonize","subtasks":[],"toolName":"gdal:polygonize"},{"task":"Refine the resultant vector layer by removing small erroneous polygons","toolId":"native:deleteholes","subtasks":[],"toolName":"native:deleteholes"}],"toolId":"","toolName":""}`;
export const MOCK_JOB = `{"code":70200,"message":"Success!","data":{"task":"Extract elevation data of Sri Lanka from multiple TIF files using the shape of the island from a vector file","subtasks":[{"task":"Merge multiple TIF files into a single raster dataset","toolId":"gdal:merge","subtasks":[],"toolName":"gdal:merge"},{"task":"Clip the merged raster dataset using the shape of the island from the vector file to extract the relevant elevation data","toolId":"gdal:cliprasterbymasklayer","subtasks":[],"toolName":"gdal:cliprasterbymasklayer"}],"toolId":"","toolName":""}}`;
export const MOCK_TOOL = `{"id":"qgis:randompointsinsidepolygons","name":"qgis:randompointsinsidepolygons","description":"Generates basic statistics for a field of the attribute table of a vector layer.","args":[{"name":"INPUT","type":"[vector: any]","description":"Vector layer to calculate the statistics on.","required":true},{"name":"POINTS_NUMBER","type":"[html]","description":"Specification of the file for the calculated statistics. One of: Skip Output,Save to a Temporary File,Save to File.","required":false},{"name":"MIN_DISTANCE","type":"[html]","description":"Specification of the file for the calculated statistics. One of: Skip Output,Save to a Temporary File,Save to File.","required":false},{"name":"OUTPUT","description":"xxxxxxx"}]}`;
5 changes: 0 additions & 5 deletions src/pages/Home/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@
padding: 0;
}
}
.case-button {
position: absolute;
bottom: 20px;
left: 20px;
}
.question-button{
position: absolute;
bottom: 20px;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Home/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Case from "@/components/Case.vue";
<el-container>
<el-aside width="30%">
<LeftBox />
<Case class="case-button" name="Calculation of Flood Affected Area" />
<Case />
</el-aside>
<el-main>
<RightBox />
Expand Down
6 changes: 3 additions & 3 deletions src/store/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ export const useJobStore = defineStore("job", () => {
let _job: Task;

async function updateData(question: string) {
const res = (await fetchJob(question)).data;
// localData = (await axios.fetchJob(`{"question":"${question}"}`)).data;
// const res = (await fetchJob(question)).data;
const res = (await fetchJob(`{ "task": "${question}" }`)).data;
console.debug("res", res);
_job = convertData(res);
_job = convertData(res.data);

function convertData(data: any) {
const children = data.subtasks;
Expand Down
2 changes: 1 addition & 1 deletion src/store/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const useTaskStore = defineStore("node", () => {
_task.value = task;
// TODO Fetch the tool
// const res = await fetchTool(node.tool.id).data;
_task.value.tool = (await fetchTool(_task.value.tool.id)).data;
_task.value.tool = (await fetchTool(_task.value.tool.id)).data.data;
console.log(_task.value);
}

Expand Down
57 changes: 29 additions & 28 deletions src/utils/graphUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
* @Author: Chris
* @Date: 2024/6/7
*/
import G6, {TreeGraphData} from "@antv/g6";
import {EdgeConfig, GraphData, NodeConfig} from "@antv/g6-core/lib/types";
import {Task} from "@/type.ts";
import G6, { TreeGraphData } from "@antv/g6";
import { EdgeConfig, GraphData, NodeConfig } from "@antv/g6-core/lib/types";
import { Task } from "@/type.ts";

export function job2G6TreeGraph(job: Task) {

function buildTreeNode(task: Task) {
const {children} = task;
const { children } = task;
const treeNode: TreeGraphData = {
id: generateId(),
label: task.name,
Expand All @@ -35,7 +34,7 @@ export function jobLeafNode2G6Graph(job: Task) {
};

function buildNode(task: Task) {
const {children} = task;
const { children } = task;
const node: NodeConfig = {
id: generateId(),
label: task.name,
Expand Down Expand Up @@ -101,32 +100,34 @@ export function textWrapping(
let res = "";
const pattern = new RegExp("[\u4E00-\u9FA5]+"); // Chinese characters

str.split("").forEach((letter, i) => {
if (pattern.test(letter)) {
// Chinese character
newLineWidth += fontSize;
} else {
// non-Chinese character
newLineWidth += G6.Util.getLetterWidth(letter, fontSize);
// mark the space between characters (could break line here)
if (letter == " ") {
newSpaceIndex = i;
newSpaceIndexLineWidth = newLineWidth;
if (str) {
str.split("").forEach((letter, i) => {
if (pattern.test(letter)) {
// Chinese character
newLineWidth += fontSize;
} else {
// non-Chinese character
newLineWidth += G6.Util.getLetterWidth(letter, fontSize);
// mark the space between characters (could break line here)
if (letter == " ") {
newSpaceIndex = i;
newSpaceIndexLineWidth = newLineWidth;
}
}
}

if (newLineWidth >= maxWidth) {
if (newSpaceIndex > newLineStartIndex) {
res += str.slice(newLineStartIndex, newSpaceIndex) + "\n";
newLineWidth -= newSpaceIndexLineWidth;
newLineStartIndex = newSpaceIndex + 1;
if (newLineWidth >= maxWidth) {
if (newSpaceIndex > newLineStartIndex) {
res += str.slice(newLineStartIndex, newSpaceIndex) + "\n";
newLineWidth -= newSpaceIndexLineWidth;
newLineStartIndex = newSpaceIndex + 1;
}
}
}

if (i == str.length - 1) {
res += str.slice(newLineStartIndex);
}
});
if (i == str.length - 1) {
res += str.slice(newLineStartIndex);
}
});
}
return res;
}
// calculation of flo|od affected area

0 comments on commit c37dd21

Please sign in to comment.