77 lines
2.0 KiB
TypeScript
77 lines
2.0 KiB
TypeScript
import { api } from "@/lib/api";
|
|
import { config } from "@/config/config";
|
|
import type {
|
|
AdjustmentStatus,
|
|
SensorPlacementScheme,
|
|
SensorPoint,
|
|
} from "./types";
|
|
|
|
export interface OptimizeSchemeInput {
|
|
scheme_name: string;
|
|
sensor_type: "pressure";
|
|
method: "sensitivity" | "kmeans";
|
|
sensor_count: number;
|
|
min_diameter: number;
|
|
}
|
|
|
|
export const optimizeSensorPlacement = async (
|
|
input: OptimizeSchemeInput,
|
|
): Promise<SensorPlacementScheme> => {
|
|
const response = await api.post<SensorPlacementScheme>(
|
|
`${config.BACKEND_URL}/api/v1/sensor-placement-optimization-runs`,
|
|
input,
|
|
);
|
|
return response.data;
|
|
};
|
|
|
|
export const getSensorPlacementScheme = async (
|
|
schemeId: number,
|
|
): Promise<SensorPlacementScheme> => {
|
|
const response = await api.get<SensorPlacementScheme>(
|
|
`${config.BACKEND_URL}/api/v1/sensor-placement-schemes/${schemeId}`,
|
|
);
|
|
return response.data;
|
|
};
|
|
|
|
export const getSensorPlacementCandidate = async (
|
|
nodeId: string,
|
|
): Promise<SensorPoint> => {
|
|
const response = await api.get<SensorPoint>(
|
|
`${config.BACKEND_URL}/api/v1/sensor-placement-candidates/${encodeURIComponent(nodeId)}`,
|
|
);
|
|
return response.data;
|
|
};
|
|
|
|
export const overwriteSensorPlacementScheme = async (
|
|
schemeId: number,
|
|
expectedSensorLocation: string[],
|
|
sensorLocation: string[],
|
|
): Promise<SensorPlacementScheme> => {
|
|
const response = await api.put<SensorPlacementScheme>(
|
|
`${config.BACKEND_URL}/api/v1/sensor-placement-schemes/${schemeId}`,
|
|
{
|
|
expected_sensor_location: expectedSensorLocation,
|
|
sensor_location: sensorLocation,
|
|
},
|
|
);
|
|
return response.data;
|
|
};
|
|
|
|
export const exportSensorPlacementExcel = async (
|
|
schemeId: number,
|
|
sensorLocation: string[],
|
|
adjustmentStatus: Record<string, AdjustmentStatus>,
|
|
) => {
|
|
const response = await api.post<Blob>(
|
|
`${config.BACKEND_URL}/api/v1/sensor-placement-schemes/${schemeId}/exports/excel`,
|
|
{
|
|
sensor_location: sensorLocation,
|
|
adjustment_status: adjustmentStatus,
|
|
},
|
|
{
|
|
responseType: "blob",
|
|
},
|
|
);
|
|
return response.data;
|
|
};
|