Commit 477ea2cc authored by dhomm's avatar dhomm
Browse files

sensor finder changes

parent 0c31b09e
......@@ -38,6 +38,7 @@ For the metadata palcement: upperarm was the: upper arm chosen
For the metadata palcement: waist was the: waist chosen
......@@ -210,7 +210,7 @@ def n_placement_restriction(n, paired_sensors, restrictions):
return p_s
def sensor_decider(sensors, placement, position_key):
def sensor_finder(sensors, placement, position_key):
This function compares certain thresholds and compares sensors
pairwise to decide which sensor belongs to a given placement.
......@@ -395,6 +395,73 @@ def sensor_decider(sensors, placement, position_key):
return "This placement is not in a subset of the used data set"
def combination_linter(file, placement, bp_key):
a = read("a:", file=file)
s = read("s:", file=file)
# remove all sensors except accelerometer and gyroscope
a = get_acc_gyr(a)
# get the frequency
freq1 = a[0].info.sample_rate
freq2 = a[1].info.sample_rate
if freq1 == freq2:
freq = freq1
raise Exception("The frequency of sensor 0 and sensor 1 need to be the same")
raise Exception("Either there are to few sensors available or sensor 0 and sensor 1 has no frequency or not the same frequency")
key = bp_key #"BODY_POSITION"
start, end = get_walking_sequences(s, freq)
sensors = get_acc_gyr(a)
# filter body parts which cannot be compared yet
bps = ["chest", "forearm", "wrist", "head", "thigh", "shin", "upperarm", "upper arm", "waist"]
s_help = []
for i in sensors:
if[key].lower() in bps:
sensors = s_help
minimum = min([len(stream) for stream in sensors])
sensors = [stream[start:end] for stream in sensors]
combi = list(paired_acc_gyr(sensors, key))
if not minimum > end:
if minimum < start:
i = 0
while i < len(combi):
if len(combi[i][0]) < start or len(combi[i][1]) < start:
print("The matadata placement: ", combi[i][0].info.metadata[key], "needed to be discarded since ther was no walking sequence available")
discarded_placement = combi[i][0].info.metadata[key]
i += 1
minimum = min([len(combi[i][0]) for i in range(len(combi))] + [len(combi[i][1]) for i in range(len(combi))])
if minimum < end:
end = minimum
print("So all sensors could be included in the decisiion process the end needed to be reset to: ", end)
elif minimum < end:
end = minimum
print("So all sensors could be included in the decisiion process the end needed to be reset to: ", end)
if start > end:
raise Exception("Somethings wrong with the walking data the start is after the end")
result = sensor_finder(combi, placement, key)
acc, gyr = result
print("For the wanted placement: ", placement, "the sensor with the metadata placement: ",[key], "was chosen.")
print("All available metadata placements were: ", [s[0].info.metadata[bp_key] for s in combi])
return result
if __name__ == "__main__":
# set properties
file = "../Proband3.mkv"
placement = "forearm"
bp_key = "BODY_POSITION"
combination_linter(file, placement, bp_key)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment