CAFE

1. 파이썬 수업

Re: 오늘의 마지막 문제. 자동화 스크립트 2번을 아래의 막대 그래프를 출력하는것으로 변경하시오 !

작성자21기_민준호|작성시간25.06.26|조회수23 목록 댓글 0

from collections import Counter

import matplotlib.pyplot as plt

import pandas as pd

 

ora_alert = open("c:\\data\\alert_log.txt")

ora_text = ora_alert.read()

lines = ora_text.split()

 

def find_errors():

    error = []

    for word in lines:

        if 'ORA-' in word:

            error.append(word.strip(':'))

    return error



def create_error_df(error):

    return pd.DataFrame(list(Counter(error).items()), columns=['에러번호', '건수'])

 

def show_graph(df_error):

    df_sort = df_error.loc[ df_error.건수 >= 20 , : ].sort_values(by='건수', ascending=False)

    x = df_sort.loc[ :, ['에러번호']]

    y = df_sort.loc[ : , ['건수']]

    plt.rcParams['font.family'] = 'Malgun Gothic'

    plt.bar(x['에러번호'], y['건수'], color='lightblue')

    plt.xticks(rotation=45)

    plt.title('ORA-에러 건수')

    plt.show()

 

while True:

    print("😀=========================================😀")

    print('dba 작업을 편하게 하기 위한 자동화 스크립트')

    print('😀1. alert log file 뒷부분')

    print('😀2. 에러 번호 개수 확인')

    print('😀3. 에러 시각화')

    print('😀exit. 프로그램 종료')

    print('==========================================')

 

    num = input('수행할 작업 번호 입력 : ')

 

    if num == '1':

        print(ora_text[-700:])

        break

 

    elif num == '2':

        print('전체 목록을 보려면 all을 입력하세요')

        errorNum = input('에러 번호를 입력하세요 : ')

        if errorNum != 'all':

            print(errorNum, 'occurs', ora_text.count(errorNum), 'times')

            break

        else:

            error = find_errors()

            df_error = create_error_df(error)

            print(df_error)

            break

 

    elif num == '3':

        error = find_errors()

        df_error = create_error_df(error)

        show_graph(df_error)

        break

 

    elif num == 'exit':

        break

 

    else:

        print('잘못된 번호입니다')

다음검색
현재 게시글 추가 기능 열기

댓글

댓글 리스트
맨위로

카페 검색

카페 검색어 입력폼