#! /usr/local/rvm/rubies/ruby-2.1.1/bin/ruby class Glucemico #include Comparable TIEMPO_MUESTRA = 24 NUM_ALIMENTOS = 4 attr_accessor :tiempo attr_accessor :individuo1,:ind1_compota_manzana,:ind1_yogurt,:ind1_chocolate,:ind1_glucosa attr_accessor :individuo2,:ind2_compota_manzana,:ind2_yogurt,:ind2_chocolate,:ind2_glucosa attr_accessor :datos_ind1,:datos_ind2,:g def self.description "clase que calcula el indice glucemico de individuos" end def initialize @alimentos_texto = ['glucosa','compota_manzana','yogurt','chocolate'] @tiempo = [0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,105,110,115,120] @individuo1 = 'ind1' @ind1_compota_manzana = [6.7,6.5,6.8,6.9,7.0,7.1,6.9,6.9,6.9,6.7,6.9,7.3,7.0,7.0,7.2,7.1,6.8,7.2,7.3,7.0,6.8,6.7,6.8,6.7,6.9] @ind1_yogurt = [6.1,6.6,6.3,6.3,6.1,6.9,6.8,6.5,6.4,6.9,6.8,6.5,6.3,6.2,6.7,6.2,5.9,5.8,5.8,5.8,5.8,5.8,5.9,6.2,6.4] @ind1_chocolate = [6.5,6.5,6.7,6.5,6.5,6.8,6.7,6.2,6.5,7.2,6.9,7.0,6.3,6.2,6.1,5.9,5.8,6.1,6.7,6.7,6.6,6.7,6.9,7.2,7.1] @ind1_glucosa = [4.9,5.3,5.9,6.7,7.2,7.6,8.0,8.2,8.2,8.4,8.3,8.3,8.0,7.5,7.1,6.8,6.8,6.9,6.8,6.3,6.2,6.3,6.2,6.3,6.1] @datos_ind1 = [@ind1_glucosa,@ind1_compota_manzana,@ind1_yogurt,@ind1_chocolate,@ind1_glucosa] @individuo2 = 'ind2' @ind2_compota_manzana = [4.6,4.8,5.3,5.6,6.1,6.5,6.6,7.0,7.0,6.8,6.4,6.3,6.1,6.1,6.2,6.0,6.1,6.1,6.2,6.3,6.4,6.1,6.1,5.7,5.9] @ind2_yogurt = [4.9,4.9,5.2,5.8,6.5,7.0,7.2,7.3,7.3,6.6,6.2,6.1,6.0,6.1,5.9,5.9,5.9,5.9,5.8,5.8,5.5,5.5,5.6,5.9,5.9] @ind2_chocolate = [4.6,4.6,4.7,4.7,4.8,4.7,4.8,4.8,4.6,4.4,4.7,4.7,4.8,4.7,5.2,5.9,5.9,5.7,5.4,5.3,5.1,4.8,4.8,4.9,5.9] @ind2_glucosa = [6.3,5.4,5.6,5.7,6.5,7.4,7.9,7.4,7.7,7.9,7.9,7.8,7.8,7.8,8.0,8.5,9.4,10.8,10.5,9.1,8.9,8.3,7.7,7.6,7.5] @datos_ind2 = [@ind2_glucosa,@ind2_compota_manzana,@ind2_yogurt,@ind2_chocolate] @datos = [@datos_ind1,@datos_ind2] @g = [[1,2,3],[4,5,6]] end # def aibc # i = 0 # r = [] # while i < @g.size # index = 1 # s = [] # while (index < @g[i].size) # if (@g[i][index] < @g[i][0]) # s << 0.0 # else # s << (((@g[i][index] - @g[i][0]) + (@g[i][index-1] - @g[i][0]))/2)*5 # end # index = index + 1 # end # r << s # i = i + 1 # end #se aplica solo a un individuo def formula_AIBC (alimentos_usuario) i = 0 r = [] #each_byte alimentos_usuario.each_with_index do |valor,i| #puts "#{valor} at #{i}" #i.to_f index=1 s=[] valor.each_with_index do |valor2,index| #puts "#{valor2} at #{index}" if (alimentos_usuario[i][index] < alimentos_usuario[i][0]) s << (0.0) else #s << (((alimento[i][index].to_f - alimento[i][0].to_f) + (alimento[i][index-1].to_f - alimento[i][0].to_f))/2)*5 a = (alimentos_usuario[i][index].to_f - alimentos_usuario[i][0].to_f) b = (alimentos_usuario[i][index-1] - alimentos_usuario[i][0]) s << (((((a)+(b))/2.0)*5.0)) end #index += 1 end #p (s) r << s #i += 1 end # suma = [] # j = 0 # while j < @g.size # k = 0 # s = 0 # while k < r[j].size # s = s + r[j][k] # k = k + 1 # end # suma << s # j = j + 1 # end # suma # end suma = [] j = 0 #puts "locoloco #{r}" alimentos_usuario.each_with_index do |valor, j| k = 0 s = 0 p = valor.reduce(:+) # alimentos_usuario.each_with_index do |valor2,k| # s = s + r[j][k] # #valor2 # #s = r.reduce(:+) # #k = k + 1 # end suma << p #j = j+1 #puts "locoloco #{p}" end suma #suma = r.reduce {:+} #puts (suma) end #e def IG a = formula_AIBC(@datos_ind1) b = formula_AIBC(@datos_ind2) #(a b).each_with_index do |i| salida=[] result=[] for i in 1..NUM_ALIMENTOS-1 parte1 = (a[i].to_f/a[0].to_f)*100 parte2 = (b[i].to_f/b[0].to_f)*100 result = ((parte1)+(parte2))/2 puts "alimento #{@alimentos_texto[i]} valor IG #{result}" #salida.insert (result) end # a.zip(b).each_with_index do |dato,i| # #puts (dato) # parte1 = (a[i+1].to_f/a[0].to_f)*100 # parte2 = (b[i+1].to_f/b[0].to_f)*100 # result = ((parte1)+(parte2))/2 # puts "alimento #{@alimentos_texto[i+1]} valor IG #{result}" # end #kaka = formula_AIBC(@datos_ind1[i][j],i) end end @prueba = Glucemico.new #puts "prueba #{@prueba.formula_AIBC}" @prueba.IG #puts (@prueba.ind2_compota_manzana) #puts "prueba2 #{@prueba.IG}" #puts "prueba #{formula_IG}" #puts "prueba #{@prueba.datos_ind1[0][0]}" #puts (@prueba.aibc)s #puts "IG_yogurt #{IG_yogurt}" # # esta formula se aplica para dos individuo # # def self.formula_IG (alimento) # result = 0 # result = (formula_IG_IND(alimento))/ 2 # # #result = (formula_IG_IND(@compota_manzana) + formula_IG_IND(@yogurt) + formula_IG_IND(@chocolate)) / 2 # return (result) # end # # # def + (other) # # Glucemico.new(individuo+other.individuo,tiempo+other.tiempo,compota_manzana+other.compota_manzana,yogurt+other.yogurt, # # chocolate+other.chocolate,glucosa+other.glucosa) # # end # # # ################################################################################################## # def individuo_to_s # imprime = "individuo: #{formula_IG(@individuo)}\n" #número de porciones # # return imprime # end # # def formula_AIBC_to_s (alimento) # imprime = "#{formula_AIBC(alimento)}" #formula # # return imprime # end # # def formula_IG_IND_to_s (alimento) # imprime = "#{formula_IG_IND(alimento)}" #formula # # return imprime # end # # def formula_IG_to_s # imprime = "#{formula_IG(alimento)}" #formula # # return imprime # end # # # # def ingredientes_to_s # # imprime = "\n" # # imprime << "Ingredientes:\n" # # imprime << "#{ingredientes.join(', ')}\n\n" #con el join añade la , y el espacio entre los elementos del array # # # # # def instrucciones_to_s # # imprime = "Instrucciones:\n" # # instrucciones.each_with_index do |instruccion, index| #nos da el valor de cada elemento del array y su indice # # imprime << "#{index + 1}) #{instruccion}\n" #index + 1 para que no empiece en 0 # # end # # # # # def to_s # # return (individuo_to_s + indice_compota_manzana_to_s + indice_yogurt_to_s + indice_chocolate_to_s ) # # end # end # # # # class individuo # # attr_accessor :ind # # # # def initialize(ind) # # @ind = ind # # end # # def formula_IG_to_s # # imprime = "#{formula_IG(alimento)}" #formula # # # # return imprime # # end # # # # def formula_IG_IND_to_s (alimento) # # imprime = "#{formula_IG_IND(alimento)}" #formula # # # # return imprime # # end # # end # # # # # # individuo,tiempo,compota_manzana,yogurt,chocolate,glucosa # # @tiempo = %w[0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120] # @ind1_compota_manzana = %w[6.7 6.5 6.8 6.9 7.0 7.1 6.9 6.9 6.9 6.7 6.9 7.3 7.0 7.0 7.2 7.1 6.8 7.2 7.3 7.0 6.8 6.7 6.8 6.7 6.9] # @ind1_yogurt = %w[6.1 6.6 6.3 6.3 6.1 6.9 6.8 6.5 6.4 6.9 6.8 6.5 6.3 6.2 6.7 6.2 5.9 5.8 5.8 5.8 5.8 5.8 5.9 6.2 6.4] # @ind1_chocolate = %w[6.5 6.5 6.7 6.5 6.5 6.8 6.7 6.2 6.5 7.2 6.9 7.0 6.3 6.2 6.1 5.9 5.8 6.1 6.7 6.7 6.6 6.7 6.9 7.2 7.1] # @ind1_glucosa = %w[4.9 5.3 5.9 6.7 7.2 7.6 8.0 8.2 8.2 8.4 8.3 8.3 8.0 7.5 7.1 6.8 6.8 6.9 6.8 6.3 6.2 6.3 6.2 6.3 6.1] # @individuo1 = Glucemico.new("ind1",@tiempo , @ind1_compota_manzana , @ind1_yogurt , @ind1_chocolate , @ind1_glucosa) # # acordarse de quitar espacio en blanco en el new( # #puts @individuo1 # puts (Glucemico.description) # puts # puts "AIBC_compota_manzana #{@individuo1.formula_AIBC(@ind1_compota_manzana)}" # puts "AIBC_yogurt #{@individuo1.formula_AIBC(@ind1_yogurt)}" # puts "AIBC_chocolate #{@individuo1.formula_AIBC(@ind1_chocolate)}" # # puts "Compota de manzana #{@individuo1.formula_AIBC (@ind1_compota_manzana)}" # # puts "yogurt #{@individuo1.formula_AIBC (@ind1_yogurt)}" # # puts "chocolate #{@individuo1.formula_AIBC (@ind1_chocolate)}" # # puts "glucosa #{@individuo1.formula_AIBC (@ind1_glucosa)}" # # puts "IG_IND_compota_manzana #{@individuo1.formula_IG_IND(@ind1_compota_manzana)}" # puts "IG_IND_yogurt #{@individuo1.formula_IG_IND(@ind1_yogurt)}" # puts "IG_IND_chocolate #{@individuo1.formula_IG_IND(@ind1_chocolate)}" # # #puts "#{@individuo1.to_s()}" # # # puts "Compota de manzana #{individuo1.formula_IG (@ind1_compota_manzana)}" # # puts "yogurt #{individuo1.formula_IG (@ind1_yogurt)}" # # puts "chocolate #{individuo1.formula_IG (@ind1_chocolate)}" # # puts "glucosa #{individuo1.formula_IG (@ind1_glucosa)}" # @ind2_compota_manzana = %w[4.6 4.8 5.3 5.6 6.1 6.5 6.6 7.0 7.0 6.8 6.4 6.3 6.1 6.1 6.2 6.0 6.1 6.1 6.2 6.3 6.4 6.1 6.1 5.7 5.9] # @ind2_yogurt = %w[4.9 4.9 5.2 5.8 6.5 7.0 7.2 7.3 7.3 6.6 6.2 6.1 6.0 6.1 5.9 5.9 5.9 5.9 5.8 5.8 5.5 5.5 5.6 5.9 5.9] # @ind2_chocolate = %w[4.6 4.6 4.7 4.7 4.8 4.7 4.8 4.8 4.6 4.4 4.7 4.7 4.8 4.7 5.2 5.9 5.9 5.7 5.4 5.3 5.1 4.8 4.8 4.9 5.9] # @ind2_glucosa = %w[6.3 5.4 5.6 5.7 6.5 7.4 7.9 7.4 7.7 7.9 7.9 7.8 7.8 7.8 8.0 8.5 9.4 10.8 10.5 9.1 8.9 8.3 7.7 7.6 7.5] # @individuo2 = Glucemico.new("ind2",@tiempo,@ind2_compota_manzana,@ind2_yogurt,@ind2_chocolate,@ind2_glucosa) # # IG_compota_manzana = (@individuo1.formula_AIBC(@ind1_compota_manzana) + @individuo2.formula_AIBC(@ind1_compota_manzana))/2 # puts "IG_compota_manzana #{IG_compota_manzana}" # # IG_yogurt = (@individuo1.formula_AIBC(@ind1_yogurt) + @individuo2.formula_AIBC(@ind2_yogurt))/2 # puts "IG_yogurt #{IG_yogurt}" # # IG_chocolate = (@individuo1.formula_AIBC(@ind1_chocolate) + @individuo2.formula_AIBC(@ind2_chocolate))/2 # puts "IG_chocolate #{IG_chocolate}" # # # IG_compota_manzana = ([@individuo1,@individuo2]) # # @individuo = individuo.new(IG_compota_manzana) # # puts (@individuo) # # #result = @individuo1 + @individuo2 # #puts (result.to_s) # @tiempo = %w[0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120] # # @individuo1 = 'ind1' # @ind1_compota_manzana = %w[6.7 6.5 6.8 6.9 7.0 7.1 6.9 6.9 6.9 6.7 6.9 7.3 7.0 7.0 7.2 7.1 6.8 7.2 7.3 7.0 6.8 6.7 6.8 6.7 6.9] # @ind1_yogurt = %w[6.1 6.6 6.3 6.3 6.1 6.9 6.8 6.5 6.4 6.9 6.8 6.5 6.3 6.2 6.7 6.2 5.9 5.8 5.8 5.8 5.8 5.8 5.9 6.2 6.4] # @ind1_chocolate = %w[6.5 6.5 6.7 6.5 6.5 6.8 6.7 6.2 6.5 7.2 6.9 7.0 6.3 6.2 6.1 5.9 5.8 6.1 6.7 6.7 6.6 6.7 6.9 7.2 7.1] # @ind1_glucosa = %w[4.9 5.3 5.9 6.7 7.2 7.6 8.0 8.2 8.2 8.4 8.3 8.3 8.0 7.5 7.1 6.8 6.8 6.9 6.8 6.3 6.2 6.3 6.2 6.3 6.1] # @datos_ind1 = [@individuo1,@tiempo,@ind1_compota_manzana,@ind1_yogurt,@ind1_chocolate,@ind1_glucosa] # # @individuo2 = 'ind2' # @ind2_compota_manzana = %w[4.6 4.8 5.3 5.6 6.1 6.5 6.6 7.0 7.0 6.8 6.4 6.3 6.1 6.1 6.2 6.0 6.1 6.1 6.2 6.3 6.4 6.1 6.1 5.7 5.9] # @ind2_yogurt = %w[4.9 4.9 5.2 5.8 6.5 7.0 7.2 7.3 7.3 6.6 6.2 6.1 6.0 6.1 5.9 5.9 5.9 5.9 5.8 5.8 5.5 5.5 5.6 5.9 5.9] # @ind2_chocolate = %w[4.6 4.6 4.7 4.7 4.8 4.7 4.8 4.8 4.6 4.4 4.7 4.7 4.8 4.7 5.2 5.9 5.9 5.7 5.4 5.3 5.1 4.8 4.8 4.9 5.9] # @ind2_glucosa = %w[6.3 5.4 5.6 5.7 6.5 7.4 7.9 7.4 7.7 7.9 7.9 7.8 7.8 7.8 8.0 8.5 9.4 10.8 10.5 9.1 8.9 8.3 7.7 7.6 7.5] # @datos_ind2 = [@individuo2,@tiempo,@ind2_compota_manzana,@ind2_yogurt,@ind2_chocolate,@ind2_glucosa]