logs-analysis-First-project

This is an internal reporting tool that produces answers by printing them out in the plain text in the Terminal. The tool produces answers to the following three questions based on the data in the database:

  1. What are the most popular three articles of all time?
  2. Who are the most popular articles authors of all time?
  3. On which days did more than 1% of requests lead to errors?

Technologies That's used (Tools)

Writing the program with tool is a Python language program that uses the psycopg2 module to connect to the database.

Python For Writing program
PostgreSQL Download For Database
VirtualBox
Vagrant
Git

VM configuration file by Udacity from here or clone the repository from [here] (https://github.com/udacity/fullstack-nanodegree-vm)

Download Project Database from newsdata

Editors

can use any editor would do you like
visual Studio Code
sublime Text
Atom
Brackets

Documentation

Python : https://docs.python.org/3/tutorial/index.html
Psycopg – PostgreSQL database adapter for Python : http://initd.org/psycopg/docs/index.html
PostgreSQL: https://www.postgresql.org/docs/9.4/index.html

System setup and how to view this project

This project makes use of Udacity's Linux-based virtual machine (VM) configuration which includes all of the necessary software to run the application.

  1. Download Vagrant and install.
  2. Download Virtual Box and install.
  3. Clone this repository to a directory of your choice.
  4. Download the newsdata.sql (extract from newsdata.zip (not provided here though)) and newsdata.py files from the respository and move them to your vagrant directory within your VM.

Run these commands from the terminal in the folder where your vagrant is installed in:

  1. vagrant up to start up the VM.
  2. vagrant ssh to log into the VM.
  3. cd /vagrant to change to your vagrant directory.
  4. psql -d news -f newsdata.sql to load the data and create the tables.
  5. Create view tables using the following command

View

     CREATE VIEW total_view AS SELECT date(time), COUNT(*) AS totview
     FROM log 
     GROUP BY date(time) 
     ORDER BY totview;
     CREATE VIEW total_errors AS SELECT date(time), COUNT(*) AS errview
     FROM log WHERE status= '404 NOT FOUND' 
     GROUP BY date(time) 
     ORDER BY errview;
    CREATE VIEW percentage_errors AS
    SELECT total_view.date, 
    round((total_errors.errview*100.0/total_view.totview), 3)AS percentage
    FROM total_view, total_errors
    WHERE total_view.date = total_errors.date
    ORDER BY total_view.date;
  1. python3 main.py to run the reporting tool.

Helpful Resources (README.md)

Python code quality Your code should be written with good Python style. The PEP8 style guide is an excellent standard to follow. You can do a quick check using the pep8 command-line tool.

For more information on writing good READMEs, From udacity see this course.

Troubleshooting

If your command prompt does not start with vagrant after typing vagrant ssh then please try the winpty vagrant ssh on your Windows system.