Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F60746259
reWriteData.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, May 2, 08:33
Size
1 KB
Mime Type
text/x-python
Expires
Sat, May 4, 08:33 (2 d)
Engine
blob
Format
Raw Data
Handle
17405299
Attached To
rACCELCLASSIFIER accelerometerEBClassifier
reWriteData.py
View Options
import
os
import
numpy
as
np
import
pandas
as
pd
import
sys
import
matplotlib.pyplot
as
plt
def
extractExpSubjSensor
(
fileName
):
name
=
os
.
path
.
basename
(
fileName
)
.
split
(
"."
)[
0
]
temp
=
name
.
find
(
"exp"
)
+
len
(
"exp"
)
expNo
=
int
(
name
[
temp
:
temp
+
2
])
temp
=
name
.
find
(
"user"
)
+
len
(
"user"
)
subjNo
=
int
(
name
[
temp
:
temp
+
2
])
temp
=
name
.
find
(
"_exp"
)
sensor
=
name
[
0
:
temp
]
return
expNo
,
subjNo
,
sensor
if
__name__
==
"__main__"
:
filenames
=
[
os
.
path
.
join
(
"../data/RawData"
,
x
)
for
x
in
os
.
listdir
(
"../data/RawData"
)
if
".txt"
in
x
and
"user"
in
x
]
labels
=
pd
.
read_csv
(
"../data/RawData/labels.txt"
,
names
=
[
"experiment"
,
"subject"
,
"label"
,
"start"
,
"end"
],
sep
=
" "
)
for
f
in
filenames
:
exp
,
subj
,
sensor
=
extractExpSubjSensor
(
f
)
fileToSave
=
"../data/dataLabeld/"
+
str
(
exp
)
+
sensor
+
".csv"
labelsThisExp
=
labels
.
loc
[
labels
[
"experiment"
]
==
exp
]
dfFile
=
pd
.
read_csv
(
f
,
names
=
[
"x"
,
"y"
,
"z"
],
sep
=
" "
)
dfFile
[
"lbl"
]
=
-
1
for
lbl
in
labelsThisExp
.
iterrows
():
start
=
lbl
[
1
][
"start"
]
stop
=
lbl
[
1
][
"end"
]
l
=
lbl
[
1
][
"label"
]
dfFile
.
loc
[
start
:
stop
+
1
,
"lbl"
]
=
l
unlabeldLen
=
len
(
dfFile
.
loc
[
dfFile
[
"lbl"
]
==
-
1
])
dfFile
.
to_csv
(
fileToSave
,
index
=
False
)
print
(
"Wrote: {}. File is {}s long, total unlabeld time {}s (unlabeld percentage: {})"
.
format
(
fileToSave
,
len
(
dfFile
)
/
50
,
unlabeldLen
/
50
,
100
*
(
unlabeldLen
/
50
)
/
(
len
(
dfFile
)
/
50
)))
Event Timeline
Log In to Comment