Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ShashkovS/16095f7ac8269c87ceeb36d427c2489b to your computer and use it in GitHub Desktop.
Save ShashkovS/16095f7ac8269c87ceeb36d427c2489b to your computer and use it in GitHub Desktop.
import re
import os
html_path = 'Y:\\'
os.chdir(html_path)
stat = {'1.Н': (57,57), '1.1': (43,57), '1.2': (49,57), '1.3': (49,57), '1.4': (28,57), '1.5': (26,57), '1.6а': (37,57), '1.6б': (37,57), '1.6в': (37,57), '1.6г': (37,57), '1.6д': (37,57), '1.7': (28,57), '1.8': (12,57), '1.9': (8,57), '1.10': (6,57), '1.11а': (6,57), '1.11б': (5,57), '1.12': (7,57), '1.13': (6,57), '1.14': (8,57), '2.Н': (73,73), '2.1': (49,73), '2.2а': (59,73), '2.2б': (58,73), '2.2в': (63,73), '2.3а': (43,73), '2.3б': (9,73), '2.4а': (51,73), '2.4б': (31,73), '2.5а': (8,73), '2.5б': (4,73), '2.6': (42,73), '2.7': (34,73), '2.8': (11,73), '2.9': (2,73), '2.10': (2,73), '2.11а': (2,73), '2.11б': (2,73), '2.12': (2,73), '3.Н': (73,73), '3.1': (44,73), '3.2': (56,73), '3.3а': (61,73), '3.3б': (49,73), '3.3в': (42,73), '3.4': (45,73), '3.5': (37,73), '3.6': (30,73), '3.7': (35,73), '3.8': (8,73), '3.9': (6,73), '3.10': (7,73), '3.11а': (2,73), '3.11б': (1,73), '4.Н': (100,100), '4.1': (54,100), '4.2': (55,100), '4.3': (46,100), '4.4': (32,100), '4.5': (20,100), '4.6а': (38,100), '4.6б': (30,100), '4.6в': (30,100), '4.7': (31,100), '4.8': (22,100), '4.9': (28,100), '4.10': (5,100), '4.11': (3,100), '5.Н': (91,91), '5.1': (56,91), '5.2': (58,91), '5.3': (54,91), '5.4': (23,91), '5.5': (33,91), '5.6а': (28,91), '5.6б': (19,91), '5.6в': (17,91), '5.6г': (17,91), '5.7': (28,91), '5.8': (28,91), '5.9а': (31,91), '5.9б': (2,91), '5.10а': (10,91), '5.10б': (9,91), '5.11': (1,91), '5.12': (2,91), '5.13': (4,91), '6.Н': (93,93), '6.1а': (69,93), '6.1б': (66,93), '6.1в': (62,93), '6.2а': (69,93), '6.2б': (41,93), '6.3': (76,93), '6.4': (36,93), '6.5': (25,93), '6.6а': (30,93), '6.6б': (16,93), '6.6в': (12,93), '6.7а': (15,93), '6.7б': (1,93), '6.8а': (23,93), '6.8б': (5,93), '6.9': (12,93), '6.10': (0,93), '6.11': (0,93), '6.12': (0,93), '6.13': (0,93), '7.Н': (87,87), '7.1': (66,87), '7.2а': (62,87), '7.2б': (30,87), '7.2в': (31,87), '7.3а': (36,87), '7.3б': (14,87), '7.4а': (35,87), '7.4б': (13,87), '7.5а': (68,87), '7.5б': (40,87), '7.6': (8,87), '7.7': (28,87), '7.8': (38,87), '7.9': (31,87), '7.10': (2,87), '7.11': (4,87), '7.12': (5,87), '8.Н': (81,81), '8.1': (60,81), '8.2': (62,81), '8.3а': (67,81), '8.3б': (55,81), '8.4а': (26,81), '8.4б': (18,81), '8.5': (57,81), '8.6а': (54,81), '8.6б': (45,81), '8.7': (9,81), '8.8': (22,81), '8.9а': (43,81), '8.9б': (42,81), '8.9в': (39,81), '8.9г': (9,81), '8.9д': (0,81), '8.10а': (5,81), '8.10б': (1,81), '8.11': (1,81), '8.12а': (2,81), '8.12б': (1,81), '9.Н': (60,60), '9.1': (26,60), '9.2': (26,60), '9.3а': (40,60), '9.3б': (40,60), '9.3в': (16,60), '9.4': (22,60), '9.5': (10,60), '9.6': (18,60), '9.7а': (26,60), '9.7б': (21,60), '9.7в': (15,60), '9.7г': (1,60), '9.8а': (17,60), '9.8б': (16,60), '9.9а': (7,60), '9.9б': (1,60), '9.10': (0,60), '9.11': (1,60), '10.Н': (88,88), '10.1': (59,88), '10.2': (67,88), '10.3': (68,88), '10.4': (35,88), '10.5а': (51,88), '10.5б': (23,88), '10.6а': (34,88), '10.6б': (20,88), '10.7а': (59,88), '10.7б': (4,88), '10.8а': (14,88), '10.8б': (3,88), '10.8в': (2,88), '10.8г': (2,88), '10.9': (3,88), '10.10': (2,88), '10.11': (0,88), '11.Н': (81,81), '11.1': (56,81), '11.2': (59,81), '11.3': (28,81), '11.4': (22,81), '11.5': (22,81), '11.6': (19,81), '11.7а': (55,81), '11.7б': (32,81), '11.8а': (26,81), '11.8б': (6,81), '11.9': (13,81), '11.10': (0,81), '11.11': (0,81), '12.Н': (89,89), '12.1': (41,89), '12.2а': (19,89), '12.2б': (34,89), '12.3': (8,89), '12.4': (55,89), '12.5': (34,89), '12.6а': (25,89), '12.6б': (23,89), '12.7': (68,89), '12.8': (22,89), '12.9': (17,89), '12.10': (44,89), '12.11': (5,89), '12.12': (5,89), '12.13': (1,89), '13.Н': (93,93), '13.1': (43,93), '13.2': (39,93), '13.3': (16,93), '13.4': (7,93), '13.5': (1,93), '13.6а': (6,93), '13.6б': (4,93), '13.7а': (63,93), '13.7б': (54,93), '13.7в': (38,93), '13.7г': (49,93), '13.7д': (41,93), '13.8': (37,93), '13.9': (27,93), '13.10': (3,93), '13.11': (4,93), '13.12': (0,93), '14.Н': (82,82), '14.1а': (68,82), '14.1б': (66,82), '14.2': (29,82), '14.3а': (50,82), '14.3б': (37,82), '14.3в': (45,82), '14.4': (43,82), '14.5а': (47,82), '14.5б': (25,82), '14.5в': (21,82), '14.6': (5,82), '14.7': (13,82), '14.8а': (31,82), '14.8б': (20,82), '14.8в': (8,82), '14.9': (6,82), '14.10а': (2,82), '14.10б': (3,82), '14.10в': (1,82), '14.11': (0,82), '14.12': (0,82), '15.Н': (86,86), '15.1': (75,86), '15.2а': (63,86), '15.2б': (51,86), '15.3': (70,86), '15.4а': (37,86), '15.4б': (15,86), '15.5': (23,86), '15.6а': (43,86), '15.6б': (10,86), '15.7а': (10,86), '15.7б': (2,86), '15.8а': (53,86), '15.8б': (15,86), '15.9': (4,86), '15.10': (0,86), '15.11а': (2,86), '15.11б': (1,86), '15.11в': (0,86), '16.Н': (78,78), '16.1': (68,78), '16.2': (53,78), '16.3': (27,78), '16.4': (55,78), '16.5а': (15,78), '16.5б': (9,78), '16.5в': (9,78), '16.6а': (6,78), '16.6б': (7,78), '16.7а': (16,78), '16.7б': (8,78), '16.7в': (12,78), '16.8': (48,78), '16.9': (48,78), '16.10': (12,78), '16.11': (28,78), '16.12': (0,78), '16.13': (4,78), '17.Н': (61,61), '17.1': (55,61), '17.2': (39,61), '17.3а': (33,61), '17.3б': (8,61), '17.4': (23,61), '17.5': (40,61), '17.6': (15,61), '17.7': (44,61), '17.8': (12,61), '17.9а': (18,61), '17.9б': (17,61), '17.10': (1,61), '17.11а': (2,61), '17.11б': (2,61), '17.12': (5,61), '18.Н': (88,88), '18.1': (44,88), '18.2': (40,88), '18.3': (12,88), '18.4': (12,88), '18.5': (11,88), '18.6': (41,88), '18.7': (5,88), '18.8': (32,88), '18.9': (22,88), '18.10': (2,88), '18.11': (2,88), '18.12': (2,88), '19.Н': (89,89), '19.1': (78,89), '19.2а': (51,89), '19.2б': (39,89), '19.3а': (16,89), '19.3б': (15,89), '19.4': (80,89), '19.5': (24,89), '19.6': (18,89), '19.7': (11,89), '19.8а': (27,89), '19.8б': (9,89), '19.9а': (19,89), '19.9б': (8,89), '19.10': (5,89), '19.11а': (13,89), '19.11б': (7,89), '20.Н': (70,70), '20.1': (55,70), '20.2': (58,70), '20.3': (50,70), '20.4': (45,70), '20.5': (18,70), '20.6': (42,70), '20.7': (32,70), '20.8а': (39,70), '20.8б': (19,70), '20.9': (13,70), '20.10': (7,70), '20.11': (5,70), '20.12': (3,70), '21.Н': (84,84), '21.1а': (61,84), '21.1б': (56,84), '21.2': (42,84), '21.3а': (32,84), '21.3б': (21,84), '21.4': (54,84), '21.5а': (57,84), '21.5б': (24,84), '21.6': (25,84), '21.7': (9,84), '21.8а': (29,84), '21.8б': (29,84), '21.9': (9,84), '21.10': (6,84), '21.11': (1,84), '22.Н': (77,77), '22.1а': (56,77), '22.1б': (49,77), '22.2а': (24,77), '22.2б': (4,77), '22.2в': (7,77), '22.3': (35,77), '22.4а': (40,77), '22.4б': (38,77), '22.4в': (40,77), '22.5': (16,77), '22.6': (23,77), '22.7': (15,77), '22.8а': (26,77), '22.8б': (19,77), '22.8в': (13,77), '22.8г': (0,77), '22.9а': (25,77), '22.9б': (11,77), '22.10': (4,77), '22.11': (4,77), '22.12': (2,77), '23.Н': (85,85), '23.1а': (77,85), '23.1б': (75,85), '23.1в': (67,85), '23.1г': (63,85), '23.2': (64,85), '23.3': (62,85), '23.4': (15,85), '23.5а': (54,85), '23.5б': (40,85), '23.6а': (14,85), '23.6б': (11,85), '23.6в': (12,85), '23.6г': (9,85), '23.6д': (9,85), '23.7а': (29,85), '23.7б': (18,85), '23.8': (5,85), '23.9': (1,85), '23.10': (8,85), '23.11': (0,85), '24.Н': (79,79), '24.1': (59,79), '24.2': (27,79), '24.3': (54,79), '24.4': (26,79), '24.5': (38,79), '24.6': (10,79), '24.7': (28,79), '24.8а': (7,79), '24.8б': (11,79), '24.9': (51,79), '24.10': (3,79), '24.11': (7,79), '24.12': (0,79), '24.13': (3,79), '24.14': (0,79), '25.Н': (66,66), '25.1а': (58,66), '25.1б': (58,66), '25.1в': (51,66), '25.2': (48,66), '25.3а': (20,66), '25.3б': (21,66), '25.4а': (39,66), '25.4б': (19,66), '25.5а': (22,66), '25.5б': (18,66), '25.5в': (18,66), '25.6': (8,66), '25.7а': (12,66), '25.7б': (10,66), '25.7в': (7,66), '25.8': (1,66), '25.9': (0,66), '25.10': (1,66), '25.11': (0,66), '26.Н': (61,61), '26.1': (49,61), '26.2': (30,61), '26.3': (53,61), '26.4': (50,61), '26.5': (21,61), '26.6': (44,61), '26.7а': (11,61), '26.7б': (9,61), '26.7в': (4,61), '26.8': (6,61), '26.9а': (0,61), '26.9б': (0,61), '26.10а': (0,61), '26.10б': (0,61), '26.10в': (0,61), '26.11': (0,61), '27.Н': (71,71), '27.1': (42,71), '27.2': (40,71), '27.3': (48,71), '27.4а': (28,71), '27.4б': (27,71), '27.5': (18,71), '27.6а': (21,71), '27.6б': (19,71), '27.7': (22,71), '27.8': (14,71), '27.9': (2,71), '27.10': (4,71), '27.11': (4,71), '28.Н': (66,66), '28.1': (36,66), '28.2': (53,66), '28.3': (40,66), '28.4': (23,66), '28.5а': (42,66), '28.5б': (13,66), '28.6': (15,66), '28.7': (28,66), '28.8': (34,66), '28.9': (2,66), '28.10': (4,66), '28.11': (1,66), '29.Н': (61,61), '29.1': (48,61), '29.2': (40,61), '29.3': (25,61), '29.4': (47,61), '29.5а': (38,61), '29.5б': (25,61), '29.6а': (40,61), '29.6б': (13,61), '29.7': (38,61), '29.8': (20,61), '29.9': (13,61), '29.10': (3,61), '29.11а': (2,61), '29.11б': (2,61), '30.Н': (44,44), '30.1': (36,44), '30.2': (28,44), '30.3': (14,44), '30.4': (30,44), '30.5': (21,44), '30.6а': (14,44), '30.6б': (12,44), '30.7': (24,44), '30.8': (28,44), '30.9': (3,44), '30.10': (7,44), '30.11': (0,44), '31.Н': (37,37), '31.1': (27,37), '31.2': (24,37), '31.3': (27,37), '31.4': (14,37), '31.5': (15,37), '31.6': (9,37), '31.7а': (23,37), '31.7б': (21,37), '31.8': (5,37), '31.9': (0,37), '31.10': (2,37), '31.11': (0,37), '31.12': (0,37)}
# Обогощаем статистику. Сложность задачи равна минимальной сложности пункта
problems = list(stat.keys())
for problem in problems:
if not problem[-1].isdigit():
stat[problem[:-1]] = (max(stat[pb][0] for pb in problems if pb.startswith(problem[:-1])),
max(stat[pb][1] for pb in problems if pb.startswith(problem[:-1])))
def cond_color(val):
if 0 <= val <= 0.5:
val *= 2
return (round((1 - val) * 248 + val * 255),
round((1 - val) * 105 + val * 235),
round((1 - val) * 107 + val * 132))
elif 0.5 <= val <= 1:
val = 2*val - 1
return (round((1 - val) * 255 + val * 99),
round((1 - val) * 235 + val * 190),
round((1 - val) * 132 + val * 123))
for filename in os.listdir(html_path):
if filename.lower().endswith('.html'):
print(filename)
with open(filename, 'r', encoding='utf-8') as f:
html = f.read()
problem_nums = []
punct_nums = []
for match in re.finditer(r'(?<="problem_num"><b>Задача )(\d+\.\d+)\.', html):
problem_nums.append((match.end(0), match.group(0)))
for match in re.finditer(r'(?<="problem_num">Задача )(\d+\.\d+)\.', html):
problem_nums.append((match.end(0), match.group(0)))
for match in re.finditer(r'(?<="punct_num"><b>)(\w+)\)', html):
punct_nums.append((match.end(0), match.group(0)))
for match in re.finditer(r'(?<="punct_num">)(\w+)\)', html):
punct_nums.append((match.end(0), match.group(0)))
problem_nums.sort()
problem_nums.append((len(html), ''))
last_pos = 0
res_data = []
for i, (prb_pos, prb_num) in enumerate(problem_nums[:-1]):
res_data.append(html[last_pos:prb_pos])
cur, tot = stat[prb_num[:-1]]
res_data.append(' <span style="background-color: RGB({},{},{});">[{:.2}, {}/{}]</span>'.format(*cond_color(cur/tot), cur/tot, cur, tot))
cur_puncts = sorted([(pnk_pos, pnk_num) for (pnk_pos, pnk_num) in punct_nums if prb_pos < pnk_pos < problem_nums[i+1][0]])
last_pos = prb_pos
for pnk_pos, pnk_num in cur_puncts:
res_data.append(html[last_pos:pnk_pos])
cur, tot = stat[prb_num[:-1]+pnk_num[:-1]]
res_data.append(' <span style="background-color: RGB({},{},{});">[{:.2}, {}/{}]</span>'.format(
*cond_color(cur / tot), cur / tot, cur, tot))
last_pos = pnk_pos
res_data.append(html[last_pos:])
new_html = ''.join(res_data)
with open(filename, 'w', encoding='utf-8') as f:
f.write(new_html)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment