time_cop 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2258a186bbf4d192ec0abac9e6f22dd176d3f8c9
4
+ data.tar.gz: 958bf194c3cb02fc9d43bda2fab21c6f0ff71ab9
5
+ SHA512:
6
+ metadata.gz: e482ce70b329d5cc198d869e781689d4984275e5a30743e1724e0e004f4489033d056a8e196d1ac2bded0669395f6c10566216c872c635c7ce0afb04b5e369b3
7
+ data.tar.gz: e2430db898725e400db4bdc078ff6f9f14af33c285a860ce32cc862104254c9f989e04fe3622ed3f16dd2c24a01649a87fcbf67e85ad3c6cc1106926b1fd365a
data/.editorconfig ADDED
@@ -0,0 +1,42 @@
1
+ # EditorConfig helps developers define and maintain consistent
2
+ # coding styles between different editors and IDEs
3
+ # editorconfig.org
4
+
5
+ root = true
6
+
7
+
8
+ [*]
9
+ end_of_line = lf
10
+ charset = utf-8
11
+ trim_trailing_whitespace = true
12
+ insert_final_newline = true
13
+ indent_style = space
14
+ indent_size = 2
15
+
16
+ [*.rb]
17
+ indent_style = space
18
+ indent_size = 2
19
+
20
+ [*.yml]
21
+ indent_style = space
22
+ indent_size = 2
23
+
24
+ [*.js]
25
+ indent_style = space
26
+ indent_size = 2
27
+
28
+ [*.hbs]
29
+ indent_style = space
30
+ indent_size = 2
31
+
32
+ [*.css]
33
+ indent_style = space
34
+ indent_size = 2
35
+
36
+ [*.html]
37
+ indent_style = space
38
+ indent_size = 2
39
+
40
+ [*.md]
41
+ trim_trailing_whitespace = false
42
+
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ *.swp
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.1
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.3
5
+ before_install: gem install bundler -v 1.13.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at samsinite@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in time_cop.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # TimeCop
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/time_cop`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'time_cop'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install time_cop
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/time_cop. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ require "bundler"
2
+ require "bundler/gem_tasks"
3
+ require "rake/testtask"
4
+
5
+ Bundler::GemHelper.install_tasks
6
+
7
+ Rake::TestTask.new(:test) do |t|
8
+ t.libs << "test"
9
+ t.libs << "lib"
10
+ t.test_files = FileList['test/**/*_test.rb']
11
+ end
12
+
13
+ task :default => :test
14
+
15
+ task :console do
16
+ require 'irb'
17
+ require 'irb/completion'
18
+ require 'pry'
19
+ require 'time_cop' # You know what to do.
20
+ ARGV.clear
21
+ IRB.start
22
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "time_cop"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/time_cop ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'time_cop'
4
+ require 'time_cop/runner'
5
+
6
+ TimeCop::Runner.invoke
@@ -0,0 +1,156 @@
1
+ require 'harvested'
2
+ require 'date'
3
+
4
+ module TimeCop
5
+ class Accountability
6
+ attr_reader :report_builder, :client, :date
7
+
8
+ DAYS_PER_WEEK = 5
9
+ HOURS_PER_WEEK = 32
10
+ HOURS_PER_DAY = HOURS_PER_WEEK / DAYS_PER_WEEK
11
+
12
+ QUARTERLY_PERIODS = {
13
+ q1: [{month: 1, day: 1}, {month: 3, day: 31}],
14
+ q2: [{month: 4, day: 1}, {month: 6, day: 30}],
15
+ q3: [{month: 7, day: 1}, {month: 9, day: 30}],
16
+ q4: [{month: 10, day: 1}, {month: 12, day: 31}]
17
+ }
18
+
19
+ def initialize(username:, password:, subdomain: 'wildland', date: Date.today, report_builder: nil)
20
+ @client = Harvest.client(username: username, password: password, subdomain: subdomain)
21
+ @date = date
22
+ @report_builder = report_builder ||
23
+ ReportBuilder.new(
24
+ client: client,
25
+ user: user,
26
+ start_date: start_of_quarter_date,
27
+ end_date: end_of_quarter_date
28
+ )
29
+ end
30
+
31
+ def account
32
+ client.account
33
+ end
34
+
35
+ def user
36
+ account.who_am_i
37
+ end
38
+
39
+ def date_from_period(period)
40
+ Date.new(date.year, period[:month], period[:day])
41
+ end
42
+
43
+ def select_quarter
44
+ QUARTERLY_PERIODS.select do |quarter, range|
45
+ start_of_range = range[0]
46
+ end_of_range = range[1]
47
+
48
+ start_date_of_range = date_from_period(start_of_range)
49
+ end_date_of_range = date_from_period(end_of_range)
50
+
51
+ (date >= start_date_of_range) && (date <= end_date_of_range)
52
+ end
53
+ end
54
+
55
+ def get_quarter
56
+ select_quarter.first[1]
57
+ end
58
+
59
+ def start_of_quarter_date
60
+ date_from_period(get_quarter[0])
61
+ end
62
+
63
+ def end_of_quarter_date
64
+ date_from_period(get_quarter[1])
65
+ end
66
+
67
+ def quarterly_tracked_time_by_user
68
+ @quarterly_tracked_time_by_user ||= report_builder.generate
69
+ end
70
+
71
+ def total_quarter_time_tracked
72
+ quarterly_tracked_time_by_user.map { |t| t.hours }.reduce(:+)
73
+ end
74
+
75
+ def total_quarter_days
76
+ (end_of_quarter_date - start_of_quarter_date).to_i
77
+ end
78
+
79
+ def business_days_between(start_date, end_date)
80
+ days_between = (end_date - start_date).to_i
81
+ return 0 unless days_between > 0
82
+
83
+ # Assuming we need to calculate days from 9th to 25th, 10-23 are covered
84
+ # by whole weeks, and 24-25 are extra days.
85
+ #
86
+ # Su Mo Tu We Th Fr Sa # Su Mo Tu We Th Fr Sa
87
+ # 1 2 3 4 5 # 1 2 3 4 5
88
+ # 6 7 8 9 10 11 12 # 6 7 8 9 ww ww ww
89
+ # 13 14 15 16 17 18 19 # ww ww ww ww ww ww ww
90
+ # 20 21 22 23 24 25 26 # ww ww ww ww ed ed 26
91
+ # 27 28 29 30 31 # 27 28 29 30 31
92
+ whole_weeks, extra_days = days_between.divmod(7)
93
+
94
+ unless extra_days.zero?
95
+ # Extra days start from the week day next to start_day,
96
+ # and end on end_date's week date. The position of the
97
+ # start date in a week can be either before (the left calendar)
98
+ # or after (the right one) the end date.
99
+ #
100
+ # Su Mo Tu We Th Fr Sa # Su Mo Tu We Th Fr Sa
101
+ # 1 2 3 4 5 # 1 2 3 4 5
102
+ # 6 7 8 9 10 11 12 # 6 7 8 9 10 11 12
103
+ # ## ## ## ## 17 18 19 # 13 14 15 16 ## ## ##
104
+ # 20 21 22 23 24 25 26 # ## 21 22 23 24 25 26
105
+ # 27 28 29 30 31 # 27 28 29 30 31
106
+ #
107
+ # If some of the extra_days fall on a weekend, they need to be subtracted.
108
+ # In the first case only corner days can be days off,
109
+ # and in the second case there are indeed two such days.
110
+ extra_days -= if start_date.next_day.wday <= end_date.wday
111
+ [start_date.next_day.sunday?, end_date.saturday?].count(true)
112
+ else
113
+ 2
114
+ end
115
+ end
116
+
117
+ (whole_weeks * 5) + extra_days
118
+ end
119
+
120
+ def total_week_days
121
+ business_days_between(start_of_quarter_date, end_of_quarter_date)
122
+ end
123
+
124
+ def expected_quarter_hours
125
+ total_week_days.to_f * HOURS_PER_DAY
126
+ end
127
+
128
+ def expected_quarter_hours_to_today
129
+ business_days_between(start_of_quarter_date, date) * HOURS_PER_DAY
130
+ end
131
+
132
+ def current_hours_delta
133
+ total_quarter_time_tracked - expected_quarter_hours_to_today
134
+ end
135
+
136
+ def quarterly_hours_delta
137
+ expected_quarter_hours - total_quarter_time_tracked
138
+ end
139
+
140
+ def quarterly_hours_per_business_day_needed
141
+ if business_days_between(date, end_of_quarter_date) == 0
142
+ quarterly_hours_delta
143
+ else
144
+ quarterly_hours_delta / business_days_between(date, end_of_quarter_date).to_f
145
+ end
146
+ end
147
+
148
+ def print_report
149
+ puts "Current Surplus(+)/Deficit(-): #{current_hours_delta.round(2)}"
150
+ puts "Quarterly Hour Target: #{expected_quarter_hours.round(2)}"
151
+ puts "Current Quarterly Charged Hours: #{total_quarter_time_tracked.round(2)}"
152
+ puts "Total Hours Needed By End Of Quarter: #{quarterly_hours_delta.round(2)}"
153
+ puts "Hours Per Business Day Average Needed To Reach Goal: #{quarterly_hours_per_business_day_needed.round(2)}"
154
+ end
155
+ end
156
+ end
@@ -0,0 +1,39 @@
1
+ require 'optparse'
2
+
3
+ module TimeCop
4
+ class OptionParser
5
+ attr_reader :args
6
+
7
+ def initialize(args)
8
+ @args = args
9
+ end
10
+
11
+ def parse
12
+ options = {}
13
+ option_parser = ::OptionParser.new do |opts|
14
+ opts.on("-u USERNAME", "--username=USERNAME", "Username to authenticate as") do |username|
15
+ options[:username] = username
16
+ end
17
+
18
+ opts.on("-p PASSWORD", "--password=PASSWORD", "Passsword to authenticate with") do |password|
19
+ options[:password] = password
20
+ end
21
+
22
+ opts.on("-h", "--help", "Prints help") do
23
+ puts opts
24
+ exit
25
+ end
26
+ end
27
+
28
+ option_parser.parse(args)
29
+
30
+ unless options[:username] && options[:password]
31
+ puts "Please specify a username and password"
32
+ puts option_parser
33
+ exit
34
+ end
35
+
36
+ options
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,22 @@
1
+ module TimeCop
2
+ class ReportBuilder
3
+ attr_reader :client, :user, :start_date, :end_date
4
+
5
+ def initialize(client:, user:, start_date:, end_date:)
6
+ @client = client
7
+ @user = user
8
+ @start_date = start_date
9
+ @end_date = end_date
10
+ end
11
+
12
+ def generate
13
+ reports.time_by_user(user, start_date, end_date)
14
+ end
15
+
16
+ private
17
+
18
+ def reports
19
+ client.reports
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,13 @@
1
+ require 'time_cop/option_parser'
2
+
3
+ module TimeCop
4
+ class Runner
5
+ def self.invoke
6
+ options_parser = OptionParser.new(ARGV)
7
+ options = options_parser.parse
8
+
9
+ accountability = Accountability.new(username: options[:username], password: options[:password])
10
+ accountability.print_report
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module TimeCop
2
+ VERSION = "0.1.0"
3
+ end
data/lib/time_cop.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "time_cop/version"
2
+ require "time_cop/accountability"
3
+ require "time_cop/report_builder"
4
+
5
+ module TimeCop
6
+ # Your code goes here...
7
+ end
data/time_cop.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'time_cop/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "time_cop"
8
+ spec.version = TimeCop::VERSION
9
+ spec.authors = ["Sam Clopton"]
10
+ spec.email = ["samsinite@gmail.com"]
11
+
12
+ spec.summary = %q{Wildland Time Accountability App}
13
+ spec.description = %q{Helps Wildland employees know how much time they have tracked, what their target hours are, and more.}
14
+ spec.homepage = "https://github.com/wildland/time_cop"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ #spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against " \
22
+ "public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_runtime_dependency "harvested", "~> 3.1.1"
33
+
34
+ spec.add_development_dependency "bundler", "~> 1.13"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "minitest", "~> 5.0"
37
+ spec.add_development_dependency "pry"
38
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: time_cop
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sam Clopton
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-01-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: harvested
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 3.1.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 3.1.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.13'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.13'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Helps Wildland employees know how much time they have tracked, what their
84
+ target hours are, and more.
85
+ email:
86
+ - samsinite@gmail.com
87
+ executables:
88
+ - time_cop
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".editorconfig"
93
+ - ".gitignore"
94
+ - ".ruby-version"
95
+ - ".travis.yml"
96
+ - CODE_OF_CONDUCT.md
97
+ - Gemfile
98
+ - README.md
99
+ - Rakefile
100
+ - bin/console
101
+ - bin/setup
102
+ - exe/time_cop
103
+ - lib/time_cop.rb
104
+ - lib/time_cop/accountability.rb
105
+ - lib/time_cop/option_parser.rb
106
+ - lib/time_cop/report_builder.rb
107
+ - lib/time_cop/runner.rb
108
+ - lib/time_cop/version.rb
109
+ - time_cop.gemspec
110
+ homepage: https://github.com/wildland/time_cop
111
+ licenses: []
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.5.1
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Wildland Time Accountability App
133
+ test_files: []