Skip to content

Commit

Permalink
chore: growth span average analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielzxccc committed May 1, 2024
1 parent f920b6c commit 527ecf7
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/modules/Reports/ReportsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,12 @@ export async function getGrowthHarvestStats(
.select([
'c.name as crop_name',
sql`ROUND(AVG(ccr.harvested_qty), 2)`.as('avg_harvest_qty'),
sql`ROUND(AVG(ccr.date_harvested - ccr.date_planted), 2)`.as(
'avg_growth_span'
),
sql`ROUND(AVG(EXTRACT(DAY FROM
CASE
WHEN batch IS NOT NULL THEN batch::timestamp - date_planted::timestamp
ELSE date_harvested::timestamp - date_planted::timestamp
END
)), 2)`.as('avg_growth_span'),
])
.leftJoin('community_farms_crops as cfc', 'c.id', 'cfc.crop_id')
.leftJoin('community_crop_reports as ccr', 'cfc.id', 'ccr.crop_id')
Expand Down

0 comments on commit 527ecf7

Please sign in to comment.