/
Rakefile
76 lines (63 loc) · 2.29 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
require 'rubygems'
require 'rake'
require File.join(File.dirname(__FILE__), 'src', 'init')
require 'customer'
require 'level'
namespace :bakery do
desc "Run all the tests"
task :test do
FileList['test/**/*_test.rb', 'test/*_test.rb'].each do |file_path|
require file_path
end
end
desc "reset game data"
task :reset do
`rm -rf #{$BAKERY_HOME}/tmp/*`
end
desc "clears bakery.log"
task :clear do
File.open($BAKERY_LOG_FILE, 'w') { |h| h.write('') }
end
namespace :reporting do
namespace :customers do
def aggregation_for map, criteria
value = criteria.kind_of?(Array) ? criteria.inject(1) {|inj, crit| map[crit]*inj } : map[criteria]
value.is_a?(Symbol) ? value.to_s : value
end
def print_sort_on criteria
Customer::CUSTOMER_CONFIG.sort do |one, other|
aggregation_for(one[1], criteria) <=> aggregation_for(other[1], criteria)
end.each do |customer_details|
values = Array(criteria).inject([]) {|inj, crit| inj << "#{crit} -> #{customer_details[1][crit]}"}
puts "#{customer_details[0]} -> {#{values.join(', ')}}"
end
end
def task_for display_name, *sorted_on
desc "Shows customers sorted on #{display_name}[#{sorted_on.join("*")}]"
task display_name do
print_sort_on(sorted_on.length > 1 ? sorted_on : sorted_on[0])
end
end
task_for :patience_count, :patience_count
task_for :patience_factor, :patience_factor
task_for :patience, :patience_factor, :patience_count
task_for :cost_inclination, :cost_inclination
end
namespace :levels do
desc "Shows customer distribution across levels"
task :customer_distribution do
customer_level_map = {}
Customer::CUSTOMER_CONFIG.each_key do |customer|
Level::LEVELS_CONFIG.each_value do |level_details|
customer_level_map[customer] ||= []
level_details[:customer_types].values.include?(customer) && (customer_level_map[customer] << level_details[:story_dir])
end
end
customer_level_map.each do |customer, level_names|
puts "#{customer} -> #{level_names.join(', ')}"
end
end
end
end
end
task :default => 'bakery:test'