промежуточный этап. Работает.
This commit is contained in:
+36
-18
@@ -16,6 +16,7 @@ MONTHS_RU = {
|
||||
9: "сентября", 10: "октября", 11: "ноября", 12: "декабря"
|
||||
}
|
||||
|
||||
|
||||
def format_date_ru(date_str):
|
||||
"""Преобразует дату формата '27.07.2026' в '27 июля 2026'"""
|
||||
try:
|
||||
@@ -24,6 +25,7 @@ def format_date_ru(date_str):
|
||||
except Exception:
|
||||
return date_str
|
||||
|
||||
|
||||
# Границы ячеек
|
||||
THIN_SIDE = Side(border_style="thin", color="D3D3D3")
|
||||
THIN_BORDER = Border(left=THIN_SIDE, right=THIN_SIDE, top=THIN_SIDE, bottom=THIN_SIDE)
|
||||
@@ -142,7 +144,7 @@ def generate_summary_excel(merged_df, date_str="27.07.2026", filename=None):
|
||||
ws.row_dimensions[current_row].hidden = False
|
||||
current_row += 1
|
||||
|
||||
# 4. КАТЕГОРИИ ОТСУТСТВИЙ (Свернуты hidden=True, ИСКЛЮЧЕНИЯ ИСКЛЮЧЕНЫ)
|
||||
# 4. КАТЕГОРИИ ОТСУТСТВИЙ (Свернуты hidden=True)
|
||||
absent_only = merged_df[
|
||||
(merged_df['Пришел'] == False) &
|
||||
(merged_df['Вид_отсутствия'].notna()) &
|
||||
@@ -186,9 +188,12 @@ def generate_summary_excel(merged_df, date_str="27.07.2026", filename=None):
|
||||
current_row += 1
|
||||
|
||||
# 6. АНОМАЛИИ (Свернут hidden=True)
|
||||
anomalies = merged_df[(merged_df['Пришел'] == True) & (merged_df['Вид_отсутствия'].notna())]
|
||||
anomalies = merged_df[
|
||||
((merged_df['Пришел'] == True) & (merged_df['Вид_отсутствия'].notna())) |
|
||||
(merged_df.get('anomaly_flag', 'NONE') == 'ANOMALY_NO_IN_HAS_ACTIVITY')
|
||||
]
|
||||
|
||||
ws.cell(row=current_row, column=1, value="Аномалии")
|
||||
ws.cell(row=current_row, column=1, value="Аномалии СКУД и 1С")
|
||||
ws.cell(row=current_row, column=2, value=len(anomalies))
|
||||
format_row_cells(ws, current_row, FILL_ANOMALY, is_bold=True, bold_font=bold_font)
|
||||
current_row += 1
|
||||
@@ -198,10 +203,16 @@ def generate_summary_excel(merged_df, date_str="27.07.2026", filename=None):
|
||||
if not anomalies.empty:
|
||||
for _, row in anomalies.iterrows():
|
||||
fio = row.get('Сотрудник', '')
|
||||
reason = row.get('Вид_отсутствия', 'Неизвестная причина')
|
||||
reason_text = f"В 1С: {reason}"
|
||||
reason = row.get('Вид_отсутствия', '')
|
||||
anom_flag = row.get('anomaly_flag', 'NONE')
|
||||
|
||||
if anom_flag == 'ANOMALY_NO_IN_HAS_ACTIVITY':
|
||||
first_act = row.get('Первая_активность', '—')
|
||||
reason_text = f"🚨 АНОМАЛИЯ СКУД: Нет входа (первая активность: {first_act})"
|
||||
else:
|
||||
reason_text = f"В 1С: {reason}"
|
||||
|
||||
cell_a = ws.cell(row=current_row, column=1, value=f"{fio} (На работе)")
|
||||
cell_a = ws.cell(row=current_row, column=1, value=f"{fio}")
|
||||
cell_b = ws.cell(row=current_row, column=2, value=reason_text)
|
||||
|
||||
cell_a.fill = FILL_ANOMALY
|
||||
@@ -223,7 +234,7 @@ def generate_summary_excel(merged_df, date_str="27.07.2026", filename=None):
|
||||
current_row += 1
|
||||
|
||||
ws.column_dimensions['A'].width = 45.0
|
||||
ws.column_dimensions['B'].width = 32.0
|
||||
ws.column_dimensions['B'].width = 38.0
|
||||
|
||||
try:
|
||||
wb.save(output_path)
|
||||
@@ -235,7 +246,7 @@ def generate_summary_excel(merged_df, date_str="27.07.2026", filename=None):
|
||||
print(f"[⚠️] Файл открыт в Excel! Сохранено как: {alt_path}")
|
||||
|
||||
|
||||
# --- 2. ДЕТАЛЬНЫЙ ОТЧЕТ ЗА ВЧЕРА ---
|
||||
# --- 2. ДЕТАЛЬНЫЙ ОТЧЕТ ЗА ВЧЕРА (С КОЛОНКОЙ 'первая активность' СРАЗУ ПОСЛЕ 'время входа') ---
|
||||
def generate_detailed_excel(merged_df, date_str="26.07.2026", filename=None):
|
||||
if not filename:
|
||||
filename = f"{format_date_ru(date_str)} отчет.xlsx"
|
||||
@@ -250,8 +261,9 @@ def generate_detailed_excel(merged_df, date_str="26.07.2026", filename=None):
|
||||
ws["B2"].font = Font(name="Arial", size=10, bold=True)
|
||||
ws["D2"].font = Font(name="Arial", size=10, bold=True)
|
||||
|
||||
# ⭐️ Порядок колонок: "первая активность" строго после "время входа"
|
||||
headers = [
|
||||
"№", "ФИО", "Подразделение", "время входа", "время выхода",
|
||||
"№", "ФИО", "Подразделение", "время входа", "первая активность", "время выхода",
|
||||
"находился в здании", "причина отсутствия", "норма", "отклонение от нормы"
|
||||
]
|
||||
ws.append([])
|
||||
@@ -269,14 +281,16 @@ def generate_detailed_excel(merged_df, date_str="26.07.2026", filename=None):
|
||||
end_col = 'Конец дня' if 'Конец дня' in merged_df.columns else 'Конец_дня'
|
||||
hours_col = 'Часы' if 'Часы' in merged_df.columns else 'Находился_в_здании'
|
||||
|
||||
chars_per_line_g = 24
|
||||
chars_per_line_h = 24
|
||||
|
||||
for idx, row in merged_df.reset_index(drop=True).iterrows():
|
||||
is_present = row.get('Пришел', False)
|
||||
absence_reason = row.get('Вид_отсутствия', '')
|
||||
has_reason = pd.notna(absence_reason) and str(absence_reason).strip() != ''
|
||||
anom_flag = row.get('anomaly_flag', 'NONE')
|
||||
|
||||
in_building_str = str(row.get(hours_col, '00:00'))
|
||||
first_act_val = row.get('Первая_активность', '—')
|
||||
|
||||
deviation_val = calculate_deviation(in_building_str, reason=absence_reason if has_reason else "", norm_hours=8, lunch_minutes=30)
|
||||
|
||||
@@ -285,6 +299,7 @@ def generate_detailed_excel(merged_df, date_str="26.07.2026", filename=None):
|
||||
row.get('Сотрудник', ''),
|
||||
row.get('Подразделение', ''),
|
||||
row.get(start_col, 'Нет входа'),
|
||||
first_act_val, # ⭐️ Колонки №5: "первая активность"
|
||||
row.get(end_col, 'Нет выхода'),
|
||||
in_building_str,
|
||||
absence_reason if has_reason else '',
|
||||
@@ -294,16 +309,19 @@ def generate_detailed_excel(merged_df, date_str="26.07.2026", filename=None):
|
||||
|
||||
row_num = 5 + idx
|
||||
|
||||
if is_present and has_reason:
|
||||
# Заливка строк по категориям
|
||||
if anom_flag == 'ANOMALY_NO_IN_HAS_ACTIVITY':
|
||||
row_fill = LIGHT_RED_FILL
|
||||
elif is_present and has_reason:
|
||||
row_fill = GREEN_FILL
|
||||
elif not is_present:
|
||||
row_fill = YELLOW_FILL if has_reason else LIGHT_RED_FILL
|
||||
else:
|
||||
row_fill = None
|
||||
|
||||
val_g_str = str(absence_reason) if has_reason else ""
|
||||
if len(val_g_str) > chars_per_line_g:
|
||||
needed_lines = math.ceil(len(val_g_str) / chars_per_line_g)
|
||||
val_h_str = str(absence_reason) if has_reason else ""
|
||||
if len(val_h_str) > chars_per_line_h:
|
||||
needed_lines = math.ceil(len(val_h_str) / chars_per_line_h)
|
||||
ws.row_dimensions[row_num].height = max(needed_lines * 18, 22)
|
||||
else:
|
||||
ws.row_dimensions[row_num].height = 20
|
||||
@@ -314,17 +332,17 @@ def generate_detailed_excel(merged_df, date_str="26.07.2026", filename=None):
|
||||
if row_fill:
|
||||
cell.fill = row_fill
|
||||
|
||||
if col_idx == 7:
|
||||
if col_idx == 8:
|
||||
cell.alignment = Alignment(horizontal="left", vertical="center", wrap_text=True)
|
||||
elif col_idx in [1, 4, 5, 6, 8, 9]:
|
||||
elif col_idx in [1, 4, 5, 6, 7, 9, 10]:
|
||||
cell.alignment = Alignment(horizontal="center", vertical="center")
|
||||
else:
|
||||
cell.alignment = Alignment(horizontal="left", vertical="center")
|
||||
|
||||
for col in ws.columns:
|
||||
col_letter = get_column_letter(col[0].column)
|
||||
if col_letter == 'G':
|
||||
ws.column_dimensions['G'].width = 25.0
|
||||
if col_letter == 'H':
|
||||
ws.column_dimensions['H'].width = 25.0
|
||||
else:
|
||||
max_len = 0
|
||||
for cell in col:
|
||||
|
||||
Reference in New Issue
Block a user