380 lines
9.7 KiB
TypeScript
380 lines
9.7 KiB
TypeScript
//@ts-nocheck
|
||
// !! 不允许使用,只是拿来参考!!!!!
|
||
import * as turf from '@turf/turf';
|
||
import { getListTaskStatus, getCameraStatusFunc } from '../useTaskState';
|
||
import Tree from '@common/components/CameraTree/Tree';
|
||
import doRequest from '../../utils/request';
|
||
import { Dayjs as Moment } from 'dayjs';
|
||
import { message } from '@zhst/meta';
|
||
import { SearchCamera } from '@common/components/CameraTree/utils';
|
||
import { get, isEmpty } from '@zhst/func';
|
||
import type { OperationType } from '../../interface'
|
||
|
||
|
||
//默认取值
|
||
let defaultFaceThreshold = 0.68;
|
||
let defaultBodyThreshold = 0.7;
|
||
//下边栏人脸数量,默认为5
|
||
let defaultFaceResultNum = 5;
|
||
//追踪圈半径长度(m),默认为150
|
||
let defaultRadius = 0.15;
|
||
//查询周期(s)默认是10,,只负责保存做展示用
|
||
let defaultQueryCycle = 10;
|
||
|
||
//获取默认半径
|
||
export const getDefaultRadius = () => {
|
||
return defaultRadius;
|
||
};
|
||
//设置默认半径
|
||
export const setDefaultRadius = (radius: number) => {
|
||
defaultRadius = radius;
|
||
};
|
||
//检索间隔时长
|
||
let searchIntervalDuration = 10;
|
||
//设置检索时长
|
||
export const setSearchIntervalDuration = (duration: number) => {
|
||
searchIntervalDuration = duration;
|
||
};
|
||
//获取检索时长
|
||
export const getSearchIntervalDuration = (time: number) => {
|
||
return time;
|
||
};
|
||
|
||
//通过id停止或启动任务
|
||
export const operateTrackById = async (smartTrackId: number, operationType: OperationType) => {
|
||
try {
|
||
const data = {
|
||
operationType,
|
||
smartTrackId,
|
||
};
|
||
await doRequest({
|
||
method: 'PUT',
|
||
url: '/singer.SmartTrackService/OperationSmartTrack',
|
||
data,
|
||
});
|
||
message.success('操作成功');
|
||
} catch (err) {
|
||
console.error(err);
|
||
message.success('操作失败');
|
||
}
|
||
};
|
||
//通过id删除追踪任务
|
||
export const deleteTrackById = async (smartTrackId: number) => {
|
||
try {
|
||
await doRequest({
|
||
method: 'DELETE',
|
||
url: '/singer.SmartTrackService/DeleteSmartTrack',
|
||
data: {
|
||
smartTrackId,
|
||
},
|
||
});
|
||
} catch (err) {
|
||
console.error(err);
|
||
}
|
||
};
|
||
|
||
//编辑追踪任务图片
|
||
export const modifyTrackImgs = async (smartTrackId: number, images: Array<Object>) => {
|
||
try {
|
||
await doRequest({
|
||
method: 'PUT',
|
||
url: '/singer.SmartTrackService/ModifyTrackImg',
|
||
data: {
|
||
images,
|
||
smartTrackId,
|
||
},
|
||
});
|
||
} catch (err) {
|
||
console.log('err', err);
|
||
}
|
||
};
|
||
//编辑高级设置
|
||
export const modifyTrackConf = async (conf: any, smartTrackId: number) => {
|
||
try {
|
||
await doRequest({
|
||
method: 'PUT',
|
||
url: '/singer.SmartTrackService/ModifyTrackConf',
|
||
data: {
|
||
conf,
|
||
smartTrackId,
|
||
},
|
||
});
|
||
} catch (err) {
|
||
console.log('err', err);
|
||
}
|
||
};
|
||
//通过id获取追踪任务
|
||
export const getTrackTaskById = async (smartTrackId = 0) => {
|
||
try {
|
||
const data = smartTrackId
|
||
? {
|
||
smartTrackId,
|
||
}
|
||
: {};
|
||
let req = await doRequest({
|
||
method: 'POST',
|
||
url: '/singer.SmartTrackService/GetSmartTrack',
|
||
data,
|
||
});
|
||
return req;
|
||
} catch (err) {
|
||
console.error(err);
|
||
}
|
||
};
|
||
|
||
//获取追踪实况
|
||
export const getTackDetailInfo = async (smartTrackId = 0) => {
|
||
const data = smartTrackId
|
||
? {
|
||
smartTrackId,
|
||
}
|
||
: {};
|
||
let req = await doRequest({
|
||
method: 'POST',
|
||
url: '/singer.SmartTrackService/GetTrackOverView',
|
||
data,
|
||
});
|
||
return req;
|
||
};
|
||
|
||
//根据传入的算力,圆心,摄像头信息计算出最后需要的摄像头信息
|
||
export const getTaskCameraByCenterAndPower = async (value: {
|
||
taskPower: {
|
||
facePower: number;
|
||
bodyPower: number;
|
||
};
|
||
cameraInfos: Array<Object>;
|
||
center: [number, number];
|
||
}) => {
|
||
let realCameraInfos = value['cameraInfos'];
|
||
//先通过摄像头id拿预处理信息
|
||
let realPreprocessInfos = [];
|
||
if (!isEmpty(realCameraInfos)) {
|
||
const { taskStatus } = await getListTaskStatus();
|
||
realPreprocessInfos = getCameraStatusFunc(taskStatus);
|
||
}
|
||
//去除由实时开启的摄像头
|
||
//缓存下已经开启的
|
||
const runRealCameraInfos: Object[] = [];
|
||
realCameraInfos = realCameraInfos.filter((v) => {
|
||
if (Tree.judgeOccupyPowerById(v['id'], realPreprocessInfos)) {
|
||
runRealCameraInfos.push(v);
|
||
}
|
||
return !Tree.judgeOccupyPowerById(v['id'], realPreprocessInfos);
|
||
});
|
||
//算力不够时选择离中心点最近的
|
||
let from = turf.point(value['center']);
|
||
if (realCameraInfos.length > value['taskPower']['bodyPower']) {
|
||
realCameraInfos
|
||
.map((v) => {
|
||
let dis = turf.distance(from, turf.point([v['longitude'], v['latitude']]));
|
||
return {
|
||
...v,
|
||
dis,
|
||
};
|
||
})
|
||
.sort((a, b) => {
|
||
return a - b;
|
||
});
|
||
realCameraInfos = realCameraInfos.slice(0, value['taskPower']['bodyPower']);
|
||
}
|
||
return [...runRealCameraInfos, ...realCameraInfos];
|
||
};
|
||
|
||
/**创建追踪任务 */
|
||
export const createIntelligentTrack = async (value: {
|
||
images: Array<Object>;
|
||
deviceIds: Array<string>;
|
||
circleCenter: [number, number];
|
||
model: number;
|
||
circleRadius: number;
|
||
facePower?: number;
|
||
bodyPower?: number;
|
||
historyTime?: [Moment, Moment];
|
||
topping?: boolean;
|
||
}) => {
|
||
const data = {
|
||
images: value['images'],
|
||
type: value['model'],
|
||
normalComputerPower: value['bodyPower'] || 0,
|
||
faceComputerPower: value['facePower'] || 0,
|
||
// deviceIds: ['129537'],
|
||
deviceIds: value['deviceIds'],
|
||
conf: {
|
||
faceThreshold: defaultFaceThreshold,
|
||
bodyThreshold: defaultBodyThreshold,
|
||
faceResultNum: defaultFaceResultNum,
|
||
radius: value['circleRadius'] * 1000,
|
||
queryCycle: defaultQueryCycle,
|
||
},
|
||
centerConf: {
|
||
centerX: value['circleCenter'][0],
|
||
centerY: value['circleCenter'][1],
|
||
},
|
||
};
|
||
const res = await doRequest({
|
||
method: 'PUT',
|
||
url: '/singer.SmartTrackService/CreateSmartTrack',
|
||
data,
|
||
});
|
||
return res;
|
||
};
|
||
|
||
//发送心跳包
|
||
export const emitHeartbeat = async (smartTrackId: number) => {
|
||
try {
|
||
await doRequest({
|
||
method: 'POST',
|
||
url: '/singer.SmartTrackService/SmartTrackHeartBeat',
|
||
data: {
|
||
smartTrackId: smartTrackId,
|
||
},
|
||
});
|
||
} catch (err) {
|
||
console.error(err);
|
||
}
|
||
};
|
||
|
||
//更改任务摄像头信息
|
||
export const ModifyTrackCameras = async (value: {
|
||
smartTrackId: number;
|
||
deviceIds: Array<number>;
|
||
centerPoint: [number, number];
|
||
}) => {
|
||
try {
|
||
await setIntelligentTrackCircleInfo(value['smartTrackId'], value['centerPoint']);
|
||
await doRequest({
|
||
url: '/singer.SmartTrackService/ModifyTrackCameras',
|
||
method: 'PUT',
|
||
data: {
|
||
smartTrackId: value['smartTrackId'],
|
||
deviceIds: value['deviceIds'],
|
||
},
|
||
});
|
||
} catch (err) {
|
||
message.error(err);
|
||
}
|
||
};
|
||
|
||
//保存智能追踪圆的信息
|
||
export const setIntelligentTrackCircleInfo = async (
|
||
smartTrackId: number,
|
||
circleCenter: [number, number]
|
||
) => {
|
||
try {
|
||
await doRequest({
|
||
url: '/singer.SmartTrackService/ModifyTrackScopeConf',
|
||
method: 'PUT',
|
||
data: {
|
||
smartTrackId: smartTrackId,
|
||
centerConf: {
|
||
centerX: get(circleCenter, '0'),
|
||
centerY: get(circleCenter, '1'),
|
||
},
|
||
},
|
||
});
|
||
} catch (err) {
|
||
message.error(err);
|
||
}
|
||
};
|
||
|
||
//智能追踪的获取摄像头
|
||
export const getTackCameraInfo = async (value: {
|
||
circleCenter: [Moment, Moment];
|
||
radius: number;
|
||
zoom: number;
|
||
}) => {
|
||
//通过圆心和半径拿取到摄像头
|
||
let circleCameraInfos = await getCameraInfoByCircle(
|
||
value['circleCenter'],
|
||
value['radius'],
|
||
value['zoom']
|
||
);
|
||
return circleCameraInfos;
|
||
};
|
||
|
||
//通过圆心和半径获取摄像头
|
||
export const getCameraInfoByCircle = async (circleCenter, radius, zoom = 16) => {
|
||
try {
|
||
let centerFeature = turf.circle(turf.point(circleCenter), radius, {
|
||
units: 'kilometers',
|
||
steps: 64,
|
||
});
|
||
let minx = 0;
|
||
let maxx = 0;
|
||
let miny = 0;
|
||
let maxy = 0;
|
||
for (let i = 0; i < 4; i++) {
|
||
let point = turf.destination(turf.point(circleCenter), radius, 90 * i, {
|
||
units: 'kilometers',
|
||
}).geometry.coordinates;
|
||
if (point[0] < minx || minx === 0) {
|
||
minx = point[0];
|
||
}
|
||
if (point[0] > maxx || maxx === 0) {
|
||
maxx = point[0];
|
||
}
|
||
if (point[1] < miny || miny === 0) {
|
||
miny = point[1];
|
||
}
|
||
if (point[1] > maxy || maxy === 0) {
|
||
maxy = point[1];
|
||
}
|
||
}
|
||
let { clusterPoint }: any = await doRequest({
|
||
url: '/singer.DeviceService/GetClusters',
|
||
method: 'POST',
|
||
data: {
|
||
northEast: { X: maxx, Y: maxy },
|
||
southWest: { X: minx, Y: miny },
|
||
zoom,
|
||
},
|
||
});
|
||
let cameraIds = [];
|
||
clusterPoint.forEach((v) => {
|
||
cameraIds.push(...v['cameraIDs']);
|
||
});
|
||
const { cameras } = await SearchCamera({
|
||
cameraId: cameraIds,
|
||
maxResults: cameraIds.length,
|
||
});
|
||
const cameraInfos = cameras.filter((v) => {
|
||
let cameraPoint = turf.point([get(v, 'longitude'), get(v, 'latitude')]);
|
||
return turf.booleanPointInPolygon(cameraPoint, centerFeature);
|
||
});
|
||
return cameraInfos;
|
||
} catch (err) {
|
||
console.error(err);
|
||
return [];
|
||
}
|
||
};
|
||
|
||
//追踪任务转化为检索的格式
|
||
export const taskInfoToSearchItem = (taskInfo) => {
|
||
let imageList = [];
|
||
get(taskInfo, 'images', []).forEach((v) => {
|
||
const url = get(v, 'conds.0.srcImageUrl');
|
||
const objectId = get(v, 'conds.0.featureInfo.objectId');
|
||
let imageItem = {
|
||
index: 0,
|
||
url,
|
||
objectId,
|
||
odRects: get(v, 'conds').map((item) => {
|
||
return {
|
||
fileKey: get(item, 'objectImageUrl'),
|
||
extendRect: {
|
||
algorithmVersion: get(item, 'alg', ''),
|
||
...get(item, 'rect', {}),
|
||
},
|
||
rect: {
|
||
algorithmVersion: get(item, 'alg', ''),
|
||
rect: get(item, 'rect', {}),
|
||
},
|
||
};
|
||
}),
|
||
};
|
||
imageList.push(imageItem);
|
||
});
|
||
return imageList;
|
||
};
|