<jupyter_start><jupyter_text>Beiwe Homestay Data from GPS TracesPeter provided the homestay data from the GPS traces and this notebook just helps take a look at it and process it for later use.<jupyter_code>import warnings
warnings.filterwarnings('ignore')<jupyter_output><empty_output><jupyter_text>Package Import<jupyter_code>import sys
import os
sys.path.append('../')

from src.visualization import visualize

import pandas as pd
pd.set_option('display.max_columns', 200)
import numpy as np

from datetime import datetime, timedelta

import matplotlib.pyplot as plt
import matplotlib.dates as mdates<jupyter_output><empty_output><jupyter_text>Data ImportWe have the files stored in the `interim` directory so we can import them by participant. Each participant has a pre- and post-move file _if_ they have data from these periods.<jupyter_code>data_dir = "../"
data = pd.DataFrame()
for file in os.listdir(f"{data_dir}data/interim/pre_post_move_homestay/"):
    if file.split("_")[0] == "homestay":
        temp = pd.read_csv(f"{data_dir}data/interim/pre_post_move_homestay/{file}",parse_dates=["start","end"],infer_datetime_format=True)
        temp = temp.iloc[:,1:]
        temp["beiwe"] = file.split("_")[1]
        temp["when"] = file.split("_")[-1].split(".")[0]
        data = data.append(temp)<jupyter_output><empty_output><jupyter_text>InspectionWe can look at a few derivatives.<jupyter_code>data["t"] = (data["end"] - data["start"]).dt.total_seconds()<jupyter_output><empty_output><jupyter_text>Comparing Lat/Long from Beiwe to Provided Address<jupyter_code># Importing the data
raw_info = pd.read_excel("../data/raw/utx000/admin/id_crossover.xlsx",sheet_name="beacon")
info = raw_info[["beiwe","lat","long","lat2","long2"]]
# filtering dataset
add = data.groupby(["beiwe","when"]).median().reset_index()
add.rename({"home.lat":"lat","home.long":"long"},axis="columns",inplace=True)
# merging
merged = add.merge(right=info,on="beiwe",suffixes=["_peter","_hagen"])
def plot_bar(df):
    """"""
    labels = []
    # pre and no move
    df_pre = df[df["when"].isin(["premove","nomove"])]
    lat_diff = abs(df_pre["lat_hagen"] - df_pre["lat_peter"])
    long_diff = abs(df_pre["long_hagen"] - df_pre["long_peter"])
    labels += list(df_pre["beiwe"].values)
    # post
    df_post = df[df["when"].isin(["postmove"])]
    lat_diff = lat_diff.append(abs(df_post["lat2"] - df_post["lat_peter"]))
    long_diff = long_diff.append(abs(df_post["long2"] - df_post["long_peter"]))
    labels += list(df_post["beiwe"].values)

    x = np.arange(len(df))
    width = 0.4

    fig, ax = plt.subplots(figsize=(16,6))
    rects1 = ax.bar(x - width/2, lat_diff, width, label='Lat', color="cornflowerblue", edgecolor="black")
    rects2 = ax.bar(x + width/2, long_diff, width, label='Long', color="seagreen", edgecolor="black")

    # Add some text for labels, title and custom x-axis tick labels, etc.
    ax.set_ylabel('Absolute Difference in Coordinates')
    ax.set_xticks(x)
    ax.set_xticklabels(labels,rotation=-30,ha="left")
    for loc in ["top","right"]:
        ax.spines[loc].set_visible(False)
    ax.legend()

    plt.show()<jupyter_output><empty_output><jupyter_text>Getting Move-Out Dates<jupyter_code>plot_bar(merged)
move = raw_info[["beiwe","original_move"]]
move.dropna(inplace=True)
move.rename({"original_move":"move"},axis="columns",inplace=True)
#move.to_csv("../data/raw/utx000/admin/move_dates-ux_s20.csv",index=False)<jupyter_output><empty_output><jupyter_text>Saving<jupyter_code>data.to_csv("../data/processed/beiwe-homestay-ux_s20.csv")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.164673157162726, 'fraction_numerical': 0.009179415855354658, 'mean_word_length': 5.7593984962406015, 'pattern_counts': {'":': 4, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '602081', 'license': 'MIT', 'n_tokens_mistral': 1342, 'n_tokens_neox': 1307, 'n_words': 226, 'path': 'notebooks/4.8.5-hef-beiwe-homestay_inspection_and_processing.ipynb', 'repo_name': 'intelligent-environments-lab/utx000', 'size': '3595'}