Skip to content

Conversation

@yokoto
Copy link
Contributor

@yokoto yokoto commented Sep 22, 2020

概要

Challenge 3 - Web Application

Deployed URL

https://enechange-ch3.herokuapp.com

不十分な点

  • production のDBが development , test と合っていない。

    • development , testmysql を使っているので、production でも mysql を使うようにする。
  • 開発環境が Docker 化されていない。

  • 市ごとのエネルギー生産量月推移ページでグラフ、テーブルが見切れてしまう。

    • グラフの方は datepicker 、 テーブルの方はページネーションのライブラリを活用するなどして、UXを改善する。
  • テストのカバレッジが不十分。

    • model specunit test を追加する。
  • view に若干ロジックが存在してしまっている。

    • active_decoratordraper を活用して、プレゼンター層を導入する。

特にアピールしたい点、独自の工夫点

  • パーフェクトRails 第11章 エキスパートRails で紹介されているようなドメイン駆動設計を意識したクラス設計を行いました。

@ghost
Copy link

ghost commented Sep 22, 2020

Sider detected 1 error and 1 warning on analyzing the commit b29c350.

We recommend fixing them as possible by updating the dependencies, configuring the analysis tool, configuring sider.yml, turning off unused tools, and so on.

If you have problems or questions still, feel free to ask us via chat. 💬


You can turn off this notification if you don't want to receive it from now on.

@cuzic
Copy link
Contributor

cuzic commented Oct 6, 2020

This is a very good PR!

@@ -0,0 +1,7 @@
class CitiesController < ApplicationController
def index
cities = City.eager_load(houses: :energies)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これ、houses を経由せずとも

Suggested change
cities = City.eager_load(houses: :energies)
cities = City.eager_load(:energies)

と書けるのではないか。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

13301ba で対応しました。


private

def energy_attributes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

このメソッド名は、 as_json とかにするのが好みであるし、
Rails の convention に従っている気がする。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

b1cf8c5 で対応しました。

validates :has_child, presence: true

def save
ActiveRecord::Base.transaction do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transaction はもっと上位にするのが適切。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10c2042 seed データの挿入時に書くように変更してみました。

{
name: city.name,
data: city.energies
.select(:energies_production)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この行、なくてもいいのではないか。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

このロジック全体的に City モデルのメソッドにする方が良かったかもしれない。

(が、そうすると逆に Service に切り出す意味がなくなるか・・・)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8c308c8 で対応しました。

このロジック全体的に City モデルのメソッドにする方が良かったかもしれない。
(が、そうすると逆に Service に切り出す意味がなくなるか・・・)

チャート出力のための処理を Service に切り出すかどうかですが、
ロジックがそこまで大きくないこともあり切り出す必要は無かったかもしれません。
(が、この技術課題でService層を作りたかったという理由で結果として切り出しました。)

end

def call(cities)
cities.select(:id, :name).map do |city|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

map を使わずに 1回のデータベースへの問合せにできる方法があります。
都市が今回は3つなので、このコードでも問題ありませんが。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最終的に

name に 都市名,
data に 年月 を key, エネルギー生産量 を value 
とするハッシュの配列

を出力する必要があり、いい感じのクエリは作れませんでした。

なんとなく GROUP BYcity も含める方向性かなと思いましたが。。

SELECT
	c.name,
	e.year,
	e.month,
	SUM(e.energy_production)
FROM
	cities c
RIGHT OUTER JOIN
	houses h ON c.id = h.city_id
RIGHT OUTER JOIN
	energies e ON h.id = e.house_id
GROUP BY
	c.name, e.year, e.month;


def house_form_params(row, city)
{
firstname: row['Firstname'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

row の Id が捨てられてしまっています。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

b29c350 で対応しました。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id というカラムは連番にして、 house_id カラムを hosues テーブルに追加した方がよかったでしょうか?

@yokoto
Copy link
Contributor Author

yokoto commented Oct 10, 2020

@cuzic レビューいただきありがとうございました。ご指摘いただいた部分を対応、コメントしました。

@yokoto yokoto requested a review from cuzic October 10, 2020 09:52
@cuzic
Copy link
Contributor

cuzic commented Oct 10, 2020

This is a very good PR

@cuzic cuzic merged commit 3f117b0 into enechange:master Oct 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants