示例#1
0
    def _create_date(cls, date_str, ctx, iau_code):
        date_str = date_str.strip()

        if '' == date_str:
            return [None, None]

        month_names = cls._month_names
        value = date_str.split()

        if len(value) != 2:
            raise ImportException(
                "ID %s: %s must have the the format MM/DD. The value is %s." %
                (iau_code, ctx, value))

        if value[0] not in month_names:
            raise ImportException(
                "ID %s: %s is an invalid month name. The value is %s." %
                (iau_code, value[0], ctx))

        month = month_names[value[0]]

        try:
            day = int(value[1])
        except ValueError:
            raise ImportException(
                "ID %s: %s is an invalid day. The value is %s." %
                (iau_code, value[1], ctx))

        return cls._validate_date(month, day, iau_code, ctx)
示例#2
0
    def _parse_text(value, ctx, session_id):
        value = value.strip()
        if '' == value:
            raise ImportException('ID %s: %s must be set.' % (session_id, ctx))

        try:
            value = str(value)
        except ValueError:
            raise ImportException("ID %s: invalid %s. Value is %s." % (session_id, ctx, value))

        return value
示例#3
0
    def _parse_session_id(value, obs_id=None):
        session_id = value.strip()
        if '' == session_id:
            raise ImportException("Session found without a session id.")

        try:
            session_id = int(session_id)
        except ValueError:
            raise ImportException("ID %s: invalid session id." % session_id)
        if session_id < 1:
            raise ImportException("ID %s: session ID must be greater than 0." % session_id)

        return session_id
示例#4
0
    def _parse_magn_id(value):
        magn_id = value.strip()
        if '' == magn_id:
            raise ImportException('Observation found without a magnitude id.')

        try:
            magn_id = int(magn_id)
        except ValueError:
            raise ImportException('ID %s: invalid magnitude id.' % magn_id)
        if magn_id < 1:
            raise ImportException('ID %s: magnitude ID must be greater than 0.' % magn_id)

        return magn_id
示例#5
0
    def _parse_elevation(self, value, session_id):
        elevation = value.strip()
        if '' == elevation:
            if self._is_permissive:
                return None
            else:
                raise ImportException("ID %s: elevation must not be empty." % session_id)

        try:
            elevation = float(elevation)
        except ValueError:
            raise ImportException("ID %s: invalid elevation value. The value is %s." % (session_id, elevation))

        return elevation
示例#6
0
    def _parse_rate_id(value):
        rate_id = value.strip()
        if '' == rate_id:
            raise ImportException('Observation found without a rate id.')

        try:
            rate_id = int(rate_id)
        except ValueError:
            raise ImportException('ID %s: invalid rate id.' % rate_id)
        if rate_id < 1:
            raise ImportException('ID %s: rate ID must be greater than 0.' %
                                  rate_id)

        return rate_id
示例#7
0
    def _parse_latitude(value, session_id):
        lat = value.strip()
        if '' == lat:
            raise ImportException("ID %s: latitude must not be empty." % session_id)

        try:
            lat = float(lat)
        except ValueError:
            raise ImportException("ID %s: invalid latitude value. The value is %s." % (session_id, lat))

        if lat < -90 or lat > 90:
            raise ImportException("ID %s: latitude must be between -90 and 90 instead of %s." % (session_id, lat))

        return lat
示例#8
0
    def _parse_longitude(value, session_id):
        long = value.strip()
        if '' == long:
            raise ImportException("ID %s: longitude must not be empty." % session_id)

        try:
            long = float(long)
        except ValueError:
            raise ImportException("ID %s: invalid longitude value. The value is %s." % (session_id, long))

        if long < -180 or long > 180:
            raise ImportException("ID %s: longitude must be between -180 and 180 instead of %s." % (session_id, long))

        return long
示例#9
0
    def _parse_freq(value, rate_id, session_id):
        value = value.strip()

        try:
            value = int(value)
        except ValueError:
            raise ImportException(
                'ID %s in session %s: %s is an invalid count of meteors.' %
                (rate_id, session_id, value))

        if value < 0:
            raise ImportException(
                'ID %s in session %s: count of meteors must be greater than 0 instead of %s.'
                % (rate_id, session_id, value))

        return value
示例#10
0
    def parse_row(self, row, cur):
        row = dict(zip(self.column_names, row))

        try:
            shower = self._parse_shower(row['shower'])
            ra = self._parse_ra(row['ra'], shower)
            dec = self._parse_dec(row['dec'], shower)
            month = self._parse_int(row['month'], 'month', shower)
            day = self._parse_int(row['day'], 'day', shower)
            self._validate_date(month, day, shower)
            if ra is None or dec is None:
                raise ImportException('ID %s: ra and dec must be set.' % shower)

        except ImportException as err:
            self._log_error(str(err))
            return False

        record = {
            'shower': shower,
            'ra': ra,
            'dec': dec,
            'month': month,
            'day': day,
        }

        try:
            cur.execute(self._insert_stmt, record)
        except Exception as e:
            raise DBException(str(e))

        return True
示例#11
0
    def _validate_total_count(self, magn, magn_id, session_id):
        is_permissive = self._is_permissive
        n_sum = 0
        for m in sorted(magn.keys(), key=int):
            n = magn[m]
            n_sum += n
            if not is_permissive and 0 == n and math.floor(n_sum) != n_sum:
                raise ImportException(
                    'ID %s in session %s: Inconsistent total count of meteors found.' %
                    (magn_id, session_id)
                )

        if math.floor(n_sum) != n_sum:
            raise ImportException(
                'ID %s in session %s: The count of meteors out of a total of %s is invalid.' %
                (magn_id, session_id, n_sum)
            )
示例#12
0
    def _parse_r_value(value, iau_code):
        r = value.strip()
        if '' == r:
            return None

        try:
            r = float(r)
        except ValueError:
            raise ImportException("ID %s: invalid r-value. The value is %s." %
                                  (iau_code, r))

        if r < 1 or r > 5:
            raise ImportException(
                "ID %s: r-value must be between 1 and 5 instead of %s." %
                (iau_code, r))

        return r
示例#13
0
    def _validate_count(n, m, magn_id, session_id):
        if n < 0.0:
            raise ImportException(
                'ID %s in session %s: Invalid count %s found for a meteor magnitude of %s.' %
                (magn_id, session_id, n, m)
            )

        n_cmp = math.floor(n)
        if n == n_cmp:
            return

        n_cmp += 0.5
        if n == n_cmp:
            return

        raise ImportException(
            'ID %s in session %s: Invalid count %s found for a meteor magnitude of %s.' %
            (magn_id, session_id, n, m))
示例#14
0
    def _parse_int(value, ctx, iau_code):
        value = value.strip()

        try:
            value = int(value)
        except ValueError:
            raise ImportException("ID %s: %s is an invalid %s." % (iau_code, value, ctx))

        return value
示例#15
0
    def _parse_velocity(value, iau_code):
        v = value.strip()
        if '' == v:
            return None

        try:
            v = float(v)
        except ValueError:
            raise ImportException(
                "ID %s: invalid velocity value. The value is %s." %
                (iau_code, v))

        if v < 11 or v > 75:
            raise ImportException(
                "ID %s: velocity must be between 11 and 75 instead of %s." %
                (iau_code, v))

        return v
示例#16
0
    def _parse_f(value, rate_id, session_id):
        f = value.strip()
        if '' == f:
            raise ImportException('ID %s in session %s: f must be set.' %
                                  (rate_id, session_id))

        try:
            f = float(f)
        except ValueError:
            raise ImportException(
                'ID %s in session %s: invalid f. The value is %s.' %
                (rate_id, session_id, f))

        if f < 1.0:
            raise ImportException(
                'ID %s in session %s: f must be greater than 1 instead of %s.'
                % (rate_id, session_id, f))

        return f
示例#17
0
    def _parse_lm(value, rate_id, session_id):
        lm = value.strip()
        if '' == lm:
            raise ImportException(
                'ID %s in session %s: limiting magnitude must be set.' %
                (rate_id, session_id))

        try:
            lm = float(lm)
        except ValueError:
            raise ImportException(
                'ID %s in session %s: invalid limiting magnitude. The value is %s.'
                % (rate_id, session_id, lm))

        if lm < 0.0 or lm > 8:
            raise ImportException(
                'ID %s in session %s: lm must be between 0 and 8 instead of %s.'
                % (rate_id, session_id, lm))

        return lm
示例#18
0
    def _parse_t_eff(self, value, rate_id, session_id):
        t_eff = value.strip()
        if '' == t_eff:
            raise ImportException('ID %s in session %s: t_eff must be set.' %
                                  (rate_id, session_id))

        try:
            t_eff = float(t_eff)
        except ValueError:
            raise ImportException(
                'ID %s in session %s: invalid t_eff. The value is %s.' %
                (rate_id, session_id, t_eff))

        if 0.0 == t_eff:
            raise ImportException('ID %s in session %s: t_eff is 0.' %
                                  (rate_id, session_id))

        if t_eff < 0.0:
            raise ImportException(
                'ID %s in session %s: t_eff must be greater than 0 instead of %s.'
                % (rate_id, session_id, t_eff))

        if t_eff > 24.0:
            raise ImportException(
                'ID %s in session %s: t_eff must be less than 24 instead of %s.'
                % (rate_id, session_id, t_eff))

        if not self._is_permissive and t_eff > 7.0:
            raise ImportException(
                'ID %s in session %s: t_eff must be less than 6 instead of %s.'
                % (rate_id, session_id, t_eff))

        return t_eff
示例#19
0
    def _parse_iau_code(value):
        iau_code = value.strip()
        if '' == iau_code:
            raise ImportException("Shower found without an iau_code.")

        return iau_code.upper()
示例#20
0
    def _parse_shower(value):
        shower = value.strip()
        if '' == shower:
            raise ImportException("Shower code must not be empty.")

        return shower.upper()