<commit_before>=begin
  * Name: nyciti_driver.rb
  * Description: 
  * Author: <NAME>
  * Date: 10/24/13
  * License: MIT
=end

require File.expand_path('../../lib/nyciti_bike/models/user.rb', __FILE__)
require File.expand_path('../../lib/nyciti_bike/web_scraper/citi_scraper.rb',
                          __FILE__)
require File.expand_path('../../lib/nyciti_bike/io/file_reader.rb', __FILE__)
require 'highline/import'
require 'optparse'
require 'ostruct'
require 'yaml'

LOGIN_SUCCESS = 'Welcome To Citi Bike!'
LOGIN_INFO = YAML.load_file(File.expand_path('../../config/citi_account.yaml',
                            __FILE__))
SECS_PER_MIN = 60.0

class Optparse

  def self.parse(args)
    # Set default values for options
    options                = OpenStruct.new
    options.trips_file     = nil
    options.trips          = 1
    options.report_full    = true

    opt_parser = OptionParser.new do |opts|
      opts.banner = "Usage: nyciti_driver.rb [options]"
      opts.separator ""
      opts.separator "Specific options:"

      # Optional arguments
      opts.on("-f", "--file [trips.csv]",
              "Use specified file for trips and user information;",
              "  otherwise, download user data from citibikenyc.com") do |file|
        options.trips_file = file
      end

      opts.on("-t", "--trip N", Integer, "Print last N trips") do |n|
        options.trips = n
      end

      opts.on("-s", "--short", "Print short user report") do |v|
        options.report_full = v
      end

      opts.separator ""
      opts.separator "Common options:"

      # Prints options summary
      opts.on_tail("-h", "--help", "Show this message") do
        puts opts
        exit
      end
    end

    opt_parser.parse!(args)
    options
  end

end

options = Optparse.parse(ARGV)

user = nil

if options.trips_file
  user = FileReader.read_trips(options.trips_file)
else
  driver   = CitiCrawler.new
  username = LOGIN_INFO['username']
  password = LOGIN_INFO['password']

  while driver.login(username, password) != LOGIN_SUCCESS
    puts "Wrong username / password"
    username = ask("Username: ")
    password = ask("Password: ") { |q| q.echo = "*" }
  end

  puts LOGIN_SUCCESS

  user = User.new(username)
  user.bike_trips = driver.get_trips
  user.bike_trips_to_csv
end

if options.full_report
  # TODO: add full report here; for now, same as simple
  printf("Total time:\t\t%d minutes\n", user.total_time / SECS_PER_MIN)
  printf("Cost per minute:\t$%.2f\n",   user.effective_cost_per_minute)
  printf("Cost per trip:\t\t$%.2f\n",   user.effective_cost_per_trip)
else
  printf("Total time:\t\t%d minutes\n", user.total_time / SECS_PER_MIN)
  printf("Cost per minute:\t$%.2f\n",   user.effective_cost_per_minute)
  printf("Cost per trip:\t\t$%.2f\n",   user.effective_cost_per_trip)
end
<commit_msg>Replace full report with save option<commit_after>=begin
  * Name: nyciti_driver.rb
  * Description: 
  * Author: <NAME>
  * Date: 10/24/13
  * License: MIT
=end

require File.expand_path('../../lib/nyciti_bike/models/user.rb', __FILE__)
require File.expand_path('../../lib/nyciti_bike/web_scraper/citi_scraper.rb',
                          __FILE__)
require File.expand_path('../../lib/nyciti_bike/io/file_reader.rb', __FILE__)
require 'highline/import'
require 'optparse'
require 'ostruct'
require 'yaml'

LOGIN_SUCCESS = 'Welcome To Citi Bike!'
LOGIN_INFO = YAML.load_file(File.expand_path('../../config/citi_account.yaml',
                            __FILE__))
SECS_PER_MIN = 60.0

class Optparse

  def self.parse(args)
    # Set default values for options
    options                = OpenStruct.new
    options.trips_file     = nil
    options.trips          = 1
    options.save           = false

    opt_parser = OptionParser.new do |opts|
      opts.banner = "Usage: nyciti_driver.rb [options]"
      opts.separator ""
      opts.separator "Specific options:"

      # Optional arguments
      opts.on("-f", "--file [trips.csv]",
              "Use specified file for trips and user information;",
              "  otherwise, download user data from citibikenyc.com") do |file|
        options.trips_file = file
      end

      opts.on("-t", "--trip N", Integer, "Print last N trips") do |n|
        options.trips = n
      end

      opts.on("-s", "--save", "Save date from citibikenyc.com to file") do |v|
        options.save = v
      end

      opts.separator ""
      opts.separator "Common options:"

      # Prints options summary
      opts.on_tail("-h", "--help", "Show this message") do
        puts opts
        exit
      end
    end

    opt_parser.parse!(args)
    options
  end

end

options = Optparse.parse(ARGV)

user = nil

if options.trips_file
  user = FileReader.read_trips(options.trips_file)
else
  driver   = CitiCrawler.new
  username = LOGIN_INFO['username']
  password = LOGIN_INFO['password']

  while driver.login(username, password) != LOGIN_SUCCESS
    puts "Wrong username / password"
    username = ask("Username: ")
    password = ask("Password: ") { |q| q.echo = "*" }
  end

  puts LOGIN_SUCCESS

  user = User.new(username)
  user.bike_trips = driver.get_trips
  user.bike_trips_to_csv if options.save
end

printf("Total time:\t\t%d minutes\n", user.total_time / SECS_PER_MIN)
printf("Cost per minute:\t$%.2f\n",   user.effective_cost_per_minute)
printf("Cost per trip:\t\t$%.2f\n",   user.effective_cost_per_trip)

{'fraction_non_alphanumeric': 0.12710765239948119, 'fraction_numerical': 0.004817491198814156, 'mean_word_length': 2.694729637234771, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '469849', 'n_tokens_mistral': 1844, 'n_tokens_neox': 1793, 'n_words': 412}