suratan.boon commited on
Commit
e773157
·
1 Parent(s): df827c0

add sqlite_db.script

Browse files
src/DB/Deliverable.csv ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ deliverable_id,project_id,title,status,risk_level,risk_level_rationale,start_date,end_date
2
+ 74897126-8d89-478d-80dc-5dd294a53cc4,5253cfae-8b21-45be-840a-0b238920bc0a,Area Assessment,done,green,No environmental threats detected.,2023-01-05,2023-03-01
3
+ 6d1f9224-b352-4a8f-956c-c3309dbdd739,5253cfae-8b21-45be-840a-0b238920bc0a,Planting Phase,ongoing,yellow,Tide schedule interference.,2023-03-15,2023-08-30
4
+ 8c51359f-f6e8-45d6-b7df-88aca3cc51bf,0f75e25f-e45a-4e94-80df-76cf130314cd,Community Engagement,done,green,High public interest and participation.,2023-02-05,2023-04-01
5
+ 27eb7392-18b4-4042-ace0-7fd17ad44f8b,0f75e25f-e45a-4e94-80df-76cf130314cd,Planting Execution,ongoing,red,Insufficient volunteer workforce.,2023-04-10,2023-10-15
6
+ 835dba37-14c5-4279-9650-fc84b260d8e7,b85a170b-368e-4176-aae7-ab223f0d31c5,Equipment Procurement,done,green,Procurement completed on time.,2023-03-05,2023-04-01
7
+ cc513b54-1d4a-42f3-b5ff-25513147cadf,b85a170b-368e-4176-aae7-ab223f0d31c5,Volunteer Training,ongoing,yellow,Training attendance dropped by 10%.,2023-04-10,2023-06-30
src/DB/Deliverable_Budget.csv ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ id,deliverable_id,wage,materials,tools_equipment,services,misc
2
+ 3b4474d8-4801-4b91-8dc2-98f7063c6fd6,74897126-8d89-478d-80dc-5dd294a53cc4,1000.0,1500.0,500.0,800.0,100.0
3
+ 37a43567-8e09-4842-8c74-1ab3a054b346,6d1f9224-b352-4a8f-956c-c3309dbdd739,1200.0,2000.0,700.0,1000.0,150.0
4
+ e2279ac6-ae29-4d28-b91a-a2565694aa77,8c51359f-f6e8-45d6-b7df-88aca3cc51bf,1500.0,1000.0,300.0,500.0,50.0
src/DB/Expense.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ expense_id,associated_deliverable_id,seller_name,seller_address,seller_phone_number,buyer_name,buyer_address,transaction_date,total_payment_amount,expense_description,status
2
+ b834564f-8721-4478-8fe6-3fee80537c9d,74897126-8d89-478d-80dc-5dd294a53cc4,EcoTools Ltd.,101 Earth Ave,0811111111,Mangrove Org,900 Forest Blvd,2023-01-20,1800.0,Survey equipment rental,approved
src/DB/Project.csv ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ project_id,title,status,detail_information,start_date,end_date
2
+ 5253cfae-8b21-45be-840a-0b238920bc0a,Mangrove Restoration,started,Restoring coastal ecosystems using mangrove plantations.,2023-01-01,2023-12-31
3
+ 0f75e25f-e45a-4e94-80df-76cf130314cd,Urban Tree Planting,started,Planting trees across the city for shade and air quality.,2023-02-01,2023-11-30
4
+ b85a170b-368e-4176-aae7-ab223f0d31c5,River Clean-up Campaign,started,Mobilizing volunteers to clean plastic from major rivers.,2023-03-01,2023-09-30
src/DB/create_sqlite_db.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sqlite3
2
+
3
+ conn = sqlite3.connect('hello_earth_data.db')
4
+ cursor = conn.cursor()
5
+
6
+ cursor.execute('''
7
+ CREATE TABLE IF NOT EXISTS Project (
8
+ project_id TEXT PRIMARY KEY,
9
+ title TEXT,
10
+ status TEXT,
11
+ detail_information TEXT,
12
+ start_date DATETIME,
13
+ end_date DATETIME
14
+ )
15
+ ''')
16
+
17
+ cursor.execute('''
18
+ CREATE TABLE IF NOT EXISTS Deliverable (
19
+ deliverable_id TEXT PRIMARY KEY,
20
+ project_id TEXT,
21
+ title TEXT,
22
+ status TEXT CHECK(status IN ('done', 'ongoing')),
23
+ risk_level TEXT CHECK(risk_level IN ('green', 'yellow', 'red')),
24
+ risk_level_rationale TEXT,
25
+ start_date DATETIME,
26
+ end_date DATETIME,
27
+ FOREIGN KEY (project_id) REFERENCES Project(project_id)
28
+ )
29
+ ''')
30
+
31
+ cursor.execute('''
32
+ CREATE TABLE IF NOT EXISTS Expense (
33
+ expense_id TEXT PRIMARY KEY,
34
+ associated_deliverable_id TEXT,
35
+ seller_name TEXT,
36
+ seller_address TEXT,
37
+ seller_phone_number TEXT,
38
+ buyer_name TEXT,
39
+ buyer_address TEXT,
40
+ transaction_date DATETIME,
41
+ total_payment_amount REAL,
42
+ expense_description TEXT,
43
+ status TEXT,
44
+ FOREIGN KEY (associated_deliverable_id) REFERENCES Deliverable(deliverable_id)
45
+ )
46
+ ''')
47
+
48
+ cursor.execute('''
49
+ CREATE TABLE IF NOT EXISTS Deliverable_Budget (
50
+ id TEXT PRIMARY KEY,
51
+ deliverable_id TEXT,
52
+ wage REAL,
53
+ materials REAL,
54
+ tools_equipment REAL,
55
+ services REAL,
56
+ misc REAL,
57
+ FOREIGN KEY (deliverable_id) REFERENCES Deliverable(deliverable_id)
58
+ )
59
+ ''')
60
+
61
+ conn.commit()
62
+ conn.close()
63
+
64
+ print("SQLite database created with the specified schema.")
src/DB/export_data.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sqlite3
2
+ import pandas as pd
3
+
4
+ def export_all_tables_to_csv(db_path='hello_earth_data.db', output_dir='.'):
5
+ conn = sqlite3.connect(db_path)
6
+ cursor = conn.cursor()
7
+
8
+ # Get list of all tables
9
+ cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
10
+ tables = [row[0] for row in cursor.fetchall()]
11
+
12
+ # Export each table
13
+ for table in tables:
14
+ df = pd.read_sql_query(f"SELECT * FROM {table}", conn)
15
+ output_path = f"{output_dir}/{table}.csv"
16
+ df.to_csv(output_path, index=False)
17
+ print(f"✅ Exported {table} to {output_path}")
18
+
19
+ conn.close()
20
+
21
+ if __name__ == '__main__':
22
+ export_all_tables_to_csv()
src/DB/hello_earth_data.db ADDED
Binary file (36.9 kB). View file
 
src/DB/mockup_data.py ADDED
@@ -0,0 +1,213 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sqlite3
2
+ import uuid
3
+
4
+ def generate_uuid():
5
+ return str(uuid.uuid4())
6
+
7
+ def insert_mock_data():
8
+ conn = sqlite3.connect('hello_earth_data.db')
9
+ cursor = conn.cursor()
10
+
11
+ mock_data = []
12
+
13
+ # Project 1
14
+ project_1_id = generate_uuid()
15
+ deliverable_1_1_id = generate_uuid()
16
+ deliverable_1_2_id = generate_uuid()
17
+ mock_data.append({
18
+ "project": {
19
+ "project_id": project_1_id,
20
+ "title": "Mangrove Restoration",
21
+ "status": "started",
22
+ "detail_information": "Restoring coastal ecosystems using mangrove plantations.",
23
+ "start_date": "2023-01-01",
24
+ "end_date": "2023-12-31"
25
+ },
26
+ "deliverables": [
27
+ {
28
+ "deliverable_id": deliverable_1_1_id,
29
+ "title": "Area Assessment",
30
+ "status": "done",
31
+ "risk_level": "green",
32
+ "risk_level_rationale": "No environmental threats detected.",
33
+ "start_date": "2023-01-05",
34
+ "end_date": "2023-03-01"
35
+ },
36
+ {
37
+ "deliverable_id": deliverable_1_2_id,
38
+ "title": "Planting Phase",
39
+ "status": "ongoing",
40
+ "risk_level": "yellow",
41
+ "risk_level_rationale": "Tide schedule interference.",
42
+ "start_date": "2023-03-15",
43
+ "end_date": "2023-08-30"
44
+ }
45
+ ],
46
+ "budgets": [
47
+ {
48
+ "id": generate_uuid(),
49
+ "deliverable_id": deliverable_1_1_id,
50
+ "wage": 1000.0,
51
+ "materials": 1500.0,
52
+ "tools_equipment": 500.0,
53
+ "services": 800.0,
54
+ "misc": 100.0
55
+ },
56
+ {
57
+ "id": generate_uuid(),
58
+ "deliverable_id": deliverable_1_2_id,
59
+ "wage": 1200.0,
60
+ "materials": 2000.0,
61
+ "tools_equipment": 700.0,
62
+ "services": 1000.0,
63
+ "misc": 150.0
64
+ }
65
+ ],
66
+ "expenses": [
67
+ {
68
+ "expense_id": generate_uuid(),
69
+ "associated_deliverable_id": deliverable_1_1_id,
70
+ "seller_name": "EcoTools Ltd.",
71
+ "seller_address": "101 Earth Ave",
72
+ "seller_phone_number": "0811111111",
73
+ "buyer_name": "Mangrove Org",
74
+ "buyer_address": "900 Forest Blvd",
75
+ "transaction_date": "2023-01-20",
76
+ "total_payment_amount": 1800.0,
77
+ "expense_description": "Survey equipment rental",
78
+ "status": "approved"
79
+ }
80
+ ]
81
+ })
82
+
83
+ # Project 2
84
+ project_2_id = generate_uuid()
85
+ deliverable_2_1_id = generate_uuid()
86
+ deliverable_2_2_id = generate_uuid()
87
+ mock_data.append({
88
+ "project": {
89
+ "project_id": project_2_id,
90
+ "title": "Urban Tree Planting",
91
+ "status": "started",
92
+ "detail_information": "Planting trees across the city for shade and air quality.",
93
+ "start_date": "2023-02-01",
94
+ "end_date": "2023-11-30"
95
+ },
96
+ "deliverables": [
97
+ {
98
+ "deliverable_id": deliverable_2_1_id,
99
+ "title": "Community Engagement",
100
+ "status": "done",
101
+ "risk_level": "green",
102
+ "risk_level_rationale": "High public interest and participation.",
103
+ "start_date": "2023-02-05",
104
+ "end_date": "2023-04-01"
105
+ },
106
+ {
107
+ "deliverable_id": deliverable_2_2_id,
108
+ "title": "Planting Execution",
109
+ "status": "ongoing",
110
+ "risk_level": "red",
111
+ "risk_level_rationale": "Insufficient volunteer workforce.",
112
+ "start_date": "2023-04-10",
113
+ "end_date": "2023-10-15"
114
+ }
115
+ ],
116
+ "budgets": [
117
+ {
118
+ "id": generate_uuid(),
119
+ "deliverable_id": deliverable_2_1_id,
120
+ "wage": 1500.0,
121
+ "materials": 1000.0,
122
+ "tools_equipment": 300.0,
123
+ "services": 500.0,
124
+ "misc": 50.0
125
+ }
126
+ ],
127
+ "expenses": []
128
+ })
129
+
130
+ # Project 3
131
+ project_3_id = generate_uuid()
132
+ deliverable_3_1_id = generate_uuid()
133
+ deliverable_3_2_id = generate_uuid()
134
+ mock_data.append({
135
+ "project": {
136
+ "project_id": project_3_id,
137
+ "title": "River Clean-up Campaign",
138
+ "status": "started",
139
+ "detail_information": "Mobilizing volunteers to clean plastic from major rivers.",
140
+ "start_date": "2023-03-01",
141
+ "end_date": "2023-09-30"
142
+ },
143
+ "deliverables": [
144
+ {
145
+ "deliverable_id": deliverable_3_1_id,
146
+ "title": "Equipment Procurement",
147
+ "status": "done",
148
+ "risk_level": "green",
149
+ "risk_level_rationale": "Procurement completed on time.",
150
+ "start_date": "2023-03-05",
151
+ "end_date": "2023-04-01"
152
+ },
153
+ {
154
+ "deliverable_id": deliverable_3_2_id,
155
+ "title": "Volunteer Training",
156
+ "status": "ongoing",
157
+ "risk_level": "yellow",
158
+ "risk_level_rationale": "Training attendance dropped by 10%.",
159
+ "start_date": "2023-04-10",
160
+ "end_date": "2023-06-30"
161
+ }
162
+ ],
163
+ "budgets": [],
164
+ "expenses": []
165
+ })
166
+
167
+ # === INSERT DATA INTO DB ===
168
+ for item in mock_data:
169
+ project = item["project"]
170
+ cursor.execute('''
171
+ INSERT INTO Project (project_id, title, status, detail_information, start_date, end_date)
172
+ VALUES (?, ?, ?, ?, ?, ?)
173
+ ''', (
174
+ project["project_id"], project["title"], project["status"],
175
+ project["detail_information"], project["start_date"], project["end_date"]
176
+ ))
177
+
178
+ for d in item.get("deliverables", []):
179
+ cursor.execute('''
180
+ INSERT INTO Deliverable (deliverable_id, project_id, title, status, risk_level,
181
+ risk_level_rationale, start_date, end_date)
182
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)
183
+ ''', (
184
+ d["deliverable_id"], project["project_id"], d["title"], d["status"],
185
+ d["risk_level"], d["risk_level_rationale"], d["start_date"], d["end_date"]
186
+ ))
187
+
188
+ for b in item.get("budgets", []):
189
+ cursor.execute('''
190
+ INSERT INTO Deliverable_Budget (id, deliverable_id, wage, materials, tools_equipment, services, misc)
191
+ VALUES (?, ?, ?, ?, ?, ?, ?)
192
+ ''', (
193
+ b["id"], b["deliverable_id"], b["wage"], b["materials"],
194
+ b["tools_equipment"], b["services"], b["misc"]
195
+ ))
196
+
197
+ for e in item.get("expenses", []):
198
+ cursor.execute('''
199
+ INSERT INTO Expense (expense_id, associated_deliverable_id, seller_name, seller_address, seller_phone_number,
200
+ buyer_name, buyer_address, transaction_date, total_payment_amount, expense_description, status)
201
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
202
+ ''', (
203
+ e["expense_id"], e["associated_deliverable_id"], e["seller_name"], e["seller_address"],
204
+ e["seller_phone_number"], e["buyer_name"], e["buyer_address"],
205
+ e["transaction_date"], e["total_payment_amount"], e["expense_description"], e["status"]
206
+ ))
207
+
208
+ conn.commit()
209
+ conn.close()
210
+ print("✅ Multiple projects inserted with UUIDs.")
211
+
212
+ if __name__ == '__main__':
213
+ insert_mock_data()