Skip to content

Commit

Permalink
precriptive analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielzxccc committed May 1, 2024
1 parent 2449686 commit cd4181f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/config/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ export const db = new Kysely<DB>({
}),
}),
// 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)
// }
// },
})
16 changes: 16 additions & 0 deletions src/modules/Analytics/AnalyticsInteractor.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import axios from 'axios'
import HttpError from '../../utils/HttpError'
import { getUserOrThrow } from '../../utils/findUser'
import * as Service from './AnalyticsService'
Expand Down Expand Up @@ -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),
Expand Down
6 changes: 6 additions & 0 deletions src/modules/Analytics/AnalyticsOpenApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
* HarvestRateResponse:
* type: object
* properties:
* difference:
* type: string
* prescriptionMessages:
* type: array
* items:
* type: string
* plant:
* type: string
* message:
Expand Down
1 change: 1 addition & 0 deletions src/modules/Analytics/AnalyticsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down

0 comments on commit cd4181f

Please sign in to comment.