Skip to content

Commit

Permalink
Merge pull request #166 from ton-society/feature/total_field_only
Browse files Browse the repository at this point in the history
Add total fields to JsonRenderMethod
  • Loading branch information
shuva10v authored Sep 16, 2024
2 parents 0c0bfad + e9377e3 commit 9f563aa
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion models/render_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ def get_items(self, res: CalculationResults, config: SeasonConfig):

class JsonRenderMethod(RenderMethod):

def __init__(self, output_name, icons_base_path=None):
def __init__(self, output_name, icons_base_path=None, aggregate_field=None):
RenderMethod.__init__(self, icons_base_path)
self.output_name = output_name
self.aggregate_field = aggregate_field

def render(self, res: CalculationResults, config: SeasonConfig):
items = self.get_items(res, config)
Expand All @@ -66,6 +67,8 @@ def render(self, res: CalculationResults, config: SeasonConfig):
'source_link': f"https://github.com/ton-society/the-open-league/tree/{self.get_commit_hash()}",
'items': items
}
if self.aggregate_field:
res['total'] = sum([x[self.aggregate_field] for x in items])
with open(self.output_name, "wt") as out:
json.dump(res, out, indent=True)

Expand Down

0 comments on commit 9f563aa

Please sign in to comment.