Skip to content
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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Conversation

liav-certora
Copy link
Contributor

No description provided.

@liav-certora liav-certora marked this pull request as draft November 24, 2024 09:24
Copy link
Collaborator

@nivcertora nivcertora left a 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,

Comment on lines +24 to +37
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()
Copy link
Collaborator

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.

Comment on lines +32 to +33
with open(f'v3-{args.proposal_id}-<title>.md', 'w') as f:
f.write(report)
Copy link
Collaborator

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?

Comment on lines +24 to +37
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()
Copy link
Collaborator

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.

Comment on lines +4 to +63
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()
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants