kpi_calculation 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e6dd1b36ebfa62e5d4c13bc601a60d4d590634cad4796e8f9dd1dab1b767a686
4
+ data.tar.gz: a14dc77959378e8800308d27f2a252313c2c0cadf476beecb5b7d1e50f621f25
5
+ SHA512:
6
+ metadata.gz: eb951e1b4fa97cde6855a874366be958e91474a2d6287233fa6576536df7e4b03bd8cbcadcdcf89d882c59d281b9614e1f3f09adea046fc6f0359fff07fb18ae
7
+ data.tar.gz: 99f985f6bf225e33a0e107e99272a10a52f36dc5644c72a949ee6efc8df2d3cfc9b66b023ac491127bf6de32bc1e5ced804e05449ca11f8dba33a4a26b8bf7dc
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in kpi_calculation.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # KpiCalculation
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/kpi_calculation`. 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
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ $ bundle add kpi_calculation
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ $ gem install kpi_calculation
16
+
17
+ ## Usage
18
+
19
+ ```Ruby
20
+ # input
21
+ sales_data_object: {performance: 100, interphone: 50, interview: 40, metering: 30, target: 20, contract: 10 }
22
+ days: 3
23
+ ```
24
+
25
+ ```Ruby
26
+ # output
27
+ [{"name":"performance","count":250,"average":83.3,"percent":null},{"name":"interphone","count":150,"average":50.0,"percent":60.0},{"name":"interview","count":100,"average":33.3,"percent":66.6},{"name":"metering","count":60,"average":20.0,"percent":60.0},{"name":"target","count":30,"average":10.0,"percent":50.0},{"name":"contract","count":10,"average":3.3,"percent":33.3}]
28
+ ```
29
+
30
+ ```Ruby
31
+ # input
32
+ sales_data_object:{a: 300, b: 200, c: 40, d: 15, e: 13, f: 9 , g: 6, h: 3, i: 2}
33
+ days:5
34
+ ```
35
+
36
+ ```Ruby
37
+ # output
38
+ [{"name":"a","count":588,"average":117.6,"percent":null},{"name":"b","count":288,"average":57.6,"percent":48.9},{"name":"c","count":88,"average":17.6,"percent":30.5},{"name":"d","count":48,"average":9.6,"percent":54.5},{"name":"e","count":33,"average":6.6,"percent":68.7},{"name":"f","count":20,"average":4.0,"percent":60.6},{"name":"g","count":11,"average":2.2,"percent":55.0},{"name":"h","count":5,"average":1.0,"percent":45.4},{"name":"i","count":2,"average":0.4,"percent":40.0}]
39
+ ```
40
+
41
+ ## Development
42
+
43
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
44
+
45
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
46
+
47
+ ## Contributing
48
+
49
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/kpi_calculation.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "kpi_calculation"
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KpiCalculation
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "kpi_calculation/version"
4
+
5
+ class KpiAggregateService
6
+ def initialize(days, sales_data_object)
7
+ @days = days
8
+ @sales_data_object = sales_data_object
9
+ end
10
+
11
+ # 3. 1つのサービスにpublicなメソッドは、原則1つにする
12
+ def call
13
+ aggregate_kpi
14
+ end
15
+
16
+ private
17
+
18
+ attr_reader :days , :sales_data_object
19
+
20
+ def aggregate_kpi
21
+ keys = sales_data_object.keys
22
+ values = sales_data_object.values
23
+ counter = 0
24
+ sums = values.map do
25
+ sum = values[counter..values.length].sum
26
+ counter = counter + 1
27
+ sum
28
+ end
29
+ keys.map.with_index do |key, index|
30
+ count = sums[index]
31
+ average = sums[index].to_f / days.to_f
32
+ unless index == 0
33
+ percent = sums[index].to_f / sums[index - 1].to_f * 100.to_f
34
+ end
35
+ {
36
+ name: key,
37
+ count: count,
38
+ average: average&.floor(1),
39
+ percent: percent&.floor(1),
40
+ }
41
+ end
42
+
43
+ end
44
+ end
45
+
46
+ module KpiCalculation
47
+ class Error < StandardError; end
48
+
49
+ def self.call(days: days, sales_data_object: sales_data_object)
50
+ kpi_aggregate_service = KpiAggregateService.new(days, sales_data_object)
51
+ kpi = kpi_aggregate_service.call
52
+ end
53
+
54
+ end
55
+
56
+
57
+
@@ -0,0 +1,4 @@
1
+ module KpiCalculation
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kpi_calculation
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - mistake-git
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-07-19 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Please refer to the README for details.
14
+ email:
15
+ - acbmstk0402@gmail.com
16
+ executables:
17
+ - kpi_calculation
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - Gemfile
22
+ - README.md
23
+ - Rakefile
24
+ - exe/kpi_calculation
25
+ - lib/kpi_calculation.rb
26
+ - lib/kpi_calculation/version.rb
27
+ - sig/kpi_calculation.rbs
28
+ homepage:
29
+ licenses: []
30
+ metadata:
31
+ homepage_uri: https://github.com/mistake-git/gem_kpi_calculation.git
32
+ source_code_uri: https://github.com/mistake-git/gem_kpi_calculation.git
33
+ changelog_uri: https://github.com/mistake-git/gem_kpi_calculation.git
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 2.6.0
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubygems_version: 3.0.1
50
+ signing_key:
51
+ specification_version: 4
52
+ summary: A gem that calculates KPIs
53
+ test_files: []