{"id":16514296,"url":"https://github.com/christophersmith/data-modeling-with-postgres","last_synced_at":"2025-06-29T13:03:08.302Z","repository":{"id":50680449,"uuid":"232084010","full_name":"christophersmith/data-modeling-with-postgres","owner":"christophersmith","description":"Udacity Data Engineering Nanodegree - Project 1 - Data modeling with Postges","archived":false,"fork":false,"pushed_at":"2020-01-06T17:08:42.000Z","size":437,"stargazers_count":4,"open_issues_count":1,"forks_count":20,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-08T15:49:48.649Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/christophersmith.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-01-06T11:09:36.000Z","updated_at":"2022-11-04T23:16:14.000Z","dependencies_parsed_at":"2022-08-02T19:16:05.379Z","dependency_job_id":null,"html_url":"https://github.com/christophersmith/data-modeling-with-postgres","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/christophersmith/data-modeling-with-postgres","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christophersmith%2Fdata-modeling-with-postgres","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christophersmith%2Fdata-modeling-with-postgres/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christophersmith%2Fdata-modeling-with-postgres/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christophersmith%2Fdata-modeling-with-postgres/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/christophersmith","download_url":"https://codeload.github.com/christophersmith/data-modeling-with-postgres/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christophersmith%2Fdata-modeling-with-postgres/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262598141,"owners_count":23334667,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T16:12:06.871Z","updated_at":"2025-06-29T13:03:08.252Z","avatar_url":"https://github.com/christophersmith.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Data Modeling with Postgres\n\n## Introduction\n\nA startup called Sparkify wants to analyze the data they've been collecting on songs and user activity on their new music streaming app. The analytics team is particularly interested in understanding what songs users are listening to. Currently, they don't have an easy way to query their data, which resides in a directory of JSON logs on user activity on the app, as well as a directory with JSON metadata on the songs in their app.\n\nThey'd like a data engineer to create a Postgres database with tables designed to optimize queries on song play analysis, and bring you on the project. Your role is to create a database schema and ETL pipeline for this analysis. You'll be able to test your database and ETL pipeline by running queries given to you by the analytics team from Sparkify and compare your results with their expected results.\n\n## Project Description\n\nIn this project, you'll apply what you've learned on data modeling with Postgres and build an ETL pipeline using Python. To complete the project, you will need to define fact and dimension tables for a star schema for a particular analytic focus, and write an ETL pipeline that transfers data from files in two local directories into these tables in Postgres using Python and SQL.\n\n## Prerequisites\n\nThis project makes the folowing assumptions:\n\n* Python 3 is available\n* `pandas` and `psycopg2` are available\n* A PosgreSQL database is available on localhost\n\n## Running the Python Scripts\n\nAt the terminal:\n\n1. ```python create_tables.py```\n2. ```python etl.py```\n\nIn IPython:\n\n1. ```run create_tables.py```\n2. ```run etl.py```\n\n## Database Schema\n\nAfter examining the Log and Song JSON files, I created a Star schema (shown below) that include one Fact table (songplays) and 4 Dimension tables.\n\n\u003cimg src=\"erd-diagram.png\" alt=\"ERD Diagram\" width=\"800\"/\u003e\n\nThis design will offer flexibility with the queries being used for analysis.\n\n## ETL Process\n\n### Song Dataset\n\nThe first dataset is a subset of real data from the Million Song Dataset. Each file is in JSON format and contains metadata about a song and the artist of that song. The files are partitioned by the first three letters of each song's track ID. For example, here are filepaths to two files in this dataset.\n\n```\nsong_data/A/B/C/TRABCEI128F424C983.json\nsong_data/A/A/B/TRAABJL12903CDCF1A.json\n```\n\nAnd below is an example of what a single song file, TRAABJL12903CDCF1A.json, looks like.\n\n```\n{\n    \"num_songs\": 1,\n    \"artist_id\": \"ARJIE2Y1187B994AB7\",\n    \"artist_latitude\": null,\n    \"artist_longitude\": null,\n    \"artist_location\": \"\",\n    \"artist_name\": \"Line Renaud\",\n    \"song_id\": \"SOUPIRU12A6D4FA1E1\",\n    \"title\": \"Der Kleine Dompfaff\",\n    \"duration\": 152.92036,\n    \"year\": 0\n}\n```\n\nThis information is parsed to populate the Songs and Artists Dimension tables.\n\n### Log Dataset\n\nThe log files in the dataset are partitioned by year and month. For example, here are filepaths to two files in this dataset.\n\n```\nlog_data/2018/11/2018-11-12-events.json\nlog_data/2018/11/2018-11-13-events.json\n```\n\nThis data contains information of which songs Users listened to at a specific time. Information is parsed to provide data for the Songplays Fact table and the Users and Time Dimension tables. The ```songplays.artist_id``` and ```songplays.song_id``` columns are populated by a lookup based on the Song Title, Artist Name and song Duration.\n\n## Description of Files\n\n### Directory: data/log_data\n\nThis directory contains a collection of JSON log files. These files are used to populate our Fact table - Song Plays - and to populate the Dimension tables for Users and Time.\n\n### Directory: data/song_data\n\nThis directory contains a collection of Song JSON files. These files are used to populate Dimension tables for Songs and Artists.\n\n## create_tables.py\n\nThis Python script recreates the database and tables used to storethe data.\n\n## etl.ipynb\n\nA Python Jupyter Notebook that was used to initially explore the data and test the ETL process.\n\n## etl.py\n\nThis Python script reads in the Log and Song data files, processes and inserts data into the database.\n\n## requirements.txt\n\nA list of Python modules used by this project.\n\n## sql_queries.py\n\nA Python script that defines all the SQL statements used by this project.\n\n## test.ipynb\n\nA Python Jupyter Notebook that was used to test that data was loaded properly.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchristophersmith%2Fdata-modeling-with-postgres","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchristophersmith%2Fdata-modeling-with-postgres","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchristophersmith%2Fdata-modeling-with-postgres/lists"}