Giter Club home page Giter Club logo

per_minute_parcer's Introduction

Per minute log ivents counter

Скрипт подготовлен как решение задачи для данного кейса:

Имеется файл events.log вида:

[2018-04-11   03:13:57]  OK

[2018-04-11   03:14:04]  OK

[2018-04-11 03:14:04] NOK

[2018-04-11 03:14:09] OK

Напишите на вашем любимом скриптовом языке программирования (Ruby, Perl, PHP, Python, Groovy, . . . ) программу, которая считывает файл и выводит число событий NOK за каждую минуту.

from collections import defaultdict

per_minute_counter = defaultdict(int)

with open('events.log', 'rt') as file:
    line = file.readline()
    while line:
        # Уберем лишние пробелы
        line = " ".join(line.split())
        if 'NOK' in line:
            line = line.split("]")

            date_parts = line[0].split(":")
            minute = date_parts[0] + ":" + date_parts[1] + "]"

            per_minute_counter[minute] += 1

        line = file.readline()

for date_time_minute, count in per_minute_counter.items():
    print(f'{date_time_minute} {count}')

per_minute_parcer's People

Contributors

dok-dev avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.