# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Development
# <NAME><br>
# 3.29.2020<br>

# +
import numpy as np
import pandas as pd
import click
from class_file_clerk import *

#automate the boring stuff
import time, os, sys, re, warnings, shutil
beep = lambda x: os.system("echo -n '\a';sleep 0.2;" * x)
if not 'nb_dir' in globals():
    nb_dir = os.getcwd()
print('notebook is at: ' + nb_dir)

# github_path = "/Users/timothytyree/Documents/GitHub/radial_cell_motion"
# sys.path.insert(0, github_path)
# # from radial_cell_motion import *
# import radial_cell_motion as rcm

# load the autoreload extension
# %load_ext autoreload
# Set extension to reload modules every time before executing code
# %autoreload 2

# + [markdown] heading_collapsed=true
# # dev. for script that takes my students and outputs their email addresses as a list

# + hidden=true
# # #!/usr/bin/python

# # #!/bin/bash/python
# my_sections = [4850, 4852, 4858]
# roster_dir = f"{nb_dir}/.."
# roster_fn = 'RosterWeek0.xlsx'
# my_tutors = ['<EMAIL>', '<EMAIL>', '<EMAIL>']

# def get_my_students(my_sections = [4850, 4852, 4858], 
#                     roster_dir = f"{nb_dir}/..", 
#                     roster_fn = 'RosterWeek0.xlsx',
#                    my_tutors = ['<EMAIL>', '<EMAIL>', '<EMAIL>']):
#     os.chdir(roster_dir)
#     df = pd.read_excel(roster_fn)
#     col = df.columns[0]
#     print(f"matching section ID's with the column, '{col}'.")
#     df['mine'] = False
#     for si in my_sections:
#         boo = df[col] == si
#         df.loc[boo, 'mine'] = True
#     df_mine = df.query('mine').copy()
#     email_col = df_mine.columns[-2]
#     print(f"email columns taken to be '{email_col}'.")

#     #to .txt file
#     save_fn = 'my_students.txt'
#     df_mine[email_col].dropna().to_csv(save_fn, index=False, header=False)
#     ns = df_mine[email_col].dropna().size
#     print(f"printed {ns} students to '{save_fn}'.")
#     return True

# + hidden=true

# def get_my_students(my_sections = [4850, 4852, 4858], 
#                     roster_dir = f"{nb_dir}/..", 
#                     roster_fn = 'RosterWeek0.xlsx',
#                    my_tutors = ['<EMAIL>', '<EMAIL>', '<EMAIL>']):
#     os.chdir(roster_dir)
#     df = pd.read_excel(roster_fn)
#     col = df.columns[0]
#     print(f"matching section ID's with the column, '{col}'.")
#     df['mine'] = False
#     for si in my_sections:
#         boo = df[col] == si
#         df.loc[boo, 'mine'] = True
#     df_mine = df.query('mine').copy()
#     email_col = df_mine.columns[-2]
#     print(f"email columns taken to be '{email_col}'.")

#     #to .txt file
#     save_fn = 'my_students.txt'
#     s_out = pd.concat([pd.Series(my_tutors),df_mine[email_col].dropna()])
#     s_out.to_csv(save_fn, index=False, header=False)
#     ns = df_mine[email_col].dropna().size
#     print(f"printed {ns} students to '{save_fn}'.")
# #     return True
#     return df_mine[email_col].dropna()

# + hidden=true
df = get_my_students()

# + hidden=true
my_tutors = ['<EMAIL>', '<EMAIL>', '<EMAIL>']
list(df.values).append(my_tutors[0])

# + hidden=true
type(df)

# + hidden=true


# + [markdown] heading_collapsed=true
# # dev. for making attendance spreadsheet

# + hidden=true


# + hidden=true


# + hidden=true
# roster_fn = 'RosterApr6_2.xlsx'
# os.path.exists(roster_fn)
# nb_dir

# + hidden=true


# + hidden=true
# roster_fn = 'RosterApr6_2.xlsx'
# pd.read_excel(roster_fn, skiprows = 14)
# df.head()

# + hidden=true


# + hidden=true
# ##Record the set of students not matched
# #emails matched/not matched as true or false (--> attendence is NaN) according to Roster data
# matched = set(out[~out['Attendence'].isna()].index)
# not_matched = set(out[out['Attendence'].isna()].index)
# #show students that attended but were not matched according to the Roster data
# # attended according to Zoom data
# d2 = d[d['Attendence']==1].set_index(email_col)
# # select Zoom data that has emails matched to Roster data
# boo = [i in matched for i in d2.index]
# # take the compliment of ^that selection to get attending students not yet accounted for
# d2 = d2[~np.array(boo)]
# d2[d2.index.name] = d2.index.values
# # d2.set_index(name_col, drop=False)[[name_col, email_col]].head()
# #record my match of Zoom names to emails so I don't need to do this over
# # save a list of students and emails from Roster that were not matched
# # out[out['Attendence'].isna()]['Student', 'User Email'].to_csv('students_not_matched_in_roster_dataset.csv')
# out.loc[not_matched]['Student'].to_csv('students_not_matched_in_roster_dataset.csv', header=True)
# #save a list of students that attended the Zoom meeting that were not matched with a Roster email
# d2.set_index(name_col)[email_col].to_csv('students_not_matched_in_zoom_dataset.csv', header=True)

# + hidden=true
#set all attendence to 0

#DONE: export in the format Khang wants
#DONE: put all ^this into a .py file

#TODO: MOVE ON WITH YOUR DAY


# + hidden=true


# + hidden=true


# + hidden=true
#in sublime_text/excel, make a "best guess" as to which students are which.  Don't focus time here unreasonably.
#DONE: use ^that dictionary to fill in missing student emails.  all but 2-3 students I could recognize.

# + hidden=true
#fill out the attendence, using the email matching routine

#wrap ^this all up in a .py file
#()#.set_index('Name (Original Name)', drop=False)
# -

# # Workflow for taking Zoom attendence to Roster spreadsheets

#WORKFLOW:
#1 re-export the roster_fn as .xlsx from Excel
#2 df = get_my_students(roster_fn = roster_fn)
os.chdir(f"{nb_dir}/../data/input/from_Student_Roster")
df_all_students = get_my_students(roster_fn = 'RosterApr6_2.xlsx')
#3 run get_attendence(df)
df_attendence = get_attendence(df)

# + [markdown] heading_collapsed=true
# # (don't waste time on distractability operations) 
# setup.py question asker for auto_attendance

# + hidden=true


# + hidden=true


# + hidden=true
# #setup sections and tas
# if __name__ == __main__:
#     #
   
#     #add yourself to ta list
#     name = input('please enter your name:')
#     email= input('please enter your email:')
#     add
#     #clear list
#     os.chdir(data_dir)

retval = input("Do you have another section? (y/n)")


# -

# # file search

# +
import class_file_clerk as cfc

#define localfile system
if not 'nb_dir' in globals():
    nb_dir = os.getcwd()
data_dir   = f"{nb_dir}/../data/input/"
output_dir = f"{nb_dir}/../data/output/"
roster_dir = f"{data_dir}from_Student_Roster/"
zoom_dir   = f"{data_dir}from_Zoom/"
# -



get_zoom_fn_list()
# os.listdir()
# os.listdir()

# +

#WORKFLOW:
#1 re-export the roster_fn as .xlsx from Excel
#2 df = get_my_students(roster_fn = roster_fn)

# df_all_students = get_my_students()
#3 run get_attendence(df)
# df_attendence = get_attendence(df)
# -

setup_file_system()

# +
# os.chdir(roster_dir)
# os.path.exists(get_roster_fn())
# print_state()

# +
os.chdir(data_dir)
assert(get_sections() is not None)
assert(get_ta() is not None)
print_state()

my_sections = list(get_sections()['Sec ID'].values)
roster_fn   = get_roster_fn()
my_tutors   = list(get_ta()['email'].values)

#take attendance
print(f'\ngetting roster data from {roster_fn}')
df = get_my_students(roster_fn=roster_fn, 
                my_sections = my_sections,
                my_tutors = my_tutors,
                skiprows = 14)
print('')
df_attendence = get_attendence(df)
print(f"\nsaved output as '{get_output_fn()}'.")
# -

data_dir
# !pwd




















StarcoderdataJupyterScriptsDedupFiltered