Logs Analysis Project
Gathering insights from a relational database via SQL queries and Python.
Views
The Python code in reports.py
makes use of several views within the news
database. If the views do not exist at runtime, the program will create them.
The views created by the program are:
datereqs
create view datereqs as
select date(time) as date, count(status) as reqs
group by date;
dateerrs
create view dateerrs as
select date(time) as date, count(status) as errs
from log
where not status = '200 OK'
group by date;
okpaths
create view okpaths as
select path from log where status = '200 OK';
totalviews
create view totalviews as
select path, count(path) from okpaths
group by path;
authortoarticle
create view authortoarticle as
select authors.name, articles.slug from authors, articles
where authors.id = articles.author;
Running the Python Code
The project has the following structure:
project-logs-analysis/
├── README.md
├── code
│ └── reports.py
reports.py
- the Python code that prints the answers to the questions above.
To run the code:
- Ensure the
fullstack-nanodegree-vm
project project has been downloaded. - Ensure VirtualBox and Vagrant have been installed.
- Copy the
reports.py
file into thevagrant
directory of thefullstack-nanodegree-vm
project. vagrant up
vagrant ssh
cd /vagrant
python reports.py
or just./reports.py
Understanding the Output
The output of the code varies slightly, depending on whether or not the views were
created before the program was run (perhaps by running psql
commands).
Both versions of the output are included: