-
Notifications
You must be signed in to change notification settings - Fork 12
Task-4 #9
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
base: master
Are you sure you want to change the base?
Task-4 #9
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| node_modules | ||
| npm-debug.log | ||
| Dockerfile* | ||
| docker-compose* | ||
| .dockerignore | ||
| .git | ||
| .gitignore | ||
| .env | ||
| */bin | ||
| */obj | ||
| README.md | ||
| LICENSE | ||
| .vscode |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,3 +25,4 @@ | |
|
|
||
| # Ignore master key for decrypting credentials and more. | ||
| /config/master.key | ||
| /.docker/*.tgz | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| FROM alpine:latest | ||
|
|
||
| LABEL Alec Pervushin <alec.for.public@gmail.com> | ||
|
|
||
| ENV RUBY_INSTALL_VERSION "0.7.0" | ||
| ENV RUBY_INSTALL_URL "https://github.com/postmodern/ruby-install/archive/v${RUBY_INSTALL_VERSION}.tar.gz" | ||
| ENV CHRUBY_VERSION '0.3.9' | ||
| ENV CHRUBY_URL "https://github.com/postmodern/chruby/archive/v${CHRUBY_VERSION}.tar.gz" | ||
|
|
||
| RUN apk update && \ | ||
| apk upgrade && \ | ||
| apk add --no-cache gnupg curl bash procps musl zlib openssl \ | ||
| patch make gcc g++ gnupg musl-dev linux-headers zlib-dev openssl-dev \ | ||
| postgresql-dev tzdata ruby readline-dev | ||
|
|
||
| SHELL ["/bin/bash", "-lc"] | ||
|
|
||
| WORKDIR /tmp | ||
|
|
||
| RUN curl -L -o ruby-install.tar.gz ${RUBY_INSTALL_URL} && \ | ||
| tar -xzvf ruby-install.tar.gz && \ | ||
| cd ruby-install-${RUBY_INSTALL_VERSION}/ && make install | ||
|
|
||
| ADD .docker/current.tgz /opt/ | ||
|
|
||
| COPY bin/install-railsexpress* /tmp/ | ||
| COPY .ruby-version* /root/ | ||
| COPY Gemfile* /tmp/ | ||
|
|
||
| RUN echo 'export RUBY_VERSION=$([ -z "$RUBY_VERSION" ] && cat ~/.ruby-version || "$RUBY_VERSION")' >> /etc/profile | ||
|
|
||
| RUN ./install-railsexpress railsexpress $RUBY_VERSION \ | ||
| --jobs=2 --cleanup --no-reinstall | ||
|
|
||
| RUN curl -L -o chruby.tar.gz ${CHRUBY_URL} && \ | ||
| tar -xzvf chruby.tar.gz && \ | ||
| cd chruby-${CHRUBY_VERSION}/ && make install && \ | ||
| echo "source /usr/local/share/chruby/chruby.sh" >> /etc/profile && \ | ||
| echo 'chruby $RUBY_VERSION' >> /etc/profile | ||
|
|
||
| RUN gem install bundler rb-readline && bundle check || bundle install | ||
|
|
||
| RUN apk del gnupg musl-dev linux-headers ruby && \ | ||
| rm -rf /tmp/* /var/cache/apk/* | ||
|
|
||
| COPY docker-entrypoint.sh* / |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,9 @@ class TripsController < ApplicationController | |
| def index | ||
| @from = City.find_by_name!(params[:from]) | ||
| @to = City.find_by_name!(params[:to]) | ||
| @trips = Trip.where(from: @from, to: @to).order(:start_time) | ||
| @trips = Trip. | ||
| joins(bus: :services). | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Смущает использование |
||
| where(from: @from, to: @to). | ||
| order(:start_time) | ||
| end | ||
| end | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| class BusesService < ApplicationRecord | ||
| belongs_to :bus | ||
| belongs_to :service | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| class EntitiesProcessing | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 плюсик за сервис |
||
| class << self | ||
| def call(file_name:, with_gc: true) | ||
| GC.disabled unless with_gc | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Опечатка |
||
|
|
||
| json = Oj.load(File.read file_name) | ||
|
|
||
| ActiveRecord::Base.transaction do | ||
| City.delete_all | ||
| Bus.delete_all | ||
| Service.delete_all | ||
| Trip.delete_all | ||
| BusesService.delete_all | ||
|
|
||
| create_cities(json) | ||
| create_services | ||
| create_buses(json) | ||
| create_trips(json) | ||
| end | ||
|
|
||
| clear_entities | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def create_buses(json) | ||
| @buses = | ||
| json.each_with_object({}) do |trip, memo| | ||
| bus_number = trip['bus']['number'] | ||
| next if memo.has_key?(bus_number) | ||
|
|
||
| memo[bus_number] = Bus.new( | ||
| number: bus_number, | ||
| model: trip['bus']['model'], | ||
| services: @services. | ||
| values_at(*trip['bus']['services']) | ||
| ) | ||
| end | ||
|
|
||
| Bus.import(@buses.values, recursive: true, raise_error: true) | ||
| end | ||
|
|
||
| def create_cities(json) | ||
| @cities = | ||
| json.each_with_object({}) do |trip, memo| | ||
| from = trip['from'] | ||
| to = trip['to'] | ||
|
|
||
| next if memo.has_key?(from) && memo.has_key?(to) | ||
| name = memo.has_key?(from) ? to : from | ||
|
|
||
| memo[name] = City.new(name: name) | ||
| end | ||
|
|
||
| City.import(@cities.values, recursive: true, raise_error: true) | ||
| end | ||
|
|
||
| def create_services | ||
| @services = | ||
| Service::SERVICES.sort.each_with_object({}) do |name, memo| | ||
| memo[name] = Service.new(name: name) | ||
| end | ||
|
|
||
| Service.import(@services.values, recursive: true, raise_error: true) | ||
| end | ||
|
|
||
| def create_trips(json) | ||
| @trips = | ||
| json.each_with_object({}) do |trip, memo| | ||
| from = @cities[trip['from']] | ||
| to = @cities[trip['to']] | ||
| bus = @buses[trip['bus']['number']] | ||
| start_time = trip['start_time'] | ||
|
|
||
|
|
||
| memo[start_time] = | ||
| Trip.new( | ||
| from: from, | ||
| to: to, | ||
| bus: bus, | ||
| start_time: start_time, | ||
| duration_minutes: trip['duration_minutes'], | ||
| price_cents: trip['price_cents'], | ||
| ) | ||
| end | ||
|
|
||
| Trip.import(@trips.values, recursive: true, raise_error: true) | ||
| end | ||
|
|
||
| def clear_entities | ||
| @trips.clear | ||
| @buses.clear | ||
| @cities.clear | ||
| @services.clear | ||
| end | ||
| end | ||
| end | ||
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,21 @@ | ||
| <li><%= "Отправление: #{trip.start_time}" %></li> | ||
| <li><%= "Прибытие: #{(Time.parse(trip.start_time) + trip.duration_minutes.minutes).strftime('%H:%M')}" %></li> | ||
| <li><%= "В пути: #{trip.duration_minutes / 60}ч. #{trip.duration_minutes % 60}мин." %></li> | ||
| <li><%= "Цена: #{trip.price_cents / 100}р. #{trip.price_cents % 100}коп." %></li> | ||
| <li><%= "Автобус: #{trip.bus.model} №#{trip.bus.number}" %></li> | ||
| <% cache [trip, trip.bus] do %> | ||
| <ul> | ||
| <li><%= "Отправление: #{trip.start_time}" %></li> | ||
| <li><%= "Прибытие: #{(Time.parse(trip.start_time) + trip.duration_minutes.minutes).strftime('%H:%M')}" %></li> | ||
| <li><%= "В пути: #{trip.duration_minutes / 60}ч. #{trip.duration_minutes % 60}мин." %></li> | ||
| <li><%= "Цена: #{trip.price_cents / 100}р. #{trip.price_cents % 100}коп." %></li> | ||
| <li><%= "Автобус: #{trip.bus.model} №#{trip.bus.number}" %></li> | ||
|
|
||
| <% if trip.bus.services.exists? %> | ||
| <li>Сервисы в автобусе:</li> | ||
| <ul> | ||
| <% trip.bus.services.each do |service| %> | ||
| <% cache service do %> | ||
| <li><%= "#{service.name}" %></li> | ||
| <% end %> | ||
| <% end %> | ||
| </ul> | ||
| <% end %> | ||
| </ul> | ||
| ==================================================== | ||
| <% end %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍