Advertisement
Guest User

Untitled

a guest
Mar 16th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.14 KB | None | 0 0
  1. //open file
  2. //init wb
  3. //init ws
  4.  
  5. let rec row_array ws row_num =
  6.     match ws.Rows[row_num] with
  7.         if row_num <= ws.Rows.Length then
  8.             ws.Range("A"+char(row_num)).Value
  9.             |::ws.Range("B"+char(row_num)).Value
  10.             |::ws.Range("C"+char(row_num)).Value
  11.             |::ws.Range("D"+char(row_num)).Value
  12.             |::ws.Range("E"+char(row_num)).Value
  13.             |::[]::(row_array ws (row_num+1))
  14.         else
  15.             []
  16.  
  17.  
  18. let sortedList this_array =
  19.     List.sortBy(fun elem -> elem[1]) this_array
  20.  
  21. let merge_rows x y tail func=
  22.     let [a, b, c, d, e] = x
  23.     let [a1, b1, d1, c1, e1] = y
  24.     if a==a1 then
  25.         [a, b, (c+c1), ((c*d+c1*d1)/(e+e1)), (e+e1)]::(func tail)
  26.     else
  27.         [a, b, c, d, e]:: (func ([a1, b1, d1, c1, e1]::tail)
  28.  
  29. let merge_last_two_rows x y =
  30.     let [a, b, c, d, e] = x
  31.     let [a1, b1, d1, c1, e1] = y
  32.     if a==a1 then
  33.         [a, b, (c+c1), ((c*d+c1*d1)/(e+e1)), (e+e1)]::[]
  34.     else
  35.         [a, b, c, d, e]::[a1, b1, d1, c1, e1]::[]
  36.  
  37. let rec average_prices sorted_list =
  38.     match  sorted_list with
  39.         |x::y::tail ->
  40.             merge_rows x y tail average_prices
  41.         |x::y ->
  42.             merge_last_two_rows x y
  43.  
  44. let ready_item_array =
  45.     let array = row_array ws 2|> sorted_list|> average_prices
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement