-
Notifications
You must be signed in to change notification settings - Fork 2
/
Importer.py
44 lines (37 loc) · 2.01 KB
/
Importer.py
1
2
3
4
5
6
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
38
39
40
41
42
43
44
from Config import logger
from DataSource.MySQLDataSource import MySQL
from Parser.HypatiaExoParser import HypatiaExoParser
import Config
def run(input_file, c, meta):
p = HypatiaExoParser(input_file, meta['normalization'])
if c:
for star, elements, planets in p.next():
try:
star.upsert(c)
logger.info('Saved star, "%s"\n', star.columns['hip'])
for catalogue, composition in elements:
# Assumption 251024: Because of the way the records are updated, if a catalogue is updated say
# from 'FeH 0.3 [Adamow et al. (2015)]' to 'FeH 0.3 [Adamow et al. (2016)]' a new catalogue is
# added and the particular composition for that catalogue will still be present with
# old catalogue in the composition table. For the above example the table composition will have
# 2 entries, one with 2015 catalogue and one with 2016
# Fix: Delete the star completely and add it again. Deleting a star, also deletes the corresponding
# composition elements, but catalogues are retained as other stars may still use it!
cid = catalogue.upsert(c)
composition.set('hip', star.columns['hip'])
composition.set('cid', cid)
composition.upsert(c)
for planet in planets:
planet.set('hip', star.columns['hip'])
planet.upsert(c)
except:
logger.exception('Saving star failed: "%s"', star.columns['hip'])
c.close()
def main():
Config.setup_logging()
c = MySQL.get_connection('astronomy_test')
# run('./Assets/test_inp.txt', c, {"normalization": "Lodders et al. (2009)"})
run('./Assets/exo_test_inp.txt', c, {"normalization": "Lodders et al. (2009)"})
# run('./Assets/hypatia_norm_16_01_10.txt', c, {"normalization": "Lodders et al. (2009)"})
if __name__ == '__main__':
main()