Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'httparty'
- ACTIVITY_URL = 'https://bidatabase.herokuapp.com/metrics/convertion/{ID}'
- LOST_URL = 'https://bidatabase.herokuapp.com/metrics/lost/{ID}'
- WON_URL = 'https://bidatabase.herokuapp.com/metrics/won/{ID}'
- OPEN_URL = 'https://bidatabase.herokuapp.com/metrics/open/{ID}'
- ACCESS_TOKEN = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJuYW1lIjoid29sb3guYmkifQ.xdops9HrflQ8Xg7U0xgzRDAdvT7vyHam4sU8cWzDmVw'
- def get(url, params)
- response = HTTParty.get(url.gsub('{ID}', params[:id].to_s), query: params, headers: { 'Authorization': ACCESS_TOKEN }, :debug_output => $stdout)
- end
- def fetch_metrics(id, date_start, date_end)
- puts "Requiring between dates: #{date_start}-#{date_end}\n"
- time_start = DateTime.new(*date_start.split("-").map(&:to_i), 00, 00, 00, '-03:00')
- time_end = DateTime.new(*date_end.split('-').map(&:to_i), 23, 59, 59, '-03:00')
- ###### CONVERTIONS - START #######
- acumulado = []
- id.each do |key|
- activity_response = get(ACTIVITY_URL, {id: key, start: time_start, end: time_end})
- # ret = {}
- # activity_response.parsed_response["data"].each do |k,v|
- # ret[k] = v
- end
- # acumulado << ret
- end
- #
- # matrix = []
- # acumulado.each do |team|
- # keys = team.keys
- # column = []
- # contador = 0
- # keys.each_with_index do |stage, index|
- # column << "#{team[stage]["incoming"]["outbound"]}\t#{team[stage]["incoming"]["inbound"]}"
- # column << (index == 3 ? "won_time" : "#{team[stage]["outgoing"]["outbound"]}\t#{team[stage]["outgoing"]["inbound"]}")
- # column << "formula#{contador}"
- # contador = contador + 1
- # end
- # matrix << column
- # end
- #
- # formula0 = "=IF(C9*C12 = 0, 0, C12/C9)\t=IF(D9*D12 = 0, 0, D12/D9)\t=IF(E9*E12 = 0, 0, E12/E9)\t=IF(F9*F12 = 0, 0, F12/F9)\t=IF(G9*G12 = 0, 0, G12/G9)\t=IF(H9*H12 = 0, 0, H12/H9)\t=IF(I9*I12 = 0, 0, I12/I9)\t=IF(J9*J12 = 0, 0, J12/J9)\t=IF(K9*K12 = 0, 0, K12/K9)\t=IF(L9*L12 = 0, 0, L12/L9)"
- # formula1 = "=IF(C12*C15 = 0, 0, C15/C12)\t=IF(D12*D15 = 0, 0, D15/D12)\t=IF(E12*E15 = 0, 0, E15/E12)\t=IF(F12*F15 = 0, 0, F15/F12)\t=IF(G12*G15 = 0, 0, G15/G12)\t=IF(H12*H15 = 0, 0, H15/H12)\t=IF(I12*I15 = 0, 0, I15/I12)\t=IF(J12*J15 = 0, 0, J15/J12)\t=IF(K12*K15 = 0, 0, K15/K12)\t=IF(L12*L15 = 0, 0, L15/L12)"
- # formula2 = "=IF(C15*C18 = 0, 0, C18/C15)\t=IF(D15*D18 = 0, 0, D18/D15)\t=IF(E15*E18 = 0, 0, E18/E15)\t=IF(F15*F18 = 0, 0, F18/F15)\t=IF(G15*G18 = 0, 0, G18/G15)\t=IF(H15*H18 = 0, 0, H18/H15)\t=IF(I15*I18 = 0, 0, I18/I15)\t=IF(J15*J18 = 0, 0, J18/J15)\t=IF(K15*K18 = 0, 0, K18/K15)\t=IF(L15*L18 = 0, 0, L18/L15)"
- #
- # ###### CONVERTIONS - END #######
- #
- # ###### WON/LOST - START #######
- # acumulado = []
- # matrix1 = []
- # matrix2 = []
- # matrix3 = []
- # matrix4 = []
- # id.each do |key|
- # column1 = []
- # column2 = []
- # column3 = []
- # column4 = []
- # close_response = get(WON_URL, {id: key, start: time_start, end: time_end})
- # lost_response = get(LOST_URL, {id: key, start: time_start, end: time_end})
- # open_response = get(OPEN_URL, {id: key})
- # column1 << close_response.parsed_response["data"]["total"]["outbound"]["count"]
- # column1 << close_response.parsed_response["data"]["total"]["inbound"]["count"]
- # column2 << close_response.parsed_response["data"]["total"]["total"]["sum"]
- # column2 << lost_response.parsed_response["data"]["total"]["total"]["sum"]
- # column3 << open_response.parsed_response["data"]["total"]["total"]["sum"]
- # column4 << open_response.parsed_response["data"]["total"]["total"]["avg"]
- # matrix1 << column1
- # matrix2 << column2
- # matrix3 << column3
- # matrix4 << column4
- # ret = {}
- # lost_response.parsed_response["data"]["breakdown"].each do |k,v|
- # ret[k] = v
- # end
- # acumulado << ret
- # end
- #
- # closed = matrix1.join("\t")
- #
- # matrix5 = []
- # lead1 = 0
- # lead2 = 0
- # acumulado.each do |team|
- # keys = team.keys
- # column = []
- # contador = 0
- # keys.each_with_index do |stage, index|
- # unless ['Falling in Love', 'Looking for Investment'].include? stage
- # if stage.include?("Lead")
- # lead1 += team[stage]["outbound"]["count"]
- # lead2 += team[stage]["inbound"]["count"]
- # elsif stage.include?("Proposal")
- # column << "#{lead1}\t#{lead2}"
- # column << "#{team[stage]["outbound"]["count"]}\t#{team[stage]["inbound"]["count"]}"
- # lead1 = 0
- # lead2 = 0
- # else
- # column << "#{team[stage]["outbound"]["count"]}\t#{team[stage]["inbound"]["count"]}"
- # end
- # end
- # end
- # matrix5 << column
- # end
- # ###### WON/LOST - END #######
- #
- # ###### FORMAT OUTPUT - START #######
- # matrix.transpose.each do |row|
- # if row.first == "\n"
- # print "\n"
- # next
- # end
- # if row[0] == "won_time"
- # puts closed
- # elsif row[0] == "formula0"
- # puts formula0
- # elsif row[0] == "formula1"
- # puts formula1
- # elsif row[0] == "formula2"
- # puts formula2
- # elsif row[0] == "formula3"
- # puts "\t"
- # else
- # puts row.join("\t")
- # end
- # end
- # puts "\n"
- # matrix3.transpose.each do |row|
- # puts row.join("\t")
- # end
- # matrix2.transpose.each do |row|
- # puts row.join("\t")
- # end
- # puts "\n"
- # puts "SFO\tLATAM\tCHILE\tARGENTINA\tNYC"
- # matrix4.transpose.each do |row|
- # puts row.join("\t")
- # end
- # puts "\n"
- # matrix5.transpose.each do |row|
- # puts row.join("\t")
- # end
- # ###### FORMAT OUTPUT - END #######
- # end
- #
- # puts "New projects\n"
- # id = [7, 14, 5, 4, 9]
- # fetch_metrics(id, '2019-01-28', '2019-02-03')
- # fetch_metrics(id, '2019-01-01', '2019-01-31')
- # fetch_metrics(id, '2019-01-01', '2019-02-03')
- # fetch_metrics(id, '2019-01-01', '2019-02-03')
- # puts "Upsellings\n"
- id = [8, 15, 6, 3, 10]
- # fetch_metrics(id, '2019-01-28', '2019-02-03')
- # fetch_metrics(id, '2019-01-01', '2019-01-31')
- # fetch_metrics(id, '2019-01-01', '2019-02-03')
- fetch_metrics(id, '2019-01-01', '2019-02-03')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement