Skip to content

Commit

Permalink
Merge pull request #3 from KatLab-MiyazakiUniv/ticket-KLI-162
Browse files Browse the repository at this point in the history
# ticket-KLI-162 Flaskサーバーを通じて撮影画像を送信
  • Loading branch information
aridome222 authored Aug 17, 2024
2 parents 334a2a4 + ff1d574 commit ba2ee31
Show file tree
Hide file tree
Showing 45 changed files with 194 additions and 1 deletion.
99 changes: 98 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ datetime = "^5.2"
opencv-python = "^4.8.0.74"
requests = "^2.31.0"
flask = "^3.0.3"
pillow = "^10.4.0"

[tool.poetry.group.dev.dependencies]
pytest = "^7.4.0"
Expand Down
9 changes: 9 additions & 0 deletions scripts/kill_official_server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

# テスト用の競技システムのWebサーバをkillする
# 使用条件
# - テスト用の競技システムが起動している
# - テスト用の競技システムとLANケーブルで接続している

KILL_SERVER_COMMAND='ps aux | grep node | grep -v "grep" | awk '\''{print $2}'\'' | sudo xargs -r kill -9'
ssh et2024@official-system "$KILL_SERVER_COMMAND"
9 changes: 9 additions & 0 deletions scripts/run_official_server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

# テスト用の競技システムのWebサーバを起動する
# 使用条件
# - テスト用の競技システムが起動している
# - テスト用の競技システムとLANケーブルで接続している

RUN_SERVER_COMMAND="cd /opt/compesys && sudo npm run start"
ssh et2024@official-system "${RUN_SERVER_COMMAND}"
77 changes: 77 additions & 0 deletions src/official_interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
"""競技システムインタフェース.
競技システムとの通信を行うクラス.
@author: YKhm20020
"""
import requests
# TODO: 詳細な画像処理を実装した後にimport追加
# from image_processing import ImageProcessing
from PIL import Image


class ResponseError(Exception):
"""レスポンスエラー用の例外."""

def __init__(self, message: str):
"""コンストラクタ.
Args:
message (string): エラーメッセージ
"""
super().__init__(message)


class OfficialInterface:
"""競技システムとの通信を行うクラス."""

SERVER_IP = "192.168.100.1" # 競技システムのIPアドレス
TEAM_ID = 93 # チームID

@classmethod
def upload_snap(cls, img_path: str) -> bool:
"""フィグ画像をアップロードする.
Args:
img_path (str): アップロードする画像のパス
Returns:
success (bool): 通信が成功したか(成功:true/失敗:false)
"""
url = f"http://{cls.SERVER_IP}/snap"
# リクエストヘッダー
headers = {
"Content-Type": "image/jpeg"
}
# リクエストパラメータ
params = {
"id": cls.TEAM_ID
}

try:
# サイズが正しくない場合はリサイズする
img = Image.open(img_path)
width, height = img.size
# if not (width == 640 and height == 480):
# ImageProcessing.resize_img(img_path, img_path, 640, 480)

# bytes型で読み込み
with open(img_path, "rb") as image_file:
image_data = image_file.read()

# APIにリクエストを送信
response = requests.post(url, headers=headers,
data=image_data, params=params)
# レスポンスのステータスコードが201の場合、通信成功
if response.status_code != 201:
raise ResponseError("Failed to send fig image.")
success = True
except Exception as e:
print(e)
success = False
return success


if __name__ == "__main__":
print("test-start")
OfficialInterface.upload_snap("../tests/testdata/img/Fig1/Fig1-1.jpeg")
print("test-end")
Binary file added tests/testdata/img/Fig1/Fig1-1.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/testdata/img/Fig1/Fig1-10.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/testdata/img/Fig1/Fig1-2.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/testdata/img/Fig1/Fig1-3.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/testdata/img/Fig1/Fig1-4.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/testdata/img/Fig1/Fig1-5.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/testdata/img/Fig1/Fig1-6.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/testdata/img/Fig1/Fig1-7.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/testdata/img/Fig1/Fig1-8.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/testdata/img/Fig1/Fig1-9.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/testdata/img/Fig2/Fig2-1.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/testdata/img/Fig2/Fig2-10.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/testdata/img/Fig2/Fig2-2.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/testdata/img/Fig2/Fig2-3.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/testdata/img/Fig2/Fig2-4.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/testdata/img/Fig2/Fig2-5.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/testdata/img/Fig2/Fig2-6.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/testdata/img/Fig2/Fig2-7.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/testdata/img/Fig2/Fig2-8.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/testdata/img/Fig2/Fig2-9.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/testdata/img/Fig3/Fig3-1.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/testdata/img/Fig3/Fig3-10.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/testdata/img/Fig3/Fig3-2.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/testdata/img/Fig3/Fig3-3.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/testdata/img/Fig3/Fig3-4.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/testdata/img/Fig3/Fig3-5.jpeg
Binary file added tests/testdata/img/Fig3/Fig3-6.jpeg
Binary file added tests/testdata/img/Fig3/Fig3-7.jpeg
Binary file added tests/testdata/img/Fig3/Fig3-8.jpeg
Binary file added tests/testdata/img/Fig3/Fig3-9.jpeg
Binary file added tests/testdata/img/Fig4/Fig4-1.jpeg
Binary file added tests/testdata/img/Fig4/Fig4-10.jpeg
Binary file added tests/testdata/img/Fig4/Fig4-2.jpeg
Binary file added tests/testdata/img/Fig4/Fig4-3.jpeg
Binary file added tests/testdata/img/Fig4/Fig4-4.jpeg
Binary file added tests/testdata/img/Fig4/Fig4-5.jpeg
Binary file added tests/testdata/img/Fig4/Fig4-6.jpeg
Binary file added tests/testdata/img/Fig4/Fig4-7.jpeg
Binary file added tests/testdata/img/Fig4/Fig4-8.jpeg
Binary file added tests/testdata/img/Fig4/Fig4-9.jpeg

0 comments on commit ba2ee31

Please sign in to comment.