Exemplo n.º 1
0
def get_ug_bl_dsos():
    global _ug_bl_dsos
    if not _ug_bl_dsos:
        ug_bl_dsos = {}

        for c in Constellation.get_all():
            ug_bl_dsos[c.id] = {}

        files = [f for f in sorted(glob.glob('app/static/webassets-external/users/glahn/img/dso/*.jpg'))] + \
            [f for f in sorted(glob.glob('app/static/webassets-external/users/laville/img/dso/*.jpg'))]

        for f in files:
            base_name = os.path.basename(f)
            if base_name.endswith('.jpg'):
                dso_name = base_name[:-len('.jpg')]
                normalized_name = normalize_dso_name(
                    denormalize_dso_name(dso_name))
                dso = DeepskyObject.query.filter_by(
                    name=normalized_name).first()
                if dso:
                    db.session.expunge(dso)
                    ug_bl_dsos[dso.constellation_id][dso.id] = dso

        _ug_bl_dsos = ug_bl_dsos
    return _ug_bl_dsos
Exemplo n.º 2
0
def deepskyobject_search():
    query = request.args.get('q', None)
    if query is None:
        abort(404)
    if query and query.isdigit():
        query = 'NGC' + query
    normalized_name = normalize_dso_name(denormalize_dso_name(query))
    dso = DeepskyObject.query.filter_by(name=normalized_name).first()
    if not dso:
        abort(404)
    return redirect(
        url_for('main_deepskyobject.deepskyobject_info', dso_id=dso.name))
Exemplo n.º 3
0
def _load_dso_apert_descriptions(owner, editor_user, repository_path,
                                 lang_code_dir, user_cache):
    dso_dir = os.path.join(repository_path, lang_code_dir, 'dso')
    for dso_file in Path(dso_dir).rglob('*.md'):
        dso_name_md = dso_file.name
        m = re.match(r'(.*?)_(\d+u\d+).md$', dso_name_md)
        if not m:
            continue
        # current_app.logger.info('Reading DSO apert description {}'.format(dso_name_md))
        with dso_file.open('r') as f:
            dso_name = denormalize_dso_name(m.group(1)).replace(' ', '')
            aperture_class = m.group(2).replace('u', '/')
            header_map = _read_header(f)
            doc_aperture = header_map.get('aperture', '')
            rating = header_map.get('rating', '5')
            created_by = _get_user_from_username(
                user_cache, header_map.get('created_by', ''), owner)
            created_date = _get_get_date_from_str(
                header_map.get('created_date', ''))
            updated_by = _get_user_from_username(
                user_cache, header_map.get('updated_by', ''), owner)
            updated_date = _get_get_date_from_str(
                header_map.get('updated_date', ''))
            created_by = created_by or editor_user
            updated_by = updated_by or owner
            text = f.read()
            uad = UserDsoApertureDescription.query.filter_by(user_id=editor_user.id)\
                                                  .filter_by(lang_code=lang_code_dir) \
                                                  .filter_by(aperture_class=aperture_class) \
                                                  .join(UserDsoApertureDescription.deepskyObject, aliased=True) \
                                                  .filter_by(name=dso_name) \
                                                  .first()
            child_uad = None
            if uad and uad.deepskyObject.master_id:
                master_dso = DeepskyObject.query.filter_by(
                    id=uad.deepskyObject.master_id).first()
                master_uad = UserDsoApertureDescription.query.filter_by(user_id=editor_user.id)\
                        .filter_by(lang_code=lang_code_dir) \
                        .filter_by(aperture_class=aperture_class) \
                        .join(UserDsoApertureDescription.deepskyObject, aliased=True) \
                        .filter_by(name=master_dso.name) \
                        .first()
                if not master_uad:
                    master_uad = UserDsoApertureDescription(
                        dso_id=master_dso.id,
                        user_id=editor_user.id,
                        lang_code=lang_code_dir,
                        aperture_class=aperture_class,
                        create_by=created_by.id,
                        create_date=created_date,
                    )
                    child_uad = uad
                    uad = master_uad
                    current_app.logger.info(
                        'Assigning aperture description from child dso to master dso. master_dso={} child_dso={}'
                        .format(master_dso.name, dso_name))
                else:
                    current_app.logger.warn(
                        'Skipping child->master aperture description assignment. Master aperture description exists. master_dso={} child_dso={}'
                        .format(master_dso.name, dso_name))

            if not uad:
                dso = DeepskyObject.query.filter_by(name=dso_name).first()
                if not dso:
                    current_app.logger.warn(
                        'dso={} not found!'.format(dso_name))
                    continue
                if dso.master_id:
                    master_dso = DeepskyObject.query.filter_by(
                        id=dso.master_id).first()
                    master_uad = UserDsoApertureDescription.query.filter_by(user_id=editor_user.id)\
                            .filter_by(lang_code=lang_code_dir) \
                            .filter_by(aperture_class=aperture_class) \
                            .join(UserDsoApertureDescription.deepskyObject, aliased=True) \
                            .filter_by(name=master_dso.name) \
                            .first()
                    if not master_uad:
                        current_app.logger.info(
                            'Assigning aperture description from child dso to master dso. master_dso={} child_dso={}'
                            .format(master_dso.name, dso_name))
                        dso = master_dso
                    else:
                        current_app.logger.warn(
                            'Skipping child->master aperture description assignment. Master aperture description exists. master_dso={} child_dso={}'
                            .format(master_dso.name, dso_name))

                uad = UserDsoApertureDescription(
                    dso_id=dso.id,
                    user_id=editor_user.id,
                    lang_code=lang_code_dir,
                    aperture_class=aperture_class,
                    create_by=created_by.id,
                    create_date=created_date,
                )
            try:
                uad.rating = int(rating)
            except ValueError:
                uad.rating = None
            uad.text = text
            uad.update_by = updated_by.id
            uad.update_date = updated_date
            db.session.add(uad)
            if child_uad:
                db.session.remove(child_uad)
Exemplo n.º 4
0
def _load_dso_descriptions(owner, editor_user, repository_path, lang_code_dir,
                           user_cache):
    dso_dir = os.path.join(repository_path, lang_code_dir, 'dso')
    for dso_file in Path(dso_dir).rglob('*.md'):
        dso_name_md = dso_file.name
        if re.match(r'.*?_(\d+u\d+).md$', dso_name_md):
            continue
        # current_app.logger.info('Reading DSO description {}'.format(dso_name_md))
        with dso_file.open('r') as f:
            dso_name = denormalize_dso_name(dso_name_md[:-3]).replace(' ', '')
            header_map = _read_header(f)
            rating = header_map.get('rating', '5')
            references = header_map.get('references', '')
            created_by = _get_user_from_username(
                user_cache, header_map.get('created_by', ''), owner)
            created_date = _get_get_date_from_str(
                header_map.get('created_date', ''))
            updated_by = _get_user_from_username(
                user_cache, header_map.get('updated_by', ''), owner)
            updated_date = _get_get_date_from_str(
                header_map.get('updated_date', ''))
            created_by = created_by or editor_user
            updated_by = updated_by or owner
            text = f.read()
            udd = UserDsoDescription.query.filter_by(user_id=editor_user.id)\
                                          .filter_by(lang_code=lang_code_dir) \
                                          .join(UserDsoDescription.deepskyObject, aliased=True) \
                                          .filter_by(name=dso_name) \
                                          .first()
            child_udd = None
            if udd and udd.deepskyObject.master_id:
                master_dso = DeepskyObject.query.filter_by(
                    id=udd.deepskyObject.master_id).first()
                master_udd = UserDsoDescription.query.filter_by(user_id=editor_user.id)\
                                               .filter_by(lang_code=lang_code_dir) \
                                               .join(UserDsoDescription.deepskyObject, aliased=True) \
                                               .filter_by(name=master_dso.name) \
                                               .first()
                if not master_udd:
                    master_udd = UserDsoDescription(
                        dso_id=master_dso.id,
                        user_id=editor_user.id,
                        lang_code=lang_code_dir,
                        cons_order=1,
                        create_by=created_by.id,
                        create_date=created_date,
                    )

                    child_udd = udd
                    udd = master_udd
                    current_app.logger.info(
                        'Assigning description from child dso to master dso. master_dso={} child_dso={}'
                        .format(master_dso.name, dso_name))
                else:
                    current_app.logger.warn(
                        'Skipping child->master dso description assignment. Master dso description exists. master_dso={} child_dso={}'
                        .format(master_dso.name, dso_name))

            if not udd:
                dso = DeepskyObject.query.filter_by(name=dso_name).first()
                if not dso:
                    current_app.logger.warn(
                        'dso={} not found!'.format(dso_name))
                    continue
                if dso.master_id:
                    master_dso = DeepskyObject.query.filter_by(
                        id=dso.master_id).first()
                    master_udd = UserDsoDescription.query.filter_by(user_id=editor_user.id)\
                            .filter_by(lang_code=lang_code_dir) \
                            .join(UserDsoDescription.deepskyObject, aliased=True) \
                            .filter_by(name=master_dso.name) \
                            .first()
                    if not master_udd:
                        current_app.logger.info(
                            'Assigning description from child dso to master dso. master_dso={} child_dso={}'
                            .format(master_dso.name, dso_name))
                        dso = master_dso
                    else:
                        current_app.logger.warn(
                            'Skipping child->master dso description assignment. Master dso description exists. master_dso={} child_dso={}'
                            .format(master_dso.name, dso_name))

                udd = UserDsoDescription(
                    dso_id=dso.id,
                    user_id=editor_user.id,
                    lang_code=lang_code_dir,
                    cons_order=1,
                    create_by=created_by.id,
                    create_date=created_date,
                )
            udd.common_name = header_map.get('name', '')
            try:
                udd.rating = int(rating)
            except ValueError:
                udd.rating = None
            udd.text = text
            udd.references = references
            udd.update_by = updated_by.id
            udd.update_date = updated_date
            db.session.add(udd)
            if child_udd:
                db.session.remove(child_udd)
Exemplo n.º 5
0
def fix_cstar_from_open_ngc(open_ngc_data_file):
    """
    Get missing cstar data from openngc
    """

    constell_dict = {}
    for co in Constellation.query.all():
        constell_dict[co.iau_code.upper()] = co.id

    existing_dsos = {}
    for dso in DeepskyObject.query.filter_by().all():
        existing_dsos[dso.name] = dso

    row_count = sum(1 for line in open(open_ngc_data_file)) - 1

    with open(open_ngc_data_file) as csvfile:
        reader = csv.DictReader(csvfile, delimiter=';')
        try:
            row_id = 0
            for row in reader:
                progress(row_id, row_count, 'Fixing CStar from OpenNGC')
                row_id += 1
                dso_name = denormalize_dso_name(row['Name']).replace(' ', '')

                dso = existing_dsos.get(dso_name, None)

                if dso is None:
                    continue

                dso.c_star_b_mag = float(
                    row['Cstar B-Mag']) if row['Cstar B-Mag'] else None
                dso.c_star_v_mag = float(
                    row['Cstar V-Mag']) if row['Cstar V-Mag'] else None
                dso.common_name = row['Common names']
                dso.descr = row['NED notes']

                db.session.add(dso)

                if row['M'] or dso.name == 'NGC5866':
                    mes_id = row['M']

                    if not mes_id:
                        mes_id = '102'

                    mes_dso = existing_dsos.get('M' + mes_id.lstrip('0'), None)
                    if mes_dso is None:
                        continue

                    mes_dso.constellation_id = dso.constellation_id
                    mes_dso.c_star_b_mag = dso.c_star_b_mag
                    mes_dso.c_star_v_mag = dso.c_star_v_mag
                    mes_dso.common_name = dso.common_name
                    mes_dso.descr = dso.descr

                    db.session.add(mes_dso)
            db.session.commit()
        except KeyError as err:
            print('\nKey error: {}'.format(err))
            db.session.rollback()
        except IntegrityError as err:
            print('\nIntegrity error {}'.format(err))
            db.session.rollback()
        print('')
Exemplo n.º 6
0
 def denormalized_name(self):
     return denormalize_dso_name(self.name)
Exemplo n.º 7
0
def import_observations(user, import_user, import_history_rec_id, file):
    log_warn = []
    log_error = []

    oal_observations = parse(file, silence=True)

    # Locations
    oal_sites = oal_observations.get_sites()
    found_locations = {}
    add_hoc_locations = {}
    if oal_sites and oal_sites.get_site():
        for oal_site in oal_sites.get_site():
            location = None
            if oal_site.get_name():
                location = Location.query.filter_by(name=oal_site.get_name()).first()
            if location is None:
                add_hoc_locations[oal_site.name] = (oal_site.get_latitude(), oal_site.get_longitude())
                log_warn.append(lazy_gettext('OAL Location "{}" not found').format(oal_site.get_name()))
            else:
                found_locations[oal_site.get_id()] = location

    # Scopes
    found_telescopes = {}
    oal_scopes = oal_observations.get_scopes()
    if oal_scopes:
        for oal_scope in oal_scopes.get_scope():
            model = oal_scope.get_model()
            telescope_type = _get_telescope_type_from_oal_scope_type(oal_scope.get_type())
            vendor = oal_scope.get_vendor()
            aperture_mm = oal_scope.get_aperture()

            focal_length_mm = None
            fixed_magnification = None
            if isinstance(oal_scope, OalscopeType):
                focal_length_mm = oal_scope.get_focalLength()
            if isinstance(oal_scope, OalfixedMagnificationOpticsType):
                fixed_magnification = oal_scope.get_magnification()

            telescope_query = Telescope.query.filter_by(user_id=current_user.id)
            if model:
                telescope_query = telescope_query.filter_by(model=model)
            if telescope_type:
                telescope_query = telescope_query.filter_by(telescope_type=telescope_type)
            if vendor:
                telescope_query = telescope_query.filter_by(vendor=vendor)
            if aperture_mm:
                telescope_query = telescope_query.filter_by(aperture_mm=aperture_mm)
            if focal_length_mm:
                telescope_query = telescope_query.filter_by(focal_length_mm=focal_length_mm)
            if fixed_magnification:
                telescope_query = telescope_query.filter_by(fixed_magnification=fixed_magnification)
            telescope = telescope_query.first()
            if not telescope:
                telescope = Telescope(
                    name=oal_scope.get_id(),
                    vendor=vendor,
                    model=model,
                    descr='',
                    aperture_mm=aperture_mm,
                    focal_length_mm=focal_length_mm,
                    fixed_magnification=fixed_magnification,
                    telescope_type=telescope_type,
                    is_default=False,
                    is_active=True,
                    is_deleted=False,
                    import_history_rec_id=import_history_rec_id,
                    user_id=current_user.id,
                    create_by=current_user.id,
                    update_by=current_user.id,
                    create_date=datetime.now(),
                    update_date=datetime.now()
                )
                db.session.add(telescope)
            found_telescopes[oal_scope.get_id()] = telescope

    # Eyepieces
    found_eyepieces = {}
    oal_eyepieces = oal_observations.get_eyepieces()
    if oal_eyepieces:
        for oal_eyepiece in oal_eyepieces.get_eyepiece():
            model = oal_eyepiece.get_model()
            vendor = oal_eyepiece.get_vendor()
            focal_length_mm = oal_eyepiece.get_focalLength()
            fov_deg = _get_angle_from_oal_angle(oal_eyepiece.get_apparentFOV())

            eyepiece_query = Eyepiece.query.filter_by(user_id=current_user.id)
            if model:
                eyepiece_query = eyepiece_query.filter_by(model=model)
            if vendor:
                eyepiece_query = eyepiece_query.filter_by(vendor=vendor)
            if focal_length_mm:
                eyepiece_query = eyepiece_query.filter_by(focal_length_mm=focal_length_mm)
            if fov_deg:
                eyepiece_query = eyepiece_query.filter_by(fov_deg=fov_deg)
            eyepiece = eyepiece_query.first()
            if not eyepiece:
                eyepiece = Eyepiece(
                    name=oal_eyepiece.get_id(),
                    vendor=vendor,
                    model=model,
                    descr='',
                    focal_length_mm=focal_length_mm,
                    fov_deg=fov_deg,
                    diameter_inch=None,
                    is_active=True,
                    is_deleted=False,
                    import_history_rec_id=import_history_rec_id,
                    user_id=current_user.id,
                    create_by=current_user.id,
                    update_by=current_user.id,
                    create_date=datetime.now(),
                    update_date=datetime.now()
                )
                db.session.add(eyepiece)
            found_eyepieces[oal_eyepiece.get_id()] = eyepiece

    # Filters
    found_filters = {}
    oal_filters = oal_observations.get_filters()
    if oal_filters:
        for oal_filter in oal_filters.get_filter():
            model = oal_filter.get_model()
            vendor = oal_filter.get_vendor()
            filter_type = _get_filter_type_from_oal_filter_kind(oal_filter.get_type())

            filter_query = Filter.query.filter_by(user_id=current_user.id)
            if model:
                filter_query = filter_query.filter_by(model=model)
            if vendor:
                filter_query = filter_query.filter_by(vendor=vendor)
            if filter_type:
                filter_query = filter_query.filter_by(filter_type=filter_type)

            filter = filter_query.first()
            if not filter:
                filter = Filter(
                    name=oal_filter.get_id(),
                    vendor=vendor,
                    model=model,
                    descr='',
                    filter_type=filter_type,
                    diameter_inch=None,
                    is_active=True,
                    is_deleted=False,
                    import_history_rec_id=import_history_rec_id,
                    user_id=current_user.id,
                    create_by=current_user.id,
                    update_by=current_user.id,
                    create_date=datetime.now(),
                    update_date=datetime.now()
                )
                db.session.add(filter)
            found_filters[oal_filter.get_id()] = filter

    # Lenses
    found_lenses = {}
    oal_lenses = oal_observations.get_lenses()
    if oal_lenses:
        for oal_lens in oal_lenses.get_lens():
            model = oal_lens.get_model()
            vendor = oal_lens.get_vendor()
            factor = oal_lens.get_factor()

            lens_query = Lens.query.filter_by(user_id=current_user.id)
            if model:
                lens_query = lens_query.filter_by(model=model)
            if vendor:
                lens_query = lens_query.filter_by(vendor=vendor)
            if factor:
                lens_query = lens_query.filter_by(magnification=factor)

            lens = lens_query.first()
            if not lens:
                lens = Lens(
                    name=oal_lens.get_id(),
                    vendor=vendor,
                    model=model,
                    descr='',
                    lens_type=None,
                    magnification=factor,
                    diameter_inch=None,
                    is_active=True,
                    is_deleted=False,
                    import_history_rec_id=import_history_rec_id,
                    user_id=current_user.id,
                    create_by=current_user.id,
                    update_by=current_user.id,
                    create_date=datetime.now(),
                    update_date=datetime.now()
                )
                db.session.add(lens)
            found_lenses[oal_lens.get_id()] = lens

    # Observations
    oal_sessions = oal_observations.get_sessions()
    found_observing_sessions = {}
    new_observing_sessions = {}
    if oal_sessions and oal_sessions.get_session():
        for oal_session in oal_sessions.get_session():
            begin = oal_session.get_begin()
            end = oal_session.get_end()
            if begin and not end:
                end = begin
            if end and not begin:
                begin = end

            observing_session = ObservingSession.query.filter(ObservingSession.user_id == user.id) \
                .filter(and_(ObservingSession.date_to >= begin, ObservingSession.date_from <= end)) \
                .first()
            if observing_session and observing_session.update_date != observing_session.create_date:
                found_observing_sessions[oal_session.get_id()] = observing_session
            else:
                location = found_locations.get(oal_session.get_site())
                location_position = add_hoc_locations.get(oal_session.get_site())
                if location:
                    title = location.name + ' ' + begin.strftime('%d.%m.%Y')
                elif begin:
                    title = begin.strftime('%d.%m.%Y')
                else:
                    title = oal_session.get_id()

                now = datetime.now()
                if not observing_session:
                    observing_session = ObservingSession(
                        user_id=user.id,
                        title=title,
                        date_from=begin,
                        date_to=end,
                        location_id=location.id if location else None,
                        location_position=location_position,
                        sqm=None,
                        faintest_star=None,
                        seeing=None,
                        transparency=None,
                        rating=None,
                        weather=oal_session.get_weather(),
                        equipment=oal_session.get_equipment(),
                        notes=oal_session.get_comments(),
                        import_history_rec_id=import_history_rec_id,
                        create_by=import_user.id,
                        update_by=import_user.id,
                        create_date=now,
                        update_date=now
                    )
                    new_observing_sessions[oal_session.get_id()] = observing_session
                else:
                    observing_session.title = title
                    observing_session.date_from = begin
                    observing_session.date_to = end
                    observing_session.location_id = location.id if location else None
                    observing_session.location_position = location_position
                    observing_session.weather = oal_session.get_weather()
                    observing_session.equipment = oal_session.get_equipment()
                    observing_session.notes = oal_session.get_comments()
                    observing_session.import_history_rec_id = import_history_rec_id
                    observing_session.update_by = import_user.id
                    observing_session.create_date = now
                    observing_session.update_date = now
                    found_observing_sessions[oal_session.get_id()] = observing_session

                db.session.add(observing_session)

    # Targets
    oal_targets = oal_observations.get_targets()
    found_dsos = {}
    found_double_stars = {}
    not_found_targets = set()
    if oal_targets and oal_targets.get_target():
        for target in oal_targets.get_target():
            if isinstance(target, (OaldeepSkyDS, OaldeepSkyMS)):
                double_star = search_double_star(target.get_name())
                if double_star:
                    found_double_stars[target.get_id()] = double_star
                else:
                    not_found_targets.add(target.get_id())
                    log_error.append(lazy_gettext('Double star "{}" not found').format(target.get_name()))
            else:
                normalized_name = normalize_dso_name_ext(denormalize_dso_name(target.get_name()))
                dso = DeepskyObject.query.filter_by(name=normalized_name).first()
                if dso:
                    found_dsos[target.get_id()] = dso
                else:
                    not_found_targets.add(target.get_id())
                    log_error.append(lazy_gettext('DSO "{}" not found').format(target.get_name()))

    oal_observations = oal_observations.get_observation()

    for oal_observation in oal_observations:
        observing_session = found_observing_sessions.get(oal_observation.get_session())
        is_session_new = False
        if not observing_session:
            observing_session = new_observing_sessions.get(oal_observation.get_session())
            is_session_new = True

        observed_double_star = found_double_stars.get(oal_observation.get_target())
        observed_dso = found_dsos.get(oal_observation.get_target())

        if not observed_dso and not observed_double_star:
            if oal_observation.get_target() not in not_found_targets:
                log_error.append(lazy_gettext('OAL Target "{}" not found.').format(oal_observation.get_target()))
            continue

        observation = None
        if not is_session_new:
            for obs in observing_session.observations:
                if obs.target_type == ObservationTargetType.DBL_STAR:
                    if observed_double_star and observed_double_star.id == obs.double_star_id:
                        observation = obs
                elif obs.target_type == ObservationTargetType.DSO:
                    if observed_dso:
                        for dso in obs.deepsky_objects:
                            if dso.id == observed_dso.id:
                                observation = obs
                                break
                if observation:
                    break

        if observation and observation.create_date != observation.update_date:
            log_warn.append(lazy_gettext('OAL Observation "{}" for session "{}" already exists and was modified by user.').format(oal_observation.get_id(), oal_observation.get_session()))
        else:
            notes = ''
            if oal_observation.get_result():
                notes = oal_observation.get_result()[0].get_description()

            location = found_locations.get(oal_observation.get_site())
            location_position = add_hoc_locations.get(oal_observation.get_site())

            if observing_session:
                if location and observing_session.location_id == location.id:
                    location = None
                if location_position and observing_session.location_position == location_position:
                    location_position = None

            telescope = found_telescopes.get(oal_observation.get_scope()) if oal_observation.get_scope() else None
            eyepiece = found_eyepieces.get(oal_observation.get_eyepiece()) if oal_observation.get_eyepiece() else None
            filter = found_filters.get(oal_observation.get_filter()) if oal_observation.get_filter() else None

            oal_lens = oal_observation.get_lens()
            lens = found_lenses.get(oal_observation.get_lens()) if oal_observation.get_lens() else None

            now = datetime.now()
            if not observation:
                observation = Observation(
                    user_id=current_user.id,
                    observing_session_id=observing_session.id if observing_session else None,
                    location_id=location.id if location else None,
                    location_position=location_position,
                    date_from=oal_observation.get_begin(),
                    date_to=oal_observation.get_end(),
                    sqm=_get_sqm_from_oal_surface_brightness(oal_observation.get_sky_quality()),
                    faintest_star=oal_observation.get_faintestStar(),
                    seeing=_get_seeing_from_oal_seeing(oal_observation.get_seeing()),
                    telescope_id=telescope.id if telescope else None,
                    eyepiece_id=eyepiece.id if eyepiece else None,
                    filter_id=filter.id if filter else None,
                    lens_id=lens.id if lens else None,
                    notes=notes,
                    import_history_rec_id=import_history_rec_id,
                    create_by=current_user.id,
                    update_by=current_user.id,
                    create_date=now,
                    update_date=now,
                )
                if observed_double_star:
                    observation.double_star_id = observed_double_star.id
                    observation.target_type = ObservationTargetType.DBL_STAR
                db.session.add(observation)
                if observed_dso:
                    observation.deepsky_objects.append(observed_dso)
                    observation.target_type = ObservationTargetType.DSO
                if observing_session:
                    observing_session.observations.append(observation)
            else:
                observation.observing_session_id = observing_session.id if observing_session else None
                observation.location_id = location.id if location else None
                observation.location_position = location_position
                observation.date_from = oal_observation.get_begin()
                observation.date_to = oal_observation.get_end()
                observation.sqm = _get_sqm_from_oal_surface_brightness(oal_observation.get_sky_quality())
                observation.faintest_star = oal_observation.get_faintestStar()
                observation.seeing = _get_seeing_from_oal_seeing(oal_observation.get_seeing())
                observation.telescope_id = telescope.id if telescope else None
                observation.eyepiece_id = eyepiece.id if eyepiece else None
                observation.filter_id = filter.id if filter else None
                observation.lens_id = lens.id if lens else None
                observation.notes = notes
                observation.import_history_rec_id = import_history_rec_id
                observation.update_by = current_user.id
                observation.create_date = now  # set create date to update date to easy detect user modifications
                observation.update_date = now
                db.session.add(observation)

            if is_session_new and observing_session:
                if not observing_session.sqm and oal_observation.get_sky_quality():
                    observing_session.sqm = _get_sqm_from_oal_surface_brightness(oal_observation.get_sky_quality())
                if not observing_session.faintest_star and oal_observation.get_faintestStar():
                    observing_session.faintest_star = oal_observation.get_faintestStar()
                if not observing_session.seeing and oal_observation.get_seeing():
                    observing_session.seeing = _get_seeing_from_oal_seeing(oal_observation.get_seeing())

    db.session.commit()

    return log_warn, log_error