Skip to content

Commit 8b85de2

Browse files
added setup script, cleaned up readme, and added if name==__main__
1 parent 80ad31a commit 8b85de2

File tree

3 files changed

+58
-21
lines changed

3 files changed

+58
-21
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
11
# simple_analytics_pipeline
22
A simple example of loading data from CSV into SQLite DB, and then representing some data as charts.
3+
4+
## Quick-Start
5+
### Download Github Repo
6+
```text
7+
git clone https://github.com/org-not-included/simple_analytics_pipeline
8+
cd simple_analytics_pipeline
9+
```
10+
### Load file and build chart
11+
```text
12+
source setup.sh
13+
```

main.py

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,26 @@ def create_chart(sql, conn, x, y):
2727
plt.show()
2828

2929

30-
# Hard code table name and local file path
31-
table_name = "sample_table"
32-
source_file = "data/sample_data.csv"
33-
# Initialize connection to database
34-
conn = sqlite3.connect("my_local.db")
35-
# Load the data into a table
36-
load_file_to_db(filename=source_file, table=table_name, conn=conn)
37-
# Preview the table
38-
preview_data(table=table_name, conn=conn)
39-
40-
charts_sql = f"""
41-
Select
42-
AVG(Value) as avg_val,
43-
Variable_category
44-
from
45-
{table_name}
46-
GROUP BY Variable_category
47-
ORDER BY AVG(Value)
48-
"""
49-
50-
create_chart(sql=charts_sql, conn=conn, x="Variable_category", y="avg_val")
30+
31+
if __name__ == "__main__":
32+
# Hard code table name and local file path
33+
table_name = "sample_table"
34+
source_file = "data/sample_data.csv"
35+
# Initialize connection to database
36+
conn = sqlite3.connect("my_local.db")
37+
# Load the data into a table
38+
load_file_to_db(filename=source_file, table=table_name, conn=conn)
39+
# Preview the table
40+
preview_data(table=table_name, conn=conn)
41+
42+
charts_sql = f"""
43+
Select
44+
AVG(Value) as avg_val,
45+
Variable_category
46+
from
47+
{table_name}
48+
GROUP BY Variable_category
49+
ORDER BY AVG(Value)
50+
"""
51+
52+
create_chart(sql=charts_sql, conn=conn, x="Variable_category", y="avg_val")

setup.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Create virtual environment, if needed
2+
if [ ! -d ".venv/" ]; then
3+
echo "Installing virutalenv..."
4+
python3 -m pip install virtualenv
5+
echo "Creating .venv/..."
6+
python3 -m virtualenv .venv/
7+
fi
8+
9+
# Activate virtual environment, if one isn't active
10+
if [ -z "$VIRTUAL_ENV" ]; then
11+
echo "Activating Virtual Environment..."
12+
. .venv/bin/activate
13+
else
14+
echo -e "Deactivating Virtual Environment: $VIRTUAL_ENV/"
15+
deactivate
16+
echo "Activating Virtual Environment..."
17+
. .venv/bin/activate
18+
fi
19+
20+
# Install PyPi packages (python requirements)
21+
pip3 install -Ir requirements.txt
22+
23+
# Load file and build chart
24+
python3 main.py

0 commit comments

Comments
 (0)