Skip to content

Commit

Permalink
feat(java-21-support): added weight reset rake, updated polyglot to i…
Browse files Browse the repository at this point in the history
…nclude java 21
  • Loading branch information
adi-herwana-nus authored and cysjonathan committed Nov 27, 2024
1 parent 379cfc0 commit f945ec1
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ gem 'rubyzip', require: 'zip'
gem 'nokogiri', '>= 1.8.1'

# Polyglot support
gem 'coursemology-polyglot', git: 'https://github.com/Coursemology/polyglot', ref: '14fbbc2'
gem 'coursemology-polyglot', git: 'https://github.com/Coursemology/polyglot', ref: 'b2ffccc'

# To assist with bulk inserts into database
gem 'activerecord-import', '>= 0.2.0'
Expand Down
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ GIT

GIT
remote: https://github.com/Coursemology/polyglot
revision: 14fbbc2943e87479f989056a0ae465f54726c4a1
ref: 14fbbc2
revision: b2ffccc6d0bf11569733eea395e31ac77df139e9
ref: b2ffccc
specs:
coursemology-polyglot (0.3.9)
coursemology-polyglot (0.3.10)
activesupport (>= 4.2)

GIT
Expand Down
8 changes: 4 additions & 4 deletions lib/tasks/db/set_polyglot_language_flags.rake
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true
namespace :db do
# Run this after adding the *_whitelisted columns to polyglot_languages table.
# (20241028141424_add_language_whitelist_flags.rb)

# These whitelists are accurate as of the date this migration is merged and performed (2024-11-18)
# This rake updates the *_whitelisted fields in the polyglot_languages table. It was created
# with the migration introducing these flags (20241028141424_add_language_whitelist_flags.rb)
# It should be run whenever any values in those flags need to be changed
# (e.g. when a new language is added)
CODAVERI_EVALUATOR_WHITELIST =
[
Coursemology::Polyglot::Language::Python::Python3Point4,
Expand Down
46 changes: 46 additions & 0 deletions lib/tasks/db/set_polyglot_language_weights.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# frozen_string_literal: true
namespace :db do
# This rake updates the weight column in the polyglot_languages table,
# changing the order in which languages are displayed in drop-down menus.

LANGUAGE_ORDERING = [
'python',
'java',
'c/c++',
'r',
'javascript'
].freeze

def version_compare(ver1, ver2)
ver1&.split('.')&.map(&:to_i) <=> ver2&.split('.')&.map(&:to_i)
end

def language_compare(lang1, lang2)
index1 = LANGUAGE_ORDERING.index { |l| lang1.polyglot_name == l }
index2 = LANGUAGE_ORDERING.index { |l| lang2.polyglot_name == l }

# Put most recent versions first
return -version_compare(lang1.polyglot_version, lang2.polyglot_version) if index1 == index2
return 1 if index1.nil?
return -1 if index2.nil?

index1 <=> index2
end

task set_polyglot_language_weights: :environment do
# this ensures all languages are loaded in the database table before flags are updated below
Coursemology::Polyglot::Language.load_languages

ActsAsTenant.without_tenant do
ActiveRecord::Base.connection.execute(
'ALTER SEQUENCE polyglot_languages_weight_seq RESTART WITH 1;'
)
# The highest weight is displayed first, so we perform assignments in reverse order
Coursemology::Polyglot::Language.all.sort(&method(:language_compare)).reverse_each do |lang|
ActiveRecord::Base.connection.execute(
"UPDATE polyglot_languages SET weight = nextval('polyglot_languages_weight_seq') WHERE name = '#{lang.name}';"
)
end
end
end
end

0 comments on commit f945ec1

Please sign in to comment.