-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtidifyKimi.py
More file actions
73 lines (64 loc) · 3.01 KB
/
tidifyKimi.py
File metadata and controls
73 lines (64 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
tidify.py
Full -> Strg-C
Daily -> Strg-V
"""
import pandas as pd
import io
import pyperclip as pc
# ------------------------------------------------------------------
# 1) Zwischenablage einlesen
# ------------------------------------------------------------------
raw = pc.paste()
df = pd.read_csv(io.StringIO(raw), sep='\t') # Google/Excel TSV
df.columns = [c.strip() for c in df.columns]
# --- Scheitel sauber numerisch machen --------------------------------
df['Scheitel'] = (df['Scheitel']
.astype(str)
.str.replace(',', '.', regex=False)
.astype(float))
# ------------------------------------------------------------------
# 2) Datum+Zeit zusammenbauen
# ------------------------------------------------------------------
df['Datetime'] = pd.to_datetime(df['Datum'].astype(str) + ' ' + df['Uhrzeit'].astype(str),
dayfirst=True)
df['Day'] = df['Datetime'].dt.date
df['Time'] = df['Datetime'].dt.strftime('%H:%M')
df['Type'] = df['H/N'].str.upper()
df['Nr'] = df.groupby(['Day', 'Type']).cumcount() + 1
# ------------------------------------------------------------------
# 3) Pivot Zeit / Scheitel
# ------------------------------------------------------------------
p_time = (df.pivot_table(index='Day', columns=['Type', 'Nr'], values='Time', aggfunc='first')
.reindex(columns=[('H', 1), ('H', 2), ('N', 1), ('N', 2)]))
p_wert = (df.pivot_table(index='Day', columns=['Type', 'Nr'], values='Scheitel', aggfunc='first')
.reindex(columns=[('H', 1), ('H', 2), ('N', 1), ('N', 2)]))
# ------------------------------------------------------------------
# 4) End-Tabelle
# ------------------------------------------------------------------
out = pd.DataFrame(index=p_time.index)
out['Datum'] = pd.to_datetime(out.index).strftime('%d.%m.%Y')
# Wochentag (lang) auf Deutsch
out['Wochentag'] = pd.to_datetime(out.index).strftime('%A').str.capitalize()
# Falls du die englischen Wochentage in deutscher Reihenfolge willst:
# mapping für deutsche Bezeichnung
de_day = {'Monday': 'Montag', 'Tuesday': 'Dienstag', 'Wednesday': 'Mittwoch',
'Thursday': 'Donnerstag', 'Friday': 'Freitag', 'Saturday': 'Samstag',
'Sunday': 'Sonntag'}
out['Wochentag'] = pd.to_datetime(out.index).strftime('%A').map(de_day)
cols = ['Wochentag', 'Datum']
for (t, n) in [('H', 1), ('H', 2), ('N', 1), ('N', 2)]:
prefix = f'HW{n}' if t == 'H' else f'NW{n}'
cols += [f'{prefix}_Zeit', f'{prefix}_m']
out[f'{prefix}_Zeit'] = p_time[(t, n)]
out[f'{prefix}_m'] = p_wert[(t, n)].round(2)
out = out.reindex(columns=cols)
# ------------------------------------------------------------------
# 5) Komma-Dezimalzeichen & TSV in Zwischenablage
# ------------------------------------------------------------------
# Dezimal-Komma für deutsche Zwischenablage
out_str = out.to_csv(sep='\t', index=False, decimal=',')
pc.copy(out_str)
print('fertig – Tages-Tabelle liegt in der Zwischenablage (Strg-V in Daily)')