...
 
Commits (4)
# Cycling Data
Consume Cycling data from rides then parse said data into CSV file for use with other programs.
Cycles -> Records Ride Data (time, distance, etc) ->
Cycles -> Records Ride Data (time, distance, etc) -> Store Data in CSV -> Access Data
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.
Created as a means 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.
......@@ -19,16 +19,22 @@ $ 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
I wanted it to be simple and not get in the way, so simply running `cycling` should work.
``` sh
$ cycling
```
## Getting Help
### Getting Help
The program accepts flags, use `-h` to read about them.
``` sh
$ cycling -h
```
### Other Flags
I want to add more flags so you can import data from AAT and output into stdout for piping in the console.
I would love to see this work with GnuPlot to create charts in the console, or export to JSON to be used with web programs.
## Development
No shard dependencies used, but make sure your version of crystal is up to date.
All development happens in the `src/` directory.
......
......@@ -2,7 +2,8 @@ require "option_parser"
require "csv"
module Cycling
VERSION = "0.1.3"
VERSION = "0.1.5"
@@data : String = "data.csv"
# Option Flags to select different options for things
OptionParser.parse do |parser|
......@@ -12,6 +13,7 @@ module Cycling
puts parser
exit
end
# If flag unknown show help but show error
parser.invalid_option do |flag|
STDERR.puts "ERROR: #{flag} is not a valid option."
STDERR.puts parser
......@@ -19,21 +21,9 @@ module Cycling
end
end
# Set the data file
@@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()
File.touch(@@data) # Create new file
# Create Header Row
first_row = CSV.build do |csv|
csv.row "Date",
......@@ -45,7 +35,6 @@ module Cycling
"Cadence",
"Comments"
end
File.write(@@data, first_row) # Write to file
end
......@@ -56,49 +45,38 @@ module Cycling
def self.build_file()
# Prompt user for info
puts "Enter your ride details..."
puts "Fields are optional, just press enter to skip"
puts "Fields are optional, just press ENTER to skip"
print "Enter Date (YYYYMMDD):"
d1 = read_line.chomp.to_i
d1 = read_line
print "Enter Distance (Miles or Kilometers):"
d2 = read_line.chomp.to_f
d2 = read_line
print "Enter Time (Enter as Seconds):"
d3 = read_line.chomp.to_f
d4 = (d3*60**2)/d2
print "Enter Max Speed (mph/kmph):"
d5 = read_line.chomp.to_f
d3 = read_line
# d4 will be set below in the conversions
print "Enter Max Speed (MPH or KPH):"
d5 = read_line
print "Enter Average Heart Rate:"
d6 = read_line.chomp.to_i
print "Enter Average Cadence (rmp):"
d7 = read_line.chomp.to_f
d6 = read_line
print "Enter Average Cadence (RPMs):"
d7 = read_line
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
d8 = read_line
# Convert to nil to save on data size
d1 = d1.empty? ? nil : d1.chomp.to_i
d2 = d2.empty? ? nil : d2.chomp.to_f32
d3 = d3.empty? ? nil : d3.chomp.to_f32
d4 = d3.nil? || d2.nil? ? nil : (d3*60**2)/d2
d5 = d5.empty? ? nil : d5.chomp.to_f32
d6 = d6.empty? ? nil : d6.chomp.to_i16
d7 = d7.empty? ? nil : d7.chomp.to_f32
d8 = d8.empty? ? nil : d8.chomp
# Build CSV Row
result = CSV.build do |csv|
csv.row @@data_date,
@@data_dist,
@@data_time,
@@data_avgs,
@@data_maxs,
@@data_ahrt,
@@data_cadn,
@@data_comm
csv.row d1,d2,d3,d4,d5,d6,d7,d8
end
# Write data to file
File.write(@@data, result, mode: "a")
end
Cycling.build_file()
# Some Text to know it all worked.
puts "Success: Data written to #{@@data}."
......