* * GetProgress to track state of a progress bar @param startTime (time.Time) - the time at which an event started @param expectedDuration (time.Duration) - how long the event is expected to last @return (float64) - the proportion of status bar completion */
(startTime time.Time, expectedDuration time.Duration)
| 14 | @return (float64) - the proportion of status bar completion |
| 15 | */ |
| 16 | func GetProgress(startTime time.Time, expectedDuration time.Duration) float64 { |
| 17 | elapsed := time.Since(startTime) |
| 18 | if elapsed <= 0 { |
| 19 | return 0 |
| 20 | } |
| 21 | if expectedDuration <= 0 { |
| 22 | return 1 |
| 23 | } |
| 24 | if elapsed <= expectedDuration { |
| 25 | return 0.8 * (float64(elapsed) / float64(expectedDuration)) |
| 26 | } |
| 27 | |
| 28 | over := elapsed - expectedDuration |
| 29 | ratio := float64(over) / float64(expectedDuration) |
| 30 | return 1 - 0.2*math.Exp(-ratio) |
| 31 | } |
| 32 | |
| 33 | func EstimateInstanceRestorationDurationGB(sizeGB int) time.Duration { |
| 34 | return estimateInstanceStorageTransferDurationGB(sizeGB) |
no outgoing calls
no test coverage detected