bx-865-apps #1
|
@ -8516,7 +8516,7 @@
|
||||||
"kind": 6,
|
"kind": 6,
|
||||||
"importPath": "back.api.views",
|
"importPath": "back.api.views",
|
||||||
"description": "back.api.views",
|
"description": "back.api.views",
|
||||||
"peekOfCode": "class FloorplanPointsView(APIView):\n def get(self, request, id):\n points = FloorplanPoints.objects.get(plan=id)\n serializer = FloorplanPointsSerializer(points, many=False)\n return JsonResponse(serializer.data, safe=False)\n def post(self, request, id):\n data = JSONParser().parse(request)\n data[\"plan\"] = id\n serializer = FloorplanPointsSerializer(data=data)\n if serializer.is_valid():",
|
"peekOfCode": "class FloorplanPointsView(APIView):\n def get(self, request, id):\n if FloorplanPoints.objects.filter(plan=id).exists():\n points = FloorplanPoints.objects.get(plan=id)\n serializer = FloorplanPointsSerializer(points, many=False)\n return JsonResponse(serializer.data, safe=False)\n else:\n return JsonResponse(\"No item\", status=400)\n def post(self, request, id):\n data = JSONParser().parse(request)",
|
||||||
"detail": "back.api.views",
|
"detail": "back.api.views",
|
||||||
"documentation": {}
|
"documentation": {}
|
||||||
},
|
},
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
import { chunks } from '~/helpers';
|
import { chunks } from '~/helpers';
|
||||||
import * as d3 from "d3";
|
import * as d3 from "d3";
|
||||||
|
|
||||||
|
const nextFrame = () => new Promise(resolve => requestAnimationFrame(resolve));
|
||||||
|
|
||||||
const point_array = useState<number[][] | undefined>('point_array', () => undefined)
|
const point_array = useState<number[][] | undefined>('point_array', () => undefined)
|
||||||
const chunk_size = useState<number>('chunk_size', () => 8)
|
const chunk_size = useState<number>('chunk_size', () => 8)
|
||||||
const threshold = useState<number>('threshold', () => 20)
|
const threshold = useState<number>('threshold', () => 20)
|
||||||
|
@ -17,7 +19,13 @@ const setActivePoint = (item: { x: number, y: number }) => {
|
||||||
active_point.value = { x: item.x, y: item.y }
|
active_point.value = { x: item.x, y: item.y }
|
||||||
}
|
}
|
||||||
|
|
||||||
const sampling_data = () => {
|
const redraw = ref(false)
|
||||||
|
|
||||||
|
const sampling_data = async () => {
|
||||||
|
if (redraw.value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
redraw.value = true
|
||||||
grid_redraw.value = true
|
grid_redraw.value = true
|
||||||
const points = point_array.value
|
const points = point_array.value
|
||||||
const chunk = chunk_size.value
|
const chunk = chunk_size.value
|
||||||
|
@ -50,12 +58,14 @@ const sampling_data = () => {
|
||||||
})
|
})
|
||||||
paths_array.value = res
|
paths_array.value = res
|
||||||
|
|
||||||
console.time('redraw D3')
|
// console.time('redraw D3')
|
||||||
const svg = d3.select('#d3svg')
|
const svg = d3.select('#d3svg')
|
||||||
// svg.selectAll("path").remove();
|
svg.selectAll("path").remove();
|
||||||
const path_elements = svg.selectAll("path")
|
const path_elements = svg.selectAll("path")
|
||||||
|
|
||||||
paths_array.value.forEach(async (element, i) => {
|
for (let i = 0; i < paths_array.value.length; i++) {
|
||||||
|
const element = paths_array.value[i];
|
||||||
|
|
||||||
let _class = '';
|
let _class = '';
|
||||||
if (element.unwalkable) {
|
if (element.unwalkable) {
|
||||||
_class += ' unwalkable'
|
_class += ' unwalkable'
|
||||||
|
@ -67,23 +77,23 @@ const sampling_data = () => {
|
||||||
}
|
}
|
||||||
const clickFunk = () => setActivePoint({ x: element.x, y: element.y })
|
const clickFunk = () => setActivePoint({ x: element.x, y: element.y })
|
||||||
if (path_elements.nodes()[i]) {
|
if (path_elements.nodes()[i]) {
|
||||||
// console.log(`update ${i}`)
|
|
||||||
d3.select(path_elements.nodes()[i])
|
d3.select(path_elements.nodes()[i])
|
||||||
// .transition()
|
|
||||||
// .duration(300)
|
|
||||||
.attr('d', element.path)
|
.attr('d', element.path)
|
||||||
.attr('class', _class)
|
.attr('class', _class)
|
||||||
.on('click', clickFunk)
|
.on('click', clickFunk)
|
||||||
} else {
|
} else {
|
||||||
// console.log(`add${i}`)
|
|
||||||
svg.append("path")
|
svg.append("path")
|
||||||
.attr('d', element.path)
|
.attr('d', element.path)
|
||||||
.attr('class', _class)
|
.attr('class', _class)
|
||||||
.on('click', clickFunk)
|
.on('click', clickFunk)
|
||||||
}
|
}
|
||||||
});
|
if (i % 10 == 0) {
|
||||||
console.timeEnd('redraw D3')
|
await nextFrame()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// console.timeEnd('redraw D3')
|
||||||
grid_redraw.value = false
|
grid_redraw.value = false
|
||||||
|
redraw.value = false
|
||||||
}
|
}
|
||||||
watch(point_array, () => {
|
watch(point_array, () => {
|
||||||
sampling_data()
|
sampling_data()
|
||||||
|
@ -98,7 +108,7 @@ watch(threshold, () => {
|
||||||
sampling_data()
|
sampling_data()
|
||||||
})
|
})
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
sampling_data()
|
// sampling_data()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
|
|
|
@ -26,17 +26,26 @@ const ch = 800
|
||||||
|
|
||||||
const title = ref()
|
const title = ref()
|
||||||
|
|
||||||
const dataToState = (data: any) => {
|
const dataToState = async (data: any) => {
|
||||||
point_array.value = data.np_field
|
point_array.value = data.np_field
|
||||||
title.value = data.title
|
title.value = data.title
|
||||||
if (data.d_size) chunk_size.value = data.d_size
|
if (data.d_size) chunk_size.value = data.d_size
|
||||||
if (data.d_border) threshold.value = data.d_border
|
if (data.d_border) threshold.value = data.d_border
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await fetch(`${config.public.apiBase}/api/floorplan/${data.id}/points`)
|
||||||
|
const points = await res.json()
|
||||||
|
target_points.value = points.points
|
||||||
|
target_array.value = points.points
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const onUpload = (event: FileUploadUploadEvent) => {
|
const onUpload = async (event: FileUploadUploadEvent) => {
|
||||||
try {
|
try {
|
||||||
const data = JSON.parse(event.xhr.response)
|
const data = JSON.parse(event.xhr.response)
|
||||||
dataToState(data.response)
|
await dataToState(data.response)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error)
|
console.log(error)
|
||||||
}
|
}
|
||||||
|
@ -46,7 +55,7 @@ const selectFileEvent = async () => {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${config.public.apiBase}/api/floorplan/${selectFile.value}`)
|
const res = await fetch(`${config.public.apiBase}/api/floorplan/${selectFile.value}`)
|
||||||
const data = await res.json()
|
const data = await res.json()
|
||||||
dataToState(data)
|
await dataToState(data)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error)
|
console.log(error)
|
||||||
}
|
}
|
||||||
|
@ -106,7 +115,7 @@ const addTargetType = (name: string) => {
|
||||||
target_type.value = name
|
target_type.value = name
|
||||||
}
|
}
|
||||||
|
|
||||||
const savePoints = async ()=>{
|
const savePoints = async () => {
|
||||||
const res = await fetch(`${config.public.apiBase}/api/floorplan/${selectFile.value}/points`, {
|
const res = await fetch(`${config.public.apiBase}/api/floorplan/${selectFile.value}/points`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -123,7 +132,9 @@ onMounted(async () => {
|
||||||
await loadFiles()
|
await loadFiles()
|
||||||
})
|
})
|
||||||
watch(grid_redraw, () => {
|
watch(grid_redraw, () => {
|
||||||
loading.value = grid_redraw.value
|
setTimeout(() => {
|
||||||
|
loading.value = grid_redraw.value
|
||||||
|
}, 100)
|
||||||
})
|
})
|
||||||
watch(active_point, () => {
|
watch(active_point, () => {
|
||||||
if (!active_point.value) return
|
if (!active_point.value) return
|
||||||
|
@ -177,7 +188,8 @@ watch(active_point, () => {
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
<label for="chunk">Значение дискретизации</label>
|
<label for="chunk">Значение дискретизации</label>
|
||||||
<InputNumber id="chunk" type="text" showButtons :min="8" :max="50" v-model="chunk_size" />
|
<InputNumber id="chunk_size" showButtons :min="0" :max="50" v-model="chunk_size"
|
||||||
|
:disabled="loading" />
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
<label for="threshold">Пороговое значение</label>
|
<label for="threshold">Пороговое значение</label>
|
||||||
|
|
|
@ -4,8 +4,12 @@ from rest_framework.views import APIView
|
||||||
from django.http import JsonResponse
|
from django.http import JsonResponse
|
||||||
|
|
||||||
from api.tracer import parse_image, read_image, numpy_zip_str_to_arr
|
from api.tracer import parse_image, read_image, numpy_zip_str_to_arr
|
||||||
from .serializers import (FloorplanListSerializer, FloorplanPointsSerializer, FloorplanSerializer,
|
from .serializers import (
|
||||||
ProductSerializer)
|
FloorplanListSerializer,
|
||||||
|
FloorplanPointsSerializer,
|
||||||
|
FloorplanSerializer,
|
||||||
|
ProductSerializer,
|
||||||
|
)
|
||||||
from .models import Floorplan, FloorplanPoints, Product
|
from .models import Floorplan, FloorplanPoints, Product
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
@ -99,11 +103,15 @@ class FloorplanView(APIView):
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
class FloorplanPointsView(APIView):
|
class FloorplanPointsView(APIView):
|
||||||
def get(self, request, id):
|
def get(self, request, id):
|
||||||
points = FloorplanPoints.objects.get(plan=id)
|
if FloorplanPoints.objects.filter(plan=id).exists():
|
||||||
serializer = FloorplanPointsSerializer(points, many=False)
|
points = FloorplanPoints.objects.get(plan=id)
|
||||||
return JsonResponse(serializer.data, safe=False)
|
serializer = FloorplanPointsSerializer(points, many=False)
|
||||||
|
return JsonResponse(serializer.data, safe=False)
|
||||||
|
else:
|
||||||
|
return JsonResponse("No item", status=400)
|
||||||
|
|
||||||
def post(self, request, id):
|
def post(self, request, id):
|
||||||
data = JSONParser().parse(request)
|
data = JSONParser().parse(request)
|
||||||
|
|
Loading…
Reference in New Issue