<jupyter_start><jupyter_text>Small functions that help filter the data<jupyter_code>def get_closest_beacon(m5cb, members_metadata, beacons_metadata):
    """
    Parameters: dataframe, dataframe, dataframe
    Returns: a table with the closest beacon for each member
    """
    
    #Create table with only closest beacon
    m1cb = m5cb[['beacon_0', 'rssi_0']].rename(
        columns = {'beacon_0': 'beacon', 'rssi_0': 'rssi'}).reset_index()

    #Add beacon metadata
    m1cb = m1cb.join(
            beacons_metadata[['company', 'type']], on='beacon').rename(
            columns = {'company': 'beacon_company', 'type': 'beacon_type'})
    #Add badge metadata
    m1cb = m1cb.join(
            members_metadata[['company']], on='member').rename(columns = {'company': 'member_company'})
    
    return m1cb
def count_to_hours(counter):
    """
    Given a count
    Returns hours
    """
    seconds = counter*15
    minutes = seconds/60
    hours = minutes/60
    return(round(hours,2))
def drop_uncompliant(mySeries):
    return mySeries[mySeries.comply != False]
def drop_board_beacons(mySeries):
    """
    Given a dataframe
    Returns a dataframe without board beacons
    """
    return mySeries[mySeries.beacon_type != 'board']<jupyter_output><empty_output><jupyter_text>Generating Dataframe of compliance hours for period one<jupyter_code>for date in period_one:
    tempHours = pd.DataFrame()
    
    #Generate the Time Frame
    day_start = date + ' 00:00:00-04:00'
    day_end = date + ' 23:59:30-04:00'
    desired_range = "datetime >= day_start & datetime < day_end"
    
    #Preparing the closest beacon and compliance data
    m5cb = pd.read_hdf(clean_store_path,'proximity/member_5_closest_beacons', where = desired_range, data_columns= True)
    m1cb = get_closest_beacon(m5cb, members_metadata, beacons_metadata)
    
    comply_data = pd.read_hdf(analysis_store_path, '/proximity/member_comply', where = desired_range, data_columns= True)
    comply_dataframe = comply_data.to_frame()
    comply_dataframe.reset_index(inplace = True)
    
    m1cb = m1cb.merge(comply_dataframe, how = 'inner', on = ['datetime', 'member'])
    m1cb_comply = drop_uncompliant(m1cb)
    #m1cb_comply = drop_board_beacons(m1cb)
    
    grouped_compliance = m1cb_comply.groupby(['member'])

    daily_compliance_counts = grouped_compliance['comply'].count()
    tempHours[date] = daily_compliance_counts.apply(count_to_hours)
    
    hours_complied_period_one = hours_complied_period_one.join(tempHours)<jupyter_output><empty_output><jupyter_text>Generating Dataframeof compliance hours for period two<jupyter_code>for date in period_two:
    tempHours = pd.DataFrame()
    
    #Generate the Time Frame
    day_start = date + ' 00:00:00-04:00'
    day_end = date + ' 23:59:30-04:00'
    desired_range = "datetime >= day_start & datetime < day_end"
    
    #Preparing the closest beacon and compliance data
    m5cb = pd.read_hdf(clean_store_path,'proximity/member_5_closest_beacons', where = desired_range, data_columns= True)
    m1cb = get_closest_beacon(m5cb, members_metadata, beacons_metadata)
    
    comply_data = pd.read_hdf(analysis_store_path, '/proximity/member_comply', where = desired_range, data_columns= True)
    comply_dataframe = comply_data.to_frame()
    comply_dataframe.reset_index(inplace = True)
    
    m1cb = m1cb.merge(comply_dataframe, how = 'inner', on = ['datetime', 'member'])
    m1cb_comply = drop_uncompliant(m1cb)
    #m1cb_comply = drop_board_beacons(m1cb)
    
    grouped_compliance = m1cb_comply.groupby(['member'])

    daily_compliance_counts = grouped_compliance['comply'].count()
    tempHours[date] = daily_compliance_counts.apply(count_to_hours)
    
    hours_complied_period_two = hours_complied_period_two.join(tempHours)
    
    
    
#Cleaning the tables
hours_complied_period_one = hours_complied_period_one.fillna(0)
hours_complied_period_two = hours_complied_period_two.fillna(0)
hours_complied_period_one.sort_index(inplace = True)
hours_complied_period_two.sort_index(inplace = True)
#Creating Period One Heatmap
plt.figure(figsize=(20,45))
sns.heatmap(hours_complied_period_one,cmap='Reds', vmax = 12, 
            cbar = True)
plt.xticks(rotation = 45)
plt.show()
#Creating Period Two Heatmap
plt.figure(figsize=(20,45))
sns.heatmap(hours_complied_period_two,cmap='Reds', vmax = 12,
            cbar = True)
plt.xticks(rotation = 50)
plt.show()
#Appending to the tables
hours_complied_period_one['Total_Hours_Complied'] = hours_complied_period_one.sum(axis=1)
hours_complied_period_two['Total_Hours_Complied'] = hours_complied_period_two.sum(axis=1)
hours_complied_period_one.head()
hours_complied_period_two.head()
member = '328SASHRV6'
hours_complied_period_two.loc[member]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10741206030150753, 'fraction_numerical': 0.02198492462311558, 'mean_word_length': 4.727817745803358, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '305509', 'license': 'MIT', 'n_tokens_mistral': 1761, 'n_tokens_neox': 1672, 'n_words': 292, 'path': 'notebooks/00-tests/misc/01.11-hours-of-compliance.ipynb', 'repo_name': 'HumanDynamics/rhythm-public-analysis-deltav18-anon', 'size': '4776'}