An internal reporting tool for use with the news database provided by Udacity as part of Udacity's Full Stack Developer program
Prerequisites:
For the following applications, ensure they are accessible from your PATH variable
- First you'll need VirtualBox installed on your machine. Find your operating system and install Virtual Box
- Next you'll need to install Vagrant
Then follow these instructions:
$ git clone https://github.com/udacity/fullstack-nanodegree-vm.git
$ cd fullstack-nanodegree-vm/vagrant
$ vagrant up
vagrant up
may take awhile to download. Wait until it is done before continuing
this project is made for python 2.7 -- the vagrant instance will have python 2.7 preinstalled
for development on your local machine you can install python 2.7.16 here
Continue running the following commands:
$ vagrant ssh
$ git clone https://github.com/lumodon/logs_analysis.git
$ cd logs_analysis
$ wget https://d17h27t6h515a5.cloudfront.net/topher/2016/August/57b5f748_newsdata/newsdata.zip
$ unzip newsdata.zip && rm newsdata.zip
$ psql -d news -f newsdata.sql && rm newsdata.sql
$ pip install -r requirements.txt
$ python init.py
$ python main.py
init.py
indexes database to allow query2.sql
to execute faster.
The project is modularized with three sql
for easier debugging (using psql -d news query{N}.sql
where N is 1-3)
main.py
then iterates over the sql files, reading them, and executing them using psycopg2
to interact with the postgresql database
query1.sql
and query3.sql
both use views to give readability where subselect queries would have been cumbersome
this project follows pep8 style guide
pudb
was used for debugging -- but is not a requirement for the project
requirements.txt
the requirements in requirements.txt from pip freeze > requirements.txt
include predefined list provided by vagrant.
psycopg2 is the only production requirement used, pudb is a dev intall. Coming from NodeJS -- I am not sure how to perform python's equivelant to npm install --save-dev ###
the vagrant system is using Python 2.7
- http://www.postgresqltutorial.com/postgresql-date/
For the formatting of date in query3.sql - https://stackoverflow.com/questions/39154661/postgresql-negative-substring-length-not-allowed-but-no-obvious-violation-in-da
Seeking how to get substring to ignore '%' symbol -- discovered there's alength
key word: used in query3.sql - https://stackoverflow.com/questions/11182339/reference-alias-calculated-in-select-in-where-clause
Struggling with not being able to useas
keyword inwhere
clause - discovered ability to use subselect (which was turned into a view) to force name of item - https://pyformat.info/
How to interpolate strings in python for use in for loop of query files - https://www.cybertec-postgresql.com/en/postgresql-speeding-up-group-by-and-joins/
query2.sql was taking 30 to 60 seconds -- by switching to this WITH format it now runs in only a matter of seconds
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to http://unlicense.org/