-
Notifications
You must be signed in to change notification settings - Fork 3
/
unisensHeaders2Excel.m
132 lines (112 loc) · 4.86 KB
/
unisensHeaders2Excel.m
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
function unisensHeaders2Excel(path)
%UNISENSHEADERS2EXCEL extract unisens header data from unisens datasets to Excel for checking or editing
% Excel data can be reintegrated again in to unisens datasets with excel2UnisensHeaders()
% Copyright 2018 movisens GmbH, Germany
addUnisensJar;
jUnisensFactory = org.unisens.UnisensFactoryBuilder.createFactory();
alldirs = rdir(path,'');
rowHeader={'path', 'measurementId', 'measurementStart', 'weekdayStart', 'sensorId', 'sensorType', 'sensorVersion', 'sensorLocation', 'duration_h', 'personId', 'age', 'height', 'weight', 'gender', 'entries', 'WARNING'};
j=0;
rows={};
dateFormatWeekday = java.text.SimpleDateFormat('EEE');
dateFormatDate = java.text.DateFormat.getDateInstance( java.text.DateFormat.MEDIUM);
dateFormatTime = java.text.DateFormat.getTimeInstance( java.text.DateFormat.SHORT);
for i=1:length(alldirs)
relPath = [alldirs(i).relativePath ];
%path to unisens file
fullpath = [path relPath filesep 'unisens.xml'];
if exist(fullpath, 'file')
jUnisens = jUnisensFactory.createUnisens([path relPath]);
duration = jUnisens.getDuration()/60/60;
customAttributes = jUnisens.getCustomAttributes();
warn = false;
warnText='';
measurementId = jUnisens.getMeasurementId();
if isempty(measurementId)
warn =true;
warnText = [warnText 'Measurement Id missing. '];
end
measurementTimeStart = jUnisens.getTimestampStart();
if isempty(measurementTimeStart)
warn =true;
warnText = [warnText 'TimestampStart missing. '];
measurementTimeStartStr='';
measurementWeekdayStartStr='';
else
measurementTimeStartStr = [ char(dateFormatDate.format(measurementTimeStart)) ' ' char(dateFormatTime.format(measurementTimeStart))];
measurementWeekdayStartStr = char(dateFormatWeekday.format(measurementTimeStart));
end
sensorId = customAttributes.get('sensorSerialNumber');
if isempty(sensorId)
warn =true;
warnText = [warnText 'sensorId missing. '];
end
sensorType = customAttributes.get('sensorType');
if isempty(sensorType)
warn =true;
warnText = [warnText 'Sensor Type missing. '];
end
sensorVersion = customAttributes.get('sensorVersion');
if isempty(sensorVersion)
warn =true;
warnText = [warnText 'Sensor Version missing. '];
end
sensorLocation = customAttributes.get('sensorLocation');
if isempty(sensorLocation)
warn =true;
warnText = [warnText 'Sensor Location missing. '];
end
personId = customAttributes.get('personId');
if isempty(personId)
warn =true;
warnText = [warnText 'personId missing. '];
end
age = str2double(customAttributes.get('age'));
if isnan(age) || age <1 || age > 105
warn =true;
warnText = [warnText 'age missing or out of range. '];
end
height = str2double(customAttributes.get('height'));
if isnan(height) || height > 250
warnText = [warnText 'height missing or out of range. '];
warn = true;
end
weight = str2double(customAttributes.get('weight'));
if isnan(weight) || weight > 150
warn = true;
warnText = [warnText 'weight missing or out of range. '];
end
entries= jUnisens.getEntries();
nEntries = entries.size();
entriesText = [];
for i=1:nEntries
if i~=1
entriesText = [entriesText ', '];
end
entriesText = [entriesText char(entries.get(i-1).getId())];
end
row = {...
relPath, ...
char(measurementId), ...
measurementTimeStartStr, ...
measurementWeekdayStartStr, ...
sensorId, ...
sensorType, ...
['''' sensorVersion], ...
sensorLocation, ...
round(duration*100)/100, ...
['''' personId], ...
age, ...
height, ...
weight, ...
customAttributes.get('gender'), ...
entriesText, ...
warnText};
j=j+1;
rows=[rows ; row];
jUnisens.closeAll();
end
end
outputMatrix = [rowHeader; rows];
xlswrite([path filesep 'Data Overview.xlsx'], outputMatrix);
end