def show_logs(): if root.filename is None or root.filename == '': root.withdraw() messagebox.showerror("Error", "Файл не выбран, выберите файл!") root.deiconify() else: file = open(root.filename) data_mass = analize_logs(file) output_window = Toplevel() output_window.geometry('600x600') textFrame = Frame(output_window, height=340, width=600) textFrame.pack(side='bottom', fill='both', expand=1) text = Text(textFrame, font='Arial 14', wrap=WORD) for i in data_mass: text.insert(1.0, str(i) + '\n' + '\n') scroollbar = Scrollbar(textFrame) scroollbar['command'] = text.yview text['yscrollcommand'] = scroollbar.set scroollbar.pack(side=RIGHT, fill=Y) text.pack(side=RIGHT, fill=BOTH) output_window.mainloop()
def condition_describer(): ''' RU: Позволяет получить инфу от пользователя, такую как: путь к логу, дату для начала анализа и дату конца анализа. EN: Allows you to receive information from the user, such as: the path to the log, the date to start the analysis and the end date of the analysis. ''' from parcer import analize_logs from filters import period_filter print("Enter the path, in that format:", '\n', 'C:\\test.../file.txt') path_to_file = input() file = open(path_to_file) print("Enter the date for start, in that format:", '\n', 'date/Mth/...') start_date = input() print("Enter the date for end, in that format:", '\n', 'date/Mth/...') end_date = input() data_mass = analize_logs(file) period_data = period_filter(data_mass, start_date, end_date) # filter massive by date return period_data
def Getter(): print("Enter the path, in that format:", '\n', 'C:\\test.../file.txt') path_to_file = input() file = open(path_to_file) print("Enter the date for start, in that format:", '\n', 'date/Mth/...') start_date = input() print("Enter the date for end, in that format:", '\n', 'date/Mth/...') end_date = input() #-------------------------------------------------------------------- data_mass = analize_logs(file) period_data = period_filter(data_mass, start_date, end_date) count = reqFreq(period_data) req_per_sec = count / 86400 req_per_min = count / 1440 req_per_hour = count / 24 #result_table = (anal_day, requests_count, req_per_sec, req_per_min, req_per_hour) result = [(start_date, count, req_per_sec, req_per_min, req_per_hour)] return result
массив данных и выводит количество запросов за временной промежуток и среднее количество запросов. EN - A function that accepts: data array and displays the number of requests for time interval and average number of requests. ''' count = len(period_data) sec_in_day = 86400 min_in_day = 1440 hour_in_day = 24 print('requests for time period - ', count) print('average number of requests per second - ', count / sec_in_day) print('average number of requests per minute - ', count / min_in_day) print('average number of requests per hour - ', count / hour_in_day) return count #test if play redusers.py if __name__ == '__main__': test_logs = open('logs.txt') data_mass = analize_logs(test_logs) period_data = period_filter(data_mass, '30/Apr', '01/May') count = reqFreq()
def show_logs_info(): #-----проверка на выбор файла----- if root.filename is None or root.filename == '': root.withdraw() messagebox.showerror( "Error", "Файл не выбран, выберите файл по-жалу-йстаааа блять!") root.deiconify() #--------------------------------- else: #-----смотрим логи за временной промежуток------ #-----функция для получения дат----- def get_time_interval(): global start_date, end_date start_date = start_date_field.get() end_date = end_date_field.get() if start_date == '' or end_date == '': messagebox.showerror("Error", "Даты не выбраны.") def period_filtering(): get_time_interval() text.delete(1.0, END) period_data = period_filter(data_mass, start_date, end_date) for n in period_data: text.insert(1.0, str(n) + '\n' + '\n') def show_period_info(): get_time_interval() text.delete(1.0, END) period_data = period_filter(data_mass, start_date, end_date) count = reqFreq(period_data) text.insert(1.0, 'запросов за временной промежуток - %s' % count, '\n', '\n', '\n') text.insert( 1.0, 'среднее число запросов в секунду - %s' % (count / 86400), '\n', '\n', '\n') text.insert( 1.0, 'среднее число запросов в минуту - %s' % (count / 1440), '\n', '\n', '\n') text.insert(1.0, 'среднее число запросов в час - %s' % (count / 24), '\n', '\n', '\n') #-----получаем файл----- file = open(root.filename) #-----анализ файла-----(filter massive by date) data_mass = analize_logs(file) #-----организовуем интерфейс----- output_window = Toplevel() output_window.geometry('600x600') textFrame = Frame(output_window, height=340, width=600) textFrame.pack(side='bottom', fill='both', expand=1) Label(textFrame, text="Введите начальную дату: (date/Mth/...)").pack(side=TOP) start_date_field = Entry(textFrame) start_date_field.pack(side=TOP) Label(textFrame, text="Введите конечную дату: (date/Mth/...)").pack(side=TOP) end_date_field = Entry(textFrame) end_date_field.pack(side=TOP) Button(textFrame, text='\n Подтвердить ввод \n', command=period_filtering).pack(side=TOP, fill=BOTH) Button(textFrame, text='\n Показать инфо за этот временной промежуток \n', command=show_period_info).pack(side=TOP, fill=BOTH) global text text = Text(textFrame, font='Arial 14', wrap=WORD) scroollbar = Scrollbar(textFrame) scroollbar['command'] = text.yview text['yscrollcommand'] = scroollbar.set scroollbar.pack(side=RIGHT, fill=Y) text.pack(side=RIGHT, fill=BOTH) #-----зацикливаем интерфейс----- output_window.mainloop()
'\n', "5) DBWriter.py (writing data to database)", '\n' ) first_decision = int(input()) #-----decision of user--- if first_decision == 1: #-if chosen Iterator---It work's print("Your choise: Parcer.py") from parcer import analize_logs print("Enter the path, in that format:", '\n', 'C:\\test.../file.txt') path_to_file = input() file = open(path_to_file) data_mass = analize_logs(file) for i in data_mass: print(i, '\n') if first_decision == 2: #-if chosen Filters--- print("Your choise: Filters.py") period_data = condition_describer() for n in period_data: print(n, '\n') if first_decision == 3: #-if chosen Redusers--- from redusers import reqFreq print("Your choise: Redusers.py")