Skip to content

Commit

Permalink
fix to reach target
Browse files Browse the repository at this point in the history
  • Loading branch information
xbjfk committed Mar 15, 2023
1 parent 1b2e8de commit 19f235c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
9 changes: 8 additions & 1 deletion CubeTime/Timer/StopwatchManager/StopwatchManager+Stats.swift
Original file line number Diff line number Diff line change
Expand Up @@ -624,16 +624,23 @@ extension StopwatchManager {


func getTimeNeededForTarget() -> TimeNeededForTarget? {
NSLog("-------------HERE1-------------")
if let compsimSession = currentSession as? CompSimSession {
let solveGroups = compsimSolveGroups!
NSLog("-------------HERE2-------------")

if solveGroups.count == 0 { return nil } else {
let lastGroupSolves = (solveGroups.last!.solves!.allObjects as! [Solve])
NSLog("-------------HERE3-------------")
let lastGroupSolves = (solveGroups.first!.solves!.allObjects as! [Solve])
if lastGroupSolves.count == 4 {
NSLog("-------------HERE4-------------")
let sortedGroup = lastGroupSolves.sorted(by: Self.sortWithDNFsLast)

let timeNeededForTarget = (compsimSession as CompSimSession).target * 3 - (sortedGroup.dropFirst().dropLast().reduce(0) {$0 + $1.timeIncPen})

NSLog("-------------HERE5-------------")
NSLog("TARGET: \((compsimSession as CompSimSession).target)")

if timeNeededForTarget < sortedGroup.last!.time {
return .notPossible
} else if timeNeededForTarget > sortedGroup.first!.time && !sortedGroup.contains(where: {$0.penalty == Penalty.dnf.rawValue}) {
Expand Down
5 changes: 5 additions & 0 deletions CubeTime/Timer/TimerHeader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ struct TimerHeader: View {
(stopwatchManager.currentSession as! CompSimSession).target = time

try! managedObjectContext.save()


stopwatchManager.timeNeededForTarget = stopwatchManager.getTimeNeededForTarget()

stopwatchManager.reachedTargets = stopwatchManager.getReachedTargets()
}
}))
.padding(.trailing, 4)
Expand Down
2 changes: 1 addition & 1 deletion CubeTime/Timer/TimerTools.swift
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ struct TimerStatsCompSim: View {
ThemedDivider()
.padding(.horizontal, 24)

TimerStatRaw(name: "TO REACH TARGET", value: stopwatchManager.wpa == nil ? nil : formatSolveTime(secs: stopwatchManager.wpa!), placeholderText: "...")
TimerStatRaw(name: "TO REACH TARGET", value: timeNeededText, placeholderText: "...")
}
.onTapGesture {
self.showStats = true
Expand Down

0 comments on commit 19f235c

Please sign in to comment.