diff --git a/carbonfootprint.csv b/carbonfootprint.csv new file mode 100644 index 0000000..1191185 --- /dev/null +++ b/carbonfootprint.csv @@ -0,0 +1,198 @@ +Food type,"kg CO2-eq/kg produce, BFM or L after conversion" +Butter,3.70 +Camembert Cheese,7.00 +Cheddar Cheese,8.70 +Cheese,5.33 +Goats Cheese,7.71 +Mozarrella,9.99 +Semi Hard Chees,8.79 +Semi-Hard,8.50 +Cream,7.92 +Almond Milk,0.39 +Bufalo Milk,2.87 +Coconut-Milk,0.39 +Cows Milk,0.54 +Goats Milk,1.41 +Soy-Milk,0.66 +Yogurt,1.17 +Apples,0.18 +Apples and Pears,0.63 +Apricots,0.43 +Artichokes,0.48 +Asparagus,0.38 +Avocados,0.43 +Bananas,0.42 +Beetroot,0.11 +Broccoli,0.37 +Cabbage,0.12 +Capsicums/Peppers,0.23 +Carrots,0.04 +Cauliflowers,0.28 +Celery,0.18 +Cherries,0.26 +Chillies,0.66 +"Citrus Fruit, Misc. ",0.33 +"Citrus Fruit, Misc. ",0.51 +Citrus Small,0.41 +Coconuts (Incl. Copra) ,1.78 +"Cranberries, Blueberries ",0.86 +Cucumbers,0.08 +Currants and Gooseberries,0.84 +Dates,0.32 +Eggplants (Aubergines) ,1.30 +Fennel,0.48 +Figs,0.43 +Garlic,0.57 +Gherkins,0.13 +Ginger,0.88 +Grapefruit and Pomelo,0.51 +Grapes,0.15 +Guavas,0.28 +Kiwi Fruit,0.28 +Lemons and Limes,0.18 +Lettuce,0.13 +Manderin,0.45 +Melons,0.30 +Mushrooms,0.06 +Olives,0.22 +Onion,0.06 +Oranges,0.18 +Peach,0.81 +Pears,0.19 +Peppers/Capsicums,0.23 +Peppers/Capsicums (G),0.90 +Melons (G),1.43 +Pineapples,0.40 +Plums and Sloes,0.32 +Potatoes,0.08 +Pumpkins,0.15 +Quinces and Pears,0.30 +Raspberries and Other Berries,0.84 +Rockmelon / Cantelope,0.25 +Spinach,0.18 +Starchy Root,0.20 +Strawberries,0.20 +Swedes (Rutabage),0.29 +"Tangerines, Mandarins Etc.",0.51 +Tomatoes,0.15 +Watermelon,0.38 +Zucchini/Button Squash,0.09 +Alfonsino,3.49 +Anglerfish,10.43 +Bass,3.60 +Beef,10.74 +Bigeye Tuna,11.44 +Buffalo,48.92 +Carp,1.73 +Catfish,"8,93" +Cephalopodsm Varied (Squid),11.61 +Chicken,1.06 +Cod,1.58 +Cod (Fish Stick),2.14 +Cuttlefish,6.39 +Diamond Fish,6.02 +Duck,2.07 +Eggs,1.30 +Emu,1.50 +Fish,2.13 +Fish (Mixed),1.04 +Flatfish,1.20 +Flatfish Varied,11.61 +Fork Beard,6.25 +Haddock,2.80 +Hake,6.88 +Hake (Fish Stick),2.14 +Hake European,9.77 +Hake Fillet,7.25 +Hake Senegal,11.61 +Herring,0.98 +Kangaroo,4.10 +Lamb,10.05 +Ling,3.13 +Ling Common,9.77 +Lobster,27.80 +Lobster,"7,62" +Mackeral,0.94 +Mackeral (Fish Stick,1.02 +Mackerel Atlantic,1.41 +Mackerel Atlantic,3.79 +Mackerel Horse,1.41 +Megrim,14.15 +Mussels,1.92 +Octopus,7.35 +Pilchard,0.78 +Pilchard,1.41 +Pollock,1.20 +Pollock,1.60 +Pollock (Fish Stick),2.14 +Pomfret,3.49 +Pomfret Atlantic,9.77 +Porbeagle,11.44 +Pork,2.11 +Prawns/Shrimp,5.25 +Rabbit,3.82 +Rhombus,8.41 +Rock Fish,6.94 +Salmon,2.04 +Sea Bass,1.91 +Shark,11.56 +Shark Mako,11.44 +Sole,20.86 +Squid,6.91 +Swordfish,11.44 +Trout,1.37 +Tuna,1.39 +Turbot,9.63 +Turkey,3.34 +Veal,21.50 +Veal Meat, +Whiting,1.54 +Whiting Blue,3.79 +Almonds,0.51 +Barley,0.11 +Beans,0.25 +Beans - Gigante/Butter,0.26 +Beans - Green,1.45 +Beans - Green Beans,0.43 +Beans - Green Beans (Phaseolus Vulgaris L.),0.24 +Beans - Pinto Usa Dried,0.73 +Beans - Plake,0.22 +Beans – French and Runner,0.52 +Cahsew Nuts,1.06 +Cereals Misc. ,0.37 +Chestnuts,0.43 +Chick Peas,0.45 +Cowpeas,0.33 +Graham Flour,0.47 +Ground Nuts,0.65 +Hazlenuts,0.43 +Lentils,1.00 +Maize,0.40 +Maize Sweet Corn,1.38 +Millet,0.47 +Nuts Misc. ,0.47 +Oat,0.67 +Oat Berry,0.88 +Oatmeal,0.74 +Oats,0.38 +Palm Nuts-Kernels (Nut Equiv.)/Oil,0.80 +Peanuts,0.80 +Peas,0.48 +Peas - Dry,0.15 +Peas - Dry,0.51 +Peas - Green,0.29 +Peas - Green – Shelled,2.46 +Peas - Yellow Dried,0.20 +Peas - Yellow Dried,0.21 +Pistachios,0.88 +Quinoa,1.10 +Rape Seed,0.29 +Rapeseed and Mustard Seed,2.09 +Rice,0.66 +Rye,0.36 +Sesame Seed,0.88 +Sorghum,0.88 +Soybean,0.38 +Sunflower Seed,1.41 +Walnuts,0.50 +Wheat,0.18 diff --git a/project.rb b/project.rb new file mode 100644 index 0000000..5c39d3d --- /dev/null +++ b/project.rb @@ -0,0 +1,640 @@ +require 'HTTParty' +require 'Nokogiri' +require "csv" +require 'gruff' +require 'catpix' + +class Recipe + def initialize(url) + @url = url + end + + def get_recipe_name + page = HTTParty.get(@url) + parse_page = Nokogiri::HTML(page) + title = parse_page.css("h1") + title_of_recipe = title.text + end + + def get_recipe_ingredient_list + + page = HTTParty.get(@url) + parse_page = Nokogiri::HTML(page) + @scraped_ingredient = [] + ingredient_list = [] + + parse_page.css(".ingredient-description").each do |a| + ing = a.text.downcase + @scraped_ingredient << ing + end + @scraped_ingredient + end + + def get_amounts_per_ingredient + @quantity = [] + + @scraped_ingredient.each do |intsearch| + a = intsearch.slice(0, 4).gsub(/[^0-9]/, '') + if intsearch.include?("teaspoon") + a = a.to_i * 5 + @quantity << a + elsif intsearch.include?("tablespoon") + a = a.to_i * 15 + @quantity << a + elsif intsearch.include?("g") + a = a.to_i + @quantity << a + elsif intsearch.include?("ml") + a = a.to_i + @quantity << a + else + a = a.to_i * 50 + @quantity << a + end + + end + @quantity + end + + + +end + +class EnvironmentImpact + + def initialize(ingredient_list) + @ingredient_list = ingredient_list + @totallist = [] + @totalcarbon = [] + end + + def get_amounts_per_ingredient + @quantity = [] + + @scraped_ingredient.each do |intsearch| + a = intsearch.slice(0, 4).gsub(/[^0-9]/, '') + if intsearch.include?("teaspoon") + a = a.to_i * 5 + @quantity << a + elsif intsearch.include?("tablespoon") + a = a.to_i * 15 + @quantity << a + elsif intsearch.include?("g") + a = a.to_i + @quantity << a + elsif intsearch.include?("ml") + a = a.to_i + @quantity << a + else + a = a.to_i * 50 + @quantity << a + end + + end + @quantity + end + + def carbon_intensity + carbonarray = [] + + CSV.foreach("carbonfootprint.csv") do |row| + carbonarray << row + end + + namelist = [] + carbonarray.each do |csv_ingredient| + @ingredient_list.each do |recipe_item| + # csv_ingredient[0] returns name + # puts csv_ingredient[0].to_s + # check if provided recipe line includes a csv ingredient name + if recipe_item.downcase.include?(csv_ingredient[0].downcase) + a = recipe_item.slice(0, 5).gsub(/[^0-9]/, '') + if recipe_item.include?("teaspoon") + a = a.to_i * 5 + elsif recipe_item.include?("tablespoon") + a = a.to_i * 15 + elsif recipe_item.slice(0,7).include?("g ") + a = a.to_i + elsif recipe_item.include?("ml") + a = a.to_i + else + a = a.to_i * 50 + end + a.to_i + #puts "#{a}g of #{csv_ingredient[0]} adds #{csv_ingredient[1].to_f * a} CO2" + b = csv_ingredient[1].to_f * a + @totalcarbon << b.to_f + else + #puts "false" + end + end + end + @totalcarbon + end + + def carbon_intensity_per_gram + carbonarray = [] + + CSV.foreach("carbonfootprint.csv") do |row| + carbonarray << row + end + + namelist = [] + carbonarray.each do |csv_ingredient| + @ingredient_list.each do |recipe_item| + # csv_ingredient[0] returns name + # puts csv_ingredient[0].to_s + # check if provided recipe line includes a csv ingredient name + if recipe_item.downcase.include?(csv_ingredient[0].downcase) + puts "Each gram of #{csv_ingredient[0]} adds #{csv_ingredient[1]} CO2" + @totallist << csv_ingredient[1].to_f + namelist << csv_ingredient[0] + else + #puts "false" + end + end + end + puts @totallist + end + + def recipeimpact + sum = 0 + @totalcarbon.each { |a| sum+=a } + sum.round(3) + #puts "This recipe puts out #{sum}g of CO2" + end + + def top5impact + sum = 0 + @totallist.sort.reverse.take(5).each { |a| sum+=a } + sum.round(3) + end + + def image + carbon = a.recipeimpact + case carbon + when 0 + puts "no carbon" + when 1..2000 + puts "carbon low" + puts " + + `*******' + .---. + ( --- ) + ( /m m\ ) + ___( = )___ + .'----`\ /'----`. + //' .-'': ;``-. `\\ + // / Y \ \\ + // / (|) \ \\ + // : .-' | `-. ; \\ + // `.__.-'^`-.__.' \\ + ^. .^.^/ \^.^. .^ + ^ / CARBON LOW \ ^ + / \ + _.' `._ + '._ _.' + `--..___ ___..--' + ``` + + + " + when 2000..4000 + puts "carbon moderately low" + puts " + __ / \ __ + ( `'.\ /.'` ) + '-._.(;;;)._.-' + .-' ,``, '-. CARBON MODERATELY LOW + (__.-'/ \'-.__)/)_ + \ /\ / / ) + '-' | \/.-') + , | .'/\'..) + |\ |/ | \_) + \ | | \_/ + | \ / + \|/ _, + / __/ / + | _/ _.' + |/__/ + \ + " + when 4000..6000 + puts "carbon medium" + puts " + + + \ ( / + `. \ ) / .' + `. \ ( / .' + `. .-''''-. .' + CARBON MEDIUM! `~._ .'/_ _\`. _.~' + `~ / / \ / \ \ ~' + _ _ _ _| _\O/ \O/_ |_ _ _ _ + | (_) /\ (_) | + _.~ \ \ / / ~._ + .~' `. `.__.' .' `~. + .' `-,,,,-' `. + .' / ) \ `. + .' / ( \ `. + / ) \ + + " + + when 6000..8000 + puts "carbon moderately high" + puts " + ____________________ + / \ + !CARBON MODERATELY HIGH! + ! ! + \____________________/ + ! ! + ! ! + L_ ! + / _)! + / /__L + _____/ (____) + (____) + _____ (____) + \_(____) + ! ! + ! ! + \__/ + "" + "" + " + when 8000..10000 + puts "carbon high" + puts " + _,.-------.,_ + ,;~' '~;, + ,; ;, + ; CARBON HIGH!!! ; + ,' ', + ,; ;, + ; ; . . ; ; + | ; ______ ______ ; | + | `/~o ~o . o~ o~\' | + | ~ ,-~~~^~, | ,~^~~~-, ~ | + | | }:{ | | + | l / | \ ! | + .~ (__,.--/ .^. \--.,__) ~. + | ---;' / | \ `;--- | + \__. \/^\/ .__/ + V| \ / |V + | |T~\___!___!___/~T| | + | |`IIII_I_I_I_IIII'| | + | \,III I I I III,/ | + \ `~~~~~~~~~~' / + \ . . / + \. ^ ./ + ^~~~^~~~^ + " + else + puts "error." + end + end + +end + +class Graph + def initialize(carbonnumber, x, y, z) + carbonnumber = @carbonnumber + x = @x + y = @y + z = @z + arg = 0 + end + + attr_accessor :carbonnumber, :x, :y, :z + + def image(arg) + @carbonnumber = arg + case @carbonnumber + when 0 + puts "no carbon" + when 1..2000 + puts "carbon low" + puts " + + `*******' + .---. + ( --- ) + ( /m m\ ) + ___( = )___ + .'----`\ /'----`. + //' .-'': ;``-. `\\ + // / Y \ \\ + // / (|) \ \\ + // : .-' | `-. ; \\ + // `.__.-'^`-.__.' \\ + ^. .^.^/ \^.^. .^ + ^ / CARBON LOW \ ^ + / \ + _.' `._ + '._ _.' + `--..___ ___..--' + ``` + + + " + when 2000..4000 + puts "carbon moderately low" + puts " + __ / \ __ + ( `'.\ /.'` ) + '-._.(;;;)._.-' + .-' ,``, '-. CARBON MODERATELY LOW + (__.-'/ \'-.__)/)_ + \ /\ / / ) + '-' | \/.-') + , | .'/\'..) + |\ |/ | \_) + \ | | \_/ + | \ / + \|/ _, + / __/ / + | _/ _.' + |/__/ + \ + " + when 4000..6000 + puts "carbon medium" + puts " + + + \ ( / + `. \ ) / .' + `. \ ( / .' + `. .-''''-. .' + CARBON MEDIUM! `~._ .'/_ _\`. _.~' + `~ / / \ / \ \ ~' + _ _ _ _| _\O/ \O/_ |_ _ _ _ + | (_) /\ (_) | + _.~ \ \ / / ~._ + .~' `. `.__.' .' `~. + .' `-,,,,-' `. + .' / ) \ `. + .' / ( \ `. + / ) \ + + " + + when 6000..8000 + puts "carbon moderately high" + puts " + ____________________ + / \ + !CARBON MODERATELY HIGH! + ! ! + \____________________/ + ! ! + ! ! + L_ ! + / _)! + / /__L + _____/ (____) + (____) + _____ (____) + \_(____) + ! ! + ! ! + \__/ + "" + "" + " + when 8000..100000 + puts "carbon high" + puts " + _,.-------.,_ + ,;~' '~;, + ,; ;, + ; CARBON HIGH!!! ; + ,' ', + ,; ;, + ; ; . . ; ; + | ; ______ ______ ; | + | `/~o ~o . o~ o~\' | + | ~ ,-~~~^~, | ,~^~~~-, ~ | + | | }:{ | | + | l / | \ ! | + .~ (__,.--/ .^. \--.,__) ~. + | ---;' / | \ `;--- | + \__. \/^\/ .__/ + V| \ / |V + | |T~\___!___!___/~T| | + | |`IIII_I_I_I_IIII'| | + | \,III I I I III,/ | + \ `~~~~~~~~~~' / + \ . . / + \. ^ ./ + ^~~~^~~~^ + " + else + puts "error." + end + end + +def bargraph(x, y, z) + @datasets = [:Recipe1, 2], [:Recipe2, 2], [:Recipe3, 2] + puts @datasets[0] + g = Gruff::Bar.new + g.title = 'Visual Multi-Line Bar Graph Test' + @datasets.each do |data| + g.data(data[0], data[1]) + end + + g.write('bar_keynote_small.png') +end + +end + +puts "Which recipes would you like to compare for their carbon footprint? (please put in URL from taste.com.au)" + +puts "Recipe 1:" +recipe1 = Recipe.new(gets.chomp) +puts "Recipe 2:" +recipe2 = Recipe.new(gets.chomp) +puts "Recipe 3:" +recipe3 = Recipe.new(gets.chomp) + +# puts out titles +# puts "You have selected:" +# puts recipe1.get_recipe_name +# puts recipe2.get_recipe_name +# puts recipe3.get_recipe_name + + +#puts recipe1.get_recipe_ingredient_list + +#carbon carbon_intensity_per_gram + + +a = EnvironmentImpact.new(recipe1.get_recipe_ingredient_list) +b = EnvironmentImpact.new(recipe2.get_recipe_ingredient_list) +c = EnvironmentImpact.new(recipe3.get_recipe_ingredient_list) + +# +# a.carbon_intensity_per_gram +# puts a.top5impact + +#puts recipe1.get_recipe_ingredient_list +#amounts = recipe1.get_amounts_per_ingredient + +# a.recipeimpact +# +# # puts recipe1.get_amounts_per_ingredient +a.carbon_intensity +b.carbon_intensity +c.carbon_intensity +# puts recipe1.get_amounts_per_ingredient.class +# puts a.recipeimpact +#amounts.zip(a.carbon_intensity_per_gram).map{|x, y| x * y} +# a.carbon_intensity_per_gram + +puts "#{recipe1.get_recipe_name} emits #{a.recipeimpact} g of CO2" +puts "#{recipe2.get_recipe_name} emits #{b.recipeimpact} g of CO2" +puts "#{recipe3.get_recipe_name} emits #{c.recipeimpact} g of CO2" + +# puts a.recipeimpact +puts "Select [1], [2] or [3]" +choice = gets.chomp + +graph1 = Graph.new(0, a.recipeimpact, b.recipeimpact, c.recipeimpact) +# graph1.bargraph(x, y, z) + +if choice == "1" + puts graph1.image(a.recipeimpact) +elsif choice == "2" + puts graph1.image(b.recipeimpact) +elsif choice == "3" + puts graph1.image(c.recipeimpact) +else + puts "Error" +end +# +# case carbon +# when 0 +# puts "no carbon" +# when 1..2000 +# puts "carbon low" +# puts " +# +# `*******' +# .---. +# ( --- ) +# ( /m m\ ) +# ___( = )___ +# .'----`\ /'----`. +# //' .-'': ;``-. `\\ +# // / Y \ \\ +# // / (|) \ \\ +# // : .-' | `-. ; \\ +# // `.__.-'^`-.__.' \\ +# ^. .^.^/ \^.^. .^ +# ^ / CARBON LOW \ ^ +# / \ +# _.' `._ +# '._ _.' +# `--..___ ___..--' +# ``` +# +# +# " +# when 2000..4000 +# puts "carbon moderately low" +# puts " +# __ / \ __ +# ( `'.\ /.'` ) +# '-._.(;;;)._.-' +# .-' ,``, '-. CARBON MODERATELY LOW +# (__.-'/ \'-.__)/)_ +# \ /\ / / ) +# '-' | \/.-') +# , | .'/\'..) +# |\ |/ | \_) +# \ | | \_/ +# | \ / +# \|/ _, +# / __/ / +# | _/ _.' +# |/__/ +# \ +# " +# when 4000..6000 +# puts "carbon medium" +# puts " +# +# +# \ ( / +# `. \ ) / .' +# `. \ ( / .' +# `. .-''''-. .' +# CARBON MEDIUM! `~._ .'/_ _\`. _.~' +# `~ / / \ / \ \ ~' +# _ _ _ _| _\O/ \O/_ |_ _ _ _ +# | (_) /\ (_) | +# _.~ \ \ / / ~._ +# .~' `. `.__.' .' `~. +# .' `-,,,,-' `. +# .' / ) \ `. +# .' / ( \ `. +# / ) \ +# +# " +# +# when 6000..8000 +# puts "carbon moderately high" +# puts " +# ____________________ +# / \ +# !CARBON MODERATELY HIGH! +# ! ! +# \____________________/ +# ! ! +# ! ! +# L_ ! +# / _)! +# / /__L +# _____/ (____) +# (____) +# _____ (____) +# \_(____) +# ! ! +# ! ! +# \__/ +# "" +# "" +# " +# when 8000..10000 +# puts "carbon high" +# puts " +# _,.-------.,_ +# ,;~' '~;, +# ,; ;, +# ; CARBON HIGH!!! ; +# ,' ', +# ,; ;, +# ; ; . . ; ; +# | ; ______ ______ ; | +# | `/~o ~o . o~ o~\' | +# | ~ ,-~~~^~, | ,~^~~~-, ~ | +# | | }:{ | | +# | l / | \ ! | +# .~ (__,.--/ .^. \--.,__) ~. +# | ---;' / | \ `;--- | +# \__. \/^\/ .__/ +# V| \ / |V +# | |T~\___!___!___/~T| | +# | |`IIII_I_I_I_IIII'| | +# | \,III I I I III,/ | +# \ `~~~~~~~~~~' / +# \ . . / +# \. ^ ./ +# ^~~~^~~~^ +# " +# else +# puts "error." +# end diff --git a/test.rb b/test.rb new file mode 100644 index 0000000..7839364 --- /dev/null +++ b/test.rb @@ -0,0 +1,371 @@ +require 'yummly' +require 'gruff' +require "csv" +require 'catpix' + +Yummly.configure do |config| + config.app_id = "8761fe27" + config.app_key = "eb9bc332198f1609d3f41f6e426fc670" + config.use_ssl = true # Default is false +end +system("clear") +puts "Welcome to the recipe factory" +puts "What are you in the mood for?" + +search_term = gets.chomp.to_s + +puts " Excellent! You chose:" +puts " #{search_term}" +puts " Good choice" +puts "give me a second" +puts "..." +sleep(1) + +search_term +result = Yummly.search(search_term) +# puts result.methods +system("clear") + +# MIGHT NEED TO BRING BACK +# puts result + +top_ten = [] +@inglist =[] +@recilist = [] + +top_ten << result.collect do |recipe| + + this_hash = {} + this_hash[recipe.name] = recipe.ingredients + @recilist << recipe.name + @inglist << recipe.ingredients + top_ten << this_hash +end + +search_result = top_ten.take(3) + +=begin + +# puts search_result[gets.chomp.to_i - 1] + +# top_ten_ingredients = [] +# +# +# puts "this is one recipe" + +# +# puts result.collect {|recipe| recipe.ingredients} + +#result.collect {|recipe| recipe.ingredients} + +# part 2 +# +# require 'HTTParty' +# require 'Nokogiri' +# +# +# # creating classes +# class Url +# def initialize(url) +# @url = url +# end +# +# attr_accessor :url +# +# def self.all +# ObjectSpace.each_object(self).to_a +# end +# end +# +# url1 = Url.new("http://www.taste.com.au/recipes/chicken-bstilla-pies/uGbryXOY?r=quickeasy/kj1r4Zny") +# url2 = Url.new("http://www.taste.com.au/recipes/beef-olive-spaghetti-bolognese/77f0654c-0c53-4f95-bc41-d864ae90426d?r=recipes/beefrecipes&c=ed77f9a0-ff56-40d0-b903-b24e86c38152/Beef%20recipes") +# url3 = Url.new("http://www.taste.com.au/recipes/pappardelle-pumpkin-bacon-torn-bread/2318e227-1dc9-463f-94ee-e4c0ddf0778f?r=recipes/pastarecipes&c=9a361b5c-6b07-48cb-ba64-399b8627268c/Pasta%20recipes") +# +# # # scraping title +# def get_recipe_title(url) +# page = HTTParty.get(url) +# parse_page = Nokogiri::HTML(page) +# title = parse_page.css("h1") +# title_of_recipe = title.text +# end +# +# # scraping ingredients +# def get_recipe_ingredient_list(url) +# +# page = HTTParty.get(url) +# parse_page = Nokogiri::HTML(page) +# @scraped_ingredient = [] +# ingredient_list = [] +# +# parse_page.css(".ingredient-description").each do |a| +# ing = a.text.downcase +# @scraped_ingredient << ing +# end +# + +recipe_list = [] +# +# Url.all.each do |i| +# recipe_list << i.url +# end +=end + +#UNMASK THESE ONES + + +@carbonarray = [] + +CSV.foreach("carbonfootprint.csv") do |row| + @carbonarray << row +end + +just_ingredients = [] + +@carbonarray.each do |ingredient_line| + just_ingredients << ingredient_line[0].downcase +end + +# this is the input from Jon + +# total = 0 +# carbonarray.each do |csv_ingredient| +# recipe.each do |recipe_item| +# # csv_ingredient[0] returns name +# # puts csv_ingredient[0].to_s +# # check if provided recipe line includes a csv ingredient name +# if recipe_item.include?(csv_ingredient[0].downcase) +# #puts "item #{csv_ingredient[0]} carbon value: #{csv_ingredient[1]}" +# total = total + csv_ingredient[1].to_i +# else +# #puts "false" +# end +# end +# end + +#puts total + +def image(carbonnumber) + case carbonnumber + when 0 + puts "no carbon" + when 1..20 + puts "carbon low" + puts " + + `*******' + .---. + ( --- ) + ( /m m\ ) + ___( = )___ + .'----`\ /'----`. + //' .-'': ;``-. `\\ + // / Y \ \\ + // / (|) \ \\ + // : .-' | `-. ; \\ + // `.__.-'^`-.__.' \\ + ^. .^.^/ \^.^. .^ + ^ / CARBON LOW \ ^ + / \ + _.' `._ + '._ _.' + `--..___ ___..--' + ``` + + + " + when 20..40 + puts "carbon moderately low" + puts " + __ / \ __ + ( `'.\ /.'` ) + '-._.(;;;)._.-' + .-' ,``, '-. CARBON MODERATELY LOW + (__.-'/ \'-.__)/)_ + \ /\ / / ) + '-' | \/.-') + , | .'/\'..) + |\ |/ | \_) + \ | | \_/ + | \ / + \|/ _, + / __/ / + | _/ _.' + |/__/ + \ + " + when 40..60 + puts "carbon medium" + puts " + + + \ ( / + `. \ ) / .' + `. \ ( / .' + `. .-''''-. .' + CARBON MEDIUM! `~._ .'/_ _\`. _.~' + `~ / / \ / \ \ ~' + _ _ _ _| _\O/ \O/_ |_ _ _ _ + | (_) /\ (_) | + _.~ \ \ / / ~._ + .~' `. `.__.' .' `~. + .' `-,,,,-' `. + .' / ) \ `. + .' / ( \ `. + / ) \ + + " + + when 60..80 + puts "carbon moderately high" + puts " + ____________________ + / \ + !CARBON MODERATELY HIGH! + ! ! + \____________________/ + ! ! + ! ! + L_ ! + / _)! + / /__L + _____/ (____) + (____) + _____ (____) + \_(____) + ! ! + ! ! + \__/ + "" + "" + " + when 80..100 + puts "carbon high" + puts " + _,.-------.,_ + ,;~' '~;, + ,; ;, + ; CARBON HIGH!!! ; + ,' ', + ,; ;, + ; ; . . ; ; + | ; ______ ______ ; | + | `/~o ~o . o~ o~\' | + | ~ ,-~~~^~, | ,~^~~~-, ~ | + | | }:{ | | + | l / | \ ! | + .~ (__,.--/ .^. \--.,__) ~. + | ---;' / | \ `;--- | + \__. \/^\/ .__/ + V| \ / |V + | |T~\___!___!___/~T| | + | |`IIII_I_I_I_IIII'| | + | \,III I I I III,/ | + \ `~~~~~~~~~~' / + \ . . / + \. ^ ./ + ^~~~^~~~^ + " + else + puts "error." + end +end + + +#as above, put top 5 values +@piearray = [] + +def carboncalc(recipe) + totallist = [] + @carbonarray.each do |csv_ingredient| + recipe.each do |recipe_item| + # csv_ingredient[0] returns name + # puts csv_ingredient[0].to_s + # check if provided recipe line includes a csv ingredient name + if recipe_item.include?(csv_ingredient[0].downcase) + # puts "item #{csv_ingredient[0]} carbon value: #{csv_ingredient[1]}" + totallist << csv_ingredient[1].to_i + else + #puts "false" + end + end + end + + sum = 0 + totallist.sort.reverse.take(5).each { |a| sum+=a } + #puts sum.to_i + # puts totallist + # totallist[0..4].each { |a| sum+=a } + #puts sum + @piearray << sum +end + +#user sel + +puts "Here are three recipes we have selected for you" +puts +puts "[1] #{@recilist[0]}....#{carboncalc(@inglist[0])}" +puts "[2] #{@recilist[1]}....#{carboncalc(@inglist[1])}" +puts "[3] #{@recilist[2]}....#{carboncalc(@inglist[2])}" +puts +puts +puts "We've rated the carbon footprint of each recipe for" +puts "you so as to better inform your decision. The lower" +puts "the number, the better it is for the environment." +puts +puts "When you're ready please select you choice" +puts " [1], [2] or [3]" + +puts @piearray + + + + @datasets = [ + [@recilist[0], [@piearray[0]]], + [@recilist[1], [@piearray[1]]], + [@recilist[2], [@piearray[2]]] + ] + + g = Gruff::Pie.new + g.title = "Carbon Comparison" + @datasets.each do |data| + g.data(data[0], data[1]) + end + + # Default theme + g.write("pie_keynote.png") + + Catpix::print_image "pie_keynote.png", + :limit_x => 1.0, + :limit_y => 0, + :center_x => true, + :center_y => true, + :bg => "white", + :bg_fill => true, + :resolution => "high" + +runner = 1 + +while runner == 1 +selection = gets.chomp.to_i +a = 10 + + if selection == 1 + # @carbon = (carboncalc(@inglist[0]) *3) + a = (@piearray[1].to_f/(@piearray[1].to_f + @piearray[2].to_f + @piearray[0].to_f)) * 100 + image(a.to_i) + runner = 0 + elsif selection == 2 + # @carbon = (carboncalc(@inglist[1]) *3) + a = (@piearray[1].to_f/(@piearray[1].to_f + @piearray[2].to_f + @piearray[0].to_f)) * 100 + image(a.to_i) + runner = 0 + elsif selection == 3 + # @carbon = (carboncalc(@inglist[2]) *3) + a = (@piearray[1].to_f/(@piearray[1].to_f + @piearray[2].to_f + @piearray[0].to_f)) * 100 + image(a.to_i) + runner = 0 + else + puts "please make valid selection [1], [2] or [3]" + runner = 1 + end +end