Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[No TIcket] put back code to rank puzzles #375

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ GEM
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
addressable (2.8.1)
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
atlassian-jwt (0.2.1)
jwt (~> 2.1)
aws-eventstream (1.2.0)
aws-partitions (1.613.0)
aws-sdk-core (3.131.5)
aws-partitions (1.621.0)
aws-sdk-core (3.133.0)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.525.0)
aws-sigv4 (~> 1.1)
Expand All @@ -38,10 +38,10 @@ GEM
rexml
differ (0.1.2)
docile (1.4.0)
faraday (2.4.0)
faraday-net_http (~> 2.0)
faraday (2.5.2)
faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4)
faraday-net_http (2.1.0)
faraday-net_http (3.0.0)
ffi (1.15.5)
gitlab (4.19.0)
httparty (~> 0.20)
Expand Down Expand Up @@ -70,31 +70,31 @@ GEM
mime-types-data (~> 3.2015)
mime-types-data (3.2022.0105)
mini_mime (1.1.2)
minitest (5.16.2)
mini_portile2 (2.8.0)
minitest (5.16.3)
mocha (1.14.0)
multi_json (1.15.0)
multi_xml (0.6.0)
multipart-post (2.2.3)
mustermann (2.0.2)
ruby2_keywords (~> 0.0.1)
nokogiri (1.13.8-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.13.8-x86_64-linux)
nokogiri (1.13.8)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
oauth (0.5.10)
octokit (5.1.0)
faraday (>= 1, < 3)
sawyer (~> 0.9)
parallel (1.22.1)
parser (3.1.2.0)
parser (3.1.2.1)
ast (~> 2.4.1)
pdd (0.21.3)
nokogiri (~> 1.10)
rainbow (~> 3.0)
ruby-filemagic (~> 0.7.2)
slop (~> 4.6)
power_assert (2.0.1)
public_suffix (4.0.7)
public_suffix (5.0.0)
racc (1.6.0)
rack (2.2.4)
rack-protection (2.2.2)
Expand All @@ -118,7 +118,7 @@ GEM
rubocop-ast (>= 1.19.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.19.1)
rubocop-ast (1.21.0)
parser (>= 3.1.1.0)
rubocop-rspec (2.12.1)
rubocop (~> 1.31)
Expand Down Expand Up @@ -173,9 +173,7 @@ GEM
slop (~> 4.4)

PLATFORMS
x86_64-darwin-19
x86_64-darwin-21
x86_64-linux
ruby

DEPENDENCIES
atlassian-jwt (~> 0.2.1)
Expand Down Expand Up @@ -207,4 +205,4 @@ DEPENDENCIES
xcop (= 0.7.1)

BUNDLED WITH
2.3.17
2.1.2
59 changes: 59 additions & 0 deletions objects/puzzles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ def group(xml)
# Take some puzzles from the XML and either close their tickets in GitHub
# or create new tickets.
def expose(xml, tickets)
close(xml, tickets)
skip_model = xml.xpath('/puzzles[@model="true"]').empty?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mbao01 I think this flag should be taken from .0pdd configuration file, not from XML

if skip_model
submit(xml, tickets)
else
submit_ranked(xml, tickets)
end
end

def close(xml, tickets)
seen = []
Kernel.loop do
puzzles = xml.xpath(
Expand All @@ -93,6 +103,9 @@ def expose(xml, tickets)
puzzle.search('issue')[0]['closed'] = Time.now.iso8601 if tickets.close(puzzle)
save(xml)
end
end

def submit(xml, tickets)
seen = []
Kernel.loop do
puzzles = xml.xpath(
Expand All @@ -115,4 +128,50 @@ def expose(xml, tickets)
save(xml)
end
end

# Reads the list of all puzzles from the XML in the storage and then
# sorts them in the right order, in which they should be present in the
# backlog.
def rank(puzzles)
LinearModel.new(@repo.name, @storage).predict(
puzzles.map { |puzzle| JSON.parse(Crack::XML.parse(puzzle.to_s).to_json)['puzzle'] }
)
end

def submit_ranked(xml, tickets)
seen = []
unique_puzzles = []
Kernel.loop do
puzzles = xml.xpath(
[
'//puzzle[@alive="true" and (not(issue) or issue="unknown")',
seen.map { |i| "and id != '#{i}'" }.join(' '),
']'
].join(' ')
)
break if puzzles.empty?
puzzle = puzzles[0]
id = puzzle.xpath('id')[0].text
unique_puzzles.append(puzzle.dup)
seen << id
end
submitted = 0
ranked_idx = rank(unique_puzzles)
Kernel.loop do
puzzles = xml.xpath(
'//puzzle[@alive="true" and (not(issue) or issue="unknown")]'
)
break if puzzles.empty? || ranked_idx.empty? || submitted >= @threshold
next_idx = ranked_idx.shift
puzzle = puzzles.find { |p| p.xpath('id')[0].text == unique_puzzles[next_idx].xpath('id')[0].text }
issue = tickets.submit(puzzle)
next if issue.nil?
puzzle.search('issue').remove
puzzle.add_child(
"<issue href='#{issue[:href]}' model='#{next_idx}'>#{issue[:number]}</issue>"
)
save(xml)
submitted += 1
end
end
end
3 changes: 3 additions & 0 deletions objects/tickets/tickets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
# SOFTWARE.

require 'haml'
require 'gitlab'
require 'octokit'
require 'jira-ruby'
require_relative '../truncated'
require_relative '../maybe_text'

Expand Down
10 changes: 10 additions & 0 deletions test/fake_log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,14 @@ def put(tag, text)
@title = text
@tag = tag
end

def get(tag)
end

def delete(time, tag)
end

def list(since = Time.now.to_i)
[]
end
end