boj-solvedac 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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/lib/boj-solvedac.rb +176 -0
  3. data/lib/data/data.rb +82 -0
  4. metadata +45 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ecbc0d0383d854651a218a98a9587de98f18197c71a101782fbbaaf1502e1a16
4
+ data.tar.gz: 42b528416563938285ff1e9bf00a9d5bed8b75faa2230f19d0edf545d410bee3
5
+ SHA512:
6
+ metadata.gz: 5ff573b1aad9e851ea7e7925db17137404e6d04b71c112de28c71d2f7c8a85bd42eb47e854107add7b9c7bc3e4a0be06d4ccccc859f1e3e2fca049ea1270512c
7
+ data.tar.gz: 7e2d8720c33f7c416155b1c1f532723e1074b8ee687c02a058eaf12294ec6d70e92ac95b537a32b05516d05c90cd37f045164aebc80785cc30a3661b870ef32f
@@ -0,0 +1,176 @@
1
+ require 'data/data.rb'
2
+
3
+ module BOJ
4
+ class BOJSolvedAC < BOJData
5
+ def initialize()
6
+ super()
7
+ @prev = ''
8
+ @levels = @@levels
9
+ @stats = {
10
+ "unrated": "0",
11
+ "bronze5": "1", "bronze4": "2", "bronze3": "3", "bronze2": "4", "bronze1": "5",
12
+ "silver5": "6", "silver4": "7", "silver3": "8", "silver2": "9", "silver1": "10",
13
+ "gold5": "11", "gold4": "12", "gold3": "13", "gold2": "14", "gold1": "15",
14
+ "platinum5": "16", "platinum4": "17", "platinum3": "18", "platinum2": "19", "platinum1": "20",
15
+ "diamond5": "21", "diamond4": "22", "diamond3": "23", "diamond2": "24", "diamond1": "25",
16
+ "ruby5": "26", "ruby4": "27", "ruby3": "28", "ruby2": "29", "ruby1": "30"
17
+ }
18
+ system('clear')
19
+ end
20
+
21
+ def command(str)
22
+ if !str.empty? and @prev != str
23
+ @prev = str
24
+ end
25
+ command, level = @prev ? @prev.split : str.split
26
+ command.downcase! if command
27
+ level.downcase! if level
28
+
29
+ case command
30
+ when 'stat' then command_stat(level)
31
+ when 'prob' then command_prob(level)
32
+ when 'random' then command_random(level)
33
+ when 'clear' then system('clear')
34
+ when 'help' then command_help
35
+ when /exit|quit/ then exit(1)
36
+ else
37
+ if command
38
+ puts "'#{command}' not found... try 'help'"
39
+ end
40
+ end
41
+ end
42
+
43
+ def command_stat(level)
44
+ @prev = ''
45
+ if level == "all"
46
+ puts "%-10s %8s %8s %8s" % ["Level", "Unsolved", "Solved", "Total"]
47
+ @stats.each_pair do |k, v|
48
+ stat = @levels[v.to_sym]
49
+ puts "%-10s %8s %8s %8s" % [k, stat[:unsolved], stat[:solved], stat[:total]]
50
+ end
51
+ elsif %w(bronze silver gold platinum diamond ruby).include? level
52
+ 5.downto(1) do |i|
53
+ stat = @levels[@stats[(level+(i.to_s)).to_sym].to_sym]
54
+ puts "%-10s unsolved(%3s) solved(%3s) total(%3s)" % [level+(i.to_s), stat[:unsolved], stat[:solved], stat[:total]]
55
+ end
56
+ else
57
+ if !level or !@stats[level.to_sym]
58
+ puts "'#{level}' level does not exist.."
59
+ return
60
+ end
61
+ stat = @levels[@stats[level.to_sym].to_sym]
62
+ puts "%-10s unsolved(%3s) solved(%3s) total(%3s)" % [level, stat[:unsolved], stat[:solved], stat[:total]]
63
+ end
64
+ end
65
+
66
+ def command_prob(op)
67
+ @prev = ''
68
+ if !op or op.empty? or (op!="solved" and !@stats[op.to_sym])
69
+ puts "'#{op}' op does not exist.."
70
+ return
71
+ end
72
+
73
+ puts "%-10s %-15s" % ["ID", "Title"]
74
+
75
+ if op == "solved"
76
+ level_min = 0
77
+ level_max = 30
78
+ solved = {}
79
+
80
+ for i in level_min..level_max do
81
+ probs = @levels[i.to_s.to_sym][:prob] # id = {title, solved}
82
+ probs.each_pair do |k, v|
83
+ if v[:solved]
84
+ solved[k.to_s.to_i] = {level: @stats.keys[i], title: v[:title]}
85
+ end
86
+ end
87
+ end
88
+
89
+ solved = solved.sort
90
+ i = 0
91
+ solved.each do |prob|
92
+ puts "%-10s%-10s%-15s" % [prob[1][:level], prob[0], prob[1][:title]]
93
+ i+=1
94
+ if (i+1)%10 == 0
95
+ print("..... [q=quit] ")
96
+ q = gets.chomp
97
+ break if q=='q'
98
+ end
99
+ end
100
+ else
101
+ list = @levels[@stats[op.to_sym].to_sym][:prob]
102
+ size = list.size
103
+ i = 0
104
+ list.each_pair do |k, v|
105
+ puts "%-10s %-15s" % [k, v[:title]]
106
+ i += 1
107
+ if (i+1)%15 == 0
108
+ print("..... (#{i}/#{size}) [q=quit] ")
109
+ q = gets.chomp
110
+ break if q=='q'
111
+ end
112
+ end
113
+ end
114
+ puts "----------------------\n"
115
+ end
116
+
117
+ def command_random(level)
118
+ problems = @levels[@stats[level.to_sym].to_sym][:prob] unless level==nil
119
+ level_str = level
120
+
121
+ if level == nil
122
+ max_level = 31
123
+ level = rand(max_level).to_s
124
+ problems = @levels[level.to_sym][:prob]
125
+ level_str = @stats.keys[level.to_i]
126
+ end
127
+
128
+ id = problems.keys[rand(problems.size)]
129
+ title = problems[id][:title]
130
+
131
+ puts
132
+ puts "Level: #{level_str}"
133
+ puts "ID : #{id} (https://www.acmicpc.net/problem/#{id})"
134
+ puts "Title: #{title}"
135
+ puts
136
+ end
137
+
138
+ def command_help
139
+ puts '''
140
+ levels you can specify:
141
+ unrated
142
+ bronze[5-1] (bronze5, bronze4, ...)
143
+ silver[5-1]
144
+ gold[5-1]
145
+ platinum[5-1]
146
+ diamond[5-1]
147
+ ruby[5-1]
148
+
149
+ Commands:
150
+ prob:
151
+ prob [LEVEL] --> display all [LEVEL] problems
152
+ prob solved --> display all solved problems by ID
153
+ stat:
154
+ stat [LEVEL | all] --> display [LEVEL]\'s or all levels
155
+ unsolved/solved/total stats
156
+ random:
157
+ random --> randomly pick a problem from all levels
158
+ random [LEVEL] --> randomly pick a problem from [LEVEL]
159
+ * hit [ENTER] to repeat the previous \'random\' command
160
+ clear:
161
+ clear --> clears the screen
162
+ exit:
163
+ exit --> terminate the program
164
+ quit:
165
+ alias to \'exit\'
166
+ '''
167
+ end
168
+
169
+ def start
170
+ while true do
171
+ print("boj-solvedac> ")
172
+ command(gets.chomp)
173
+ end
174
+ end
175
+ end
176
+ end
@@ -0,0 +1,82 @@
1
+ class BOJData
2
+ def initialize()
3
+ @@levels = {}
4
+ fetch_data
5
+ end
6
+
7
+ def fetch_data
8
+ fetch_level_data
9
+ fetch_problems_data
10
+ fetch_solved_data
11
+ end
12
+
13
+ def fetch_level_data
14
+ puts "Feteching level stats..."
15
+ if !File::exists?("stats/level-stat.dat")
16
+ system("clear")
17
+ puts "'stats/level-stat.dat' does not exist... fetching"
18
+ system("mkdir stats 2> /dev/null")
19
+ system("curl -o stats/level-stat.dat https://raw.githubusercontent.com/jioneeu/boj-solvedac/master/lib/data/stats/level-stat.dat")
20
+ end
21
+ stats = IO.readlines("stats/level-stat.dat")
22
+ stats.each do |stat|
23
+ stat = stat.split(',')
24
+ level = stat[0]
25
+ unsolved = stat[1]
26
+ solved = stat[2]
27
+ total = stat[3].chomp
28
+
29
+ @@levels[level.to_sym] = {unsolved: unsolved, solved: solved, total: total, prob: {}}
30
+ end
31
+ end
32
+
33
+ def fetch_problems_data
34
+ puts "fetching problems...."
35
+ system("mkdir stats/problems 2> /dev/null")
36
+ level_min = 0
37
+ level_max = 30
38
+ for i in level_min..level_max do
39
+ path = "stats/problems/level#{i}.dat"
40
+ if !File::exists?(path)
41
+ system("clear")
42
+ puts "'stats/problems/level#{i}.dat' does not exist... fetching"
43
+ system("curl -o stats/problems/level#{i}.dat https://raw.githubusercontent.com/jioneeu/boj-solvedac/master/lib/data/stats/problems/level#{i}.dat")
44
+ end
45
+ arr = IO.readlines(path)
46
+ # problem id, title
47
+ arr.each do |prob|
48
+ id, title = prob.chomp.split(',')
49
+ solved = false
50
+ @@levels[i.to_s.to_sym][:prob][id.to_sym] = {title: title, solved: solved}
51
+ end
52
+ end
53
+ end
54
+
55
+ def fetch_solved_data
56
+ path = "stats/solved-problems.dat"
57
+ if !File::exists?(path)
58
+ puts "No solved data exists... skipping"
59
+ return
60
+ end
61
+ File.open("stats/solved-problems.dat", "r+")
62
+ solved = IO.read(path).to_s.chomp.split(' ')
63
+ solved_size = solved.size
64
+ level_min = 0
65
+ level_max = 30
66
+
67
+ for i in level_min..level_max do
68
+ solved_prob = 0
69
+ level = @@levels[i.to_s.to_sym][:prob] # id = {title, solved}
70
+ solved.each do |solved_id|
71
+ if level[solved_id.to_sym] != nil
72
+ level[solved_id.to_sym][:solved] = true
73
+ solved_prob += 1
74
+ end
75
+ end
76
+ @@levels[i.to_s.to_sym][:solved] = solved_prob
77
+ @@levels[i.to_s.to_sym][:unsolved] = ((@@levels[i.to_s.to_sym][:unsolved].to_i) - solved_prob).to_s
78
+
79
+ break if solved_prob == solved_size
80
+ end
81
+ end
82
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: boj-solvedac
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jione Eu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-05-25 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/boj-solvedac.rb
20
+ - lib/data/data.rb
21
+ homepage: https://solved.ac/
22
+ licenses:
23
+ - MIT
24
+ metadata:
25
+ documentation_uri: https://github.com/jioneeu/boj-solvedac
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubygems_version: 3.1.2
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Baekjoon Online Judge - Solved.ac Command Line Interface tool
45
+ test_files: []