Skip to content

Wartijn/pace-calculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pace calculator is a tool that calculates pace (min/km), distance (km) or time. Enter two of these units as input and the output will be the third unit.

Requirements

Python 3.6 or higher

Usage

Download pacecalc.py and execute it by supplying it with a three-word sentence that's constructed like this: [first_unit] [preposition] [second_unit]

Some examples:

  • ./pacecalc.py 45:00 at 4:40 outputs 11:25km
  • ./pacecalc.py marathon in 2:01:09 outputs 2:52min/km
  • ./pacecalc.py 15km at 3:23 outputs 50:45min/km

Supported sentence formats

  • [distance] in [time] which outputs pace
  • [distance] at [pace] which outputs time
  • [time] at [pace] which outputs distance

Distance inputs

Distance takes a number [n], which can be an integer or a double. The following input formats are accepted:

  • [n], [n]km or [n]k for kilometers.
  • [n]mi for miles

There are two pre-set distances that are not prepended by a number:

  • m or marathon
  • hm or "half marathon". This last one needs to be surrounded by quotes.

Time input

Pace Calculator accepts time input in two different formats: with or without letters.

Without letters

H:M:S. Hours are optional, so 02:03 is 2 minutes and 3 seconds. The numbers can be zero padded, but don't have to be: 01:02:03, 1:2:3 and 1:02:3 are equivalent.

In fact, you can add as many leading zeros as you like and minutes and seconds can be higher than 60. You can write the previous example as 000000062:03 if you like.

With letters

To input time with letters, enter a number [n] followed by an h, m or s for hours minutes or seconds respectively. This is the format [n]h[n]m[n]s, where [n] is an integer and each of the number-letter combinations is optional.

If the only input is either hours or minutes, they can be entered as a double (e.g 1.5m) or as time (e.g 1:30m). This doesn't work for seconds, which only accepts integers.

Time input examples

Some examples of valid inputs:

  • 01h02m03s
  • 01:02:03
  • 1h2m
  • 1h3s
  • 01:02h
  • 2.5m
  • 2:30
  • 90s
  • .5h

These inputs are invalid:

  • 0.5s (seconds are always integers)
  • :30h (time notation needs a number at both sides of the colon. 0:30h and .5h are valid)
  • 30m1h (the order of the letters can't be changed)
  • 1h30 (numbers are always followed by a letter. Add an m or s at the end, or remove all letters and enter 1:30:00)
  • 1:30h20s (only integers are allowed if you use multiple letters. Valid alternatives are: 1:30:20 and 1h30m20s)

Pace input

Pace input is in minutes per kilometer. This can be whole minutes (M), minutes and seconds (M:S e.g. 1:30), or minutes with seconds as a fraction (M.S e.g. 1.5). Just like the time input, leading zeros don't matter and you can add values higher than 60. Unlike the time input, you can't add hours or use letters.

Output

The outputs are given in this format:

  • distance in kilometers, with numbers after the decimal point added where needed. Examples: 12km, 12.1km, 0.12km
  • time in minutes and seconds. Hours are added if time >= 1 hour. Examples 5:00, 1:05:00
  • pace in minutes per kilometer. Minutes and seconds Examples: 5:00min/km, 65:00min/km

Note: Outputs are always in kilometers. Even if the input distance is in miles, pace will be in min/km.

Development

The dependencies can be installed by running poetry install. If you'd like to contribute, please add tests and run black.

Some notes

Negative numbers

It's possible to add negative numbers to the inputs, but this isn't covered in any tests and I might add checks to prevent these inputs.

Supported sentences

The following sentences are supported:

  • [distance] in [time] (output: pace)
  • [distance] at [pace] (output: time)
  • [time] at [pace] (output: distance)

This leaves the following sentences that you could make, but are currently not supported:

  • [pace] [preposition] [time] (output: distance)
  • [pace] [preposition] [distance] (output: time)
  • [time] [preposition] [distance] (output: pace)

The reason they are not supported is that the supported sentences already provide every combination of units, and I don't know what prepositions I should add to the unsupported sentences to turn them into something that make sense. I haven't run into a situation where I felt that I should use anything else than the supported sentences, although that might be because I'm familiar with the limits of this script.

About

A cli tool that calculates your pace, time or distance

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages