-
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.
Merge pull request #39 from Sage-Bionetworks-Workflows/bwmac/orca-175…
…/add_csv_updater [ORCA-175] Add `CsvUpdater` and `update_csv` command
- Loading branch information
Showing
16 changed files
with
570 additions
and
1 deletion.
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
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,58 @@ | ||
from collections import defaultdict | ||
from csv import DictWriter | ||
from dataclasses import dataclass | ||
from pathlib import Path | ||
from typing import List | ||
|
||
from dcqc.parsers import CsvParser | ||
from dcqc.suites.suite_abc import SuiteABC | ||
|
||
|
||
@dataclass | ||
class CsvUpdater: | ||
input_path: Path | ||
output_path: Path | ||
parser: CsvParser | ||
|
||
def __init__(self, input_path: Path, output_path: Path): | ||
self.output_path = output_path | ||
self.input_path = input_path | ||
|
||
def update(self, suites: List[SuiteABC]): | ||
suite_dict = defaultdict(list) | ||
# {url: [list_of_statuses]} data structure to allow for multi-file targets | ||
# TODO add support for suites with multiple files in them (multi) | ||
for suite in suites: | ||
url = suite.target.files[0].url | ||
status = suite.get_status() | ||
suite_dict[url].append(status.value) | ||
# Evaluate dcqc_status for each url | ||
collapsed_dict = {} | ||
for url, statuses in suite_dict.items(): | ||
if "RED" in statuses: | ||
collapsed_dict[url] = "RED" | ||
elif "AMBER" in statuses: | ||
collapsed_dict[url] = "AMBER" | ||
elif "GREEN" in statuses: | ||
collapsed_dict[url] = "GREEN" | ||
else: | ||
collapsed_dict[url] = "NONE" | ||
# Create CSV data structure | ||
row_list = [] | ||
parser = CsvParser(self.input_path) | ||
for _, csv_data in parser.list_rows(): | ||
csv_data["dcqc_status"] = collapsed_dict[csv_data["url"]] | ||
row_list.append(csv_data) | ||
|
||
if row_list: | ||
keys = row_list[0].keys() | ||
# Export updated CSV | ||
self.output_path.parent.mkdir(parents=True, exist_ok=True) | ||
with open( | ||
str(self.output_path), "w+", newline="", encoding="utf-8" | ||
) as output_file: | ||
dict_writer = DictWriter(output_file, keys) | ||
dict_writer.writeheader() | ||
dict_writer.writerows(row_list) | ||
else: | ||
raise ValueError("No rows found in input CSV") |
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 @@ | ||
url,file_type,md5_checksum |
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,4 @@ | ||
url,file_type,md5_checksum | ||
syn://syn51585496,TXT,38b86a456d1f441008986c6f798d5ef9 | ||
syn://syn51585494,TXT,a542e9b744bedcfd874129ab0f98c4ff | ||
syn://syn51585495,TIFF,38b86a456d1f441008986c6f798d5ef9 |
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,179 @@ | ||
[ | ||
{ | ||
"type": "TiffSuite", | ||
"target": { | ||
"id": "0001", | ||
"files": [ | ||
{ | ||
"url": "syn://syn51585496", | ||
"metadata": { | ||
"md5_checksum": "c7b08f6decb5e7572efbe6074926a843" | ||
}, | ||
"type": "TIFF", | ||
"name": "circuit.tif", | ||
"local_path": "/tmp/dcqc-staged-7onezxv1/circuit.tif" | ||
} | ||
], | ||
"type": "SingleTarget" | ||
}, | ||
"suite_status": { | ||
"required_tests": [ | ||
"Md5ChecksumTest", | ||
"FileExtensionTest", | ||
"LibTiffInfoTest" | ||
], | ||
"skipped_tests": [], | ||
"status": "GREEN" | ||
}, | ||
"tests": [ | ||
{ | ||
"type": "FileExtensionTest", | ||
"tier": 1, | ||
"is_external_test": false, | ||
"status": "passed" | ||
}, | ||
{ | ||
"type": "GrepDateTest", | ||
"tier": 4, | ||
"is_external_test": true, | ||
"status": "passed" | ||
}, | ||
{ | ||
"type": "LibTiffInfoTest", | ||
"tier": 2, | ||
"is_external_test": true, | ||
"status": "passed" | ||
}, | ||
{ | ||
"type": "Md5ChecksumTest", | ||
"tier": 1, | ||
"is_external_test": false, | ||
"status": "passed" | ||
}, | ||
{ | ||
"type": "TiffTag306DateTimeTest", | ||
"tier": 4, | ||
"is_external_test": true, | ||
"status": "passed" | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "TiffSuite", | ||
"target": { | ||
"id": "0002", | ||
"files": [ | ||
{ | ||
"url": "syn://syn51585494", | ||
"metadata": { | ||
"md5_checksum": "9cee1b0e8c4d051fabea82b62ae69404" | ||
}, | ||
"type": "TIFF", | ||
"name": "test_contains_word_date.tif", | ||
"local_path": "/tmp/dcqc-staged-ddxo9fx2/test_contains_word_date.tif" | ||
} | ||
], | ||
"type": "SingleTarget" | ||
}, | ||
"suite_status": { | ||
"required_tests": [ | ||
"Md5ChecksumTest", | ||
"FileExtensionTest", | ||
"LibTiffInfoTest" | ||
], | ||
"skipped_tests": [], | ||
"status": "RED" | ||
}, | ||
"tests": [ | ||
{ | ||
"type": "FileExtensionTest", | ||
"tier": 1, | ||
"is_external_test": false, | ||
"status": "passed" | ||
}, | ||
{ | ||
"type": "GrepDateTest", | ||
"tier": 4, | ||
"is_external_test": true, | ||
"status": "failed" | ||
}, | ||
{ | ||
"type": "LibTiffInfoTest", | ||
"tier": 2, | ||
"is_external_test": true, | ||
"status": "failed" | ||
}, | ||
{ | ||
"type": "Md5ChecksumTest", | ||
"tier": 1, | ||
"is_external_test": false, | ||
"status": "passed" | ||
}, | ||
{ | ||
"type": "TiffTag306DateTimeTest", | ||
"tier": 4, | ||
"is_external_test": true, | ||
"status": "passed" | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "TiffSuite", | ||
"target": { | ||
"id": "0003", | ||
"files": [ | ||
{ | ||
"url": "syn://syn51585495", | ||
"metadata": { | ||
"md5_checksum": "28a9ee7d0e994d494068ce8d6cda0268" | ||
}, | ||
"type": "TIFF", | ||
"name": "test_image_dirty_datetime.tif", | ||
"local_path": "/tmp/dcqc-staged-5m6d8fdj/test_image_dirty_datetime.tif" | ||
} | ||
], | ||
"type": "SingleTarget" | ||
}, | ||
"suite_status": { | ||
"required_tests": [ | ||
"Md5ChecksumTest", | ||
"FileExtensionTest", | ||
"LibTiffInfoTest" | ||
], | ||
"skipped_tests": [], | ||
"status": "AMBER" | ||
}, | ||
"tests": [ | ||
{ | ||
"type": "FileExtensionTest", | ||
"tier": 1, | ||
"is_external_test": false, | ||
"status": "passed" | ||
}, | ||
{ | ||
"type": "GrepDateTest", | ||
"tier": 4, | ||
"is_external_test": true, | ||
"status": "passed" | ||
}, | ||
{ | ||
"type": "LibTiffInfoTest", | ||
"tier": 2, | ||
"is_external_test": true, | ||
"status": "passed" | ||
}, | ||
{ | ||
"type": "Md5ChecksumTest", | ||
"tier": 1, | ||
"is_external_test": false, | ||
"status": "passed" | ||
}, | ||
{ | ||
"type": "TiffTag306DateTimeTest", | ||
"tier": 4, | ||
"is_external_test": true, | ||
"status": "failed" | ||
} | ||
] | ||
} | ||
] |
Oops, something went wrong.