Guest User

Untitled

a guest
Jul 19th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.83 KB | None | 0 0
  1. for outCome in outComeOrder {
  2. if let oddItem = outComeMap[outCome] as? NSDictionary {
  3.  
  4. var handicapOddItem: [String: Any] = [:]
  5. if name == "handicap" {
  6. print("--- handicap odd ---")
  7. print(oddItem)
  8. for key in oddItem.allKeys {
  9. if key as! String == "outCome" {
  10. handicapOddItem[key as! String] = const.string.handicapOdd + outCome
  11. } else {
  12. handicapOddItem[key as! String] = oddItem[key]
  13. }
  14. }
  15. print(handicapOddItem)
  16.  
  17. // получить селектор
  18. // постучать в oddsTypeMap с этим селектором
  19. // выцепить нужные итемы
  20. // добавить в них oddTypeName
  21. let handicapSelectors = oddGroup["selectors"] as! [String]
  22. let selector = handicapSelectors.first!
  23. var winningPair: [[String : Any]] = []
  24.  
  25. if let oddsTypeMap = match["oddsTypeMap"] as? NSDictionary {
  26. if let handicapItems = oddsTypeMap[selector] as? [String : Any] {
  27. if let oddTypeName = handicapItems["oddTypeName"] as? String {
  28. handicapOddItem["oddTypeName"] = oddTypeName
  29. }
  30.  
  31.  
  32.  
  33. if let oddsMap = handicapItems["oddsMap"] as? NSDictionary {
  34. var allValues = oddsMap.allValues as! [[String: Any]]
  35.  
  36. var handicapMap: [Float: Any] = [:]
  37. ///////////////////
  38. let sortedValues = allValues.sorted {
  39. abs(Float($0["specialValue"] as! String)!) < abs(Float($1["specialValue"] as! String)!)
  40. }
  41. print(sortedValues)
  42. /////////////////
  43.  
  44. var absSpecialValues: [Float] = []
  45.  
  46.  
  47. sortedValues.forEach {
  48. let specialValue = $0["specialValue"] as! String
  49. if let floatSpecialValue = Float(specialValue) {
  50. let absSpecValue = abs(floatSpecialValue)
  51.  
  52. absSpecialValues.append(absSpecValue)
  53. absSpecialValues = absSpecialValues.removeDuplicates()
  54.  
  55. }
  56. }
  57. print(handicapMap)
  58. print(absSpecialValues)
  59. // собрать массив массивов с оддсами с одинаковым спешиалВэлью
  60.  
  61. sortedValues.forEach {
  62. if let floatSpecialValue = Float($0["specialValue"] as! String) {
  63. let absSpecValue = abs(floatSpecialValue)
  64.  
  65. for specialValue in absSpecialValues {
  66. if specialValue == absSpecValue {
  67.  
  68. }
  69. }
  70. }
  71. }
  72.  
  73. // составить мапу [abs(specialValue) : 2x oddItem]
  74. for specialValue in absSpecialValues {
  75. var sortedBySpecialValueArray: [[String: Any]] = []
  76.  
  77. sortedValues.forEach {
  78. if let floatSpecialValue = Float($0["specialValue"] as! String) {
  79. let absSpecValue = abs(floatSpecialValue)
  80. if absSpecValue == specialValue {
  81. sortedBySpecialValueArray.append($0)
  82. }
  83. }
  84. }
  85.  
  86. handicapMap[specialValue] = sortedBySpecialValueArray
  87.  
  88. }
  89.  
  90. // найти в мапе пару с наименьшей разницей между коэффициентами
  91. var lowestDiff: Float = 10.0 // default value is needed for (if coeffDiff < currentLowestDiff) to work
  92. var diffArray: [Float] = []
  93.  
  94. var specialValueWithLowestDiff: Float = 0.0
  95. var specialValueDiffArray: [Float] = []
  96.  
  97. for specialValue in absSpecialValues {
  98. let pair = handicapMap[specialValue]!
  99.  
  100. var coeffDiff: Float = 0.0
  101. var coeffArray: [Float] = []
  102.  
  103. for handicapOdd in pair as! NSArray {
  104. if let coeff = (handicapOdd as! [String: Any])["coefficient"] as? String {
  105. if let floatCoeff = Float(coeff) {
  106. coeffArray.append(floatCoeff)
  107. }
  108. }
  109. }
  110. if coeffArray.count > 1 {
  111. coeffDiff = abs(coeffArray[0] - coeffArray[1])
  112. diffArray.append(coeffDiff)
  113. specialValueDiffArray.append(specialValue)
  114. }
  115.  
  116. if coeffDiff < lowestDiff {
  117. lowestDiff = coeffDiff
  118. specialValueWithLowestDiff = specialValue
  119. }
  120. }
  121.  
  122.  
  123. // найти пару с коэффициентами ближайшими к 1.8
  124.  
  125. var lowestDiff18: Float = 10.0
  126. var specialValueWithLowestDiff18: Float = 0.0
  127.  
  128. var diff18Array: [Float] = []
  129. var specialValuesDiff18Array: [Float] = []
  130.  
  131. for specialValue in absSpecialValues {
  132. let pair = handicapMap[specialValue]!
  133.  
  134. var diff18_1: Float = 0.0
  135. var diff18_2: Float = 0.0
  136. var coeffArray: [Float] = []
  137.  
  138. for handicapOdd in pair as! NSArray {
  139. if let coeff = (handicapOdd as! [String: Any])["coefficient"] as? String {
  140. if let floatCoeff = Float(coeff) {
  141. coeffArray.append(floatCoeff)
  142. }
  143. }
  144. }
  145.  
  146. if coeffArray.count > 1 {
  147. diff18_1 = abs(coeffArray[0] - 1.8)
  148. diff18_2 = abs(coeffArray[1] - 1.8)
  149.  
  150. let diff18 = (diff18_1 + diff18_2) / 2.0
  151. // print(diff18)
  152. diff18Array.append(diff18)
  153. specialValuesDiff18Array.append(specialValue)
  154.  
  155. if diff18 < lowestDiff18 {
  156. lowestDiff18 = diff18
  157.  
  158. specialValueWithLowestDiff18 = specialValue
  159. }
  160. }
  161. }
  162.  
  163. // расставить элементы specialValueDiffArray в соответствии с отсортированным diffArray
  164. var sortDict: [Float : Float] = [:]
  165. for i in 0..<diffArray.count {
  166. sortDict[specialValueDiffArray[i]] = diffArray[i]
  167. }
  168.  
  169. var specialValuesSortedByDiff = Array(sortDict.keys).sorted {
  170. sortDict[$0]! < sortDict[$1]!
  171. }
  172. print(specialValuesSortedByDiff)
  173.  
  174. var diff18SortDict: [Float : Float] = [:]
  175. for i in 0..<diff18Array.count {
  176. diff18SortDict[specialValuesDiff18Array[i]] = diff18Array[i]
  177. }
  178. var specialValuesSortedByDiff18 = Array(diff18SortDict.keys).sorted {
  179. diff18SortDict[$0]! < diff18SortDict[$1]!
  180. }
  181.  
  182. print(specialValuesSortedByDiff18)
  183.  
  184. print("== SV for PAIR /w lowest diff ==")
  185. print(specialValuesSortedByDiff.first!)
  186.  
  187. print("== SV for PAIR /w lowest diff18 ==")
  188. print(specialValuesSortedByDiff.first!)
  189.  
  190. if let diffSpecialValue = specialValuesSortedByDiff.first,
  191. let diff18SpecialValue = specialValuesSortedByDiff.first {
  192.  
  193. var sv: Float = 0.0
  194. if diffSpecialValue == diff18SpecialValue {
  195. sv = diffSpecialValue
  196. } else {
  197. sv = diff18SpecialValue
  198. }
  199.  
  200. winningPair = handicapMap[sv] as! [[String : Any]]
  201. print(winningPair)
  202. // обыграть кейс, когда winningPair содержит больше чем 2 оддса
  203. // составить мапу [specialValueDescription : [odd1, odd2]]
  204.  
  205.  
  206. var currentLowestDiff18: Float = 0.0
  207. var currentPair: [[String: Any]] = []
  208. var winningMap: [String : Any] = [:]
  209.  
  210. var svArray: [String] = []
  211. for odd in winningPair {
  212. let specialValueDescription = odd["specialValueDescription"] as! String
  213. svArray.append(specialValueDescription)
  214. }
  215. svArray.removeDuplicates()
  216.  
  217. for sv in svArray {
  218. var pair: [[String: Any]] = []
  219. for odd in winningPair {
  220. if sv == odd["specialValueDescription"] as! String {
  221. pair.append(odd)
  222. }
  223. }
  224. winningMap[sv] = pair
  225. //////////////////////////// TODO
  226. // for odd in pair {
  227. // mi.oddsList.append(odd as! NSDictionary)
  228. // }
  229. //////////////////////////// TODO
  230. }
  231.  
  232. print(winningMap)
  233. if winningPair.count == 2 {
  234. for odd in winningPair {
  235. mi.oddsList.append(odd as! NSDictionary)
  236. }
  237. } else {
  238. // считай хули
  239. print(winningMap)
  240.  
  241. }
  242.  
  243.  
  244.  
  245.  
  246. }
  247. }
  248.  
  249. }
  250. }
  251. // mi.oddsList.append(handicapOddItem as! NSDictionary)
  252. } else {
  253. mi.oddsList.append(oddItem)
  254. }
  255. } else {
  256. mi.oddsList.append(["coefficient" : "-", "outCome" : outCome])
  257. }
  258. }
Add Comment
Please, Sign In to add comment