mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-30 03:08:56 -04:00
Refactored reports to use pregenerated docs instead (#2831)
* Refactored reports to use pregenerated docs instead * Fixed e2e test * Fixed anothr bug * Cleanup * Fixed timezone conversion * Updated ref files * Updated reference files, refreshed ui/ux for report generation. Buttons toggle on and off based on if report exists * Fixed linting errors, removed pytz * Fixed test failure * e2e test fix * Speeding up unit tests * Removed python time library that was causing performance issues with unit tests * Updated poetry lock * Unit test improvements * Made change that ken reccomended
This commit is contained in:
50
app/utils/s3_csv.py
Normal file
50
app/utils/s3_csv.py
Normal file
@@ -0,0 +1,50 @@
|
||||
import csv
|
||||
import io
|
||||
|
||||
from app.utils.csv import convert_report_date_to_preferred_timezone
|
||||
|
||||
|
||||
def convert_s3_csv_timestamps(csv_content):
|
||||
if isinstance(csv_content, bytes):
|
||||
csv_content = csv_content.decode("utf-8")
|
||||
|
||||
reader = csv.reader(io.StringIO(csv_content))
|
||||
|
||||
time_column_index = None
|
||||
try:
|
||||
header = next(reader)
|
||||
for i, col in enumerate(header):
|
||||
if col.strip().lower() == "time":
|
||||
time_column_index = i
|
||||
break
|
||||
|
||||
output = io.StringIO()
|
||||
writer = csv.writer(output)
|
||||
writer.writerow(header)
|
||||
yield output.getvalue()
|
||||
output.truncate(0)
|
||||
output.seek(0)
|
||||
except StopIteration:
|
||||
return
|
||||
|
||||
if time_column_index is None:
|
||||
for row in reader:
|
||||
writer.writerow(row)
|
||||
yield output.getvalue()
|
||||
output.truncate(0)
|
||||
output.seek(0)
|
||||
return
|
||||
|
||||
for row in reader:
|
||||
if len(row) > time_column_index and row[time_column_index]:
|
||||
try:
|
||||
row[time_column_index] = convert_report_date_to_preferred_timezone(
|
||||
row[time_column_index]
|
||||
)
|
||||
except Exception: # nosec B110
|
||||
pass
|
||||
|
||||
writer.writerow(row)
|
||||
yield output.getvalue()
|
||||
output.truncate(0)
|
||||
output.seek(0)
|
||||
Reference in New Issue
Block a user