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

Wee2 arunachalam #93

Open
wants to merge 30 commits into
base: week2_assignment
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
913d30b
Update pet.rb
arunac535 Jan 2, 2023
0a9109f
Update prime_numbers.rb
arunac535 Jan 2, 2023
563e21e
Update pet.rb
arunac535 Jan 2, 2023
ba4479b
Update pet.rb
arunac535 Jan 2, 2023
7d9bcfa
Update prime_numbers.rb
arunac535 Jan 3, 2023
1c8abe3
Update pet.rb
arunac535 Jan 4, 2023
b98ad46
Add hello_wolrd from previous year
hrushikeshj Jan 10, 2023
ef6ea0e
Add hello_wolrd from previous year
hrushikeshj Jan 10, 2023
f07a650
Merge pull request #99 from IRIS-NITK/week3_assignment
hrushikeshj Jan 10, 2023
ae786d7
Football scaffold
hrushikeshj Jan 10, 2023
43a7123
add hello_world test
hrushikeshj Jan 10, 2023
3a2d7c1
Merge branch 'main' of https://github.com/IRIS-NITK/IRIS-RoR-Bootcamp…
hrushikeshj Jan 10, 2023
6409413
Update README.md
hrushikeshj Jan 10, 2023
14066df
Update README.md
hrushikeshj Jan 10, 2023
a73e7fe
update gitignore
hrushikeshj Jan 10, 2023
e9de726
Merge branch 'main' of https://github.com/IRIS-NITK/IRIS-RoR-Bootcamp…
hrushikeshj Jan 10, 2023
4246703
Merge branch 'IRIS-NITK:main' into wee2_Arunachalam
arunac535 Jan 10, 2023
231ad31
Update README.md
hrushikeshj Jan 11, 2023
28e54c7
Merge branch 'main' into week3_assignment
hrushikeshj Jan 11, 2023
1c2644f
Add football assignment
hrushikeshj Jan 12, 2023
8ce42c0
Add football assignment
hrushikeshj Jan 12, 2023
41b465e
Update README.md
hrushikeshj Jan 12, 2023
8b67128
add tests
hrushikeshj Jan 13, 2023
0a1ae8d
Add week 3 tests
hrushikeshj Jan 13, 2023
27b02ad
Add week 3 tests
hrushikeshj Jan 13, 2023
5c5a1cd
Add week 3 tests
hrushikeshj Jan 13, 2023
77ab65b
Add week 3 tests
hrushikeshj Jan 13, 2023
221d1cd
Update README.md
hrushikeshj Jan 13, 2023
e314722
Add creating tables for week-3 (#108)
mittal-parth Jan 13, 2023
f25d3e6
Merge branch 'IRIS-NITK:main' into wee2_Arunachalam
arunac535 Jan 16, 2023
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
2 changes: 0 additions & 2 deletions .github/pr-labeler.yml

This file was deleted.

19 changes: 0 additions & 19 deletions .github/workflows/pr-labeler.yml

This file was deleted.

39 changes: 39 additions & 0 deletions .github/workflows/week3_intro.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: 'Week 3 getting started'

on:
pull_request:
types: [synchronize, opened, reopened, edited]
branches:
- 'week3_*'

workflow_dispatch:

jobs:
week3:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
working-directory: week_3/hello_world
bundler-cache: true

- name: Install NPM packages
uses: bahmutov/npm-install@v1
with:
working-directory: week_3/hello_world

- name: Copy Test File
working-directory: week_3
run: cp page_controller_test.rb hello_world/test/controllers

- name: Test Rails
working-directory: week_3/hello_world
run: |
bundle exec rails db:create
bundle exec rails db:migrate
bundle exec rails test
35 changes: 35 additions & 0 deletions .github/workflows/week3_model.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: 'Week 3 Model'

on:
pull_request:
types: [synchronize, opened, reopened, edited]
branches:
- 'week3_*'

workflow_dispatch:

jobs:
week3_model:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
working-directory: week_3/football
bundler-cache: true

- name: Install NPM packages
uses: bahmutov/npm-install@v1
with:
working-directory: week_3/football

- name: Test FootballFPlayers
working-directory: week_3/football
run: |
bundle exec rails db:create
bundle exec rails db:migrate
bundle exec rails test:models
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ capybara-*.html
/db/*.sqlite3
/db/*.sqlite3-journal
/db/*.sqlite3-[0-9]*
**/db/*.sqlite3
**/db/*.sqlite3-journal
**/db/*.sqlite3-[0-9]*
/public/system
/coverage/
/spec/tmp
Expand Down Expand Up @@ -51,4 +54,7 @@ yarn-debug.log*


**/imp.rb
**/p_imp.rb
**/p_imp.rb

**/log/*
**/tmp/*
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ In the first week, we will introduce you to basic concepts related to Web Develo
## [Week 2 - Ruby](/week_2)
In this week, we'll take a look at Ruby and instructions to get your device ready for creating Ruby on Rails projects.

## [Week 3 - Getting Started with Rails and Model](/week_3)
In this we will learn how to install Ruby and Rails,
create a new Rails project and build a simple website.

Later we will take a closer look at Model of the MVC Architecture and talk about databases and working with records.

## Contact
In case of doubts related to the Bootcamp, feel free to reach out to the mentors on the [**#doubts**](https://discord.com/channels/1052463702558908416/1052467811143913552) channel on [Discord](https://discord.gg/HQKpB6XH).
23 changes: 18 additions & 5 deletions week_2/pet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ def initialize(name: , animal_type_id: , food_consumed_per_day:)

# Return the habitat of the pet
def habitat
raise NotImplementedError # TODO

HABITATS.each do|k,v|
if v.include?(animal_type_id)
return k
end
end
end

# Returns the cost of food required to feed the animal
Expand All @@ -66,7 +71,8 @@ def food_cost_per_day
# cat = Pet.new(name: 'cat', animal_type_id: 6, food_consumed_per_day: 0.4)
# cat.food_required(28) = 11.2 (0.4 * 28)
def food_required(days)
raise NotImplementedError # TODO

return food_consumed_per_day*days
end

# This function takes the number of `days` as the input
Expand All @@ -76,7 +82,8 @@ def food_required(days)
# cat = Pet.new(name: 'cat', animal_type_id: 6, food_consumed_per_day: 0.4)
# cat.food_cost(28) = 8960
def food_cost(days)
raise NotImplementedError # TODO

return food_cost_per_day*days
end

# This function takes an array of pets and the `days`
Expand All @@ -90,7 +97,7 @@ def food_cost(days)
# snake = Pet.new(name: 'python', animal_type_id: 4, food_consumed_per_day: 0.3)
# Pet.cost_to_feed([cat, dog, fish, snake], 6) will return 6180.0
def self.cost_to_feed(pets, days)
raise NotImplementedError # TODO
return pets.reduce(0) { |sum,pets| sum+ pets.food_cost(days)}
end

# This function takes an array of pets as input
Expand All @@ -110,6 +117,12 @@ def self.cost_to_feed(pets, days)
#
# Note - Order is not important
def self.group_by_animal_type(pets)
raise NotImplementedError # TODO
grp=Hash.new
pets.group_by {|pet| pet.animal_type_id}.each do |id,pets|
petname=[]
pets.each {|pet| petname << pet.name }
grp[id] = petname
end
return grp
end
end
22 changes: 21 additions & 1 deletion week_2/prime_numbers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,25 @@
# We will raise an `ArgumentError` exception to let the caller know that
# their function arguments were incorrect.
def prime_numbers(n:)
raise NotImplementedError # TODO

if n<2
raise ArgumentError
end
arr=[]
for i in 2..n do
count =0
for j in 2..i
if i%j == 0
count+=1
else
next
end
end
if count>1
next
else
arr.push(i)
end
end
return arr
end
72 changes: 72 additions & 0 deletions week_3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Week 3 - Getting Started with Rails + Models

In this week we will get started with Rails.

At first, we will create a simple rails app with two pages, a Home Page and an About Me page.

Follow [these](./getting_started_with_rails.md) instructions to get started.

# Models

We take a closer look at _Model_ of the MVC architecture and talk about
databases, migrations and working with records.

The _model_ layer is responsible for storing and processing data.

We store data in a _relational database_ and process it in the
`app/models` of the Rails application.

A _relational database_ stores information as a set of tables with columns
and rows (_records_). The tables and their columns are together called
a _schema_. You can think of relational database as a spreadsheet with
each table on a different sheet.

> There are other non-tabular databases as well, which are better suited
> to specific problems: [What is a Database | Oracle](https://www.oracle.com/in/database/what-is-database/)

_Structured Query Language_ (SQL) is used to access and manipulate
databases. SQL can retrieve, create, read, update and destroy records,
modify schema and more. Working with SQL directly is difficult, so we
usually have a Rails equivalent.

The assignment is split into different sub-tasks, each testing a
different aspect of Model layer.

> We will be using SQLite as our database program, as it requires no
> setup and is Rails's default.


## Task 1 - Creating Tables

Relational databases stores information using tables. You can think of
tables and their columns as the format in which data is stored.

In this sub-task, we will build an activity tracker because as programmers we spend long hours sitting and need to keep track of our health. During the course of this bootcamp, we'll build the entire application, adding functionality each week. At the end, you'll have a fully functional acticity tracker!

Head over to [activity-tracker](./activity-tracker/README.md) to learn more.

## Task 2 - Working with Records

Once a table is created, we have to fill it with actual data. In
particular, we can create, read, update and destroy records in a table.
Each operation maps to a different SQL command and a different Rails
equivalent.

In this sub-task, we will work on some statistics from Football!

Head over to [football](football/README.md) directory to learn more.


## Interactive Console

The Rails console is useful for testing out quick ideas with code and
debugging applications.

```bash
rails console
```

This should open a console, similar to IRB in the first session. We can
access your model functions and execute any valid ruby code.

- [The Rails Command Line](https://guides.rubyonrails.org/command_line.html#bin-rails-console)
1 change: 1 addition & 0 deletions week_3/activity-tracker/.ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby-3.0.5
72 changes: 72 additions & 0 deletions week_3/activity-tracker/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby "3.0.5"

# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.0.4"

# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
gem "sprockets-rails"

# Use sqlite3 as the database for Active Record
gem "sqlite3", "~> 1.4"

# Use the Puma web server [https://github.com/puma/puma]
gem "puma", "~> 5.0"

# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]
gem "importmap-rails"

# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
gem "turbo-rails"

# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
gem "stimulus-rails"

# Build JSON APIs with ease [https://github.com/rails/jbuilder]
gem "jbuilder"

# Use Redis adapter to run Action Cable in production
# gem "redis", "~> 4.0"

# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
# gem "kredis"

# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
# gem "bcrypt", "~> 3.1.7"

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]

# Reduces boot times through caching; required in config/boot.rb
gem "bootsnap", require: false

# Use Sass to process CSS
# gem "sassc-rails"

# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem "image_processing", "~> 1.2"

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[ mri mingw x64_mingw ]
end

group :development do
# Use console on exceptions pages [https://github.com/rails/web-console]
gem "web-console"

# Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
# gem "rack-mini-profiler"

# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
# gem "spring"
end

group :test do
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
gem "capybara"
gem "selenium-webdriver"
gem "webdrivers"
end
Loading