-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auto Report Generation #19
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Several comments for now,
def main(): | ||
args = parse_args() | ||
|
||
with open(args.template) as f: | ||
template = f.read() | ||
|
||
report = ReportGenerator(template, AaveTags(args.proposal_id).tag_mappings).report | ||
|
||
with open(f'v3-{args.proposal_id}-<title>.md', 'w') as f: | ||
f.write(report) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Must have Docs both here and in the general readme file.
with open(f'v3-{args.proposal_id}-<title>.md', 'w') as f: | ||
f.write(report) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldnt be the proposal_title field instead of -<title>.md?
def main(): | ||
args = parse_args() | ||
|
||
with open(args.template) as f: | ||
template = f.read() | ||
|
||
report = ReportGenerator(template, AaveTags(args.proposal_id).tag_mappings).report | ||
|
||
with open(f'v3-{args.proposal_id}-<title>.md', 'w') as f: | ||
f.write(report) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the project logger here.
class ReportGenerator: | ||
LOOP_COMMAND = 'loop' | ||
|
||
def __init__(self, template: str, tag_mappings: dict[str, str | list[str]]) -> None: | ||
self.report = self.__generate_report(template, tag_mappings) | ||
|
||
@staticmethod | ||
def __generate_report(template: str, tag_mappings: dict[str, str | list[str]]) -> str: | ||
res = ReportGenerator.__replace_loops(template, tag_mappings) | ||
res = ReportGenerator.__fill_tags(res, tag_mappings) | ||
return res | ||
|
||
@staticmethod | ||
def __fill_tags(template: str, tag_mappings: dict[str, str | list[str]]) -> str: | ||
res = template | ||
for tag, value in tag_mappings.items(): | ||
if isinstance(value, str): | ||
res = res.replace(f'<{tag}>', value) | ||
return res | ||
|
||
@staticmethod | ||
def __replace_loops(template: str, tag_mappings: dict[str, str | list[str]]) -> str: | ||
pattern = rf'<{ReportGenerator.LOOP_COMMAND}:([^>]+)>' | ||
matches = re.findall(pattern, template) | ||
res = template | ||
for m in matches: | ||
loop_tag_mapping = {tag: tag_mappings[tag] for tag in m.split(',')} | ||
res = ReportGenerator.__unroll_loop(res, m, loop_tag_mapping) | ||
return res | ||
|
||
@staticmethod | ||
def __unroll_loop(template: str, looping_tags: str, loop_tag_mappings: dict[str, list[str]]) -> str: | ||
start_tag = f'<{ReportGenerator.LOOP_COMMAND}:{looping_tags}>' | ||
end_tag = f'</{ReportGenerator.LOOP_COMMAND}>' | ||
|
||
start_index = template.index(start_tag) + len(start_tag) | ||
end_index = template.index(end_tag) | ||
|
||
loop_template = template[start_index:end_index].strip() | ||
|
||
loop_result = ReportGenerator.__build_loop_content(loop_template, loop_tag_mappings) | ||
|
||
return template[:template.index(start_tag)] + loop_result + template[end_index + len(end_tag):] | ||
|
||
@staticmethod | ||
def extract_loop_values_lengths(values: list[list[str]]) -> int: | ||
expected_length = len(values[0]) | ||
for v in values: | ||
if len(v) != expected_length: | ||
raise ValueError('lengths not equal') | ||
return expected_length | ||
|
||
@staticmethod | ||
def __build_loop_content(loop_template: str, loop_tag_mappings: dict[str, list[str]]) -> str: | ||
loop_count = ReportGenerator.extract_loop_values_lengths(list(loop_tag_mappings.values())) | ||
res = '' | ||
for i in range(loop_count): | ||
res += ReportGenerator.__fill_tags(loop_template, | ||
{tag: values[i] for tag, values in loop_tag_mappings.items()}) + '\n' | ||
return res.strip() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add Docs to all methods in the class
No description provided.