├── README.md ├── birth.py ├── graph.py ├── extracurricular_analysis.py ├── quest_grad_rate.py ├── grad_proj4 ├── grad_project.py └── jsc.py /README.md: -------------------------------------------------------------------------------- 1 | ## QuestBridge Internship 2014 2 | 3 | jsc.py: the purpose of this code was to create customized terminal commands using the REST API, rather than resort to using a traditional GUI. 4 | -------------------------------------------------------------------------------- /birth.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | from numpy import random 3 | import matplotlib.pyplot as plt 4 | import sys 5 | 6 | names = [] # names ommited for privacy reasons 7 | 8 | random.seed(500) 9 | random_names = [names[random.randint(low=0,high=len(names))] for i in range(1000)] 10 | 11 | 12 | births = [random.randint(low=0,high=1000) for i in range(1000)] 13 | births[:10] 14 | 15 | 16 | BabyDataSet = zip(random_names,births) 17 | BabyDataSet[:10] 18 | 19 | df = pd.DataFrame(data = BabyDataSet, columns=['Names', 'Births']) 20 | df.to_csv('births1880.txt',index=False,header=False) 21 | 22 | df = pd.read_csv('births1880.txt', names = ['Names', 'Births']) 23 | 24 | name = df.groupby('Names') 25 | 26 | df = name.sum() 27 | print df 28 | sorted_df = df.sort(['Births'], ascending = False) 29 | print sorted_df 30 | 31 | sorted_df.plot(kind = 'line') 32 | plt.show() 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /graph.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | from collections import Counter 4 | 5 | import csv 6 | import matplotlib.pyplot as plt 7 | import numpy.numarray as na 8 | import parse 9 | 10 | MY_FILE = "../data/sample_sfpd_incident_all.csv" 11 | 12 | def visualize_days(): 13 | """Visualize data by day of week""" 14 | 15 | # grab our parsed data that we parsed earlier 16 | data_file = parse.parse(MY_FILE, ",") 17 | # make a new variable, 'counter', from iterating through each 18 | # line of data in the parsed data, and count how many incidents 19 | # happen on each day of the week 20 | counter = Counter(item["DayOfWeek"] for item in data_file) 21 | 22 | # separate the x-axis data (the days of the week) from the 23 | # 'counter' variable from the y-axis data (the number of 24 | # incidents for each day) 25 | data_list = [ 26 | counter["Monday"], 27 | counter["Tuesday"], 28 | counter["Wednesday"], 29 | counter["Thursday"], 30 | counter["Friday"], 31 | counter["Saturday"], 32 | counter["Sunday"] 33 | ] 34 | day_tuple = tuple(["Mon", "Tues", "Wed", "Thurs", "Fri", "Sat", "Sun"]) 35 | 36 | # with that y-axis data, assign it to a matplotlib plot instance 37 | plt.plot(data_list) 38 | # create the amount of ticks needed for our x-axis, and assign 39 | # the labels 40 | plt.xticks(range(len(day_tuple)), day_tuple) 41 | 42 | # save the plot! 43 | plt.savefig("Days.png") 44 | 45 | # close plot file 46 | plt.clf() 47 | 48 | def main(): 49 | visualize_days() 50 | 51 | if __name__ == "__main__": 52 | main() 53 | -------------------------------------------------------------------------------- /extracurricular_analysis.py: -------------------------------------------------------------------------------- 1 | import csv 2 | import StringIO as st 3 | 4 | def search_words(key): 5 | counter = 0 6 | with open('filename.csv', 'rb') as csvfile: 7 | spamreader = csv.reader(csvfile, quotechar = ' ',) 8 | for row in spamreader: 9 | mount = 0 10 | for x in row: 11 | for word in x.replace('.','').replace("!", '').replace("-", '').replace(":", '').replace('"', '').replace("(",'').replace(")",'').lower().split(): 12 | if word == key: 13 | count = 1 14 | if count == 1: 15 | mount += 1 16 | if mount > 0: 17 | counter += 1 18 | print counter 19 | 20 | def search_titles(key): 21 | counter = 0 22 | with open('filename.csv', 'rb') as csvfile: 23 | spamreader = csv.reader(csvfile, quotechar = ' ',) 24 | for row in spamreader: 25 | mount = 0 26 | for x in row: 27 | if x.lower() == key.lower(): 28 | count = 1 29 | if count == 1: 30 | mount += 1 31 | if mount > 0: 32 | counter += 1 33 | print counter 34 | 35 | def search(key): 36 | counter = 0 37 | with open('filename.csv', 'rb') as csvfile: 38 | spamreader = csv.reader(csvfile, quotechar = ' ',) 39 | for row in spamreader: 40 | mount = 0 41 | for x in row: 42 | if x.lower() == key.lower(): 43 | count = 1 44 | if count == 1: 45 | mount += 1 46 | else: 47 | for word in x.replace('.','').replace("!", '').replace('"', '').replace("-", '').replace(":", '').replace("(",'').replace(")",'').split(): 48 | if word == key or word == key: 49 | count = 1 50 | if count == 1: 51 | mount += 1 52 | if mount > 0: 53 | counter += 1 54 | print counter 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /quest_grad_rate.py: -------------------------------------------------------------------------------- 1 | ########################## 2 | # Lesley Cordero 3 | # Quest Project 4 | ########################## 5 | 6 | from xlrd import open_workbook,XL_CELL_TEXT 7 | import csv 8 | 9 | def graduation(): 10 | book = open_workbook("quest.xlsx") 11 | # opens excel 12 | sheet = book.sheet_by_index(0) 13 | book2 = open_workbook("partners.xlsx") 14 | sheet2 = book2.sheet_by_index(0) 15 | liss = [] 16 | liss2 = [] 17 | # create empty list to append cells 18 | tcount = 0 19 | # counts total number of quest scholars in excel file 20 | gcount = 0 21 | # counts number of quest scholars that graduated 22 | x = 0 23 | # set first index number to 0 24 | for col in sheet.col(0): 25 | # iterate through first column 26 | liss.append(col) 27 | for col2 in sheet2.col(0): 28 | liss2.append(col2) 29 | for item in liss: 30 | # iterate through each item in list 31 | if x + 1 < len(liss): 32 | # if x + 1 is less than the length of list, proceed because 33 | # then program will not have run into empty cells 34 | if str(liss[x]) == str(liss[x+1]): 35 | # if cell values are equal, they are same person 36 | tcount = tcount 37 | # since they are the same person, the total count doesnt change 38 | else: 39 | # otherwise, it's a new person 40 | if str(sheet.cell(x,2)) in str(liss2): 41 | tcount = tcount + 1 42 | # that means they went to one of our partners, so add to 43 | # total count 44 | if str(sheet.cell(x,1)) == "text:u'Y'": 45 | gcount = gcount + 1 46 | if x + 1 == len(liss): 47 | # if x + 1 is less than the length of list, proceed because 48 | # then program will not have run into empty cells 49 | if str(sheet.cell(x,2)) in str(liss2): 50 | if str(sheet.cell(x,1)) == "text:u'Y'": 51 | gcount = gcount + 1 52 | x = x + 1 53 | print tcount 54 | print gcount 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /grad_proj4: -------------------------------------------------------------------------------- 1 | ########################## 2 | # Lesley Cordero 3 | # Quest Project 4 | # The following script counts the number of graduated quest scholars 5 | ########################## 6 | 7 | from xlrd import open_workbook,XL_CELL_TEXT 8 | import csv 9 | 10 | def graduation(): 11 | book = open_workbook("graduation.xls") 12 | sheet = book.sheet_by_index(0) 13 | # Opens clearinghouse excel sheet 14 | partners = [] 15 | finalists = [] 16 | scholars = [] 17 | tcount = 0 18 | gcount = 0 19 | bcount = 0 20 | x = 0 21 | 22 | for col in sheet.col(0): 23 | finalists.append(col) 24 | # Iterates and appends finalists to the empty list created earlier 25 | with open('IDs.csv', 'rb') as csvfile: 26 | spamreader = csv.reader(csvfile, quotechar = ' ',) 27 | # Opens CSV file and iterates through 28 | for row in spamreader: 29 | for it in row: 30 | item = "text:u'" + it + "_'" 31 | scholars.append(item) 32 | # Fixes format of entries to compare to clearinghouse data 33 | with open('partners.csv', 'rb') as csvfile: 34 | spamreader = csv.reader(csvfile, quotechar = ' ',) 35 | # Again, opens CSV file containing partner colleges and appends each 36 | # entry to the empty list created earlier. Also again, fixes format. 37 | for row in spamreader: 38 | for it in row: 39 | item = "text:u'" + it + "'" 40 | partners.append(item) 41 | for item in finalists: 42 | # Iterates through clearinghouse IDs appended to the empty list 43 | if x + 1 < len(finalists): 44 | if str(finalists[x]) == str(finalists[x+1]): 45 | tcount = tcount 46 | # If the ID remains the same (is equal to eachother), total 47 | # count remains the same 48 | else: 49 | # Otherwise, it's a different person. therefore, we check the ID 50 | # to see whether they're a Quest Scholar 51 | if str(finalists[x]) in scholars: 52 | tcount = tcount + 1 53 | # If they are a QS, add one to the total count 54 | if str(sheet.cell(x,1)) == "text:u'Y'": 55 | # If the graduated cell is then equal to a yes, 56 | # the student graduated with some sort of degree 57 | cell = str(sheet.cell(x,3)) 58 | cell = cell.split() 59 | # To ensure they didnt graduate with just an associate's 60 | # we split the degree column by whitespace and check 61 | # to see if the first item is the string "Associate" 62 | if cell[0] != "text:u'ASSOCIATE": 63 | gcount = gcount + 1 64 | # If not equal to associate, add one to the graduated 65 | # count 66 | if str(sheet.cell(x,1)) == "text:u'N'": 67 | if str(sheet.cell(x,2)) == "empty:''": 68 | # If the graduated cell is equal to a no, we must make sure 69 | # the data is not simply missing. If the column is empty, 70 | # add to the blank count 71 | bcount = bcount + 1 72 | if x + 1 == len(finalists): 73 | # the following code is the same as previously coded. 74 | if str(finalists[x]) in scholars: 75 | tcount = tcount + 1 76 | if str(sheet.cell(x,1)) == "text:u'Y'": 77 | cell = str(sheet.cell(x,3)) 78 | cell = cell.split() 79 | if cell[0] != "text:u'ASSOCIATE": 80 | gcount = gcount + 1 81 | if str(sheet.cell(x,1)) == "text:u'N'": 82 | if str(sheet.cell(x,2)) == "empty:''": 83 | bcount = bcount + 1 84 | x = x + 1 85 | # Add one to the index counter! 86 | print tcount 87 | print gcount 88 | print bcount 89 | # Print the total count, graduated number of students, and the blank count! 90 | -------------------------------------------------------------------------------- /grad_project.py: -------------------------------------------------------------------------------- 1 | ######################################################## 2 | # Lesley Cordero 3 | # Quest Project 3 4 | # Partner graduation rate of Quest Scholars, excluding transfers (Fall 08 and before) 5 | ######################################################## 6 | 7 | from xlrd import open_workbook,XL_CELL_TEXT 8 | import csv 9 | 10 | def graduation(): 11 | book = open_workbook("graduation.xls") 12 | sheet = book.sheet_by_index(0) 13 | partners = [] # partner school appendage 14 | finalists = [] # scholars IDs 15 | scholars = [] 16 | total = 0 # number of students 17 | gcount = 0 # graduated students 18 | bcount = 0 # blank cell students 19 | x = 0 20 | # Begins x index number at 0 since it counts number of students, not transitions 21 | for col in sheet.col(0): 22 | # iterates through first column and appends to list 23 | finalists.append(col) 24 | with open('partners.csv', 'rb') as csvfile: 25 | spamreader = csv.reader(csvfile, quotechar = ' ',) 26 | # Opens CSV file and iterates through all filled cells 27 | for row in spamreader: 28 | for it in row: 29 | item = "text:u'" + it + "'" 30 | # fixes format to compare to clearinghousedata 31 | partners.append(item) 32 | # appends each partner college to a list for comparison later on 33 | with open('IDs.csv', 'rb') as csvfile: 34 | spamreader = csv.reader(csvfile, quotechar = ' ',) 35 | for row in spamreader: 36 | for it in row: 37 | item = "text:u'" + it + "_'" 38 | # Fixes ID format to match format of Clearinghouse data 39 | scholars.append(item) 40 | # Appends to list to compare to clearinghouse data 41 | for item in finalists: 42 | # Iterates through item of finalist IDs 43 | if x + 1 < len(finalists): 44 | # Proceed so long as the index number does not exceed the length of 45 | # the list. 46 | if str(finalists[x]) == str(finalists[x+1]): 47 | total = total 48 | # If the ID numbers remain the same, it is the same person so the 49 | # total count remains the same 50 | else: 51 | # Otherwise, it's a new person 52 | if str(finalists[x]) in scholars: 53 | if str(sheet.cell(x,2)) in partners: 54 | # since this is excluding transfer students, we have to check 55 | # to make sure that the student is both a Quest Scholar and still 56 | # attends a partner school 57 | total = total + 1 58 | # If they appear in these lists, increase the total by 1 59 | if str(sheet.cell(x,1)) == "text:u'Y'": 60 | # If the graduated? cell is equal to yes, then they graduated 61 | # from somewhere 62 | cell = str(sheet.cell(x,3)) 63 | cell = cell.split() 64 | # To make sure the degree is a bachelor's, split the degree 65 | # cell by whitespace 66 | if cell[0] != "text:u'ASSOCIATE": 67 | # Check first string- if not equal to associate, 68 | # they graduated from a bachelor's or master's 69 | gcount = gcount + 1 70 | # therefore, increase the graduated count by 1. 71 | if x + 1 == len(finalists): 72 | # The following code is the same as the previous. 73 | if str(finalists[x]) in scholars: 74 | if str(sheet.cell(x,2)) in partners: 75 | total = total + 1 76 | if str(sheet.cell(x,1)) == "text:u'Y'": 77 | cell = str(sheet.cell(x,3)) 78 | cell = cell.split() 79 | if cell[0] != "text:u'ASSOCIATE": 80 | gcount = gcount + 1 81 | x = x + 1 82 | # Increases index to proceed to next student in excel file/list 83 | print total 84 | print gcount 85 | print bcount 86 | # Prints the total number of students, followed by number graduated and blank cell count! 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /jsc.py: -------------------------------------------------------------------------------- 1 | import click 2 | import requests 3 | import json 4 | import pprint 5 | from click import pass_context 6 | from io import BytesIO 7 | import ctx 8 | import os 9 | import sys 10 | import getopt 11 | from cmd import Cmd 12 | import argparse 13 | from click import ClickException, UsageError, BadParameter, Abort, MissingParameter 14 | from utils import make_str, make_default_short_help, echo 15 | from configparser import SafeConfigParser 16 | 17 | class Interface(Cmd): 18 | 19 | @click.command('groups', short_help='Shows groups.') 20 | @pass_context 21 | 22 | def do_groups(self): 23 | """Shows groups changes in the current working directory. \n Format: groups""" 24 | 25 | headers = {'content-type': 'application/json'} 26 | url = "http://10.5.4.87:11880/rest/management/groups/ftp.ivydb.com" 27 | r = requests.get(url, cookies=ctx.cookies,headers=headers) 28 | dictionary = r.json() 29 | for entry in dictionary: 30 | print(entry['name']) 31 | 32 | 33 | def do_useradd(self, username): 34 | """Allows you to insert a new user. \n Format: useradd userName""" 35 | 36 | body = { 37 | "username": str(username), 38 | "login": "", 39 | "password": "", 40 | } 41 | body["login"] = input("Enter login:") 42 | body["password"] = input("Enter password") 43 | 44 | headers = {'content-type': 'application/json'} 45 | url = "http://10.5.4.87:11880/rest/management/accounts/ftp.ivydb.com" 46 | r = requests.get(url, body, cookies=ctx.cookies,headers=headers) 47 | print("User successfully added") 48 | 49 | 50 | def do_userdel(self, account): 51 | """Allows the deletion of a user. \n Format: userdel accountName""" 52 | 53 | headers = {'content-type': 'application/json'} 54 | url = "http://10.5.4.87:11880/rest/management/groups/ftp.ivydb.com/" + account 55 | r = requests.get(url, account, cookies=ctx.cookies,headers=headers) 56 | print("User successfully deleted") 57 | 58 | 59 | def do_groupadd(self, groupName): 60 | """Allows the addition of a group. \n Format: groupadd groupName""" 61 | 62 | body = { 63 | "name": str(groupName) 64 | } 65 | headers = {'content-type': 'application/json'} 66 | url = "http://10.5.4.87:11880/rest/management/groups/ftp.ivydb.com" 67 | r = requests.get(url, body, cookies=ctx.cookies,headers=headers) 68 | print("Group successfully added") 69 | 70 | 71 | def do_cat(self): 72 | """Allows you to view all accounts. \n Format: cat""" 73 | 74 | headers = {'content-type': 'application/json'} 75 | url = "http://10.5.4.87:11880/rest/management/account-infos/ftp.ivydb.com" 76 | r = requests.get(url, cookies=ctx.cookies,headers=headers) 77 | dictionary = r.json() 78 | for key, value in dictionary: 79 | print(key, value) 80 | 81 | 82 | def do_getaccount(self, account): 83 | """Allows access to account information. \n Format: getaccount accountName""" 84 | 85 | headers = {'content-type': 'application/json'} 86 | url = "http://10.5.4.87:11880/rest/management/accounts/ftp.ivydb.com/" + account 87 | r = requests.get(url, account, cookies=ctx.cookies,headers=headers) 88 | print(r.json()) 89 | 90 | 91 | def do_passwd(self, userName): 92 | """Allows you to change the password of a new user. \n Format: passwd userName""" 93 | 94 | headers = {'content-type': 'application/json'} 95 | url = "http://10.5.4.87:11880/rest/management/accounts/ftp.ivydb.com/" + userName 96 | r = requests.get(url, userName, cookies=ctx.cookies,headers=headers) 97 | body = r.json() 98 | body["password"] = input("Enter new password:") 99 | 100 | headers = {'content-type': 'application/json'} 101 | url = "http://10.5.4.87:11880/rest/management/accounts/ftp.ivydb.com" 102 | r = requests.get(url, body, cookies=ctx.cookies,headers=headers) 103 | print("User password successfully changed.") 104 | 105 | 106 | 107 | 108 | CONTEXT_SETTINGS = dict(auto_envvar_prefix='JSC') 109 | class Handle: 110 | 111 | @click.command('groups', short_help='Shows groups.') 112 | @pass_context 113 | def main(args, ctx): 114 | argv = args 115 | 116 | parser = SafeConfigParser() 117 | parser.readfp(sys.stdin) 118 | 119 | config = dict((section, dict((option, parser.get(section, option)) 120 | for option in parser.options(section))) 121 | for section in parser.sections()) 122 | p = argparse.ArgumentParser() 123 | subparsers = p.add_subparsers() 124 | 125 | # groups command 126 | groups_parser = subparsers.add_parser('groups') 127 | groups_parser.set_defaults(funct = Interface.do_groups) 128 | for param in argv[1:]: 129 | groups_parser.add_argument(param) 130 | 131 | if args and not ctx.allow_extra_args and not ctx.resilient_parsing: 132 | ctx.fail('Got unexpected extra argument%s (%s)' 133 | % (len(args) != 1 and 's' or '', 134 | ' '.join(map(make_str, args)))) 135 | 136 | # useradd command 137 | useradd_parser = subparsers.add_parser('useradd') 138 | useradd_parser.set_defaults(func=Interface.do_useradd) 139 | for param in argv[1:]: 140 | useradd_parser.add_argument(param) 141 | 142 | if args and not ctx.allow_extra_args and not ctx.resilient_parsing: 143 | ctx.fail('Got unexpected extra argument%s (%s)' 144 | % (len(args) != 1 and 's' or '', 145 | ' '.join(map(make_str, args)))) 146 | 147 | # userdel command 148 | userdel_parser = subparsers.add_parser('userdel') 149 | userdel_parser.set_defaults(func=Interface.do_userdel) 150 | for param in argv[1:]: 151 | userdel_parser.add_argument(param) 152 | 153 | if args and not ctx.allow_extra_args and not ctx.resilient_parsing: 154 | ctx.fail('Got unexpected extra argument%s (%s)' 155 | % (len(args) != 1 and 's' or '', 156 | ' '.join(map(make_str, args)))) 157 | 158 | # groupadd command 159 | groupadd_parser = subparsers.add_parser('groupadd') 160 | groupadd_parser.set_defaults(func=Interface.do_groupadd) 161 | for param in argv[1:]: 162 | groupadd_parser.add_argument(param) 163 | 164 | if args and not ctx.allow_extra_args and not ctx.resilient_parsing: 165 | ctx.fail('Got unexpected extra argument%s (%s)' 166 | % (len(args) != 1 and 's' or '', 167 | ' '.join(map(make_str, args)))) 168 | 169 | # cat command 170 | cat_parser = subparsers.add_parser('cat') 171 | cat_parser.set_defaults(func=Interface.do_cat) 172 | for param in argv[1:]: 173 | cat_parser.add_argument(param) 174 | 175 | if args and not ctx.allow_extra_args and not ctx.resilient_parsing: 176 | ctx.fail('Got unexpected extra argument%s (%s)' 177 | % (len(args) != 1 and 's' or '', 178 | ' '.join(map(make_str, args)))) 179 | 180 | # getaccount command 181 | getaccount_parser = subparsers.add_parser('getaccount') 182 | getaccount_parser.set_defaults(func=Interface.do_getaccount) 183 | for param in argv[1:]: 184 | getaccount_parser.add_argument(param) 185 | 186 | if args and not ctx.allow_extra_args and not ctx.resilient_parsing: 187 | ctx.fail('Got unexpected extra argument%s (%s)' 188 | % (len(args) != 1 and 's' or '', 189 | ' '.join(map(make_str, args)))) 190 | 191 | # passwd command 192 | passwd_parser = subparsers.add_parser('passwd') 193 | passwd_parser.set_defaults(func=Interface.do_passwd) 194 | for param in argv[1:]: 195 | passwd_parser.add_argument(param) 196 | 197 | if args and not ctx.allow_extra_args and not ctx.resilient_parsing: 198 | ctx.fail('Got unexpected extra argument%s (%s)' 199 | % (len(args) != 1 and 's' or '', 200 | ' '.join(map(make_str, args)))) 201 | 202 | 203 | # begin accepting commands from user 204 | interface = Interface() 205 | interface.prompt(">") 206 | interface.cmdloop("Starting prompt...") 207 | ctx.login('admin', argv[0]) 208 | 209 | args = p.parse_args() 210 | args.func(args) 211 | 212 | 213 | def fail(self, message): 214 | """Aborts program with a specific error message. 215 | :param message: the error message to fail with.""" 216 | raise UsageError(message, self) 217 | 218 | 219 | 220 | if __name__ == "__main__": 221 | Handle.main(sys.argv[1:], ctx) 222 | 223 | --------------------------------------------------------------------------------