Example #1
0
def wifiSequence(priorInfo,
                 sensorFiles,
                 personID="pete",
                 device="360n5",
                 debugFlag=False):
    acceTimeList, acceValueList = loadAcceData(sensorFiles[0],
                                               relativeTime=False,
                                               deviceID=device)
    wifiTimeList, wifiScanList = loadMovingWifi(sensorFiles[1])

    # Count step
    acceValueArray = butterFilter(acceValueList)
    # Algorithm of step counter
    sc = SimpleStepCounter(personID)
    allIndexList = sc.countStep(acceTimeList, acceValueArray)
    wifiList = []

    # For debugging
    if debugFlag:
        stIndexList = allIndexList[0::3]
        stTimeList = [acceTimeList[i] for i in stIndexList]
        stValueList = [acceValueArray[i] for i in stIndexList]
        pkIndexList = allIndexList[1::3]
        pkTimeList = [acceTimeList[i] for i in pkIndexList]
        pkValueList = [acceValueArray[i] for i in pkIndexList]
        print "The average of peak values is ", np.mean(pkValueList)
        edIndexList = allIndexList[2::3]
        edTimeList = [acceTimeList[i] for i in edIndexList]
        edValueList = [acceValueArray[i] for i in edIndexList]
        stepNum = len(pkTimeList)
        print "Step number is ", stepNum
        print "Peak value at last", pkValueList[
            -1], "Peak value at first", pkValueList[0]
        print "The last duration is ", stTimeList[-1] - edTimeList[-2]
        # Plot the axes
        plt.xlabel("$time(s)$")
        plt.ylabel("$acceleration(m/s^2)$")
        acceLine, = plt.plot(acceTimeList,
                             acceValueArray,
                             lw=1,
                             color="blue",
                             label="Acceleration")
        stepPeaker, = plt.plot(pkTimeList,
                               pkValueList,
                               "rx",
                               ms=10,
                               label="Step Peaks")
        stepStarter, = plt.plot(stTimeList,
                                stValueList,
                                "yx",
                                ms=8,
                                label="Step Starts")
        stepEnder, = plt.plot(edTimeList,
                              edValueList,
                              "gx",
                              ms=5,
                              label="Step Ends")
        plt.legend(handles=[acceLine, stepPeaker, stepStarter, stepEnder],
                   fontsize=20)
        plt.show()
    else:
        pkIndexList = allIndexList[1::3]
        pkTimeList = [acceTimeList[i] for i in pkIndexList]
        stepNum = min(priorInfo[2], len(pkIndexList))
        sp = priorInfo[0]
        ep = priorInfo[1]
        locList = genLocation(sp, ep, stepNum)
        # log information
        # print "Location number: ", len(locList), " and step number: ", stepNum

        # len(locList) = stepNum + 1
        currentWifiIndex = 0
        for i in range(len(locList)):
            startWifiTime = pkTimeList[i - 1] if i >= 1 else 0
            endWifiTime = pkTimeList[i] if i < len(locList) - 1 else -1
            currentWifiIndex, currentWifiDict = wifiExtract(
                startWifiTime, endWifiTime, wifiTimeList, wifiScanList,
                currentWifiIndex)
            if currentWifiDict == None:
                continue
            locNow = locList[i]
            wifiList.append((locNow[0], locNow[1], currentWifiDict))

    return wifiList
@file: activitydemo.py
@software: PyCharm Community Edition
"""

import matplotlib.pyplot as plt

from matplotlib.ticker import MultipleLocator, FormatStrFormatter

from comutil import *
from dataloader import loadAcceData, loadGyroData

if __name__ == "__main__":
    sensorFilePath = ("20170622153925_acce.csv", "20170622153925_gyro.csv")

    # Load accelerometer data from files
    acceTimeList, acceValueList = loadAcceData(sensorFilePath[0])
    windowSize = 7
    acceVotList, acceVarList = varOfAcce(acceTimeList, acceValueList,
                                         windowSize)

    # Stationary
    timeListForStat = acceVotList[51:341]
    timeListForStat = [t - timeListForStat[0] for t in timeListForStat]
    valueListForStat = acceVarList[51:341]

    # Walking
    timeListForWalk = acceVotList[1511:1801]
    timeListForWalk = [t - timeListForWalk[0] for t in timeListForWalk]
    valueListForWalk = acceVarList[1511:1801]

    gyroTimeList, gyroValueList = loadGyroData(sensorFilePath[1])
Example #3
0
        # bigger than the last gyroscope time
        if acceTimeList[i] > gyroTimeList[-1] or math.fabs(
                acceTimeList[i] - gyroTimeList[-1]) < 0.002:
            a2gIndexList.append(len(gyroTimeList) - 1)
            continue
        for j in range(gyroStartIndex, len(gyroTimeList)):
            if math.fabs(acceTimeList[i] - gyroTimeList[j]) < 0.002:
                a2gIndexList.append(j)
                gyroStartIndex = j + 1
                break
            baseTime = acceTimeList[i]
            # Now, the gyroscope should be determined
            if gyroTimeList[j] > baseTime:
                targetIndex = j if gyroTimeList[
                    j] - baseTime < baseTime - gyroTimeList[j - 1] else j - 1
                a2gIndexList.append(targetIndex)
                gyroStartIndex = targetIndex + 1
                break
    return a2gIndexList


if __name__ == "__main__":
    sensorFilePath = ("./Examples/PDRTest/20170622153925_acce.csv",
                      "./Examples/PDRTest/20170622153925_gyro.csv")
    # Load accelerometer data from files
    acceTimeList, acceValueList = loadAcceData(sensorFilePath[0],
                                               relativeTime=False)
    gyroTimeList, gyroValueList = loadGyroData(sensorFilePath[1],
                                               relativeTime=False)
    agTimeAlign(acceTimeList, gyroTimeList)
    print("Done.")
Example #4
0
                else:
                    stepIndexList[-1] = startIndex
            stepIndexList.append(startIndex)
            stepIndexList.append(peakIndex)
            stepIndexList.append(endIndex)
        return stepIndexList


if __name__ == "__main__":
    # Accelerometer data for step counting
    # acceDataFilePath = "./Examples/StepCounter/20170707201405_acce.csv"
    # acceDataFilePath = "./Examples/ExtendedKF/20180118102918_acce.csv"
    # acceDataFilePath = "./Examples/SimplePDR/20170702210514_acce.csv"
    acceDataFilePath = "./Examples/neufloor/0.0-y.csv"

    acceTimeList, acceValueList = loadAcceData(acceDataFilePath)

    # Smoothing filter - sliding windows
    # size = 7
    # acceValueList = [averageValue(acceValueList, t, size) for t in range(len(acceValueList))]

    acceValueArray = butterFilter(acceValueList)

    # para = modelParameterDict.get("pete")
    # Algorithm of step counter
    # sc = SimpleStepCounter(para[0], para[1], para[2], para[3])
    sc = SimpleStepCounter(personID="pete")
    allIndexList = sc.countStep(acceTimeList, acceValueArray)

    peakIndexList = allIndexList[1::3]
    peakTimeList = [acceTimeList[i] for i in peakIndexList]
Example #5
0
                break  # outer for clause
            stepIndexList.append(startIndex)
            stepIndexList.append(peakIndex)
            stepIndexList.append(endIndex)
        return stepIndexList


if __name__ == "__main__":
    # Prior Information
    person = "pete"
    device = "360n5"
    # Accelerometer data for step counting
    acceDataFilePath = "./Examples/StepCounter/20170707201405_acce.csv"
    acceDataFilePath = "./Examples/ExtendedKF/20180118102918_acce.csv"

    acceTimeList, acceValueList = loadAcceData(acceDataFilePath,
                                               deviceID=device)

    # Smoothing filter - sliding windows
    # size = 7
    # acceValueList = [averageValue(acceValueList, t, size) for t in range(len(acceValueList))]

    acceValueArray = butterFilter(acceValueList)

    # para = modelParameterDict.get("pete")
    # Algorithm of step counter
    # sc = SimpleStepCounter(para[0], para[1], para[2], para[3])
    sc = SimpleStepCounter(personID=person)
    allIndexList = sc.countStep(acceTimeList, acceValueArray)

    peakIndexList = allIndexList[1::3]
    peakTimeList = [acceTimeList[i] for i in peakIndexList]
Example #6
0
            thirdMoveVector = (49.8, 1.95)
            rawDataArray.extend(rawDataArrayofThird)
            routeRotClockWise = thirdRouteRotClockWise
            moveVector = thirdMoveVector
            dataBelongs = "t3"

        errorListInSensorError = []
        for i in range(min(len(stepLengthErrorList), len(headingErrorList))):
            slError4Test = stepLengthErrorList[i]
            headingError4Test = headingErrorList[i]
            errorBySteps = []
            for k in range(10):
                for j in range(len(rawDataArray)):
                    filePaths = rawDataArray[j]
                    # Load sensor data from files
                    acceTimeList, acceValueList = loadAcceData(
                        filePaths[0], relativeTime=False)
                    gyroTimeList, gyroValueList = loadGyroData(
                        filePaths[1], relativeTime=False)
                    wifiTimeList, wifiScanList = loadMovingWifi(filePaths[2])
                    # load real locations
                    locRealDF = pd.read_csv(filePaths[3])
                    locRealList = [(loc[0], loc[1])
                                   for loc in locRealDF.values]

                    locEstWorldList = secondAiFi.onlineViterbi(
                        acceTimeList,
                        acceValueList,
                        gyroTimeList,
                        gyroValueList,
                        wifiTimeList,
                        wifiScanList,