Commits (3)
# Cycling Data
Consume Cycling data from rides then parse said data into csv file for use with other programs.
Consume Cycling data from rides then parse said data into CSV file for use with other programs.
Cycles -> Records Ride Data (time, distance, etc) ->
This was created as a tool to solve my simple problem of entering cycling and training data offline and quickly without fuss on any device that can run a terminal emulator.
## Installation
To install the program run use the crystal compiler to handle it.
``` sh
$ crystal build src/cycling.cr --release
TODO: Write installation instructions here
You can optionally use Cake in the directory to compile. Cake is a version of a Makefile specifically for Crystal projects.
``` sh
$ cake
If you're not familiar with building programs in Crystal or want to know more refer to the [using the compiler section of the crystal docs](https://crystal-lang.org/reference/using_the_compiler/#crystal-build).
## Usage
TODO: Write usage instructions here
``` sh
$ cycling
## Getting Help
The program accepts flags, use `-h` to read about them.
``` sh
$ cycling -h
## Development
TODO: Write development instructions here
No shard dependencies used, but make sure your version of crystal is up to date.
All development happens in the `src/` directory.
## Contributing
......@@ -2,40 +2,104 @@ require "option_parser"
require "csv"
module Cycling
VERSION = "0.1.1"
VERSION = "0.1.3"
# Notes
# Currently just works as a test version, it does the very very basic functions.
# TODO: Break out into components
# Option Flags to select different options for things
OptionParser.parse do |parser|
parser.banner = "Usage: cycling [arguments]"
parser.on("-o", "--output", "Output the data to I/O for use in other programs"){puts "Not Available yet..."}
parser.on("-h", "--help", "Show this help") do
puts parser
parser.invalid_option do |flag|
STDERR.puts "ERROR: #{flag} is not a valid option."
STDERR.puts parser
# Set the data file
data = "data.csv"
@@data_date : Int32 = 0
@@data_dist : Float64 = 0
@@data_time : Float64 = 0
@@data_avgs : Float64 = 0
@@data_maxs : Float64 = 0
@@data_ahrt : Int32 = 0
@@data_cadn : Float64 = 0
@@data_comm : String = ""
@@data : String = "data.csv"
# Create a new file if once doesn't exist
def self.create_file(data)
File.touch(data) # Create new file
def self.create_file()
File.touch(@@data) # Create new file
# Create Header Row
first_row = CSV.build do |csv|
csv.row "Distance (km)", "Time (secs)", "Average Speed (km/h)", "Maximum Speed (km/h)", "Average Heart Rate", "Cadence", "Comments"
csv.row "Date",
"Average Speed",
"Maximum Speed",
"Average Heart Rate",
File.write(data, first_row) # Write to file
File.write(@@data, first_row) # Write to file
# Check if data file exist or create it
File.exists?(data) ? true : Cycling.create_file(data)
# TODO: Have OptionParser create flags for use in the application right around here.
File.exists?(@@data) ? true : Cycling.create_file()
# Create new row of test data
result = CSV.build do |csv|
csv.row 30, 3600, 30, 35, 130, nil, nil
def self.build_file()
# Prompt user for info
puts "Enter your ride details..."
puts "Fields are optional, just press enter to skip"
print "Enter Date (YYYYMMDD):"
d1 = read_line.chomp.to_i
print "Enter Distance (Miles or Kilometers):"
d2 = read_line.chomp.to_f
print "Enter Time (Enter as Seconds):"
d3 = read_line.chomp.to_f
# Write data to file
File.write(data, result, mode: "a")
d4 = (d3*60**2)/d2
print "Enter Max Speed (mph/kmph):"
d5 = read_line.chomp.to_f
print "Enter Average Heart Rate:"
d6 = read_line.chomp.to_i
print "Enter Average Cadence (rmp):"
d7 = read_line.chomp.to_f
print "Enter Comments:"
d8 = read_line.chomp
@@data_date = d1.nil? ? 0 : d1
@@data_dist = d2.nil? ? 0.0 : d2
@@data_time = d3.nil? ? 0.0 : d3
@@data_avgs = d4.nil? ? 0.0 : d4
@@data_maxs = d5.nil? ? 0.0 : d5
@@data_ahrt = d6.nil? ? 0 : d6
@@data_cadn = d7.nil? ? 0.0 : d7
@@data_comm = d8.nil? ? "" : d8
result = CSV.build do |csv|
csv.row @@data_date,
# Write data to file
File.write(@@data, result, mode: "a")
# Some Text to know it all worked.
puts "Success: Data written to #{data}."
puts "Success: Data written to #{@@data}."