Initial commit

This commit is contained in:
2020-07-19 14:55:14 +03:00
commit 1c410da387
7 changed files with 98 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
.vscode/
output/*.txt

75
gen_formula.py Normal file
View File

@@ -0,0 +1,75 @@
from jinja2 import Environment, FileSystemLoader
import os
def column_code(num):
result = ''
alfa_count = 1 + ord('Z') - ord('A')
shift = ord('A') - 1
while num > 0:
if num <= alfa_count:
result = chr(shift + num) + result
num = 0
else:
cur_chr = ((num -1) % alfa_count) + 1
num = int((num -1) / alfa_count)
result = chr(shift + cur_chr) + result
return result
def column_num(code):
result = 0
alfa_count = 1 + ord('Z') - ord('A')
shift = ord('A') - 1
mult = 1
length = len(code)
while length > 0:
cur_chr = code[-1]
result = result + mult * (ord(cur_chr) - shift)
length -= 1
if 0 == length:
code = ''
else:
code = code[:-1]
mult *= alfa_count
return result
def generate_columns():
column_start = column_num('H')
column_end = column_num('ZZ')
column_current = column_start
while(column_current <= column_end):
yield column_code(column_current)
column_current += 1
def render_template(name, template):
vals = {
'сol_start': 'H',
'row_num': 4,
'fixed_row': 3,
'columns': [c for c in generate_columns()]
}
print(template.render(vals))
def init_templates():
names = ['wins_formula', 'wins_red_formula', 'wins_black_formula']
templates = {}
env = Environment(
loader=FileSystemLoader(os.path.join(os.path.dirname(os.path.dirname(__file__)),'templates'))
)
for name in names:
templates[name] = env.get_template(f'{name}.jinja2')
return templates
def main():
templates = init_templates()
for template in templates.items():
print(template[0], template[1])
render_template(template[0], template[1])
if __name__ == "__main__":
main()

0
output/placeholder Normal file
View File

3
templates/base.jinja2 Normal file
View File

@@ -0,0 +1,3 @@
=SUM(
{% block conditions %}{% endblock %}
)

View File

@@ -0,0 +1,6 @@
{% extends 'base.jinja2' %}
{% block conditions %}
{% for column in columns %}
IF(AND({{column}}{{row_num}}={{column}}${{fixed_row}};{{column}}${{fixed_row}}="Ч");1;0);
{% endfor %}
{% endblock %}

View File

@@ -0,0 +1,6 @@
{% extends 'base.jinja2' %}
{% block conditions %}
{% for column in columns %}
IF({{column}}{{row_num}}={{column}}${{fixed_row}};1;0);
{% endfor %}
{% endblock %}

View File

@@ -0,0 +1,6 @@
{% extends 'base.jinja2' %}
{% block conditions %}
{% for column in columns %}
IF(AND({{column}}{{row_num}}={{column}}${{fixed_row}};{{column}}${{fixed_row}}="К");1;0);
{% endfor %}
{% endblock %}