Skip to content

Commit

Permalink
Update rails
Browse files Browse the repository at this point in the history
  • Loading branch information
ferblape committed Nov 5, 2024
1 parent a06c678 commit 5cb17bb
Show file tree
Hide file tree
Showing 19 changed files with 353 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.2
3.3.4
152 changes: 96 additions & 56 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,67 +1,81 @@
GEM
remote: https://rubygems.org/
specs:
actionmailer (7.1.4.1)
actionpack (= 7.1.4.1)
actionview (= 7.1.4.1)
activejob (= 7.1.4.1)
activesupport (= 7.1.4.1)
mail (~> 2.5, >= 2.5.4)
net-imap
net-pop
net-smtp
actioncable (7.2.2)
actionpack (= 7.2.2)
activesupport (= 7.2.2)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
zeitwerk (~> 2.6)
actionmailbox (7.2.2)
actionpack (= 7.2.2)
activejob (= 7.2.2)
activerecord (= 7.2.2)
activestorage (= 7.2.2)
activesupport (= 7.2.2)
mail (>= 2.8.0)
actionmailer (7.2.2)
actionpack (= 7.2.2)
actionview (= 7.2.2)
activejob (= 7.2.2)
activesupport (= 7.2.2)
mail (>= 2.8.0)
rails-dom-testing (~> 2.2)
actionpack (7.1.4.1)
actionview (= 7.1.4.1)
activesupport (= 7.1.4.1)
actionpack (7.2.2)
actionview (= 7.2.2)
activesupport (= 7.2.2)
nokogiri (>= 1.8.5)
racc
rack (>= 2.2.4)
rack (>= 2.2.4, < 3.2)
rack-session (>= 1.0.1)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
actiontext (7.1.4.1)
actionpack (= 7.1.4.1)
activerecord (= 7.1.4.1)
activestorage (= 7.1.4.1)
activesupport (= 7.1.4.1)
useragent (~> 0.16)
actiontext (7.2.2)
actionpack (= 7.2.2)
activerecord (= 7.2.2)
activestorage (= 7.2.2)
activesupport (= 7.2.2)
globalid (>= 0.6.0)
nokogiri (>= 1.8.5)
actionview (7.1.4.1)
activesupport (= 7.1.4.1)
actionview (7.2.2)
activesupport (= 7.2.2)
builder (~> 3.1)
erubi (~> 1.11)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
activejob (7.1.4.1)
activesupport (= 7.1.4.1)
activejob (7.2.2)
activesupport (= 7.2.2)
globalid (>= 0.3.6)
activemodel (7.1.4.1)
activesupport (= 7.1.4.1)
activerecord (7.1.4.1)
activemodel (= 7.1.4.1)
activesupport (= 7.1.4.1)
activemodel (7.2.2)
activesupport (= 7.2.2)
activerecord (7.2.2)
activemodel (= 7.2.2)
activesupport (= 7.2.2)
timeout (>= 0.4.0)
activestorage (7.1.4.1)
actionpack (= 7.1.4.1)
activejob (= 7.1.4.1)
activerecord (= 7.1.4.1)
activesupport (= 7.1.4.1)
activestorage (7.2.2)
actionpack (= 7.2.2)
activejob (= 7.2.2)
activerecord (= 7.2.2)
activesupport (= 7.2.2)
marcel (~> 1.0)
activesupport (7.1.4.1)
activesupport (7.2.2)
base64
benchmark (>= 0.3)
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
concurrent-ruby (~> 1.0, >= 1.3.1)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
logger (>= 1.4.2)
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
securerandom (>= 0.3)
tzinfo (~> 2.0, >= 2.0.5)
base64 (0.2.0)
benchmark (0.3.0)
bigdecimal (3.1.8)
bootsnap (1.18.3)
bootsnap (1.18.4)
msgpack (~> 1.2)
builder (3.3.0)
byebug (11.1.3)
Expand All @@ -76,7 +90,7 @@ GEM
core_docs (0.9.11)
yard (~> 0.9.11)
crass (1.0.6)
date (3.3.4)
date (3.4.0)
debugging (2.1.0)
paint (>= 0.9, < 3.0)
drb (2.2.1)
Expand All @@ -99,10 +113,10 @@ GEM
interactive_editor (0.0.12)
spoon (~> 0.0.6)
io-console (0.7.2)
irb (1.14.0)
irb (1.14.1)
rdoc (>= 4.0.0)
reline (>= 0.4.2)
irbtools (4.0.11)
irbtools (4.1.0)
clipboard (>= 1.4, < 3.0)
code (>= 0.9.4, < 2.0)
coderay (~> 1.1)
Expand All @@ -112,7 +126,7 @@ GEM
fancy_irb (~> 2.1)
hirb (~> 0.7, >= 0.7.3)
interactive_editor (~> 0.0, >= 0.0.12)
irb (>= 1.12.0, < 1.15)
irb (>= 1.13.0, < 1.15)
looksee (~> 5.0)
methodfinder (~> 2.2, >= 2.2.5)
object_shadow (~> 1.1)
Expand All @@ -124,7 +138,8 @@ GEM
listen (3.9.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
loofah (2.22.0)
logger (1.6.1)
loofah (2.23.1)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
looksee (5.0.0)
Expand All @@ -139,9 +154,8 @@ GEM
mini_mime (1.1.5)
mini_portile2 (2.8.7)
minitest (5.25.1)
msgpack (1.7.2)
mutex_m (0.2.0)
net-imap (0.4.14)
msgpack (1.7.3)
net-imap (0.5.0)
date
net-protocol
net-pop (0.1.2)
Expand All @@ -150,13 +164,14 @@ GEM
timeout
net-smtp (0.5.0)
net-protocol
nio4r (2.7.4)
nokogiri (1.16.7)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
object_shadow (1.1.1)
os (1.1.4)
paint (2.3.0)
pg (1.5.6)
pg (1.5.9)
psych (5.1.2)
stringio
racc (1.8.1)
Expand All @@ -165,39 +180,64 @@ GEM
rack (>= 3.0.0)
rack-test (2.1.0)
rack (>= 1.3)
rails (0.9.5)
actionmailer (>= 0.6.1)
actionpack (>= 1.4.0)
activerecord (>= 1.6.0)
rake (>= 0.4.15)
rackup (2.2.0)
rack (>= 3)
rails (7.2.2)
actioncable (= 7.2.2)
actionmailbox (= 7.2.2)
actionmailer (= 7.2.2)
actionpack (= 7.2.2)
actiontext (= 7.2.2)
actionview (= 7.2.2)
activejob (= 7.2.2)
activemodel (= 7.2.2)
activerecord (= 7.2.2)
activestorage (= 7.2.2)
activesupport (= 7.2.2)
bundler (>= 1.15.0)
railties (= 7.2.2)
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
rails-html-sanitizer (1.6.0)
loofah (~> 2.21)
nokogiri (~> 1.14)
railties (7.2.2)
actionpack (= 7.2.2)
activesupport (= 7.2.2)
irb (~> 1.13)
rackup (>= 1.0.0)
rake (>= 12.2)
thor (~> 1.0, >= 1.2.2)
zeitwerk (~> 2.6)
rake (13.2.1)
rb-fsevent (0.11.2)
rb-inotify (0.11.1)
ffi (~> 1.0)
rdoc (6.7.0)
psych (>= 4.0.0)
reline (0.5.9)
reline (0.5.10)
io-console (~> 0.5)
ruby_engine (2.0.3)
ruby_version (1.0.3)
securerandom (0.3.1)
spoon (0.0.6)
ffi
stringio (3.1.1)
thor (1.3.2)
timeout (0.4.1)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
unicode-display_width (2.6.0)
useragent (0.16.10)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
wirb (2.2.2)
paint (>= 0.9, < 3.0)
yard (0.9.36)
zeitwerk (2.6.16)
yard (0.9.37)
zeitwerk (2.7.1)

PLATFORMS
ruby
Expand All @@ -212,4 +252,4 @@ DEPENDENCIES
rails

BUNDLED WITH
2.1.4
2.5.22
39 changes: 39 additions & 0 deletions bin/data_sync
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

OPTIONS="--defer-constraints --disable-user-triggers --no-sequences"

# guaguas (54499)
# sumar (36105)
# mataro (86518)
# alcobendas (51099)
# barcelona (86160)
# metro madrid (33249)
# IMI (45047)

# all tables
pgsync $OPTIONS

# Manually add new entities here
entities="54499 36105 86518 51099 86160 33249 45047"

for entity_id in $entities; do
# tenders
pgsync $OPTIONS tenders "WHERE contractor_entity_id = ${entity_id}"

# contracts
pgsync $OPTIONS contracts "WHERE contractor_entity_id = ${entity_id}"

# documents
pgsync $OPTIONS documents "WHERE documentable_type = 'Tender' and documentable_id IN (SELECT id from tenders WHERE contractor_entity_id = ${entity_id})"
pgsync $OPTIONS documents "WHERE documentable_type = 'Tender' and documentable_id IN (SELECT id from tenders WHERE contractor_entity_id = ${entity_id})"
done

# refresh views
bin/rails dbviews:refresh_search
bin/rails dbviews:refresh_analysis

# refresh elasticsearch
bin/rails chewy:reset

# refresh internal contracts
bin/rails seed:update_internal_contracts
13 changes: 13 additions & 0 deletions bin/dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

if ! command -v foreman &> /dev/null
then
echo "Installing foreman..."
gem install foreman
fi

if [[ $1 = "--sidekiq" ]] || [[ $1 = "-s" ]]; then
foreman start -f Procfile_with_sidekiq.dev
else
foreman start -f Procfile.dev
fi
15 changes: 15 additions & 0 deletions bin/prepare_experiment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require "csv"

# This file dumps in a CSV the questions and answers from the database
# This CSV will be used later to run the experiment (run_experiment.rb)
# Where an experiment is a variation of the parameters used to generate the answer, the prompt and the weights
# that needs to be measured

CSV.open("base.csv", "wb") do |csv|
csv << ["id", "question", "answer", "prompt", "weights"]
QuestionAnswer.order(id: :asc).each do |qa|
csv << [qa.id, qa.question, qa.answer, qa.prompt, qa.weights]
end
end
3 changes: 3 additions & 0 deletions bin/production_deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

curl -k -XPOST -H "Authorization: Token token="$DEPLOY_BOT_TOKEN $PRODUCTION_DEPLOY_URL
26 changes: 26 additions & 0 deletions bin/run_experiment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

require "csv"

# This file loads the base CSV generated in prepare_experiment.rb, and runs the experiment
# updating the CSV with the new answers and prompts

if ARGV.size != 1
raise "Error: the name of the experiment results file is required. It should include the .csv extension"
end

# Base is generated in prepare_experiment.rb with the current answers and prompts
base_csv = CSV.read("base.csv", headers: true)

CSV.open(ARGV[0], "wb") do |csv|
csv << ["id","question", "answer", "prompt", "weights", "experiment_answer", "experiment_prompt"]
base_csv.each do |row|

qa = QuestionAnswer.find(row["id"])

responder = Assistant::AnswerQuestionWithOpenAI.new(qa.question)
experiment_prompt, _, experiment_answer = responder.call

csv << [row["id"], row["question"], row["answer"], row["prompt"], row["weights"], experiment_answer, experiment_prompt]
end
end
2 changes: 1 addition & 1 deletion bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require "fileutils"
APP_ROOT = File.expand_path("..", __dir__)

def system!(*args)
system(*args, exception: true)
system(*args) || abort("\n== Command #{args} failed ==")
end

FileUtils.chdir APP_ROOT do
Expand Down
17 changes: 17 additions & 0 deletions bin/spring
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env ruby

# This file loads spring without using Bundler, in order to be fast.
# It gets overwritten when you run the `spring binstub` command.

unless defined?(Spring)
require 'rubygems'
require 'bundler'

lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read)
spring = lockfile.specs.detect { |spec| spec.name == "spring" }
if spring
Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
gem 'spring', spring.version
require 'spring/binstub'
end
end
Loading

0 comments on commit 5cb17bb

Please sign in to comment.