-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
style: address linting and typing issues (#29)
- Loading branch information
1 parent
d7ecb6b
commit 3159337
Showing
8 changed files
with
150 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,48 @@ | ||
import click | ||
"""CLI module for converting TES and WES data to WRROC.""" | ||
|
||
import json | ||
|
||
import click | ||
|
||
from crategen.converter_manager import ConverterManager | ||
|
||
|
||
@click.command() | ||
@click.option('--input', prompt='Input file', help='Path to the input JSON file.') | ||
@click.option('--output', prompt='Output file', help='Path to the output JSON file.') | ||
@click.option('--conversion-type', prompt='Conversion type', type=click.Choice(['tes-to-wrroc', 'wes-to-wrroc']), help='Type of conversion to perform.') | ||
@click.option("--input", prompt="Input file", help="Path to the input JSON file.") | ||
@click.option("--output", prompt="Output file", help="Path to the output JSON file.") | ||
@click.option( | ||
"--conversion-type", | ||
prompt="Conversion type", | ||
type=click.Choice(["tes-to-wrroc", "wes-to-wrroc"]), | ||
help="Type of conversion to perform.", | ||
) | ||
def cli(input, output, conversion_type): | ||
""" | ||
Command Line Interface for converting TES/WES to WRROC. | ||
"""Command Line Interface for converting TES/WES to WRROC. | ||
Args: | ||
input: Path to the input JSON file. | ||
output: Path to the output JSON file. | ||
conversion_type: Type of conversion to perform. Choices are "tes-to-wrroc" and "wes-to-wrroc". | ||
Example: | ||
$ crategen --input data.json --output result.json --conversion-type tes-to-wrroc | ||
""" | ||
manager = ConverterManager() | ||
|
||
# Load input data from JSON file | ||
with open(input, 'r') as input_file: | ||
with open(input) as input_file: | ||
data = json.load(input_file) | ||
|
||
# Perform the conversion based on the specified type | ||
if conversion_type == 'tes-to-wrroc': | ||
if conversion_type == "tes-to-wrroc": | ||
result = manager.convert_tes_to_wrroc(data) | ||
elif conversion_type == 'wes-to-wrroc': | ||
elif conversion_type == "wes-to-wrroc": | ||
result = manager.convert_wes_to_wrroc(data) | ||
|
||
# Save the result to the output JSON file | ||
with open(output, 'w') as output_file: | ||
with open(output, "w") as output_file: | ||
json.dump(result, output_file, indent=4) | ||
|
||
if __name__ == '__main__': | ||
|
||
if __name__ == "__main__": | ||
cli() |
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,13 +1,40 @@ | ||
"""Manager for handling TES and WES to WRROC conversions.""" | ||
|
||
from .converters.tes_converter import TESConverter | ||
from .converters.wes_converter import WESConverter | ||
|
||
|
||
class ConverterManager: | ||
"""Manages conversion between TES/WES and WRROC formats. | ||
Attributes: | ||
tes_converter: An instance of TESConverter for TES data conversions. | ||
wes_converter: An instance of WESConverter for WES data conversions. | ||
""" | ||
|
||
def __init__(self): | ||
"""Initializes the converters for TES and WES.""" | ||
self.tes_converter = TESConverter() | ||
self.wes_converter = WESConverter() | ||
|
||
def convert_tes_to_wrroc(self, tes_data): | ||
"""Converts TES data to WRROC format. | ||
Args: | ||
tes_data: The TES data to be converted. | ||
Returns: | ||
The converted data in WRROC format. | ||
""" | ||
return self.tes_converter.convert_to_wrroc(tes_data) | ||
|
||
def convert_wes_to_wrroc(self, wes_data): | ||
"""Converts WES data to WRROC format. | ||
Args: | ||
wes_data: The WES data to be converted. | ||
Returns: | ||
The converted data in WRROC format. | ||
""" | ||
return self.wes_converter.convert_to_wrroc(wes_data) |
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,10 +1,29 @@ | ||
"""Abstract base class for converters between TES/WES and WRROC formats.""" | ||
|
||
from abc import ABC, abstractmethod | ||
|
||
|
||
class AbstractConverter(ABC): | ||
"""Abstract converter for TES/WES to WRROC and vice versa.""" | ||
|
||
@abstractmethod | ||
def convert_to_wrroc(self, data): | ||
"""Convert data to WRROC format""" | ||
|
||
"""Convert data to WRROC format. | ||
Args: | ||
data: The data to be converted. | ||
Returns: | ||
The data converted to WRROC format. | ||
""" | ||
|
||
@abstractmethod | ||
def convert_from_wrroc(self, wrroc_data): | ||
"""Convert WRROC data to the original format""" | ||
"""Convert WRROC data to the original format. | ||
Args: | ||
wrroc_data: The WRROC data to be converted. | ||
Returns: | ||
The data converted back to the original format. | ||
""" |
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,30 @@ | ||
"""Utility functions for handling data conversion.""" | ||
|
||
import datetime | ||
|
||
|
||
def convert_to_iso8601(timestamp): | ||
""" | ||
Convert a given timestamp to ISO 8601 format. | ||
Handles multiple formats including RFC 3339, ISO 8601 with and without fractional seconds. | ||
"""Convert a given timestamp to ISO 8601 format. | ||
Handles multiple formats including RFC 3339, ISO 8601 with and without fractional seconds. | ||
Args: | ||
timestamp (str): The timestamp to be converted. | ||
Returns: | ||
str: The converted timestamp in ISO 8601 format, or None if the input format is incorrect. | ||
""" | ||
if timestamp: | ||
# List of supported formats | ||
formats = [ | ||
"%Y-%m-%dT%H:%M:%S.%fZ", # RFC 3339 with fractional seconds | ||
"%Y-%m-%dT%H:%M:%SZ", # RFC 3339 without fractional seconds | ||
"%Y-%m-%dT%H:%M:%S%z", # ISO 8601 with timezone | ||
"%Y-%m-%dT%H:%M:%S.%f%z", # ISO 8601 with fractional seconds and timezone | ||
"%Y-%m-%dT%H:%M:%S.%fZ", | ||
"%Y-%m-%dT%H:%M:%SZ", | ||
"%Y-%m-%dT%H:%M:%S%z", | ||
"%Y-%m-%dT%H:%M:%S.%f%z", | ||
] | ||
for fmt in formats: | ||
try: | ||
return datetime.datetime.strptime(timestamp, fmt).isoformat() + "Z" | ||
except ValueError: | ||
continue | ||
# Handle incorrect format or other issues | ||
return None | ||
return None |
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,10 @@ | ||
pre-push: | ||
commands: | ||
ruff: | ||
files: git diff --name-only --diff-filter=d $(git merge-base origin/main HEAD)..HEAD | ||
run: poetry run ruff check {files} | ||
glob: '*.py' | ||
mypy: | ||
files: git diff --name-only --diff-filter=d $(git merge-base origin/main HEAD)..HEAD | ||
run: poetry run mypy {files} | ||
glob: '*.py' |
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