diff --git a/src/config/database.ts b/src/config/database.ts index 48143b9..baf09c1 100644 --- a/src/config/database.ts +++ b/src/config/database.ts @@ -12,10 +12,10 @@ export const db = new Kysely({ }), }), // plugins: [new ParseJSONResultsPlugin()], - log(event) { - if (event.level === 'query') { - log.info(event.query.sql) - log.info(event.query.parameters) - } - }, + // log(event) { + // if (event.level === 'query') { + // log.info(event.query.sql) + // log.info(event.query.parameters) + // } + // }, }) diff --git a/src/modules/Analytics/AnalyticsInteractor.ts b/src/modules/Analytics/AnalyticsInteractor.ts index c1ccd96..ef9a9a9 100644 --- a/src/modules/Analytics/AnalyticsInteractor.ts +++ b/src/modules/Analytics/AnalyticsInteractor.ts @@ -1,3 +1,4 @@ +import axios from 'axios' import HttpError from '../../utils/HttpError' import { getUserOrThrow } from '../../utils/findUser' import * as Service from './AnalyticsService' @@ -63,7 +64,22 @@ export async function getLatestHarvestRate(farmid: string, userid: string) { descriptiveMessage = `You are ${difference}% in harvest rate compared to your previous harvest` } + const results = await axios.post( + `${process.env.PYTHON_API}/predict-prescription`, + [ + { + crop_yield: latestHarvestRate, + withered_crops: Number(latestReport.withered_crops), + }, + ] + ) + + const prescriptionMessages = results.data[0] + .predicted_prescription as string[] + return { + difference, + prescriptionMessages, plant: latestReport.name, message: descriptiveMessage, latestHarvestRate: latestHarvestRate.toFixed(2), diff --git a/src/modules/Analytics/AnalyticsOpenApi.ts b/src/modules/Analytics/AnalyticsOpenApi.ts index 8b2b334..d200638 100644 --- a/src/modules/Analytics/AnalyticsOpenApi.ts +++ b/src/modules/Analytics/AnalyticsOpenApi.ts @@ -52,6 +52,12 @@ * HarvestRateResponse: * type: object * properties: + * difference: + * type: string + * prescriptionMessages: + * type: array + * items: + * type: string * plant: * type: string * message: diff --git a/src/modules/Analytics/AnalyticsService.ts b/src/modules/Analytics/AnalyticsService.ts index 903c68d..8f41e7b 100644 --- a/src/modules/Analytics/AnalyticsService.ts +++ b/src/modules/Analytics/AnalyticsService.ts @@ -10,6 +10,7 @@ export async function getLatestReport(farmid: string) { 'ccr.planted_qty', 'c.name', 'ccr.crop_id', + 'ccr.withered_crops', eb .selectFrom('community_crop_reports as ccrp') .select(['planted_qty'])