import pandas as pd
import sys
import subprocess
import os

root_dir = "."

sn_to_name = {
        '6348C01835': 'EB79',
        '6348C01910': 'EB81',
        '6221C43829': 'BX992',
        }


# Move to Montana style directories
for root, dirs, files in os.walk(root_dir):
    for f in files:
        full_path = os.path.join(root, f)
        if not os.path.isfile(full_path):
            continue
        if 'hourly' in full_path:
            dev = f.split('_')[0]
            new_path = full_path.replace('hourly',
                                         os.path.join('data', 'gnss', dev)
                                         )

            new_dir = new_path.split(os.sep)
            n = 0
            for d in new_dir:
                if d == dev:
                    break
                n += 1
            #print(new_dir[0:n+1])
            new_dir = os.path.join(*new_dir[0:n+1])
            #print(f'{new_dir=}')
            if full_path != new_path:
                print(f'{full_path} -> {new_path}')
                os.makedirs(new_dir, exist_ok=True)
                os.rename(full_path, new_path)
