Skip to content

Commit 9658a11

Browse files
committed
started data connection #2
Signed-off-by: Alejandro Ouslan <alejandro.ouslan@upr.edu>
1 parent 973ace3 commit 9658a11

9 files changed

+46
-45
lines changed

.dockerignore

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
notebooks/
1+
earnotebooks/
22

33
# Ignore all pkl files
44
*.pkl
@@ -14,7 +14,11 @@ notebooks/
1414
data/raw/*.csv.gz
1515
data/shape_files/*.zip
1616
*.csv.gz
17-
*.zip
17+
18+
# Exceptions
19+
!data/shape_files/states.zip
20+
!data/processed/blocks.parquet
21+
!data/processed/lodes.parquet
1822

1923
# Ignore Python bytecode files
2024
*.pyc

docker-compose.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ services:
3636
networks:
3737
- timescale_network
3838
pgadmin:
39-
image: dpage/pgadmin4:4.23
39+
image: dpage/pgadmin4:8.8
4040
container_name: dev_pgadmin4
4141
environment:
4242
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_EMAIL}

docs/conclusion.md

Whitespace-only changes.

docs/literature.md

Whitespace-only changes.

environment.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ dependencies:
1111
- numpy=1.26.4
1212
- ipykernel=6.29.3
1313
- dash=2.17.0
14-
#- plotly-geo=1.0.0
14+
- pyarrow=16.1.0
15+
- psycopg2=2.9.9
1516
- pip:
1617
- geoarrow-rust-core==0.2.0
18+
- python-dotenv==1.0.1
1719
- pyogrio==0.8.0

main.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from src.data.data_process import DataProcess
2+
3+
def main() -> None:
4+
DataProcess()
5+
6+
if __name__ == "__main__":
7+
main()

requirements.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ geoarrow-rust-core==0.2.0
77
pyogrio==0.8.0
88
geopandas==0.14.4
99
pyarrow==16.1.0
10-
gunicorn==22.0.0
10+
gunicorn==22.0.0
11+
psycopg2==2.9.9
12+
python-dotenv==1.0.1

src/data/data_db_create.py

+26-39
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import psycopg2
21
import os
2+
import psycopg2
33
from dotenv import load_dotenv
44
load_dotenv()
55

@@ -14,28 +14,41 @@ def __init__(self):
1414
f"host={df_port} "
1515
f"port={df_port}")
1616
self.conn = psycopg2.connect(connection_url)
17+
self.create_state_tables()
1718

1819
def create_state_tables(self):
1920
cursor = self.conn.cursor()
2021
query = """CREATE TABLE IF NOT EXISTS states(
21-
id serial primary key,
22+
state_id serial primary key,
23+
state_num varchar(2) NOT NULL,
2224
state_abbr varchar(2) NOT NULL,
2325
state_name varchar(100) NOT NULL,
2426
geom geometry NOT NULL
2527
);
2628
"""
27-
cursor.execute(query,)
29+
cursor.execute(query)
2830
self.conn.commit()
2931

30-
def create_block_tables(self):
32+
def create_blocks_tables(self):
3133
cursor = self.conn.cursor()
3234
query = """CREATE TABLE IF NOT EXISTS blocks(
3335
block_id serial primary key,
3436
states foreign key (state_name) references states(state_name),
3537
geom geometry NOT NULL
3638
);
3739
"""
38-
cursor.execute(query,)
40+
cursor.execute(query)
41+
self.conn.commit()
42+
43+
def create_puma_tables(self):
44+
cursor = self.conn.cursor()
45+
query = """CREATE TABLE IF NOT EXISTS pumas(
46+
puma serial primary key,
47+
states foreign key (state_name) references states(state_name),
48+
geom geometry NOT NULL
49+
);
50+
"""
51+
cursor.execute(query)
3952
self.conn.commit()
4053

4154
def create_lodes_tables(self):
@@ -44,15 +57,12 @@ def create_lodes_tables(self):
4457
state_name foreign key (state_name) references states(state_name),
4558
);
4659
"""
47-
cursor.execute(query,)
60+
cursor.execute(query)
4861
self.conn.commit()
4962

5063
def create_distance_tables(self):
5164
pass
5265

53-
def create_distance_tables(self):
54-
pass
55-
5666
def create_movs_tables(self):
5767
cursor = self.conn.cursor()
5868
query = """CREATE TABLE IF NOT EXISTS ledes(
@@ -63,40 +73,17 @@ def create_movs_tables(self):
6373
net_value FLOAT NOT NULL
6474
);
6575
"""
66-
cursor.execute(query,)
76+
cursor.execute(query)
6777
self.conn.commit()
6878

69-
def create_distance_tables(self):
70-
pass
71-
7279
def create_movs_tables(self):
7380
cursor = self.conn.cursor()
7481
query = """CREATE TABLE IF NOT EXISTS ledes(
7582
block_id serial primary key,
7683
state_name foreign key (state_name) references states(state_name),
7784
);
7885
"""
79-
cursor.execute(query,)
80-
self.conn.commit()
81-
82-
def create_sex_tables(self):
83-
pass
84-
85-
def create_race_tables(self):
86-
pass
87-
88-
89-
def create_distance_tables(self):
90-
pass
91-
92-
def create_movs_tables(self):
93-
cursor = self.conn.cursor()
94-
query = """CREATE TABLE IF NOT EXISTS ledes(
95-
block_id serial primary key,
96-
state_name foreign key (state_name) references states(state_name),
97-
);
98-
"""
99-
cursor.execute(query,)
86+
cursor.execute(query)
10087
self.conn.commit()
10188

10289
def create_sex_tables(self):
@@ -107,12 +94,12 @@ def create_race_tables(self):
10794

10895
def create_hypertable(self):
10996
cursor = self.conn.commit()
110-
query = """select create_hypertable(
111-
'ledes',
112-
interval '1 year'
113-
)
97+
query = """SELECT create_hypertable(
98+
'ledes',
99+
interval '1 year'
100+
);
114101
"""
115-
cursor.execute(query,)
102+
cursor.execute(query)
116103
self.conn.commit()
117104

118105
if __name__ == "__main__":

src/visualization/data_graph.py

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ def load_shape_data(self):
1515
return shp
1616

1717
def create_graph_dataset(self) -> gpd.GeoDataFrame:
18-
1918
df = self.data.rename({"state": "STUSPS"})
2019
df = df.with_columns(pl.col("STUSPS").str.to_uppercase())
2120
df = df.to_pandas()

0 commit comments

Comments
 (0)