-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from KatLab-MiyazakiUniv/ticket-KLI-165
close #KLI-165 Webアプリによる走行ログ可視化
- Loading branch information
Showing
7 changed files
with
415 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
**/__pycache__/ | ||
.coverage | ||
coverage* | ||
coverage* | ||
*.jpeg | ||
*.csv | ||
*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
""" | ||
CSVファイルをJSONファイルに変換するクラス. | ||
@author Keiya121 | ||
""" | ||
|
||
import csv | ||
import json | ||
import os | ||
from typing import List | ||
|
||
|
||
class CSVToJSONConverter: | ||
"""CSVファイルをJSONファイルに変換するクラス.""" | ||
|
||
def __init__(self, csv_file_path: str) -> None: | ||
"""コンストラクタ. | ||
Args: | ||
csv_file_path (str): CSVファイルのパス | ||
""" | ||
self.csv_file_path = csv_file_path | ||
self.json_file_path = self._get_json_file_path() | ||
|
||
def convert(self) -> None: | ||
"""CSVファイルを読み込み、JSONファイルに変換する.""" | ||
data = self._read_csv() | ||
self._write_json(data) | ||
|
||
def _read_csv(self) -> List[dict]: | ||
"""CSVファイルを読み込み、辞書のリストを返す. | ||
Return: | ||
run_log_data (List[dict]): 走行ログデータ | ||
""" | ||
run_log_data = [] | ||
with open(self.csv_file_path, mode='r', encoding='utf-8') as csv_file: | ||
reader = csv.DictReader(csv_file, fieldnames=[ | ||
'brightness', 'rightPWM', 'leftPWM', 'R', 'G', 'B']) | ||
for row in reader: | ||
run_log_data.append(row) | ||
return run_log_data | ||
|
||
def _write_json(self, run_log_data: List[dict]) -> None: | ||
"""データをJSONファイルに書き込む. | ||
Args: | ||
run_log_data (List[dict]): 走行ログデータ | ||
""" | ||
json_data = {'runLog': run_log_data} | ||
|
||
# JSONファイルの保存先フォルダーを確認し、存在しない場合は作成 | ||
os.makedirs(os.path.dirname(self.json_file_path), exist_ok=True) | ||
|
||
with open(self.json_file_path, mode='w', | ||
encoding='utf-8') as json_file: | ||
json.dump(json_data, json_file, ensure_ascii=False, indent=4) | ||
|
||
def _get_json_file_path(self) -> str: | ||
"""JSONファイルのパスを作成する. | ||
Return: | ||
json_file_path (str): jsonファイルのパス | ||
""" | ||
base, _ = os.path.splitext(os.path.basename(self.csv_file_path)) | ||
json_file_path = os.path.join( | ||
'src', 'server', 'run_log_json', base + '.json') | ||
return json_file_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,21 @@ | ||
# flaskサーバ | ||
走行体から画像ファイルを取得するflaskサーバプログラムです。 | ||
server()は、"http://"サーバIPアドレス":8000/"にアクセスされたときに実行されます。 | ||
走行体や走行ログ確認用Webアプリと通信を行うflaskサーバプログラム。 | ||
server()は、"http://"サーバIPアドレス":8000/"にアクセスされたときに実行される。 | ||
|
||
## サーバの立て方 | ||
|
||
etrobocon2024-camera-system/ディレクトリ内で以下のコマンドを実行する。$から前は含まない。 | ||
``` | ||
<~etrobocon2024-camera-system>$ poetry run python3 src/server/flask_server.py | ||
<~etrobocon2024-camera-system>$ make server | ||
``` | ||
上のコマンドで実行出来ない場合は,次のコマンドを実行する | ||
|
||
## データ送信 | ||
画像ファイルを送信する | ||
``` | ||
<~etrobocon2024-camera-system>$ poetry run python src/server/flask_server.py | ||
$ curl -X POST -F "file=@"画像ファイルのパス"" http://サーバIPアドレス:8000/images | ||
``` | ||
|
||
## データ送信 | ||
ファイルを送信する | ||
実行ログを送信する | ||
``` | ||
$ curl -X POST -F "file=@"画像ファイルのパス"" http://"サーバIPアドレス":8000/upload | ||
$ curl -X POST -F "file=@"ログファイルのパス"" http://サーバIPアドレス:8000/run-log | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters