Storing data in SQL DB and retrieved with SQLAlchemy.
Data project with the graphs generated on the browser using HighCharts.
NOTE : Should have pip installed
pip install virtualenv
virtualenv venv
source venv/bin/activate
Once it is activated, it will show (venv) before the username as shown below :
(venv) username project
$
deactivate
copy the link of ssh clone from the repository and run command as follows :
git clone [email protected]:mountblue/cohort-16-python/arkadu_kumar/dataproject-sqlalchemy.git
After succesfully cloning the repository, change directory to dataproject-sqlalchemy by following command
cd dataproject-sqlalchemy
To install all the dependencies or requirements, run the command :
pip install -r requirements.txt
NOTE : Make sure to have virtual environment activated so it installs in the virtual environment.
Download the csv file from the link and paste it in the directory datasets/csv
with the name population_estimates_csv.csv
datasets/csv/population_estimates_csv.csv
To install PostgreSQL, first refresh your server’s local package index:
sudo apt update
Then, install the Postgres package along with a -contrib package that adds some additional utilities and functionality:
sudo apt install postgresql postgresql-contrib
One way is to switch over to the postgres account on your server by typing:
sudo -i -u postgres
Then you can access the Postgres prompt by typing:
postgres@server:~$ psql
This will log you into the PostgreSQL prompt, and from here you are free to interact with the database management system right away.
To exit out of the PostgreSQL prompt, run the following:
postgres=# \q
This will bring you back to the postgres Linux command prompt. To return to your regular system user, run the exit command:
postgres@server:~$ exit
Another way to connect to the Postgres prompt is to run the psql command as the postgres account directly with sudo:
sudo -u postgres psql
This will log you directly into Postgres without the intermediary bash shell in between.
Again, you can exit the interactive Postgres session by typing:
postgres=# \q
Start postgres psql
sudo -u postgres psql
Type in the command:
postgres=# \i create_user.sql
This will create the user and database. Then, exit postgres psql
postgres=# \q
python3 generating_json.py
That will generate the JSON files.
NOTE: There should be json
folder in datasets
folder, like datasets/json
, otherwise, it will throw a error that directory not exist.
Next run the command :
python3 -m http.server
It starts a localhost server. Head to that url and open project.html
file to see the graphs.
To stop the server: Click Ctrl^c
Start postgres psql
sudo -u postgres psql
Type in the command:
postgres=# \i delete_user.sql
This will create the user and database. Then, exit postgres psql
postgres=# \q
JSON files are located in datasets/json
for each graph.
JSON files only contains data required for respective graph plots.
I have used HighCharts JavaScript Lib for plotting graphs on Browser.