Skip to content

Commit

Permalink
Add tasting notes to Coffee Bag
Browse files Browse the repository at this point in the history
  • Loading branch information
miharekar committed Dec 8, 2024
1 parent 641611f commit 79014f6
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ GEM
fugit (~> 1.11.0)
railties (>= 7.1)
thor (~> 1.3.1)
sorbet-runtime (0.5.11685)
sorbet-runtime (0.5.11690)
sqlite3 (2.4.0-aarch64-linux-gnu)
sqlite3 (2.4.0-arm64-darwin)
sqlite3 (2.4.0-x86_64-linux-gnu)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/coffee_bags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def load_roasters
end

def coffee_bag_params
cb_params = params.require(:coffee_bag).permit(:name, :url, :roaster_id, :roast_date, :roast_level, :country, :region, :farm, :farmer, :variety, :elevation, :processing, :harvest_time, :quality_score, :image)
cb_params = params.require(:coffee_bag).permit(:name, :url, :roaster_id, :roast_date, :roast_level, :country, :region, :farm, :farmer, :variety, :elevation, :processing, :harvest_time, :quality_score, :tasting_notes, :image)
roaster = Current.user.roasters.find_by(id: cb_params[:roaster_id])
cb_params[:roaster_id] = @roaster.id if roaster.blank?
cb_params
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default class extends Controller {

populateFields(data) {
const fields = [
'name', 'roast_level', 'country', 'region', 'farm', 'farmer', 'variety', 'elevation', 'processing', 'harvest_time', 'quality_score'
'name', 'roast_level', 'country', 'region', 'farm', 'farmer', 'variety', 'elevation', 'processing', 'harvest_time', 'quality_score', 'tasting_notes'
]

fields.forEach(field => {
Expand Down
8 changes: 6 additions & 2 deletions app/lib/templates/coffee_extraction_prompt.text.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Parse the content above and extract the following attributes about the coffee:
- processing
- harvest_time
- quality_score
- tasting_notes

Guidelines:
1. Extract the information as accurately as possible from the HTML content.
Expand All @@ -39,8 +40,11 @@ After extraction, format your output as a JSON object. Include all specified att
"elevation": "1900m",
"processing": "Washed",
"harvest_time": "October-December",
"quality_score": "88"
"quality_score": "88",
"tasting_notes": "Plum, strawberry, dark chocolate"
}
</example_output>

Ensure your JSON is properly formatted. Do not include any text or formatting outside of the JSON object in your final output.
Ensure your JSON is properly formatted.
Do not include any text or formatting outside of the JSON object in your final output.
If you can't find any information, return an empty JSON object.
2 changes: 1 addition & 1 deletion app/models/airtable/coffee_bags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class CoffeeBags < Base
TABLE_NAME = "Coffee Bags".freeze
TABLE_DESCRIPTION = "Coffee Bags from Visualizer".freeze
STANDARD_FIELDS = %w[
country elevation farm farmer harvest_time processing quality_score region roast_date roast_level variety
country elevation farm farmer harvest_time processing quality_score region roast_date roast_level variety tasting_notes
].index_by { |f| f.to_s.humanize }
FIELD_OPTIONS = {
"roast_date" => {type: "date", options: {dateFormat: {name: "local"}}}
Expand Down
5 changes: 3 additions & 2 deletions app/models/coffee_bag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class CoffeeBag < ApplicationRecord
include Airtablable
include Squishable

DISPLAY_ATTRIBUTES = %i[roast_level country region farm farmer variety elevation processing harvest_time quality_score].freeze
DISPLAY_ATTRIBUTES = %i[roast_level country region farm farmer variety elevation processing harvest_time quality_score tasting_notes].freeze

after_save_commit :update_shots, if: -> { saved_changes.keys.intersect?(%w[name roast_date roast_level roaster_id]) }

Expand All @@ -18,7 +18,7 @@ class CoffeeBag < ApplicationRecord
scope :filter_by_name, ->(name) { where("LOWER(coffee_bags.name) = ?", name.downcase.squish) }
scope :order_by_roast_date, -> { order("roast_date DESC NULLS LAST") }

squishes :country, :elevation, :farm, :farmer, :harvest_time, :name, :processing, :quality_score, :region, :roast_level, :url, :variety
squishes :country, :elevation, :farm, :farmer, :harvest_time, :name, :processing, :quality_score, :region, :roast_level, :url, :variety, :tasting_notes

validates :name, presence: true, uniqueness: {scope: %i[roaster_id roast_date], case_sensitive: false} # rubocop:disable Rails/UniqueValidationWithoutIndex

Expand Down Expand Up @@ -57,6 +57,7 @@ def update_shots
# region :string
# roast_date :date
# roast_level :string
# tasting_notes :string
# url :string
# variety :string
# created_at :datetime not null
Expand Down
3 changes: 2 additions & 1 deletion app/models/parsers/beanconqueror.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def set_coffee_bag_attributes(shot)
elevation: bean_information&.dig("elevation"),
processing: bean_information&.dig("processing"),
harvest_time: bean_information&.dig("harvest_time"),
quality_score: brewdata.dig("bean", "cupping_points")
quality_score: brewdata.dig("bean", "cupping_points"),
tasting_notes: brewdata.dig("bean", "aromatics")
}
shot.coffee_bag.update(attributes)
end
Expand Down
6 changes: 5 additions & 1 deletion app/views/coffee_bags/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@
<%= f.label :quality_score, class: "standard-label" %>
<%= f.text_field :quality_score, class: "mt-1 standard-input" %>
</div>
<div class="col-span-6 sm:col-span-4">
<div class="col-span-6">
<%= f.label :tasting_notes, class: "standard-label" %>
<%= f.text_field :tasting_notes, class: "mt-1 standard-input" %>
</div>
<div class="col-span-6">
<div data-controller="image-form">
<%= f.label :image, "Image", class: "standard-label" %>
<% if @coffee_bag.image.attached? && @coffee_bag.image.persisted? && @coffee_bag.image.variable? %>
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20241208084540_add_tasting_notes_to_coffee_bags.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddTastingNotesToCoffeeBags < ActiveRecord::Migration[8.0]
def change
add_column :coffee_bags, :tasting_notes, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[8.0].define(version: 2024_12_05_115746) do
ActiveRecord::Schema[8.0].define(version: 2024_12_08_084540) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_catalog.plpgsql"
enable_extension "pg_stat_statements"
Expand Down Expand Up @@ -86,6 +86,7 @@
t.datetime "updated_at", null: false
t.string "airtable_id"
t.string "url"
t.string "tasting_notes"
t.index ["airtable_id"], name: "index_coffee_bags_on_airtable_id"
t.index ["roaster_id"], name: "index_coffee_bags_on_roaster_id"
end
Expand Down
1 change: 1 addition & 0 deletions test/models/parsers/beanconqueror_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def new_shot(path, user: @user)
assert_equal "Processing 1", shot.coffee_bag.processing
assert_equal "Harvest 1", shot.coffee_bag.harvest_time
assert_equal "99", shot.coffee_bag.quality_score
assert_equal "Schokolade, Haselnuss, Rund", shot.coffee_bag.tasting_notes
end
test "extracts real beanconqueror file with id to an existing shot and overwrites the information" do
user = create(:user)
Expand Down

0 comments on commit 79014f6

Please sign in to comment.