<jupyter_start><jupyter_text>Define Term Dates<jupyter_code># Define the dates
number_of_terms=3
term_start_dates=['28/09/2020','11/01/2021','26/04/2021']
term_end_dates=['18/12/2020','26/03/2021','11/06/2021']
reading_week_dates=['09/11/2020','15/02/2021']
# Convert the string to dates
term_start_dates=[pd.to_datetime(date, format='%d/%m/%Y') for date in term_start_dates]
term_end_dates=[pd.to_datetime(date, format='%d/%m/%Y') for date in term_end_dates]
reading_week_dates=[pd.to_datetime(date, format='%d/%m/%Y') for date in reading_week_dates]<jupyter_output><empty_output><jupyter_text>Create the Calendar DataFrame<jupyter_code>def get_term_number(df):
    if (df['Date']>=reading_week_dates[0]) & (df['Date']<=(reading_week_dates[0] + pd.Timedelta(6,unit='days'))):
        return 'Reading Week 1'
    elif (df['Date']>=reading_week_dates[1]) & (df['Date']<=(reading_week_dates[1] + pd.Timedelta(6,unit='days'))):
        return 'Reading Week 2'
    if (df['Date']>=term_start_dates[0]) & (df['Date']<=term_end_dates[0]):
        return 'Term 1'
    elif (df['Date']>term_end_dates[0]) & (df['Date']<term_start_dates[1]):
        return 'Christmas Holidays'
    elif (df['Date']>=term_start_dates[1]) & (df['Date']<=term_end_dates[1]):
        return 'Term 2'
    elif( df['Date']>term_end_dates[1]) & (df['Date']<term_start_dates[2]):
        return 'Easter Holidays'
    elif (df['Date']>=term_start_dates[2]) & (df['Date']<=term_end_dates[2]):
        return 'Term 3'

calendar=pd.DataFrame(columns=['Date'])
calendar['Date']=pd.date_range(start=term_start_dates[0], end=term_end_dates[number_of_terms-1])
if os.name=='nt':
    calendar['Date_F']=calendar['Date'].dt.strftime('%#d %B %Y')
else:
    calendar['Date_F']=calendar['Date'].dt.strftime('%-d %B %Y')
calendar['Day'] =calendar['Date'].dt.day
calendar['Week Day']=calendar['Date'].dt.day_name()
calendar['Week Day'] = pd.Categorical(calendar['Week Day'], categories=
    ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday', 'Sunday'],
    ordered=True)
calendar['Academic_Week_Number'] = calendar['Date'].apply(lambda x: (x.isocalendar()[1]-35) if (x.isocalendar()[1]-35)>0 else (x.isocalendar()[1]+18))
calendar['Term Class']=calendar.apply(get_term_number,axis=1)<jupyter_output><empty_output><jupyter_text>Add Planned Hours<jupyter_code>calendar['Planned_work_hours']=5<jupyter_output><empty_output><jupyter_text>Add number of Hours required for Coursework<jupyter_code>calendar['Hours_required_for_Coursework']=1
# Adding contingency of 1.2<jupyter_output><empty_output><jupyter_text>Calculate the Workload<jupyter_code>calendar['Workload']=(calendar['Hours_required_for_Coursework']/calendar['Planned_work_hours'])
calendar.to_csv('calendar.csv')<jupyter_output><empty_output><jupyter_text>Get the HeatMap<jupyter_code>calendar[calendar['Date'].dt.month==9].head()
academic_year = list(range(9,13)) + list(range(1,7))
monthly=calendar[calendar['Date'].dt.month==10].pivot(index='Academic_Week_Number', columns='Week Day', values='Workload')
yearly=calendar.pivot(index='Week Day', columns='Academic_Week_Number', values='Workload')
monthly
yearly
annotations_monthly=calendar[calendar['Date'].dt.month==10].pivot(index='Academic_Week_Number', columns='Week Day', values='Day')
annotations_yearly=calendar.pivot(index='Week Day', columns='Academic_Week_Number', values='Day')
dates_monthly=calendar[calendar['Date'].dt.month==10].pivot(index='Academic_Week_Number', columns='Week Day', values='Date_F')
dates_yearly = calendar.pivot(index='Week Day', columns='Academic_Week_Number', values='Date_F')<jupyter_output><empty_output><jupyter_text>Month wise<jupyter_code>def generate_heatmap(df, dates, title='', autosize=True, width=None, height=None, x_label='', y_label='', side="bottom"):

    data = go.Heatmap(z=df,
                      x=df.columns,
                      y=df.index,
                      hovertext=dates,
                      ygap=3,
                      xgap=3,
                      hoverongaps = False,
                      showscale = False,
                      colorscale=['rgb(0,100,0)', 'rgb(100,0,0)'], zmax=1.5, zmid=0.5, zmin=0,
                      hovertemplate = '%{hovertext}<br>Workload: <b>%{z:%}</b><extra></extra>')
                      
    layout = go.Layout(autosize=autosize,
                       width=width,
                       height=height,
                       title="<b>{}</b>".format(title),
                       title_x=0.5,
                       xaxis_title='<b>{}</b>'.format(x_label),
                       yaxis_title='<b>{}</b>'.format(y_label),
                       template="simple_white",
                       xaxis=dict(side=side, showline=False,ticks=''),
                       yaxis=dict(autorange="reversed", showline=False,ticks=''),
                       margin=dict(pad=5),
                       showlegend=False, 
                       hoverlabel=dict(align = 'auto',bordercolor='rgb(48,48,48)',bgcolor='rgb(48,48,48)',font=dict(color='white')))

    fig = go.Figure(data=data, layout=layout)
    return fig
                    
def generate_month_wise(monthly, annotations, dates_monthly): 
    fig=generate_heatmap(monthly,dates_monthly,title='October', y_label='Academic Week Number', side="top")
    for i in np.arange(len(monthly.columns)):
        for j in np.arange(len(monthly.index)):
            if not np.isnan(annotations.iloc[j,i]):
                fig.add_annotation(x=monthly.columns[i],y=monthly.index[j],text=int((annotations.iloc[j,i])),
                                   font_color='white',showarrow=False)
    fig.show()

generate_month_wise(monthly,annotations_monthly,dates_monthly)<jupyter_output><empty_output><jupyter_text>Year wise<jupyter_code>def generate_yearwise(yearly,annotations,dates_yearly):
    fig=generate_heatmap(yearly,dates_yearly, autosize=False, width=1200, height=400, x_label='Academic Week Number')
    fig.show()
generate_yearwise(yearly, annotations_yearly,dates_yearly)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17131011608623548, 'fraction_numerical': 0.025538971807628524, 'mean_word_length': 4.4827272727272724, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 52, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '508101', 'license': 'MIT', 'n_tokens_mistral': 2187, 'n_tokens_neox': 2028, 'n_words': 251, 'path': 'test.ipynb', 'repo_name': 'Aru2612/Coursework_Heatmap', 'size': '6030'}