Merge pull request #1 from tcbuck/master

monday files
This commit is contained in:
najomar68 2017-08-14 15:37:06 +10:00 committed by GitHub
commit 19ae9785e7
3 changed files with 1209 additions and 0 deletions

198
carbonfootprint.csv Normal file
View file

@ -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
1 Food type kg CO2-eq/kg produce, BFM or L after conversion
2 Butter 3.70
3 Camembert Cheese 7.00
4 Cheddar Cheese 8.70
5 Cheese 5.33
6 Goats Cheese 7.71
7 Mozarrella 9.99
8 Semi Hard Chees 8.79
9 Semi-Hard 8.50
10 Cream 7.92
11 Almond Milk 0.39
12 Bufalo Milk 2.87
13 Coconut-Milk 0.39
14 Cows Milk 0.54
15 Goats Milk 1.41
16 Soy-Milk 0.66
17 Yogurt 1.17
18 Apples 0.18
19 Apples and Pears 0.63
20 Apricots 0.43
21 Artichokes 0.48
22 Asparagus 0.38
23 Avocados 0.43
24 Bananas 0.42
25 Beetroot 0.11
26 Broccoli 0.37
27 Cabbage 0.12
28 Capsicums/Peppers 0.23
29 Carrots 0.04
30 Cauliflowers 0.28
31 Celery 0.18
32 Cherries 0.26
33 Chillies 0.66
34 Citrus Fruit, Misc. 0.33
35 Citrus Fruit, Misc. 0.51
36 Citrus Small 0.41
37 Coconuts (Incl. Copra) 1.78
38 Cranberries, Blueberries 0.86
39 Cucumbers 0.08
40 Currants and Gooseberries 0.84
41 Dates 0.32
42 Eggplants (Aubergines) 1.30
43 Fennel 0.48
44 Figs 0.43
45 Garlic 0.57
46 Gherkins 0.13
47 Ginger 0.88
48 Grapefruit and Pomelo 0.51
49 Grapes 0.15
50 Guavas 0.28
51 Kiwi Fruit 0.28
52 Lemons and Limes 0.18
53 Lettuce 0.13
54 Manderin 0.45
55 Melons 0.30
56 Mushrooms 0.06
57 Olives 0.22
58 Onion 0.06
59 Oranges 0.18
60 Peach 0.81
61 Pears 0.19
62 Peppers/Capsicums 0.23
63 Peppers/Capsicums (G) 0.90
64 Melons (G) 1.43
65 Pineapples 0.40
66 Plums and Sloes 0.32
67 Potatoes 0.08
68 Pumpkins 0.15
69 Quinces and Pears 0.30
70 Raspberries and Other Berries 0.84
71 Rockmelon / Cantelope 0.25
72 Spinach 0.18
73 Starchy Root 0.20
74 Strawberries 0.20
75 Swedes (Rutabage) 0.29
76 Tangerines, Mandarins Etc. 0.51
77 Tomatoes 0.15
78 Watermelon 0.38
79 Zucchini/Button Squash 0.09
80 Alfonsino 3.49
81 Anglerfish 10.43
82 Bass 3.60
83 Beef 10.74
84 Bigeye Tuna 11.44
85 Buffalo 48.92
86 Carp 1.73
87 Catfish 8,93
88 Cephalopodsm Varied (Squid) 11.61
89 Chicken 1.06
90 Cod 1.58
91 Cod (Fish Stick) 2.14
92 Cuttlefish 6.39
93 Diamond Fish 6.02
94 Duck 2.07
95 Eggs 1.30
96 Emu 1.50
97 Fish 2.13
98 Fish (Mixed) 1.04
99 Flatfish 1.20
100 Flatfish Varied 11.61
101 Fork Beard 6.25
102 Haddock 2.80
103 Hake 6.88
104 Hake (Fish Stick) 2.14
105 Hake European 9.77
106 Hake Fillet 7.25
107 Hake Senegal 11.61
108 Herring 0.98
109 Kangaroo 4.10
110 Lamb 10.05
111 Ling 3.13
112 Ling Common 9.77
113 Lobster 27.80
114 Lobster 7,62
115 Mackeral 0.94
116 Mackeral (Fish Stick 1.02
117 Mackerel Atlantic 1.41
118 Mackerel Atlantic 3.79
119 Mackerel Horse 1.41
120 Megrim 14.15
121 Mussels 1.92
122 Octopus 7.35
123 Pilchard 0.78
124 Pilchard 1.41
125 Pollock 1.20
126 Pollock 1.60
127 Pollock (Fish Stick) 2.14
128 Pomfret 3.49
129 Pomfret Atlantic 9.77
130 Porbeagle 11.44
131 Pork 2.11
132 Prawns/Shrimp 5.25
133 Rabbit 3.82
134 Rhombus 8.41
135 Rock Fish 6.94
136 Salmon 2.04
137 Sea Bass 1.91
138 Shark 11.56
139 Shark Mako 11.44
140 Sole 20.86
141 Squid 6.91
142 Swordfish 11.44
143 Trout 1.37
144 Tuna 1.39
145 Turbot 9.63
146 Turkey 3.34
147 Veal 21.50
148 Veal Meat
149 Whiting 1.54
150 Whiting Blue 3.79
151 Almonds 0.51
152 Barley 0.11
153 Beans 0.25
154 Beans - Gigante/Butter 0.26
155 Beans - Green 1.45
156 Beans - Green Beans 0.43
157 Beans - Green Beans (Phaseolus Vulgaris L.) 0.24
158 Beans - Pinto Usa Dried 0.73
159 Beans - Plake 0.22
160 Beans – French and Runner 0.52
161 Cahsew Nuts 1.06
162 Cereals Misc. 0.37
163 Chestnuts 0.43
164 Chick Peas 0.45
165 Cowpeas 0.33
166 Graham Flour 0.47
167 Ground Nuts 0.65
168 Hazlenuts 0.43
169 Lentils 1.00
170 Maize 0.40
171 Maize Sweet Corn 1.38
172 Millet 0.47
173 Nuts Misc. 0.47
174 Oat 0.67
175 Oat Berry 0.88
176 Oatmeal 0.74
177 Oats 0.38
178 Palm Nuts-Kernels (Nut Equiv.)/Oil 0.80
179 Peanuts 0.80
180 Peas 0.48
181 Peas - Dry 0.15
182 Peas - Dry 0.51
183 Peas - Green 0.29
184 Peas - Green – Shelled 2.46
185 Peas - Yellow Dried 0.20
186 Peas - Yellow Dried 0.21
187 Pistachios 0.88
188 Quinoa 1.10
189 Rape Seed 0.29
190 Rapeseed and Mustard Seed 2.09
191 Rice 0.66
192 Rye 0.36
193 Sesame Seed 0.88
194 Sorghum 0.88
195 Soybean 0.38
196 Sunflower Seed 1.41
197 Walnuts 0.50
198 Wheat 0.18

640
project.rb Normal file
View file

@ -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

371
test.rb Normal file
View file

@ -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