def split_tyc(): db = SkyMapDatabase() db.commit_query(""" ALTER TABLE hiptyc_tyc_main ADD COLUMN `TYC1` INT AFTER `TYC`, ADD COLUMN `TYC2` INT AFTER `TYC1`, ADD COLUMN `TYC3` INT AFTER `TYC2` """) db.commit_query(""" UPDATE hiptyc_tyc_main SET TYC1=CAST(substr(TYC, 1, 4) AS UNSIGNED), TYC2=CAST(substr(hiptyc_tyc_main.TYC, 5, 6) AS UNSIGNED), TYC3=CAST(substr(hiptyc_tyc_main.TYC, 11, 2) AS UNSIGNED) """) db.add_index("hiptyc_tyc_main", "TYC1") db.add_index("hiptyc_tyc_main", "TYC2") db.add_index("hiptyc_tyc_main", "TYC3") db.add_multiple_column_index("hiptyc_tyc_main", ("TYC1", "TYC2", "TYC3"), "TYC", unique=True)
def build_milkyway_database(): print("") print("Building milky way boundary database") db = SkyMapDatabase() # Drop table db.drop_table("milkyway") # Create table db.commit_query("""CREATE TABLE milkyway ( id INT PRIMARY KEY , curve_id INT, ra REAL, dec REAL )""") # Fill table point_id = 0 curve_id = 0 curve_id, point_id = parse_file(os.path.join(DATA_FOLDER, "milkyway.txt"), db, curve_id, point_id) curve_id, point_id = parse_file(os.path.join(DATA_FOLDER, "magellanic_clouds.txt"), db, curve_id, point_id) db.close()
def split_tyc(): db = SkyMapDatabase() db.commit_query(""" ALTER TABLE hiptyc_tyc_main ADD COLUMN `TYC1` INT AFTER `TYC`, ADD COLUMN `TYC2` INT AFTER `TYC1`, ADD COLUMN `TYC3` INT AFTER `TYC2` """) db.commit_query("""DROP FUNCTION IF EXISTS SPLIT_TYC""") db.commit_query(""" CREATE FUNCTION SPLIT_TYC(str VARCHAR(255), pos INT) RETURNS INT BEGIN SET str = TRIM(str); WHILE INSTR(str, ' ') > 0 DO SET str = REPLACE(str, ' ', ' '); END WHILE; SET str = REPLACE( SUBSTRING( SUBSTRING_INDEX(str, ' ', pos), CHAR_LENGTH( SUBSTRING_INDEX(str, ' ', pos - 1) ) + 1 ) , ' ', '' ); RETURN CAST(str AS UNSIGNED); END; """) db.commit_query(""" UPDATE hiptyc_tyc_main SET TYC1=SPLIT_TYC(TYC, 1), TYC2=SPLIT_TYC(TYC, 2), TYC3=SPLIT_TYC(TYC, 3) """) db.add_index("hiptyc_tyc_main", "TYC1") db.add_index("hiptyc_tyc_main", "TYC2") db.add_index("hiptyc_tyc_main", "TYC3") db.add_multiple_column_index("hiptyc_tyc_main", ("TYC1", "TYC2", "TYC3"), "TYC", unique=True)
def build_label_database(): db = SkyMapDatabase() db.drop_table("skymap_labels") # Create table db.commit_query("""CREATE TABLE skymap_labels ( label_id INT PRIMARY KEY, label_text TEXT, fontsize TEXT, width REAL, height REAL)""") stars = [ Star(r) for r in db.query( """SELECT * FROM skymap_stars WHERE proper_name is not null""") ] p = Point(0, 0) i = 0 nstars = len(stars) for n, s in enumerate(stars): sys.stdout.write("\r{}%".format(int(round(100 * n / float(nstars))))) sys.stdout.flush() if not s.proper_name.strip() and not s.identifier_string.strip(): continue if s.proper_name: i += 1 if db.query_one( """SELECT * FROM skymap_labels WHERE label_text="{}" AND fontsize="{}" """ .format(s.proper_name, "tiny")) is None: l = Label(p, s.proper_name, fontsize="tiny", render_size=True) size = l.size db.commit_query( """INSERT INTO skymap_labels VALUES ({}, "{}", "{}", {}, {})""" .format(i, s.proper_name, "tiny", size[0], size[1])) if s.identifier_string: i += 1 if db.query_one( """SELECT * FROM skymap_labels WHERE label_text="{}" AND fontsize="{}" """ .format(s.identifier_string, "tiny")) is None: l = Label(p, s.identifier_string.strip(), fontsize="tiny", render_size=True) size = l.size db.commit_query( """INSERT INTO skymap_labels VALUES ({}, "{}", "{}", {}, {})""" .format(i, s.identifier_string, "tiny", size[0], size[1])) db.close()