Skip to content

Excel Extraction Tables Module

Tables module.

Functions to create sql table strings and return in loading/creation order.

activity_species_table()

Generate activity_species sql string.

Returns table based on activity_species ERD diagram

Returns:

Name Type Description
sql_str str

returns string of sql code

Source code in report_generator/excel_extraction/tables.py
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
def activity_species_table() -> str:
    """Generate activity_species sql string.

    Returns table based on activity_species ERD diagram

    Returns:
        sql_str: returns string of sql code
    """
    sql_str = """
    CREATE TABLE IF NOT EXISTS activity_species(
        activity_species_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
        species_id INTEGER NOT NULL,
        activity_id INTEGER NOT NULL,
        -- PRIMARY KEY (species_id, activity_id),
        FOREIGN KEY (species_id)
            REFERENCES species (species_id),
        FOREIGN KEY (activity_id)
            REFERENCES activity (activity_id)
    )

    """

    return sql_str

activity_table()

Generate activity sql string.

Returns table based on activity ERD diagram

Returns:

Name Type Description
sql_str str

returns string of sql code

Source code in report_generator/excel_extraction/tables.py
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
def activity_table() -> str:
    """Generate activity sql string.

    Returns table based on activity ERD diagram

    Returns:
        sql_str: returns string of sql code
    """
    sql_str = """
    CREATE TABLE IF NOT EXISTS activity(
        activity_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
        activity_kind TEXT
    )

    """

    return sql_str

admin_user_table()

Generate admin sql string.

Returns table based on species ERD diagram

Returns:

Name Type Description
sql_str str

returns string of sql code

Source code in report_generator/excel_extraction/tables.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
def admin_user_table() -> str:
    """Generate admin sql string.

    Returns table based on species ERD diagram

    Returns:
        sql_str: returns string of sql code
    """
    sql_str = """
    CREATE TABLE IF NOT EXISTS admin_user (
        admin_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
        admin_name TEXT NOT NULL,
        admin_password TEXT NOT NULL
    )
    """

    return sql_str

continent_table()

Generate continent sql string.

Returns table based on continent ERD diagram

Returns:

Name Type Description
sql_str str

returns string of sql code

Source code in report_generator/excel_extraction/tables.py
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
def continent_table() -> str:
    """Generate continent sql string.

    Returns table based on continent ERD diagram

    Returns:
        sql_str: returns string of sql code
    """
    sql_str = """
    CREATE TABLE IF NOT EXISTS continent(
        continent_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
        continent_name TEXT NOT NULL
    )

    """

    return sql_str

country_table()

Generate country sql string.

Returns table based on country ERD diagram

Returns:

Name Type Description
sql_str str

returns string of sql code

Source code in report_generator/excel_extraction/tables.py
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
def country_table() -> str:
    """Generate country sql string.

    Returns table based on country ERD diagram

    Returns:
        sql_str: returns string of sql code
    """
    sql_str = """
    CREATE TABLE IF NOT EXISTS country (
        country_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
        country_name TEXT,
        continent_id INTEGER,
        FOREIGN KEY (continent_id)
            REFERENCES continent (continent_id)
        UNIQUE(country_name, continent_id)
    )


    """

    return sql_str

family_table()

Generate family sql string.

Returns table based on family ERD diagram

Returns:

Name Type Description
sql_str str

returns string of sql code

Source code in report_generator/excel_extraction/tables.py
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
def family_table() -> str:
    """Generate family sql string.

    Returns table based on family ERD diagram

    Returns:
        sql_str: returns string of sql code
    """
    sql_str = """
    CREATE TABLE IF NOT EXISTS family(
        family_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
        family_name TEXT NOT NULL,
        order_id INTEGER NOT NULL,
        FOREIGN KEY (order_id)
            REFERENCES order_taxon (order_id)

    )

    """

    return sql_str

genus_table()

Generate genus sql string.

Returns table based on genus ERD diagram

Returns:

Name Type Description
sql_str str

returns string of sql code

Source code in report_generator/excel_extraction/tables.py
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
def genus_table() -> str:
    """Generate genus sql string.

    Returns table based on genus ERD diagram

    Returns:
        sql_str: returns string of sql code
    """
    sql_str = """
    CREATE TABLE IF NOT EXISTS genus(
        genus_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
        genus_name  TEXT NOT NULL,
        family_id INTEGER NOT NULL,
        FOREIGN KEY (family_id)
            REFERENCES family (family_id)
    )

    """

    return sql_str

geo_location_species_table()

Generate geo_location_species sql string.

Returns table based on geo_location_species ERD diagram

Returns:

Name Type Description
sql_str str

returns string of sql code

Source code in report_generator/excel_extraction/tables.py
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
def geo_location_species_table() -> str:
    """Generate geo_location_species sql string.

    Returns table based on geo_location_species ERD diagram

    Returns:
        sql_str: returns string of sql code
    """
    sql_str = """
    CREATE TABLE IF NOT EXISTS geo_location_species(
        geo_location_species_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
        geo_location_id INTEGER,
        species_id INTEGER,
        -- PRIMARY KEY (species_id, geo_location_id),
        FOREIGN KEY (species_id)
            REFERENCES species (species_id),
        FOREIGN KEY (geo_location_id)
            REFERENCES geo_location (geo_location_id)
    )

    """

    return sql_str

geo_location_table()

Generate geo_location sql string.

Returns table based on geo_location ERD diagram

Returns:

Name Type Description
sql_str str

returns string of sql code

Source code in report_generator/excel_extraction/tables.py
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
def geo_location_table() -> str:
    """Generate geo_location sql string.

    Returns table based on geo_location ERD diagram

    Returns:
        sql_str: returns string of sql code
    """
    sql_str = """
    CREATE TABLE IF NOT EXISTS geo_location(
        geo_location_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
        region_name TEXT,
        latitude REAL,
        longitude REAL,
        country_id INTEGER,
        FOREIGN KEY (country_id)
            REFERENCES country (country_id)
        UNIQUE(region_name, country_id)
    )

    """

    return sql_str

get_tables_sql()

Generate sql string.

Calls tables functions in order and joins them to create one large sql query string list

Returns:

Name Type Description
sql_create_tables_str list

list of strings to create all tables

Source code in report_generator/excel_extraction/tables.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
def get_tables_sql() -> list:
    """Generate sql string.

    Calls tables functions in order and joins them to create one large sql query string list

    Returns:
        sql_create_tables_str (list): list of strings to create all tables
    """
    tables_list = [
        order_table(),
        family_table(),
        genus_table(),
        pop_trend_table(),
        iucn_table(),
        parity_mode_table(),
        continent_table(),
        country_table(),
        geo_location_table(),
        micro_habitat_table(),
        activity_table(),
        nesting_site_table(),
        species_table(),
        nesting_site_species_table(),
        activity_species_table(),
        micro_habitat_species_table(),
        geo_location_species_table(),
        site_user_table(),
        admin_user_table(),
    ]

    return tables_list

iucn_table()

Generate iucn sql string.

Returns table based on iucn ERD diagram

Returns:

Name Type Description
sql_str str

returns string of sql code

Source code in report_generator/excel_extraction/tables.py
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
def iucn_table() -> str:
    """Generate iucn sql string.

    Returns table based on iucn ERD diagram

    Returns:
        sql_str: returns string of sql code
    """
    sql_str = """
    CREATE TABLE IF NOT EXISTS iucn (
        iucn_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
        iucn_status TEXT NOT NULL
    )

    """

    return sql_str

micro_habitat_species_table()

Generate micro_habitat_species sql string.

Returns table based on micro_habitat_species ERD diagram

Returns:

Name Type Description
sql_str str

returns string of sql code

Source code in report_generator/excel_extraction/tables.py
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
def micro_habitat_species_table() -> str:
    """Generate micro_habitat_species sql string.

    Returns table based on micro_habitat_species ERD diagram

    Returns:
        sql_str: returns string of sql code
    """
    sql_str = """
    CREATE TABLE IF NOT EXISTS micro_habitat_species(
        micro_habitat_species_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
        species_id INTEGER,
        micro_habitat_id INTEGER,
        micro_habitat_pref_rank INTEGER,
        -- PRIMARY KEY (species_id, micro_habitat_id),
        FOREIGN KEY (species_id)
            REFERENCES species (species_id),
        FOREIGN KEY (micro_habitat_id)
            REFERENCES micro_habitat (micro_habitat_id)
    )

    """

    return sql_str

micro_habitat_table()

Generate micro_habitat sql string.

Returns table based on micro_habitat ERD diagram

Returns:

Name Type Description
sql_str str

returns string of sql code

Source code in report_generator/excel_extraction/tables.py
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
def micro_habitat_table() -> str:
    """Generate micro_habitat sql string.

    Returns table based on micro_habitat ERD diagram

    Returns:
        sql_str: returns string of sql code
    """
    sql_str = """
    CREATE TABLE IF NOT EXISTS micro_habitat(
        micro_habitat_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
        micro_habitat_name TEXT
    )

    """

    return sql_str

nesting_site_species_table()

Generate nesting site species sql string.

Returns table based on nesting site species ERD diagram

Returns:

Name Type Description
sql_str str

returns string of sql code

Source code in report_generator/excel_extraction/tables.py
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
def nesting_site_species_table() -> str:
    """Generate nesting site species sql string.

    Returns table based on nesting site species ERD diagram

    Returns:
        sql_str: returns string of sql code
    """
    sql_str = """

    CREATE TABLE IF NOT EXISTS nesting_site_species (
        nesting_site_species_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
        species_id INTEGER NOT NULL,
        nesting_site_id INTEGER NOT NULL,
        -- PRIMARY KEY (species_id, nesting_site_id),
        FOREIGN KEY (species_id)
            REFERENCES species (species_id),
        FOREIGN KEY (nesting_site_id)
            REFERENCES nesting_site (nesting_site_id)
    )

    """

    return sql_str

nesting_site_table()

Generate nesting_site sql string.

Returns table based on nesting_site ERD diagram

Returns:

Name Type Description
sql_str str

returns string of sql code

Source code in report_generator/excel_extraction/tables.py
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
def nesting_site_table() -> str:
    """Generate nesting_site sql string.

    Returns table based on nesting_site ERD diagram

    Returns:
        sql_str: returns string of sql code
    """
    sql_str = """
    CREATE TABLE IF NOT EXISTS nesting_site(
        nesting_site_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
        nesting_site_desc TEXT
    )

    """

    return sql_str

order_table()

Generate order sql string.

Returns table based on order ERD diagram

Returns:

Name Type Description
sql_str str

returns string of sql code

Source code in report_generator/excel_extraction/tables.py
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
def order_table() -> str:
    """Generate order sql string.

    Returns table based on order ERD diagram

    Returns:
        sql_str: returns string of sql code
    """
    sql_str = """
    CREATE TABLE IF NOT EXISTS order_taxon(
        order_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
        order_taxon_name TEXT NOT NULL
    )

    """

    return sql_str

parity_mode_table()

Generate parity_mode sql string.

Returns table based on parity_mode ERD diagram

Returns:

Name Type Description
sql_str str

returns string of sql code

Source code in report_generator/excel_extraction/tables.py
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
def parity_mode_table() -> str:
    """Generate parity_mode sql string.

    Returns table based on parity_mode ERD diagram

    Returns:
        sql_str: returns string of sql code
    """
    sql_str = """
    CREATE TABLE IF NOT EXISTS parity_mode(
        parity_mode_id  INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
        parity_mode_desc TEXT NOT NULL
    )

    """

    return sql_str

pop_trend_table()

Generate pop_trend sql string.

Returns table based on pop_trend ERD diagram

Returns:

Name Type Description
sql_str str

returns string of sql code

Source code in report_generator/excel_extraction/tables.py
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
def pop_trend_table() -> str:
    """Generate pop_trend sql string.

    Returns table based on pop_trend ERD diagram

    Returns:
        sql_str: returns string of sql code
    """
    sql_str = """
    CREATE TABLE IF NOT EXISTS pop_trend(
        pop_trend_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
        pop_trend_status TEXT NOT NULL
    )

    """

    return sql_str

site_user_table()

Generate site_user sql string.

Returns table based on species ERD diagram

Returns:

Name Type Description
sql_str str

returns string of sql code

Source code in report_generator/excel_extraction/tables.py
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
def site_user_table() -> str:
    """Generate site_user sql string.

    Returns table based on species ERD diagram

    Returns:
        sql_str: returns string of sql code
    """
    sql_str = """
    CREATE TABLE IF NOT EXISTS site_user (
      "user_id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
      "first_name" varchar(200) NOT NULL,
      "last_name" varchar(200) NOT NULL,
      "educational_inst" varchar(200) NOT NULL,
      "user_name" varchar(200) NOT NULL,
      "email_address" varchar(254) NOT NULL,
      "password" varchar(200) NOT NULL
    )
    """
    return sql_str

species_table()

Generate species sql string.

Returns table based on species ERD diagram

Returns:

Name Type Description
sql_str str

returns string of sql code

Source code in report_generator/excel_extraction/tables.py
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
def species_table() -> str:
    """Generate species sql string.

    Returns table based on species ERD diagram

    Returns:
        sql_str: returns string of sql code
    """
    sql_str = """
    CREATE TABLE IF NOT EXISTS species(
        species_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
        species_name_common TEXT,
        species_name_latin TEXT,
        size_max_male REAL,
        size_max_female REAL,
        size_max_record REAL,
        longevity REAL,
        clutch_min INTEGER,
        clutch_max INTEGER,
        clutch_avg REAL,
        egg_diameter REAL,
        range_size REAL,
        elevation_min INTEGER,
        elevation_max REAL,
        elevation_avg REAL,
        img_uri_female TEXT,
        img_uri_male TEXT,
        verif_status BOOL,
        parity_mode_id INTEGER,
        pop_trend_id INTEGER,
        iucn_id INTEGER,
        genus_id INTEGER,
        FOREIGN KEY (parity_mode_id)
            REFERENCES parity_mode(parity_mode_id),
        FOREIGN KEY (pop_trend_id)
            REFERENCES pop_trend(pop_trend_id),
        FOREIGN KEY (iucn_id)
            REFERENCES iucn(iucn_id),
        FOREIGN KEY (genus_id)
            REFERENCES genus (genus_id)
    )
    """

    return sql_str