Optimize Data Improvement Page (#4356)

* feat: Add data improvement page to crops controller

This commit introduces a new data improvement page to the crops controller. The page displays tabbed lists of crops with missing data, allowing users to easily identify areas for data quality improvement.

The following data quality categories are included:
- Crops without photos
- Crops without descriptions
- Crops without a youtube video
- Crops without alternate names
- Crops without a scientific name with a wikidata id
- Crops without row spacing
- Crops without sun requirements
- Crops without height

All lists are sorted by planting count in descending order.

* refactor: Optimize data improvement page to load tab data on demand

This commit refactors the data improvement page to load data for each tab on demand, rather than loading all queries at once. This improves the performance of the page by only executing the query for the currently active tab.

The controller action now uses a `case` statement based on a `tab` URL parameter to execute the appropriate query. The view has been updated to pass this parameter when a tab is clicked.

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
This commit is contained in:
google-labs-jules[bot]
2025-12-01 19:41:28 +10:30
committed by GitHub
parent 30e7c5d01c
commit 323c7dc3ee
5 changed files with 51 additions and 0 deletions

View File

@@ -149,6 +149,32 @@ class CropsController < ApplicationController
respond_with @crop
end
def data_improvement
@active_tab = params[:tab] || 'photos'
@crops = case @active_tab
when 'photos'
Crop.approved.where(photo_associations_count: 0).order(plantings_count: :desc)
when 'descriptions'
Crop.approved.where(description: [nil, '']).order(plantings_count: :desc)
when 'youtube'
Crop.approved.where(en_youtube_url: [nil, '']).order(plantings_count: :desc)
when 'alternate_names'
Crop.approved.left_joins(:alternate_names).where(alternate_names: { id: nil }).order(plantings_count: :desc)
when 'wikidata'
crops_with_wikidata = Crop.joins(:scientific_names).where.not(scientific_names: { wikidata_id: nil }).distinct
Crop.approved.where.not(id: crops_with_wikidata).order(plantings_count: :desc)
when 'row_spacing'
Crop.approved.where(row_spacing: nil).order(plantings_count: :desc)
when 'sun_requirements'
Crop.approved.where(sun_requirements: [nil, '']).order(plantings_count: :desc)
when 'height'
Crop.approved.where(height: nil).order(plantings_count: :desc)
else
Crop.none
end
end
private
def notifier

View File

@@ -0,0 +1,10 @@
%table.table.table-striped
%thead
%tr
%th Name
%th Plantings
%tbody
- crops.each do |crop|
%tr
%td= link_to crop.name, crop
%td= crop.plantings_count

View File

@@ -0,0 +1,13 @@
%h1 Data Improvement
- tabs = { photos: "Photos", descriptions: "Descriptions", youtube: "YouTube videos", alternate_names: "Alternate names", wikidata: "Wikidata ID", row_spacing: "Row spacing", sun_requirements: "Sun requirements", height: "Height" }
%ul.nav.nav-tabs
- tabs.each do |key, value|
%li{class: ('active' if @active_tab == key.to_s)}
= link_to value, data_improvement_crops_path(tab: key)
.tab-content
.tab-pane.active
%h2= "Crops without #{tabs[@active_tab.to_sym]}"
= render 'crop_list', crops: @crops

View File

@@ -3,6 +3,7 @@
- content_for :buttonbar do
- if can? :wrangle, Crop
= link_to 'Wrangle Crops', wrangle_crops_path, class: 'btn btn-secondary'
= link_to 'Data Improvement', data_improvement_crops_path, class: 'btn btn-info'
- if can? :create, Crop
= link_to 'Add New Crop', new_crop_path, class: 'btn btn-primary'

View File

@@ -89,6 +89,7 @@ Rails.application.routes.draw do
get 'wrangle'
get 'hierarchy'
get 'search'
get 'data_improvement'
end
end