-
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.
- Loading branch information
Showing
7 changed files
with
180 additions
and
23 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,50 @@ | ||
""" | ||
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: | ||
"""コンストラクタ.""" | ||
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ファイルを読み込み、辞書のリストを返す.""" | ||
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: | ||
data.append(row) | ||
return data | ||
|
||
def _write_json(self, data: List[dict]) -> None: | ||
"""データをJSONファイルに書き込む.""" | ||
json_data = {'runLog': 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ファイルのパスを作成する.""" | ||
base, _ = os.path.splitext(os.path.basename(self.csv_file_path)) | ||
return os.path.join('src', 'server', 'run_log_json', base + '.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
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