ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
anaconda-project 0.9.1 requires ruamel-yaml, which is not installed.
boto3 1.17.70 requires botocore<1.21.0,>=1.20.70, but you have botocore 1.17.43 which is incompatible.
awscli 1.19.70 requires botocore==1.20.70, but you have botocore 1.17.43 which is incompatible.
aiobotocore 1.2.1 requires botocore<1.19.53,>=1.19.52, but you have botocore 1.17.43 which is incompatible.
2. Data Processing
2.1 시작
편의를 위해, api-examples/examples/data-processing 폴더 아래에 ipynb 파일을 생성하여 진행합니다.
api-examples/examples/data-processing/process_data.py 파일을 참고하여 진행합니다.
2.2 Module Import
필요한 모듈을 불러옵니다.
import mdf_iter # MDF4 데이터 불러오는 라이브러리
import canedge_browser # 로컬 또는 S3에 저장된 데이터 가져오는 라이브러리
import can_decoder # 데이터를 복호화하는 라이브러리
import pandas as pd # 데이터분석 라이브러리
from datetime import datetime, timezone # 날짜와 시간 데이터를 가져올 수 있는 파이썬 라이브러리
from utils import setup_fs, load_dbc_files, restructure_data, add_custom_sig, ProcessData # 폴더 내 위치한 Custom 라이브러리
2.3 변수 설정
기기 및 경로, 시간을 지정합니다.
# specify devices to process (from local/S3), DBC files and start time
devices = ["LOG/958D2219"]
dbc_paths = ["dbc_files/CSS-Electronics-SAE-J1939-DEMO.dbc"]
start = datetime(year=2020, month=1, day=13, hour=0, tzinfo=timezone.utc)
s3 또는 로컬에 저장한 파일을 불러옵니다.
만약 s3에 저장한 경우라면, s3=True를 입력합니다.
# setup filesystem (local/S3), load DBC files and list log files for processing
fs = setup_fs(s3=False, key="", secret="", endpoint="")
List 형태로 입력한 dbc 파일 경로를 받아 변환 규칙 데이터베이스 List를 생성합니다.
이를 사람이 읽을 수 있게 변환이 필요합니다. CAN DBC는 CAN ID에 맞는 변환 규칙을 갖고 있습니다.
실습에 사용하는 코드는 같은 폴더 내에 위치한 모든 로그 파일을 읽어 하나의 데이터프레임으로 만드는데 사용합니다.
canedge_browser.get_log_files는 조건에 맞는 로그 파일 경로를 List로 반환합니다.
log_files = canedge_browser.get_log_files(fs, devices, start_date=start)
print(f"Found a total of {len(log_files)} log files")
# Expected
" Found a total of 2 log files "
def add_custom_sig(df_phys, signal1, signal2, function, new_signal):
"""Helper function for calculating a new signal based on two signals and a function.
Returns a dataframe with the new signal name and physical values
"""
import pandas as pd
try:
s1 = df_phys[df_phys["Signal"] == signal1]["Physical Value"].rename(signal1)
s2 = df_phys[df_phys["Signal"] == signal2]["Physical Value"].rename(signal2)
df_new_sig = pd.merge_ordered(s1, s2, on="TimeStamp", fill_method="ffill",).set_index("TimeStamp")
df_new_sig = df_new_sig.apply(lambda x: function(x[0], x[1]), axis=1).dropna().rename("Physical Value").to_frame()
df_new_sig["Signal"] = new_signal
df_phys = df_phys.append(df_new_sig)
except:
print(f"Warning: Custom signal {new_signal} not created\n")
return df_phys