22 lines
724 B
TypeScript
22 lines
724 B
TypeScript
import createHttpError from "http-errors"
|
|
import { makePrivateAutoPrediction } from "../predictionServices"
|
|
import { IPredictionTable } from "../../types/db-model"
|
|
|
|
export async function buildAutoPrediction(
|
|
csv_string: string,
|
|
prediction_period: IPredictionTable['period_type']
|
|
) {
|
|
const result = await makePrivateAutoPrediction({
|
|
csv_string,
|
|
prediction_period,
|
|
value_column: 'amount',
|
|
})
|
|
|
|
if (!result) throw createHttpError(422, 'Prediksi gagal: model tidak mengembalikan hasil.')
|
|
|
|
if (result.mape > 50) {
|
|
throw createHttpError(422, `Prediksi tidak layak karena MAPE terlalu tinggi (${result.mape.toFixed(2)}%). Harap periksa data input.`)
|
|
}
|
|
|
|
return result
|
|
} |