Skip to content

Commit

Permalink
Update schema
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhdu committed Oct 19, 2018
1 parent 02faf4a commit fa4c270
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 71 deletions.
41 changes: 2 additions & 39 deletions density/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,49 +196,12 @@ def insert_density_data(cursor, data):
.astimezone(pytz.timezone("US/Eastern"))
.replace(tzinfo=None)) # drop timezone info for Postgres

# TODO: do a schema migration to make this data normalization moot
parent_ids = {
101: 84, # Lerner
109: 79, # Lehman Library
115: 103, # Butler
117: 103, # Butler 301
124: 146, # Avery
153: 75, # John Jay
2: 2, # Uris,
97: 62, # East Asian Library
99: 15, # NoCo
}
ids = {
100: 145, # Science and Engineering Library
102: 150, # Lerner 1
103: 151, # Lerner 2
104: 152, # Lerner 3
105: 153, # Lerner 4
106: 154, # Lerner 5
107: 85, # Roone Arledge Auditorium
110: 139, # Lehman Library 2
111: 140, # Lehman Library 3
116: 130, # Butler Library 2
117: 131, # Butler Library 3
118: 171, # Butler Library 301
119: 132, # Butler Library 4
120: 133, # Butler Library 5
121: 134, # Butler Library 6
122: 138, # Butler Library stk
125: 147, # Architectural and Fine Arts Library 1
126: 148, # Architectural and Fine Arts Library 2
127: 149, # Architectural and Fine Arts Library 3
155: 125, # John Jay Dining Hall
192: 155, # JJ's Place
96: 23, # Uris/Watson Library
98: 144, # Starr East Asian Library
}

for key, value in data.items():
group = {
"id": ids[int(key)],
"id": int(key),
"name": value["name"],
"parent_id": parent_ids[int(value["parent_id"])]
"parent_id": int(value["parent_id"])
}
client_count = int(value["client_count"])
if groups[group["id"]] != group:
Expand Down
63 changes: 31 additions & 32 deletions scripts/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,44 +26,43 @@ CREATE TABLE density_data (
);

CREATE INDEX ON density_data (group_id, dump_time);
CREATE INDEX ON density_data (parent_id);
CREATE TABLE oauth_data (
uni TEXT NOT NULL,
code VARCHAR(64) NOT NULL,
CONSTRAINT oauth_unique_code UNIQUE(code)
);

INSERT INTO buildings (id, name) VALUES
(103, 'Butler'),
(146, 'Avery'),
(15, 'Northwest Corner Building'),
(2, 'Uris'),
(62, 'East Asian Library'),
(75, 'John Jay'),
(79, 'Lehman Library'),
(84, 'Lerner');
(117, 'Butler'),
(124, 'Avery'),
(99, 'Northwest Corner Building'),
(2, 'Uris'),
(97, 'East Asian Library'),
(153, 'John Jay'),
(109, 'Lehman Library'),
(101, 'Lerner');

INSERT INTO routers (id, name, building_id) VALUES
(152, 'Lerner 3', 84),
(150, 'Lerner 1', 84),
(155, 'JJ''s Place', 75),
(130, 'Butler Library 2', 103),
(148, 'Architectural and Fine Arts Library 2', 146),
(134, 'Butler Library 6', 103),
(144, 'Starr East Asian Library', 62),
(151, 'Lerner 2', 84),
(85, 'Roone Arledge Auditorium', 84),
(133, 'Butler Library 5', 103),
(140, 'Lehman Library 3', 79),
(171, 'Butler Library 301', 103),
(153, 'Lerner 4', 84),
(145, 'Science and Engineering Library', 15),
(149, 'Architectural and Fine Arts Library 3', 146),
(139, 'Lehman Library 2', 79),
(154, 'Lerner 5', 84),
(131, 'Butler Library 3', 103),
(125, 'John Jay Dining Hall', 75),
(138, 'Butler Library stk', 103),
(132, 'Butler Library 4', 103),
(23, 'Uris/Watson Library', 2),
(147, 'Architectural and Fine Arts Library 1', 146);
(104, 'Lerner 3', 101),
(102, 'Lerner 1', 101),
(192, 'JJ''s Place', 153),
(116, 'Butler Library 2', 117),
(126, 'Architectural and Fine Arts Library 2', 124),
(121, 'Butler Library 6', 117),
(98, 'Starr East Asian Library', 97),
(103, 'Lerner 2', 101),
(107, 'Roone Arledge Auditorium', 101),
(120, 'Butler Library 5', 117),
(111, 'Lehman Library 3', 109),
(118, 'Butler Library 301', 117),
(105, 'Lerner 4', 101),
(100, 'Science and Engineering Library', 99),
(127, 'Architectural and Fine Arts Library 3', 124),
(110, 'Lehman Library 2', 109),
(106, 'Lerner 5', 101),
(117, 'Butler Library 3', 117),
(155, 'John Jay Dining Hall', 153),
(122, 'Butler Library stk', 117),
(119, 'Butler Library 4', 117),
(96, 'Uris/Watson Library', 2),
(125, 'Architectural and Fine Arts Library 1', 124);

0 comments on commit fa4c270

Please sign in to comment.