change encoding of csv, add BOM to csv, add option --excel for csv
This commit is contained in:
parent
8cb0852249
commit
4000072839
@ -412,7 +412,8 @@ class ECU:
|
|||||||
if mod_globals.opt_csv and mod_globals.ext_cur_DTC == '000000':
|
if mod_globals.opt_csv and mod_globals.ext_cur_DTC == '000000':
|
||||||
# prepare to csv save
|
# prepare to csv save
|
||||||
self.minimumrefreshrate = 0
|
self.minimumrefreshrate = 0
|
||||||
#csvline = "sep=\\t\n"
|
if mod_globals.opt_excel:
|
||||||
|
csvline = "sep="+mod_globals.opt_csv_sep+"\n"
|
||||||
csvline = "Time"
|
csvline = "Time"
|
||||||
nparams = 0
|
nparams = 0
|
||||||
for dr in datarefs:
|
for dr in datarefs:
|
||||||
@ -425,7 +426,7 @@ class ECU:
|
|||||||
if mod_globals.opt_usrkey: csvline += ";User events"
|
if mod_globals.opt_usrkey: csvline += ";User events"
|
||||||
csvline = pyren_encode(csvline)
|
csvline = pyren_encode(csvline)
|
||||||
if nparams:
|
if nparams:
|
||||||
csv_start_time = datetime.now().timestamp()
|
csv_start_time = int(round(time.time() * 1000))
|
||||||
csv_filename = datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
|
csv_filename = datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
|
||||||
#here the problem with russian letters. and very long name
|
#here the problem with russian letters. and very long name
|
||||||
csv_filename = csv_filename+'_'+self.ecudata['ecuname']+'_'+path
|
csv_filename = csv_filename+'_'+self.ecudata['ecuname']+'_'+path
|
||||||
@ -436,7 +437,8 @@ class ECU:
|
|||||||
csv_filename = csv_filename.replace(' ','_')
|
csv_filename = csv_filename.replace(' ','_')
|
||||||
#if mod_globals.os == 'android':
|
#if mod_globals.os == 'android':
|
||||||
# csv_filename = csv_filename.encode("ascii","ignore")
|
# csv_filename = csv_filename.encode("ascii","ignore")
|
||||||
csvf = open("./csv/"+pyren_encode(csv_filename), "wb")
|
csvf = open("./csv/"+pyren_encode(csv_filename), "w", encoding='utf-8' )
|
||||||
|
csvf.write('\ufeff')
|
||||||
|
|
||||||
DTCpos = path.find('DTC')
|
DTCpos = path.find('DTC')
|
||||||
if DTCpos > 0:
|
if DTCpos > 0:
|
||||||
@ -480,12 +482,15 @@ class ECU:
|
|||||||
|
|
||||||
if mod_globals.opt_csv_human and csvf!=0:
|
if mod_globals.opt_csv_human and csvf!=0:
|
||||||
csvline = csvline + "\n"
|
csvline = csvline + "\n"
|
||||||
csvline = csvline.replace(',','.')
|
csvline = csvline.replace('.',mod_globals.opt_csv_dec)
|
||||||
csvline = csvline.replace(';',',')
|
csvline = csvline.replace(',',mod_globals.opt_csv_dec)
|
||||||
csvf.write(pyren_decode(csvline).encode('utf8'))
|
csvline = csvline.replace(';',mod_globals.opt_csv_sep)
|
||||||
|
csvf.write(csvline)
|
||||||
csvf.flush()
|
csvf.flush()
|
||||||
time_delata = datetime.now().timestamp()-csv_start_time
|
time_diff = int(round(time.time() * 1000))-csv_start_time
|
||||||
csvline = datetime.fromtimestamp(time_delata).strftime("%S.%f")[:-3]
|
time_sec = str(time_diff//1000)
|
||||||
|
time_ms = str((time_diff)%1000)
|
||||||
|
csvline = time_sec.zfill(2)+mod_globals.opt_csv_dec+time_ms.zfill(3)
|
||||||
|
|
||||||
#Collect all the requests from the current screen
|
#Collect all the requests from the current screen
|
||||||
if mod_globals.opt_performance and self.elm.performanceModeLevel > 1 and mod_globals.opt_csv_only:
|
if mod_globals.opt_performance and self.elm.performanceModeLevel > 1 and mod_globals.opt_csv_only:
|
||||||
@ -664,11 +669,15 @@ class ECU:
|
|||||||
self.elm.rsp_cache[req] = rsp
|
self.elm.rsp_cache[req] = rsp
|
||||||
|
|
||||||
csvline = csvline + "\n"
|
csvline = csvline + "\n"
|
||||||
csvline = csvline.replace(',','.')
|
csvline = csvline.replace('.',mod_globals.opt_csv_dec)
|
||||||
csvline = csvline.replace(';',',')
|
csvline = csvline.replace(',',mod_globals.opt_csv_dec)
|
||||||
csvf.write(pyren_decode(csvline).encode('utf8'))
|
csvline = csvline.replace(';',mod_globals.opt_csv_sep)
|
||||||
|
csvf.write(csvline)
|
||||||
csvf.flush()
|
csvf.flush()
|
||||||
csvline = datetime.fromtimestamp((reqTime-startTime)/1000).strftime("%S.%f")[:-3]
|
time_diff = reqTime-startTime
|
||||||
|
time_sec = str(time_diff//1000)
|
||||||
|
time_ms = str((time_diff)%1000)
|
||||||
|
csvline = time_sec.zfill(2)+mod_globals.opt_csv_dec+time_ms.zfill(3)
|
||||||
|
|
||||||
for dr in datarefs:
|
for dr in datarefs:
|
||||||
datastr = dr.name
|
datastr = dr.name
|
||||||
@ -678,7 +687,7 @@ class ECU:
|
|||||||
if dr.type=='Parameter':
|
if dr.type=='Parameter':
|
||||||
datastr, help, csvd = get_parameter( self.Parameters[dr.name], self.Mnemonics, self.Services, self.elm, self.calc )
|
datastr, help, csvd = get_parameter( self.Parameters[dr.name], self.Mnemonics, self.Services, self.elm, self.calc )
|
||||||
if csvf!=0 and (dr.type=='State' or dr.type=='Parameter'):
|
if csvf!=0 and (dr.type=='State' or dr.type=='Parameter'):
|
||||||
csvline += ";" + pyren_encode(csvd)
|
csvline += ';' + csvd
|
||||||
|
|
||||||
csvf.close()
|
csvf.close()
|
||||||
|
|
||||||
|
@ -17,6 +17,9 @@ opt_scan = False
|
|||||||
opt_csv = False
|
opt_csv = False
|
||||||
opt_csv_only = False
|
opt_csv_only = False
|
||||||
opt_csv_human = False
|
opt_csv_human = False
|
||||||
|
opt_csv_sep = ","
|
||||||
|
opt_csv_dec = "."
|
||||||
|
opt_excel = False
|
||||||
opt_usrkey = ""
|
opt_usrkey = ""
|
||||||
opt_verbose = False
|
opt_verbose = False
|
||||||
opt_cmd = False
|
opt_cmd = False
|
||||||
@ -38,7 +41,7 @@ opt_performance = False
|
|||||||
opt_minordtc = False
|
opt_minordtc = False
|
||||||
opt_ref = "" #alternative ref set for acf
|
opt_ref = "" #alternative ref set for acf
|
||||||
opt_mtc = "" #alternative mtc set for acf
|
opt_mtc = "" #alternative mtc set for acf
|
||||||
dumpName = ""
|
dumpName = ""
|
||||||
|
|
||||||
state_scan = False
|
state_scan = False
|
||||||
|
|
||||||
|
@ -214,6 +214,12 @@ def optParser():
|
|||||||
default=False,
|
default=False,
|
||||||
action="store_true")
|
action="store_true")
|
||||||
|
|
||||||
|
parser.add_argument("--excel",
|
||||||
|
help="Save csv in excel compatible format",
|
||||||
|
dest="excel",
|
||||||
|
default=False,
|
||||||
|
action="store_true")
|
||||||
|
|
||||||
options = parser.parse_args()
|
options = parser.parse_args()
|
||||||
|
|
||||||
if not options.port and mod_globals.os != 'android':
|
if not options.port and mod_globals.os != 'android':
|
||||||
@ -260,6 +266,13 @@ def optParser():
|
|||||||
print("Development MODE")
|
print("Development MODE")
|
||||||
mod_globals.opt_dev = True
|
mod_globals.opt_dev = True
|
||||||
mod_globals.opt_devses = options.dev
|
mod_globals.opt_devses = options.dev
|
||||||
|
mod_globals.opt_excel = options.excel
|
||||||
|
if mod_globals.opt_excel:
|
||||||
|
mod_globals.opt_csv_sep = ';'
|
||||||
|
mod_globals.opt_csv_dec = ','
|
||||||
|
else:
|
||||||
|
mod_globals.opt_csv_sep = ','
|
||||||
|
mod_globals.opt_csv_dec = '.'
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
'''Main function'''
|
'''Main function'''
|
||||||
|
Loading…
x
Reference in New Issue
Block a user