-
Notifications
You must be signed in to change notification settings - Fork 0
/
FilesMgr.py
95 lines (66 loc) · 2.67 KB
/
FilesMgr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!pyton
# -*- coding: utf-8 -*-
import csv
import fnmatch
import os
import tkinter as tk
from tkinter import filedialog
import pandas as pd
import toml
class CFileMgr:
root = []
mainRecDir = ''
# 0 - Head, 1 - Neck, 2 - Waist / Knee
sensorMacs = []
dlgDir = []
selFile = ''
carpetFilePath = ''
selFileDateTime = []
recFileList = []
sensorsRawData = []
carpetDateTime = ''
def SetDefaultDirs(self):
cfg = toml.load("cfg.toml")
self.carpetDataDir = cfg['General']['carpetDataDir']
self.mainRecDir = cfg['General']['mainRecDir']
self.sensorMacs = cfg['General']['sensorMacs']
self.dlgDir = self.mainRecDir + "\\" + self.sensorMacs[0]
self.sensors_full_paths = list(
map("\\".join, zip([self.mainRecDir] * 3, self.sensorMacs)))
def GetCarpetFilePath(self):
return self.carpetFilePath
def GetSensorsData(self):
return self.sensorsRawData
def Run(self):
self.SetDefaultDirs()
self.selFile = self.OpenFile(self.dlgDir)
self.carpetFilePath = self.OpenFile(self.carpetDataDir)
self.CreateFileList(self.sensors_full_paths)
self.ImportData()
def OpenFile(self, dlgDir):
root = tk.Tk()
root.withdraw()
fileName = tk.filedialog.askopenfilename(
initialdir=dlgDir, title="Select file", filetypes=(("csv or txt files", "*.csv; *.txt"), ("all files", "*.*")))
return fileName
def CreateFileList(self, sensors_full_paths):
startStr = "2018"
dateStartIdx = self.selFile.find(startStr)
self.selFileDateTime = self.selFile[dateStartIdx:dateStartIdx+23]
sensors_full_paths = list(
map("\\".join, zip([self.mainRecDir] * 3, self.sensorMacs)))
# Taking only one sensor folder - assuming they all have the same recording...
self.recFileList = []
for curDir in sensors_full_paths:
curDirfileList = os.listdir(curDir)
for filename in curDirfileList:
if fnmatch.fnmatch(filename, "*" + self.selFileDateTime + "*.csv"):
self.recFileList.append(curDir + "\\" + filename)
if len(self.recFileList) != len(self.sensorMacs):
# TODO: Do something if not all sensors files exist:
print('Not all sensors files exist. Please, pick another file...')
# print(*self.recFileList, sep='\n')
def ImportData(self):
self.sensorsRawData = []
for iFile in self.recFileList:
self.sensorsRawData.append(pd.read_csv(iFile))