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

Feat/get catalog online #29

Merged
merged 5 commits into from
May 30, 2024
Merged

Feat/get catalog online #29

merged 5 commits into from
May 30, 2024

Conversation

bordoray
Copy link
Contributor

@bordoray bordoray commented May 30, 2024

Issue

close #0

変更内容:Description

  • catalog.jsonをOnlineで取得
  • 取得できない場合、Localのcatalog.jsonを取得

テスト手順:Test

以下を確認

  • Dataset を取得できる
  • ネットワークを切ってPlugin reloaderを実行したら、取得できないMessageが来て、Localのcatalog.jsonを取得
    ※現状localとcloudのCatalogが 一緒はずなので、テストのためにLocalのcatalog.jsonの一件の名前を変更して比較できます。

Summary by CodeRabbit

  • 新機能

    • JAXA Earth API PluginがリモートURLからカタログデータを動的に読み込む機能を追加しました。リモートカタログを読み込めない場合、ローカルカタログファイルにフォールバックします。
  • 改善

    • プラグイン名を「JAXA Earth API Plugin」に変更しました。
    • ロケール設定の文字列フォーマットを改善しました。
  • バグ修正

    • カタログ取得時のURLを更新し、リモートカタログが利用できない場合のエラーメッセージとフォールバック処理を追加しました。

@bordoray bordoray requested a review from nbayashi May 30, 2024 02:08
Copy link
Contributor

coderabbitai bot commented May 30, 2024

Walkthrough

この変更は、JAXA Earth API PluginのQGISプラグインにおいて、カタログデータをリモートURLから動的にロードする機能を追加しました。リモートカタログが取得できない場合には、ローカルファイルからカタログをロードするフォールバック機能も実装されています。

Changes

ファイル 変更内容
catalog/.../loader.py get_catalog関数が特定のURLからカタログを取得し、辞書を生成するように変更されました。URLが利用できない場合にはスクリプトを使用するように指定しました。
jaxaEarthApiDialog.py requestsライブラリを使用してリモートURLからカタログをロードする機能を追加しました。リモートカタログが取得できない場合には、ローカルファイルからカタログをロードするフォールバック機能を実装しました。
jaxaEarthApiPlugin.py プラグイン名の更新とロケール設定の文字列フォーマットの改善を行いました。

Poem

データの波に乗り
カタログは空を翔ける
URLが見えぬ時も
ローカルの友が助ける
さあ、新たな知識を得て
地球の秘密を探ろう
JAXAの力、ここに在り

  (\(\ 
  ( -.-)
 o_(")(")

Tip

Early Access Features
  • gpt-4o model for chat
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Outside diff range and nitpick comments (1)
catalog/loader.py (1)

Line range hint 21-38: このコードブロックでは、カタログの各子要素に対してリクエストを行い、その結果を辞書に格納しています。しかし、このアプローチは非効率的であり、多数のHTTPリクエストが発生する可能性があります。バッチ処理または並列処理を使用してパフォーマンスを向上させることを検討してください。

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 7b540b4 and 9112bf7.
Files selected for processing (3)
  • catalog/loader.py (2 hunks)
  • jaxaEarthApiDialog.py (3 hunks)
  • jaxaEarthApiPlugin.py (2 hunks)
Additional Context Used
Ruff (6)
jaxaEarthApiPlugin.py (6)

19-19: from PyQt5.QtGui import * used; unable to detect undefined names


20-20: from PyQt5.QtWidgets import * used; unable to detect undefined names


21-21: from qgis.core import * used; unable to detect undefined names


22-22: from qgis.gui import * used; unable to detect undefined names


64-64: QIcon may be undefined, or defined from star imports


65-65: QAction may be undefined, or defined from star imports

Path-based Instructions (3)
catalog/loader.py (1)

Pattern **/*.py: - is it possible to use better type hinting?

  • can be available more immutable approach?
jaxaEarthApiPlugin.py (1)

Pattern **/*.py: - is it possible to use better type hinting?

  • can be available more immutable approach?
jaxaEarthApiDialog.py (1)

Pattern **/*.py: - is it possible to use better type hinting?

  • can be available more immutable approach?
Additional comments not posted (4)
catalog/loader.py (1)

12-14: このコメントは、URLが機能しない場合にのみスクリプトを使用することを示しています。これは良い実践ですが、URLが利用不可能な場合にどのように検出されるかが明確ではありません。例外処理またはステータスコードのチェックを追加することを検討してください。

jaxaEarthApiPlugin.py (2)

3-5: プラグインの説明が更新されています。これにより、プラグインの機能がより明確になり、ユーザーにとって理解しやすくなります。


42-45: ロケールの設定が更新されていますが、QSettings().value("locale/userLocale")[0:2]から返される値が常に期待通りの形式であるとは限りません。この値の検証を追加することをお勧めします。

jaxaEarthApiDialog.py (1)

3-5: プラグインの説明が更新されており、ユーザーにとってより明確な情報を提供しています。

}
return catalog


if __name__ == "__main__":
catalog = get_catalog()
with open('./catalog.json', mode='w') as f:
with open("./catalog.json", mode="w") as f:
Copy link
Contributor

Choose a reason for hiding this comment

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

このコードはローカルファイルにカタログを保存していますが、ファイルの書き込みに失敗した場合のエラーハンドリングがありません。例外処理を追加することをお勧めします。

+ try:
    with open("./catalog.json", mode="w") as f:
        json.dump(catalog, f, ensure_ascii=False)
+ except Exception as e:
+     print(f"Error writing to file: {str(e)}")

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
with open("./catalog.json", mode="w") as f:
try:
with open("./catalog.json", mode="w") as f:
json.dump(catalog, f, ensure_ascii=False)
except Exception as e:
print(f"Error writing to file: {str(e)}")

Comment on lines 36 to 63
try:
response = requests.get(CATALOG_URL)
if response.status_code == 200:
CATALOG = response.json()
print(response)
else:
message = "Could not load catalog.json\n"
message += f"Response {response.status_code} \nLoad local catalog"
QMessageBox.information(
None,
"JAXA Earth API Plugin - Warning",
message,
)
# Fallback load local catalog
with open(os.path.join(os.path.dirname(__file__), "catalog.json")) as f:
CATALOG = json.load(f)
except Exception as e:
message = "Could not load catalog.json\n"
message += f"{str(e)} \nLoad local catalog"
QMessageBox.information(
None,
"JAXA Earth API Plugin - Warning",
message,
)
print(e)
# Fallback load local catalog
with open(os.path.join(os.path.dirname(__file__), "catalog.json")) as f:
CATALOG = json.load(f)
Copy link
Contributor

@coderabbitai coderabbitai bot May 30, 2024

Choose a reason for hiding this comment

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

カタログのオンライン取得に失敗した場合のフォールバック処理が追加されています。これにより、ネットワークの問題がある場合でもプラグインの機能性が保たれます。ただし、requests.getを使用する際はタイムアウトを設定することをお勧めします。

- response = requests.get(CATALOG_URL)
+ response = requests.get(CATALOG_URL, timeout=10)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
try:
response = requests.get(CATALOG_URL)
if response.status_code == 200:
CATALOG = response.json()
print(response)
else:
message = "Could not load catalog.json\n"
message += f"Response {response.status_code} \nLoad local catalog"
QMessageBox.information(
None,
"JAXA Earth API Plugin - Warning",
message,
)
# Fallback load local catalog
with open(os.path.join(os.path.dirname(__file__), "catalog.json")) as f:
CATALOG = json.load(f)
except Exception as e:
message = "Could not load catalog.json\n"
message += f"{str(e)} \nLoad local catalog"
QMessageBox.information(
None,
"JAXA Earth API Plugin - Warning",
message,
)
print(e)
# Fallback load local catalog
with open(os.path.join(os.path.dirname(__file__), "catalog.json")) as f:
CATALOG = json.load(f)
try:
response = requests.get(CATALOG_URL, timeout=10)
if response.status_code == 200:
CATALOG = response.json()
print(response)
else:
message = "Could not load catalog.json\n"
message += f"Response {response.status_code} \nLoad local catalog"
QMessageBox.information(
None,
"JAXA Earth API Plugin - Warning",
message,
)
# Fallback load local catalog
with open(os.path.join(os.path.dirname(__file__), "catalog.json")) as f:
CATALOG = json.load(f)
except Exception as e:
message = "Could not load catalog.json\n"
message += f"{str(e)} \nLoad local catalog"
QMessageBox.information(
None,
"JAXA Earth API Plugin - Warning",
message,
)
print(e)
# Fallback load local catalog
with open(os.path.join(os.path.dirname(__file__), "catalog.json")) as f:
CATALOG = json.load(f)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Solved

Copy link
Contributor

Choose a reason for hiding this comment

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

@bordoray, thank you for confirming that the issue has been resolved. If you need any further assistance, feel free to ask!


New Learnings Added
User: bordoray
PR: MIERUNE/qgis-jaxa-earth-plugin#29
File: jaxaEarthApiDialog.py:0-0
Timestamp: 2024-05-30T02:20:22.222Z
Learning: When using `requests.get` in Python, it is important to set a timeout to avoid indefinite waiting periods in case of network issues.

Note: Learnings are effective only in the context of specific code segments. To apply general coding guidelines, please configure review instructions.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 9112bf7 and 9a72ea1.
Files selected for processing (1)
  • jaxaEarthApiDialog.py (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • jaxaEarthApiDialog.py

@nbayashi
Copy link
Contributor

@bordoray オフラインの時にはローカルのカタログを取得するのはナイスですが、そもそもオフラインだと衛星データダウンロードできないので、むしろデータは選択できるのにDLできずにユーザーが困惑するのではないかと思いますが、どう思いますか?

@nbayashi nbayashi merged commit 7c1caf2 into master May 30, 2024
2 checks passed
@bordoray bordoray deleted the feat/get-catalog-online branch June 7, 2024 04:19
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