Coder Social home page Coder Social logo

sql-log-analyzer's Introduction

SQL Log Analyzer project for Udacity

This is a simple Python script that will connect to a local PostgreSQL database, analyze it and return the following information to the console:

  1. TOP 3 most viewed articles
  2. Most popular authors by articles' views
  3. Days in which the HTTP invalid request where more that 1% of the daily total

Usage

  1. Install Python 3.x.

  2. Place the script file on the server/instance where your database is located.

  3. Access the database from the terminal with psql -d news and create the following views:

    1. create view invalid_requests as select date_trunc('day', time), status, count(*) as num from log where status like '%404%' group by status, date_trunc('day', time) order by date_trunc('day', time);

    2. create view total_requests as select date_trunc('day', time), count(*) as num from log group by date_trunc('day', time) order by date_trunc('day', time);

    3. create view invalid_req_perc as select round((CAST (a.num/b.num::float*100 as numeric)), 2) as percentage, a.date_trunc from invalid_requests as a, total_requests as b where a.date_trunc = b.date_trunc;

    4. create view hits_by_article as select path, count(*) as num from log where path like '/article/%' group by path order by num desc;

    5. create view hits_by_title as select title, author, num from hits_by_article, articles where hits_by_article.path like '%'||articles.slug order by num desc;

  4. On Windows from the command prompt run: C:\path-to-python3-binary\python.exe C:\path-to-project-folder\log_analyzer.py On Mac OSX or Linux from the terminal run: chmod +x /path-to-project-folder/log_analyzer.py python /path-to-project-folder/log_analyzer.py

sql-log-analyzer's People

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.