Skip to content

Commit

Permalink
Modify duplicate check for importSprints & ignore case sensitivity in…
Browse files Browse the repository at this point in the history
… importTimeLogs
  • Loading branch information
imhlas committed Apr 8, 2024
1 parent dd0918d commit fb4c5d5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
30 changes: 16 additions & 14 deletions scripts/importSprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,20 @@ def fetch_group_id(group_name):
finally:
close_db_connection(conn, cur)

def check_if_row_exists(row, group_id):
def check_if_row_exists(group_id, sprint_number):
conn, cur = get_db_connection()
query = """
SELECT EXISTS (
SELECT 1 FROM sprints
WHERE group_id = %s AND sprint = %s AND start_date = %s AND end_date = %s
)
"""
cur.execute(query, (group_id, row[1], row[2], row[3]))
result = cur.fetchone()
return result[0]
try:
query = """
SELECT EXISTS (
SELECT 1 FROM sprints
WHERE group_id = %s AND sprint = %s
)
"""
cur.execute(query, (group_id, sprint_number))
result = cur.fetchone()
return result[0]
finally:
close_db_connection(conn, cur)

def insert_into_database(row, group_id):
try:
Expand All @@ -74,15 +77,14 @@ def process_file(filepath):
invalid_rows = []

for row in reader:
print(row)
conversion_success, error_conversion = convert_row(row)
if conversion_success:
group_id, error_group_id = fetch_group_id(conversion_success['group_name'])
if group_id:
if not check_if_row_exists(row, group_id):
insert_into_database(row, group_id)
else:
if check_if_row_exists(group_id, conversion_success['sprint_number']):
invalid_rows.append((row, "Sprint already exists in the database"))
else:
insert_into_database(row, group_id)
else:
invalid_rows.append((row, error_group_id))
else:
Expand Down
15 changes: 7 additions & 8 deletions scripts/importTimeLogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def check_if_row_exists(date, minutes, description, student_number, sprint_id):
query = """
SELECT EXISTS (
SELECT 1 FROM time_logs
WHERE date = %s AND minutes = %s AND description = %s AND student_number = %s AND sprint_id = %s
WHERE date = %s AND minutes = %s AND LOWER(description) = LOWER(%s) AND student_number = %s AND sprint_id = %s
)
"""
cur.execute(query, (date, minutes, description, student_number, sprint_id))
Expand Down Expand Up @@ -108,16 +108,15 @@ def process_file(filepath):
invalid_rows = []

for row in reader:
print(row)
if len(row) < 6:
if len(row) < 5:
invalid_rows.append((row, "Missing values"))
continue

student_number = row[1]
sprint_str = row[2]
hours_str = row[3]
date_str = row[4]
description = row[5]
student_number = row[0]
sprint_str = row[1]
hours_str = row[2]
date_str = row[3]
description = row[4]

minutes, error_minutes = convert_hours_to_minutes(hours_str)
date, error_date = validate_and_format_date(date_str)
Expand Down

0 comments on commit fb4c5d5

Please sign in to comment.