Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Add new fields from gdynia api (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anakin100100 authored Apr 3, 2022
1 parent 6adab4e commit 11d3996
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 22 deletions.
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ GEM
crack (0.4.5)
rexml
crass (1.0.6)
debug (1.4.0)
debug (1.5.0)
irb (>= 1.3.6)
reline (>= 0.2.7)
devise (4.8.1)
Expand Down Expand Up @@ -157,15 +157,15 @@ GEM
nokogiri (1.13.3-x86_64-linux)
racc (~> 1.4)
orm_adapter (0.5.0)
parallel (1.22.0)
parallel (1.22.1)
parser (3.1.1.0)
ast (~> 2.4.1)
pg (1.3.4)
pg_search (2.3.6)
activerecord (>= 5.2)
activesupport (>= 5.2)
public_suffix (4.0.6)
puma (5.6.2)
puma (5.6.4)
nio4r (~> 2.0)
raabro (1.4.0)
racc (1.6.0)
Expand Down
10 changes: 8 additions & 2 deletions app/clients/gdynia_extra_data_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@ def raw_schools
raw_data = JSON.parse(response.body)

raw_data.map do |raw_record|
# We are interested in the following fields: "w51", "wx2", "wx3", "w68", "w88"
# We are intersted in the following fields: "w51", "wx2", "wx3", "w68", "w88",
# "opis_szkoły", "sport", "jezyki_obce", "profile_klas", "zajecia_dodatkowe"
{
'rspo' => raw_record.fetch('rspo').to_i,
'w51' => raw_record.fetch('w51').to_i,
'wx2' => raw_record.fetch('wx2').to_i,
'wx3' => raw_record.fetch('wx3').to_i,
'w68' => raw_record.fetch('w68').to_f,
'w88' => raw_record.fetch('w88').to_f
'w88' => raw_record.fetch('w88').to_f,
'opis_szkoly' => raw_record.fetch('opis_szkoly'),
'sport' => raw_record.fetch('sport'),
'jezyki_obce' => raw_record.fetch('jezyki_obce'),
'profile_klas' => raw_record.fetch('profile_klas'),
'zajecia_dodatkowe' => raw_record.fetch('zajecia_dodatkowe')
}
end
end
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/institutions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ def index
@paginated_institutions = institutions.paginate(page: @page, per_page: @page_size)

render status: '200', json: {
"results": @paginated_institutions,
"page": @page,
"totalItems": @paginated_institutions.size,
results: @paginated_institutions,
page: @page,
totalItems: Institution.count
}
end

Expand Down
13 changes: 12 additions & 1 deletion app/services/gdynia_extra_data_mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@
# "wx3","Oddziały sportowe"
# "w68","Zmianowość"
# "w88","Liczba uczniów na nauczyciela"
# "opis_szkoły","Opis szkoły"
# "sport", "Zajęcia sportowe oferowane przez szkołę"
# "jezyki_obce", "Zajęcia językowe oferowane przez szkołę"
# "profile_klas", "Profile klas które są oferowane przez daną szkołę"
# "zajecia_dodatkowe", "Zajęcia dodatkowe oferowane przez szkołę"

# We are intersted in the following fields: "w51", "wx2", "wx3", "w68", "w88"
# We are intersted in the following fields: "w51", "wx2", "wx3", "w68", "w88",
# "opis_szkoły", "sport", "jezyki_obce", "profile_klas", "zajecia_dodatkowe"
class GdyniaExtraDataMapper < ApplicationService
def call(raw_data)
raw_data.each do |raw_school|
Expand All @@ -29,6 +35,11 @@ def call(raw_data)
rspo_match[:sport_facilities] = raw_school.fetch('wx3')
rspo_match[:working_time] = raw_school.fetch('w68')
rspo_match[:students_per_teacher] = raw_school.fetch('w88')
rspo_match[:description] = raw_school.fetch('opis_szkoly')
rspo_match[:sports] = raw_school.fetch('sport').join(',')
rspo_match[:foreign_languages] = raw_school.fetch('jezyki_obce').join(',')
rspo_match[:class_profiles] = raw_school.fetch('profile_klas').join(',')
rspo_match[:extracurricular_activities] = raw_school.fetch('zajecia_dodatkowe').join(',')

rspo_match.save
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AddNewFieldsFromGdyniaToInstitutions < ActiveRecord::Migration[7.0]
def change
add_column :institutions, :description, :string
add_column :institutions, :sports, :string
add_column :institutions, :foreign_languages, :string
add_column :institutions, :class_profiles, :string
add_column :institutions, :extracurricular_activities, :string
end
end
7 changes: 6 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2022_02_12_134157) do
ActiveRecord::Schema[7.0].define(version: 2022_03_31_043816) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
enable_extension "plpgsql"
Expand Down Expand Up @@ -76,6 +76,11 @@
t.string "county", null: false
t.string "municipality", null: false
t.string "town", null: false
t.string "description"
t.string "sports"
t.string "foreign_languages"
t.string "class_profiles"
t.string "extracurricular_activities"
t.index ["institution_type_id"], name: "index_institutions_on_institution_type_id"
end

Expand Down
12 changes: 12 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,15 @@ paramenters:
id:int, required
it specifies the internal id of the institution to be shown
this is not the RSPO id of the institution


### Institution model

in the institution model the data that comes from Gdyania API as a list is joined using a comma. for example

"zajecia_dodatkowe": [
"klub turystyczny",
"sekcja karate"
]

institution_from_gdynia.exatracurricular_activities will return "klub turystyczny,sekcja karate"
46 changes: 44 additions & 2 deletions spec/clients/gdynia_extra_data_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,38 @@

require 'rails_helper'

# Field info
# kod,nazwa,komentarz,opis,ikona,jednostka,okres,ostatnia_aktualizacja
# "w92","Liczba etatów przypadających na jednego nauczyciela"
# "w110","Nauczyciele wspomagający"
# "w161","Uczniowie pochodzący spoza Gdyni"
# "w51","Klasy integracyjne"
# "wx1","Aktualny dzienny koszt oświaty"
# "wx2","Liczba sal lekcyjnych"
# "wx3","Oddziały sportowe"
# "w68","Zmianowość"
# "w88","Liczba uczniów na nauczyciela"
# "opis_szkoły","Opis szkoły"
# "sport", "Zajęcia sportowe oferowane przez szkołę"
# "jezyki_obce", "Zajęcia językowe oferowane przez szkołę"
# "profile_klas", "Profile klas które są oferowane przez daną szkołę"
# "zajecia_dodatkowe", "Zajęcia dodatkowe oferowane przez szkołę"

# We are intersted in the following fields: "w51", "wx2", "wx3", "w68", "w88",
# "opis_szkoły", "sport", "jezyki_obce", "profile_klas", "zajecia_dodatkowe"

# Database fields:
# add_column :institutions, :integration_classes, :integer
# add_column :institutions, :classrooms, :integer
# add_column :institutions, :sport_facilities, :integer
# add_column :institutions, :working_time, :integer
# add_column :institutions, :studerns_per_teacher, :integer
# add_column :institutions, :description, :string
# add_column :institutions, :sports, :string
# add_column :institutions, :foreign_languages, :string
# add_column :institutions, :class_profiles, :string
# add_column :institutions, :extracurricular_activities, :string

RSpec.describe 'GdyniaExtraDataClient' do
describe '#raw_schools' do
# We are disabling webmock because we want to connect to the real api
Expand All @@ -24,15 +56,25 @@
'wx3' => 30,
'w68' => 40,
'w88' => 50,
'rspo' => institution_1.rspo_institution_id
'rspo' => institution_1.rspo_institution_id,
'opis_szkoly' => 'Opis szkoły',
'sport' => ['koszykówka', 'siatkówka'],
'jezyki_obce' => ['angielski', 'niemiecki'],
'profile_klas' => ['matematyczny', 'fizyczny'],
'zajecia_dodatkowe' => ['chór', 'matematyka']
},
{
'w51' => 101,
'wx2' => 201,
'wx3' => 301,
'w68' => 401,
'w88' => 501,
'rspo' => institution_2.rspo_institution_id
'rspo' => institution_2.rspo_institution_id,
'opis_szkoly' => 'Opis szkoły',
'sport' => ['koszykówka', 'siatkówka'],
'jezyki_obce' => ['angielski', 'niemiecki'],
'profile_klas' => ['matematyczny', 'fizyczny'],
'zajecia_dodatkowe' => ['chór', 'matematyka']
}
]

Expand Down
16 changes: 8 additions & 8 deletions spec/requests/get_all_institutions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

it 'returns 10 institutions when no page_size is specified' do
get '/institutions'
expect(JSON.parse(response.body)["results"].size).to equal(10)
expect(JSON.parse(response.body)['results'].size).to equal(10)
end

it 'returns the correct number of institutions when page_size is specified' do
(1..20).each do |page_size|
get '/institutions', params: { page_size: page_size }
expect(JSON.parse(response.body)["results"].size).to equal(page_size)
expect(JSON.parse(response.body)["totalItems"]).to equal(page_size)
expect(JSON.parse(response.body)['results'].size).to equal(page_size)
expect(JSON.parse(response.body)['totalItems']).to equal(Institution.count)
end
end

Expand All @@ -35,14 +35,14 @@
end

it "returns empty array when there aren't enough institutions" do
get '/institutions', params: { page: 99999999 }
expect(JSON.parse(response.body)["results"].size).to equal(0)
expect(JSON.parse(response.body)["page"]).to equal(99999999)
get '/institutions', params: { page: 99_999_999 }
expect(JSON.parse(response.body)['results'].size).to equal(0)
expect(JSON.parse(response.body)['page']).to equal(99_999_999)
end

it "returns the correct page when page is specified" do
it 'returns the correct page when page is specified' do
get '/institutions', params: { page: 15 }
expect(JSON.parse(response.body)["page"]).to equal(15)
expect(JSON.parse(response.body)['page']).to equal(15)
end
end
end
25 changes: 23 additions & 2 deletions spec/services/gdynia_extra_data_mapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,26 @@
# "wx3","Oddziały sportowe"
# "w68","Zmianowość"
# "w88","Liczba uczniów na nauczyciela"
# "opis_szkoły","Opis szkoły"
# "sport", "Zajęcia sportowe oferowane przez szkołę"
# "jezyki_obce", "Zajęcia językowe oferowane przez szkołę"
# "profile_klas", "Profile klas które są oferowane przez daną szkołę"
# "zajecia_dodatkowe", "Zajęcia dodatkowe oferowane przez szkołę"

# We are intersted in the following fields: "w51", "wx2", "wx3", "w68", "w88"
# We are intersted in the following fields: "w51", "wx2", "wx3", "w68", "w88",
# "opis_szkoły", "sport", "jezyki_obce", "profile_klas", "zajecia_dodatkowe"

# Database fields:
# add_column :institutions, :integration_classes, :integer
# add_column :institutions, :classrooms, :integer
# add_column :institutions, :sport_facilities, :integer
# add_column :institutions, :working_time, :integer
# add_column :institutions, :studerns_per_teacher, :integer
# add_column :institutions, :description, :string
# add_column :institutions, :sports, :string
# add_column :institutions, :foreign_languages, :string
# add_column :institutions, :class_profiles, :string
# add_column :institutions, :extracurricular_activities, :string

RSpec.describe 'GdyniaExtraDataMapper', type: :service do
describe '#call' do
Expand All @@ -35,7 +46,12 @@
'wx3' => 30,
'w68' => 40,
'w88' => 50,
'rspo' => institution_created.rspo_institution_id
'rspo' => institution_created.rspo_institution_id,
'opis_szkoly' => 'Opis szkoły',
'sport' => ['koszykówka', 'piłka nożna'],
'jezyki_obce' => %w[angielski niemiecki],
'profile_klas' => %w[matematyczny fizyczny],
'zajecia_dodatkowe' => ['klub turystyczny', 'matematyka']
}
]
GdyniaExtraDataMapper.new.call(mock_gdynia_api_data)
Expand All @@ -45,6 +61,11 @@
expect(institution_from_database.sport_facilities).to eq(30)
expect(institution_from_database.working_time).to eq(40)
expect(institution_from_database.students_per_teacher).to eq(50)
expect(institution_from_database.description).to eq('Opis szkoły')
expect(institution_from_database.sports).to eq('koszykówka,piłka nożna')
expect(institution_from_database.foreign_languages).to eq('angielski,niemiecki')
expect(institution_from_database.class_profiles).to eq('matematyczny,fizyczny')
expect(institution_from_database.extracurricular_activities).to eq('klub turystyczny,matematyka')
end
end
end

0 comments on commit 11d3996

Please sign in to comment.