{%- set h_sep = '#{:-<57}#'.format('') %} {%- set d_line = '{:#<59}'.format('') %} {% macro centered_line(text) %} #{{ text | center(57) }}# {%- endmacro %} {% macro table_line_header(list) %} {% if list|length == 4 %} {{'# %-17s| %-11s|%11s |%10s #'|format(fields_name[list[0]],fields_name[list[1]],fields_name[list[2]],fields_name[list[3]])}} {% elif list|length == 3 %} {{'# %-11s|%22s |%18s #'|format(fields_name[list[0]],fields_name[list[1]],fields_name[list[2]])}} {% endif %} {%- endmacro %} {% macro table_line_data(list) %} {% if list|length == 4 %} {{'# %-17s| %-11s|%11.2f |%10.2f #'|format(list[0],list[1],list[2],list[3]*last_field_m)}} {% elif list|length == 3 %} {{'# %-11s|%22.2f |%18.2f #'|format(list[0],list[1],list[2]*last_field_m)}} {% endif %} {%- endmacro %} {% macro head(title,date) %} {{ centered_line('%s: %-s'|format(entity, item)) }} {{ centered_line('Global usage from %s to %s' | format(header.start, header.end)) }} {%- endmacro %} {% macro total_line(title,value,unit) %} {{'# %-28s %12.2f %-13s#'|format(title, value, unit)}} {%- endmacro %} {% if carbon == True %} {%- set last_field = 'carbon' %} {%- set last_field_m = 10**-3 %} {% else %} {%- set last_field = 'money' %} {%- set last_field_m = 1 %} {% endif %} {% if type == 'user' or type == 'user_account' %} {%- set entity = 'USER' %} {%- set item = header.user %} {%if type == 'user' %} {%- set fields = ['account', 'cluster','time',last_field]%} {% endif %} {% elif type == 'account' or type == 'account_all' %} {%- set entity = 'ACCOUNT' %} {%- set item = header.account %} {%if type == 'account' %} {%- set fields = ['cluster','time',last_field]%} {%else %} {%- set fields = ['user', 'cluster','time',last_field]%} {% endif %} {% elif type == 'acctbilling' %} {%- set fields = ['account','time',last_field]%} {% endif %} {{ h_sep }} {{ head(title, date) }} {{ h_sep }} {{table_line_header(fields)-}} {{ h_sep }} {% for block in data %} {%- set field_values = [] %} {% for field in fields %} {%- set temp = field_values.append(block[field]) %} {%- endfor %} {{table_line_data(field_values)}} {%- endfor %} {{ h_sep }} {{ total_line("Total costs:", total.money, fields_name['money']) }} {{ total_line("Total walltime:", total.time, fields_name['time']) }} {{ total_line("Estimated carbon footprint:", total.carbon*10**-3, fields_name['carbon']) }} {{ h_sep }}