Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if name == "handicap" {
- print("--- handicap odd ---")
- print(oddItem)
- for key in oddItem.allKeys {
- if key as! String == "outCome" {
- handicapOddItem[key as! String] = const.string.handicapOdd + outCome
- } else {
- handicapOddItem[key as! String] = oddItem[key]
- }
- }
- print(handicapOddItem)
- // получить селектор
- // постучать в oddsTypeMap с этим селектором
- // выцепить нужные итемы
- // добавить в них oddTypeName
- let handicapSelectors = oddGroup["selectors"] as! [String]
- let selector = handicapSelectors.first!
- var winningPair: [[String : Any]] = []
- if let oddsTypeMap = match["oddsTypeMap"] as? NSDictionary {
- if let handicapItems = oddsTypeMap[selector] as? [String : Any] {
- if let oddTypeName = handicapItems["oddTypeName"] as? String {
- handicapOddItem["oddTypeName"] = oddTypeName
- }
- if let oddsMap = handicapItems["oddsMap"] as? NSDictionary {
- var allValues = oddsMap.allValues as! [[String: Any]]
- var handicapMap: [Float: Any] = [:]
- ///////////////////
- let sortedValues = allValues.sorted {
- abs(Float($0["specialValue"] as! String)!) < abs(Float($1["specialValue"] as! String)!)
- }
- print(sortedValues)
- /////////////////
- var absSpecialValues: [Float] = []
- sortedValues.forEach {
- let specialValue = $0["specialValue"] as! String
- if let floatSpecialValue = Float(specialValue) {
- let absSpecValue = abs(floatSpecialValue)
- absSpecialValues.append(absSpecValue)
- absSpecialValues = absSpecialValues.removeDuplicates()
- }
- }
- print(handicapMap)
- print(absSpecialValues)
- // собрать массив массивов с оддсами с одинаковым спешиалВэлью
- sortedValues.forEach {
- if let floatSpecialValue = Float($0["specialValue"] as! String) {
- let absSpecValue = abs(floatSpecialValue)
- for specialValue in absSpecialValues {
- if specialValue == absSpecValue {
- }
- }
- }
- }
- // составить мапу [abs(specialValue) : 2x oddItem]
- for specialValue in absSpecialValues {
- var sortedBySpecialValueArray: [[String: Any]] = []
- sortedValues.forEach {
- if let floatSpecialValue = Float($0["specialValue"] as! String) {
- let absSpecValue = abs(floatSpecialValue)
- if absSpecValue == specialValue {
- sortedBySpecialValueArray.append($0)
- }
- }
- }
- handicapMap[specialValue] = sortedBySpecialValueArray
- }
- // найти в мапе пару с наименьшей разницей между коэффициентами
- var lowestDiff: Float = 10.0 // default value is needed for (if coeffDiff < currentLowestDiff) to work
- var diffArray: [Float] = []
- var specialValueWithLowestDiff: Float = 0.0
- var specialValueDiffArray: [Float] = []
- for specialValue in absSpecialValues {
- let pair = handicapMap[specialValue]!
- var coeffDiff: Float = 0.0
- var coeffArray: [Float] = []
- for handicapOdd in pair as! NSArray {
- if let coeff = (handicapOdd as! [String: Any])["coefficient"] as? String {
- if let floatCoeff = Float(coeff) {
- coeffArray.append(floatCoeff)
- }
- }
- }
- if coeffArray.count > 1 {
- coeffDiff = abs(coeffArray[0] - coeffArray[1])
- diffArray.append(coeffDiff)
- specialValueDiffArray.append(specialValue)
- }
- if coeffDiff < lowestDiff {
- lowestDiff = coeffDiff
- specialValueWithLowestDiff = specialValue
- }
- }
- // найти пару с коэффициентами ближайшими к 1.8
- var lowestDiff18: Float = 10.0
- var specialValueWithLowestDiff18: Float = 0.0
- var diff18Array: [Float] = []
- var specialValuesDiff18Array: [Float] = []
- for specialValue in absSpecialValues {
- let pair = handicapMap[specialValue]!
- var diff18_1: Float = 0.0
- var diff18_2: Float = 0.0
- var coeffArray: [Float] = []
- for handicapOdd in pair as! NSArray {
- if let coeff = (handicapOdd as! [String: Any])["coefficient"] as? String {
- if let floatCoeff = Float(coeff) {
- coeffArray.append(floatCoeff)
- }
- }
- }
- if coeffArray.count > 1 {
- diff18_1 = abs(coeffArray[0] - 1.8)
- diff18_2 = abs(coeffArray[1] - 1.8)
- let diff18 = (diff18_1 + diff18_2) / 2.0
- // print(diff18)
- diff18Array.append(diff18)
- specialValuesDiff18Array.append(specialValue)
- if diff18 < lowestDiff18 {
- lowestDiff18 = diff18
- specialValueWithLowestDiff18 = specialValue
- }
- }
- }
- // расставить элементы specialValueDiffArray в соответствии с отсортированным diffArray
- var sortDict: [Float : Float] = [:]
- for i in 0..<diffArray.count {
- sortDict[specialValueDiffArray[i]] = diffArray[i]
- }
- var specialValuesSortedByDiff = Array(sortDict.keys).sorted {
- sortDict[$0]! < sortDict[$1]!
- }
- print(specialValuesSortedByDiff)
- var diff18SortDict: [Float : Float] = [:]
- for i in 0..<diff18Array.count {
- diff18SortDict[specialValuesDiff18Array[i]] = diff18Array[i]
- }
- var specialValuesSortedByDiff18 = Array(diff18SortDict.keys).sorted {
- diff18SortDict[$0]! < diff18SortDict[$1]!
- }
- print(specialValuesSortedByDiff18)
- print("== SV for PAIR /w lowest diff ==")
- print(specialValuesSortedByDiff.first!)
- print("== SV for PAIR /w lowest diff18 ==")
- print(specialValuesSortedByDiff.first!)
- if let diffSpecialValue = specialValuesSortedByDiff.first,
- let diff18SpecialValue = specialValuesSortedByDiff.first {
- var sv: Float = 0.0
- if diffSpecialValue == diff18SpecialValue {
- sv = diffSpecialValue
- } else {
- sv = diff18SpecialValue
- }
- winningPair = handicapMap[sv] as! [[String : Any]]
- print(winningPair)
- // обыграть кейс, когда winningPair содержит больше чем 2 оддса
- // составить мапу [specialValueDescription : [odd1, odd2]]
- var currentLowestDiff18: Float = 0.0
- var currentPair: [[String: Any]] = []
- var winningMap: [String : Any] = [:]
- var svArray: [String] = []
- for odd in winningPair {
- let specialValueDescription = odd["specialValueDescription"] as! String
- svArray.append(specialValueDescription)
- }
- svArray.removeDuplicates()
- for sv in svArray {
- var pair: [[String: Any]] = []
- for odd in winningPair {
- if sv == odd["specialValueDescription"] as! String {
- pair.append(odd)
- }
- }
- winningMap[sv] = pair
- //////////////////////////// TODO
- // for odd in pair {
- // mi.oddsList.append(odd as! NSDictionary)
- // }
- //////////////////////////// TODO
- }
- print(winningMap)
- if winningPair.count == 2 {
- for odd in winningPair {
- mi.oddsList.append(odd as! NSDictionary)
- }
- } else {
- // считай хули
- print(winningMap)
- }
- }
- }
- }
- }
- // mi.oddsList.append(handicapOddItem as! NSDictionary)
- } else {
- mi.oddsList.append(oddItem)
- }
- } else {
- mi.oddsList.append(["coefficient" : "-", "outCome" : outCome])
- }
Add Comment
Please, Sign In to add comment