-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
132 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# local working copies | ||
exports/ | ||
**/__pycache__/ | ||
documents/edu.uh.publications.courses/raw/**/*.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,34 @@ | ||
import csv | ||
from pathlib import Path | ||
from alive_progress import alive_bar | ||
|
||
|
||
''' | ||
Combines all CSV data for this dataset into | ||
a single records.csv file | ||
''' | ||
def process(source: Path, destination: Path): | ||
# print(source.name) | ||
destination.mkdir(exist_ok=True) | ||
# print(source.name) | ||
destination.mkdir(exist_ok=True) | ||
with alive_bar() as bar: | ||
with open(destination / 'records.csv', 'w') as export: | ||
# declare writer | ||
writer = csv.writer(export) | ||
# get first file in source | ||
first_file = [f for f in source.iterdir() | ||
if f.match('*.csv')][0] | ||
# write the header row | ||
with open(first_file, 'r') as f: | ||
# declare writer | ||
writer = csv.writer(export) | ||
# get first file in source | ||
first_file = [f for f in source.iterdir() if f.match('*.csv')][0] | ||
# write the header row | ||
with open(first_file, 'r') as f: | ||
reader = csv.reader(f) | ||
for row in reader: | ||
# ONLY write the first row (header row) | ||
writer.writerow(row) | ||
break | ||
# write the other rows | ||
for csvfile in source.iterdir(): | ||
if(csvfile.match('*.csv')): | ||
with open(csvfile, 'r') as f: | ||
reader = csv.reader(f) | ||
# skip the first row (header) | ||
next(reader) | ||
for row in reader: | ||
# ONLY write the first row (header row) | ||
writer.writerow(row) | ||
break | ||
# write the other rows | ||
for csvfile in source.iterdir(): | ||
if(csvfile.match('*.csv')): | ||
with open(csvfile, 'r') as f: | ||
reader = csv.reader(f) | ||
# skip the first row (header) | ||
next(reader) | ||
for row in reader: | ||
writer.writerow(row) | ||
writer.writerow(row) | ||
bar() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import csv | ||
from bundle import util | ||
from pathlib import Path | ||
from alive_progress import alive_bar | ||
|
||
|
||
|
||
''' | ||
Iterates over records.csv to pair | ||
'catoid' and 'coid' values with their | ||
corresponding 'department' and 'catalogNumber' pairs | ||
''' | ||
def process(source: Path, destination: Path): | ||
# prepares destination | ||
destination.mkdir(exist_ok=True) | ||
|
||
KNOWN_COURSES = set() | ||
|
||
# iterates over records.csv | ||
with open(destination / '..' / 'edu.uh.grade_distribution' / 'records.csv') as infile: | ||
reader = csv.DictReader(infile) | ||
for row in reader: | ||
KNOWN_COURSES.add(f'{row["SUBJECT"].strip()} {row["CATALOG NBR"].strip()}') | ||
|
||
# create the output file | ||
with open(destination / 'pairs.csv', 'w') as outfile: | ||
writer = csv.DictWriter(outfile, ['catoid', 'coid', 'department', 'catalogNumber']) | ||
# for every catalog's index.csv file | ||
for p in source.glob('**/index.csv'): | ||
with alive_bar(util.file_len(p)) as bar: | ||
with open(p, 'r') as infile: | ||
reader = csv.DictReader(infile) | ||
# for every row in this index.csv file | ||
for row in reader: | ||
# check if there's a match | ||
for course in KNOWN_COURSES: | ||
if course.lower().strip() in row["course_title"].lower().strip(): | ||
writer.writerow({ | ||
"catoid": row["catoid"], | ||
"coid": row["coid"], | ||
"department": course.split(' ')[0], | ||
"catalogNumber": course.split(' ')[1] | ||
}) | ||
bar() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
# see: https://stackoverflow.com/q/845058 | ||
def file_len(fname): | ||
with open(fname) as f: | ||
for i, l in enumerate(f): | ||
pass | ||
return i + 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
alive-progress==1.5.1 | ||
colorama==0.4.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
**.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters