location_utils.py
def gen_loc_file(filein: str, dir: str = None) -> str:
    """
    Generate location data file.

    Remove and print out records misplaced by timestamp.

    :param filein: Path to the data file generated from PowerSense.
    :param dir: Target directory to save location data file.
    :return: Path to the generated location data file.
    """

    filename, ext = splitext(basename(filein))
    if not dir:
        dir = os.getcwd()
    fileout = pathjoin(dir, '_'.join([filename, 'location' + ext]))
    with open(fileout, 'wt') as fout:
        writer = csv.writer(fout)
        with open(filein) as fin:
            reader = csv.reader(fin)
            header = next(reader, None)
            assert header, 'data file should have header.'
            writer.writerow((header[-2], header[-7], header[-6]))
            prev = next(reader, None)
            assert prev, 'data file should have at least one line of data.'
            prev = (prev[-2], prev[-7], prev[-6])
            for row in reader:
                r = (row[-2], row[-7], row[-6])
                if all(d for d in r):
                    if float(prev[0]) < float(r[0]):
                        writer.writerow(r)
                        prev = r
                    else:
                        # TODO: numpy.memmap for external sort if file too large
                        print(prev, '>=', r)
    return fileout

    Generate location data file.

    Remove and print out records misplaced by timestamp.

    :param filein: Path to the data file generated from PowerSense.
    :param dir: Target directory to save location data file.
    :return: Path to the generated location data file.
    
Generate location data file.
Remove and print out records misplaced by timestamp.
Generate location data file . Remove and print out records misplaced by timestamp .
def gen_loc_file(filein: str, dir: str = None) -> str:
    filename, ext = splitext(basename(filein))
    if not dir:
        dir = os.getcwd()
    fileout = pathjoin(dir, '_'.join([filename, 'location' + ext]))
    with open(fileout, 'wt') as fout:
        writer = csv.writer(fout)
        with open(filein) as fin:
            reader = csv.reader(fin)
            header = next(reader, None)
            assert header, 'data file should have header.'
            writer.writerow((header[-2], header[-7], header[-6]))
            prev = next(reader, None)
            assert prev, 'data file should have at least one line of data.'
            prev = (prev[-2], prev[-7], prev[-6])
            for row in reader:
                r = (row[-2], row[-7], row[-6])
                if all(d for d in r):
                    if float(prev[0]) < float(r[0]):
                        writer.writerow(r)
                        prev = r
                    else:
                        print(prev, '>=', r)
    return fileout
def gen_loc_file ( filein : str , dir : str = None ) -> str : filename , ext = splitext ( basename ( filein ) ) if not dir : dir = os . getcwd ( ) fileout = pathjoin ( dir , '_' . join ( [ filename , 'location' + ext ] ) ) with open ( fileout , 'wt' ) as fout : writer = csv . writer ( fout ) with open ( filein ) as fin : reader = csv . reader ( fin ) header = next ( reader , None ) assert header , 'data file should have header.' writer . writerow ( ( header [ - 2 ] , header [ - 7 ] , header [ - 6 ] ) ) prev = next ( reader , None ) assert prev , 'data file should have at least one line of data.' prev = ( prev [ - 2 ] , prev [ - 7 ] , prev [ - 6 ] ) for row in reader : r = ( row [ - 2 ] , row [ - 7 ] , row [ - 6 ] ) if all ( d for d in r ) : if float ( prev [ 0 ] ) < float ( r [ 0 ] ) : writer . writerow ( r ) prev = r else : print ( prev , '>=' , r ) return fileout
Generate location data file.
Generate location data file .
"""
    Generate location data file.

    Remove and print out records misplaced by timestamp.

    :param filein: Path to the data file generated from PowerSense.
    :param dir: Target directory to save location data file.
    :return: Path to the generated location data file.
    """ # TODO: numpy.memmap for external sort if file too large
Path to the generated location data file.
Path to the generated location data file .
filein
str
Path to the data file generated from PowerSense.
Path to the data file generated from PowerSense .
dir
str
Target directory to save location data file.
Target directory to save location data file .