meta data for this page
Különbségek
A kiválasztott változat és az aktuális verzió közötti különbségek a következők.
| Előző változat mindkét oldalonElőző változatKövetkező változat | Előző változat | ||
| shell:riportok:gather_data:dsmadmc_to_excel.sh [2026/03/03 20:23] – admin | shell:riportok:gather_data:dsmadmc_to_excel.sh [2026/03/03 21:29] (aktuális) – admin | ||
|---|---|---|---|
| Sor 1: | Sor 1: | ||
| - | < | + | <WRAP prewrap> |
| + | < | ||
| + | #!/bin/bash | ||
| set -e | set -e | ||
| SCRIPT_DIR=" | SCRIPT_DIR=" | ||
| Sor 21: | Sor 23: | ||
| def convert_value(val): | def convert_value(val): | ||
| - | """ | ||
| if not val or not isinstance(val, | if not val or not isinstance(val, | ||
| return val | return val | ||
| Sor 27: | Sor 28: | ||
| if not val: | if not val: | ||
| return val | return val | ||
| - | # Ezres elválasztó vessző eltávolítása (pl. " | ||
| - | # De csak ha tizedesponttal van (angol formátum) | ||
| cleaned = val | cleaned = val | ||
| if ',' | if ',' | ||
| - | # Angol formátum: 1,234.56 | ||
| cleaned = val.replace(',', | cleaned = val.replace(',', | ||
| elif ',' | elif ',' | ||
| - | # Lehet magyar formátum (1.234,56) vagy sima ezres (1,234) | ||
| - | # Ellenőrizzük, | ||
| parts = val.split(',' | parts = val.split(',' | ||
| if len(parts) == 2 and len(parts[1]) == 3 and parts[1].isdigit(): | if len(parts) == 2 and len(parts[1]) == 3 and parts[1].isdigit(): | ||
| - | # Ezres elválasztó: | ||
| cleaned = val.replace(',', | cleaned = val.replace(',', | ||
| elif len(parts) == 2 and parts[1].replace(' | elif len(parts) == 2 and parts[1].replace(' | ||
| - | # Magyar tizedes: 1234,56 -> 1234.56 | ||
| cleaned = val.replace(',', | cleaned = val.replace(',', | ||
| - | | ||
| - | # Próbáljuk int-ként | ||
| try: | try: | ||
| if ' | if ' | ||
| Sor 50: | Sor 42: | ||
| except: | except: | ||
| pass | pass | ||
| - | | ||
| - | # Próbáljuk float-ként | ||
| try: | try: | ||
| f = float(cleaned) | f = float(cleaned) | ||
| - | # Ha egész szám, int-ként adjuk vissza | ||
| if f == int(f) and abs(f) < 1e15: | if f == int(f) and abs(f) < 1e15: | ||
| return int(f) | return int(f) | ||
| Sor 60: | Sor 49: | ||
| except: | except: | ||
| pass | pass | ||
| - | | ||
| return val | return val | ||
| + | |||
| + | def looks_like_number(val): | ||
| + | """ | ||
| + | if not val: | ||
| + | return False | ||
| + | # Csak szamjegyek, vesszo, pont, szokoz, minusz | ||
| + | cleaned = val.replace(',', | ||
| + | return cleaned.isdigit() | ||
| def remove_hdr(c): | def remove_hdr(c): | ||
| - | ls=c.split(' | + | ls = c.split(' |
| + | | ||
| + | | ||
| for l in ls: | for l in ls: | ||
| - | if ' | + | if ' |
| - | if l.strip().startswith(' | + | |
| + | | ||
| + | if l.strip().startswith(' | ||
| + | | ||
| if not ds: | if not ds: | ||
| - | if any(x in l for x in ['IBM Spectrum',' | + | if any(x in l for x in ['IBM Spectrum', |
| - | if l.strip()=='' | + | ' |
| - | if ds: | + | |
| - | if not r:r=[l for l in ls if not any(x in l for x in ['IBM Spectrum',' | + | if l.strip() == '' |
| + | | ||
| + | if ds: | ||
| + | | ||
| + | if not r: | ||
| + | | ||
| + | '(c) Copyright', | ||
| return ' | return ' | ||
| def parse_fw(c): | def parse_fw(c): | ||
| - | ls=c.split(' | + | ls = c.split(' |
| - | for i,l in enumerate(ls): | + | |
| - | if re.match(r' | + | |
| - | if di is None or di==0: | + | for i, l in enumerate(ls): |
| - | hl=ls[:di];dl=ls[di];dls=ls[di+1: | + | if re.match(r' |
| - | cp=[];ind=False;st=0 | + | |
| - | for i,ch in enumerate(dl): | + | |
| - | if ch==' | + | if di is None or di == 0: |
| - | elif ch!=' | + | |
| - | if ind: | + | |
| - | if not cp:return None | + | header_end = di |
| - | hd=[] | + | header_start = di |
| - | for s,e in cp: | + | for i in range(di - 1, -1, -1): |
| - | pts=[] | + | line = ls[i].strip() |
| + | if line == '': | ||
| + | header_start = i + 1 | ||
| + | break | ||
| + | header_start = i | ||
| + | | ||
| + | hl = ls[header_start:header_end] | ||
| + | | ||
| + | | ||
| + | | ||
| + | cp = [] | ||
| + | | ||
| + | | ||
| + | for i, ch in enumerate(dl): | ||
| + | if ch == ' | ||
| + | | ||
| + | | ||
| + | elif ch != ' | ||
| + | | ||
| + | | ||
| + | if ind: | ||
| + | | ||
| + | if not cp: | ||
| + | | ||
| + | | ||
| + | hd = [] | ||
| + | for s, e in cp: | ||
| + | pts = [] | ||
| for h in hl: | for h in hl: | ||
| - | if len(h)> | + | if len(h) > s: |
| - | p=h[s: | + | p = h[s:min(e, len(h))].strip() |
| - | if p: | + | if p and p not in [' |
| + | | ||
| hd.append(' | hd.append(' | ||
| - | res=[hd];cr=None | + | |
| + | | ||
| + | | ||
| + | prev_had_hyphen = False | ||
| + | | ||
| for l in dls: | for l in dls: | ||
| - | if not l.strip() | + | if not l.strip(): |
| - | | + | continue |
| - | | + | if l.strip().startswith(' |
| - | if ic and cr: | + | |
| - | for idx,(s,e) in enumerate(cp): | + | |
| - | | + | first_col_raw |
| - | cl=l[s: | + | |
| - | if cl: | + | |
| - | | + | is_continuation = False |
| - | elif cr[idx]: | + | if first_col_val |
| - | else: | + | is_continuation = True |
| + | elif prev_had_hyphen and len(l) > 0 and l[0] == ' ': | ||
| + | is_continuation = True | ||
| + | | ||
| + | if is_continuation | ||
| + | for idx, (s, e) in enumerate(cp): | ||
| + | | ||
| + | if cell_val: | ||
| + | | ||
| + | if prev_val: | ||
| + | if prev_val.endswith(' | ||
| + | # Kotojellel vegzodik -> egybeírjuk | ||
| + | | ||
| + | elif looks_like_number(prev_val) and looks_like_number(cell_val): | ||
| + | # Mindketto szam -> egybeírjuk (szam tortese) | ||
| + | | ||
| + | else: | ||
| + | # Szoveg -> szokozzel | ||
| + | | ||
| + | else: | ||
| + | | ||
| + | prev_had_hyphen = any(v.endswith(' | ||
| else: | else: | ||
| - | if cr:res.append([convert_value(re.sub(r' | + | if cr is not None: |
| - | cr=[] | + | cleaned = [] |
| - | for s,e in cp: | + | for val in cr: |
| - | if cr:res.append([convert_value(re.sub(r' | + | if val: |
| + | val = re.sub(r' | ||
| + | val = re.sub(r' | ||
| + | val = val.strip() | ||
| + | cleaned.append(convert_value(val)) | ||
| + | res.append(cleaned) | ||
| + | | ||
| + | cr = [] | ||
| + | for s, e in cp: | ||
| + | | ||
| + | prev_had_hyphen = any(v.endswith(' | ||
| + | | ||
| + | if cr is not None: | ||
| + | cleaned = [] | ||
| + | for val in cr: | ||
| + | if val: | ||
| + | val = re.sub(r' | ||
| + | val = re.sub(r' | ||
| + | val = val.strip() | ||
| + | cleaned.append(convert_value(val)) | ||
| + | res.append(cleaned) | ||
| + | | ||
| return res | return res | ||
| def parse_csv(c): | def parse_csv(c): | ||
| - | ls=c.strip().split(' | + | ls = c.strip().split(' |
| + | | ||
| for l in ls: | for l in ls: | ||
| - | if not l.strip() or l.strip().startswith(' | + | if not l.strip() or l.strip().startswith(' |
| + | | ||
| try: | try: | ||
| - | rd=csv.reader(StringIO(l)) | + | rd = csv.reader(StringIO(l)) |
| for rw in rd: | for rw in rd: | ||
| - | if rw: | + | if rw: |
| - | except: | + | |
| + | except: | ||
| + | | ||
| return r if r else None | return r if r else None | ||
| def parse_sys(c): | def parse_sys(c): | ||
| - | secs=re.split(r' | + | secs = re.split(r' |
| + | | ||
| for s in secs: | for s in secs: | ||
| - | s=s.strip() | + | s = s.strip() |
| - | if not s: | + | if not s: |
| - | tm=re.search(r' | + | |
| - | t=tm.group(1).strip() if tm else "" | + | tm = re.search(r' |
| - | tb=parse_fw(s) | + | t = tm.group(1).strip() if tm else "" |
| - | if tb and len(tb)> | + | tb = parse_fw(s) |
| - | for i,r in enumerate(tb): | + | if tb and len(tb) > 1: |
| + | for i, r in enumerate(tb): | ||
| + | | ||
| ad.extend(tb if not ad else tb[1:]) | ad.extend(tb if not ad else tb[1:]) | ||
| return ad if ad else None | return ad if ad else None | ||
| def detect(c): | def detect(c): | ||
| - | c=remove_hdr(c) | + | c = remove_hdr(c) |
| - | if not c.strip(): | + | if not c.strip(): |
| - | if ' | + | |
| - | ls=c.split(' | + | if ' |
| + | | ||
| + | ls = c.split(' | ||
| for l in ls[:20]: | for l in ls[:20]: | ||
| - | if re.match(r' | + | if re.match(r' |
| - | cc=sum(1 for l in ls[:10] if ',' | + | |
| - | if cc> | + | cc = sum(1 for l in ls[:10] if ',' |
| + | if cc > 3: | ||
| + | | ||
| return [[convert_value(l.strip())] for l in ls if l.strip()] | return [[convert_value(l.strip())] for l in ls if l.strip()] | ||
| def sn(fn): | def sn(fn): | ||
| - | n=Path(fn).stem | + | n = Path(fn).stem |
| - | if ' | + | if ' |
| - | for c in [' | + | |
| + | | ||
| + | for c in [' | ||
| + | | ||
| return n[:31] | return n[:31] | ||
| - | sd=Path(sys.argv[1]);of=sd/ | + | sd = Path(sys.argv[1]) |
| - | if not fs: | + | of = sd / sys.argv[2] |
| + | fs = sorted(sd.glob(' | ||
| + | if not fs: | ||
| + | | ||
| + | | ||
| print(f" | print(f" | ||
| - | wb=Workbook();wb.remove(wb.active) | + | |
| - | hf=PatternFill(start_color=' | + | wb = Workbook() |
| - | hfn=Font(bold=True, | + | wb.remove(wb.active) |
| - | bd=Border(left=Side(style=' | + | hf = PatternFill(start_color=' |
| - | un={} | + | hfn = Font(bold=True, |
| + | bd = Border(left=Side(style=' | ||
| + | | ||
| + | un = {} | ||
| for f in fs: | for f in fs: | ||
| print(f" | print(f" | ||
| - | try: | + | try: |
| - | except Exception as e: | + | |
| - | dt=detect(ct) | + | except Exception as e: |
| - | if not dt:dt=[[l] for l in ct.split(' | + | |
| - | if not dt: | + | |
| - | bs=sn(f.name);nm=bs;cn=1 | + | |
| - | while nm in un: | + | dt = detect(ct) |
| - | un[nm]=True | + | if not dt: |
| - | ws=wb.create_sheet(title=nm) | + | |
| - | for ri,rw in enumerate(dt, | + | if not dt: |
| - | for ci,cl in enumerate(rw, | + | |
| - | ws.cell(ri, | + | |
| - | if ri==1: | + | bs = sn(f.name) |
| - | ws.cell(ri, | + | |
| - | for ci in range(1, | + | |
| - | mx=max((len(str(c.value or '' | + | while nm in un: |
| - | ws.column_dimensions[get_column_letter(ci)].width=min(mx+2, | + | |
| - | if len(dt)> | + | |
| - | ws.freeze_panes=' | + | un[nm] = True |
| + | | ||
| + | ws = wb.create_sheet(title=nm) | ||
| + | for ri, rw in enumerate(dt, | ||
| + | for ci, cl in enumerate(rw, | ||
| + | ws.cell(ri, ci, value=cl) | ||
| + | if ri == 1: | ||
| + | | ||
| + | | ||
| + | | ||
| + | ws.cell(ri, ci).border = bd | ||
| + | | ||
| + | for ci in range(1, ws.max_column + 1): | ||
| + | mx = max((len(str(c.value or '' | ||
| + | ws.column_dimensions[get_column_letter(ci)].width = min(mx + 2, 50) | ||
| + | | ||
| + | if len(dt) > 1: | ||
| + | | ||
| + | ws.freeze_panes = ' | ||
| wb.save(of) | wb.save(of) | ||
| print(f" | print(f" | ||
| print(f" | print(f" | ||
| PYEOF | PYEOF | ||
| - | </ | + | |
| + | </file></ | ||