Guest User

Untitled

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