lib/inat/data/query.rb in inat-get-0.8.0.12 vs lib/inat/data/query.rb in inat-get-0.8.0.13

- old
+ new

@@ -12,14 +12,19 @@ require_relative 'enums/qualitygrade' require_relative 'types/std' require_relative 'types/location' require_relative 'types/extras' -class Query +class INat::Query - include LogDSL + using INat::Types::Std + include INat + include INat::App + include INat::App::Logger::DSL + include INat::Data::Types + private def parse_accuracy value case value when true, false @api_params[:acc] = value @db_where << [ "o.positional_accuracy IS#{ value && ' NOT' || '' } NULL", [] ] @@ -1075,21 +1080,21 @@ # 1. Проверяем наличие актуального реквеста actual_time = 0 if mode != UpdateMode::MINIMAL actual_time = Time::new - Period::parse(G.config[:data][:update_period]) end - actuals = Request::from_db_rows(DB.execute("SELECT * FROM requests WHERE time >= ?", actual_time.to_db)).select { |rq| self.in?(rq.query) } + actuals = Entity::Request::from_db_rows(DB.execute("SELECT * FROM requests WHERE time >= ?", actual_time.to_db)).select { |rq| self.in?(rq.query) } end if actuals.empty? || mode == UpdateMode::FORCE # 2. Ищем чего бы обновить - request = Request::from_db_rows(DB.execute("SELECT * FROM requests WHERE query = ?", api_query)).first + request = Entity::Request::from_db_rows(DB.execute("SELECT * FROM requests WHERE query = ?", api_query)).first updated_since = nil if request == nil query_string = api_query project_id = @api_params[:project_id] project_id = nil unless Integer === project_id - request = Request::create query_string, project_id + request = Entity::Request::create query_string, project_id request.save else updated_since = request.time if mode != UpdateMode::RELOAD end if request.active @@ -1102,34 +1107,34 @@ params = @api_params.dup params[:updated_since] = updated_since if updated_since && updated_since != Time::at(0) tt = nil cc = 0 current_time = Time::new - API::query(:observations, **params) do |json, total| + INat::API::query(:observations, **params) do |json, total| tt ||= total cc += 1 pc = cc * 100 / tt td = (Time::new - current_time) / cc te = (td * (tt - cc)).to_i pe = Period::make seconds: te pt = Period::make seconds: (Time::new - current_time).to_i Status::status nil, "Query \##{ @int_key } : R\##{ request.id } : parsed #{ format("%d of %d : %3d%% : time %s remain %s", cc, tt, pc, pt.to_hs, pe.to_hs) }" - obs = Observation::parse json + obs = Entity::Observation::parse json obs.save DB.execute "INSERT OR REPLACE INTO request_observations (request_id, observation_id) VALUES (?, ?);", request.id, obs.id end request.active = false end # Считываем свежедобаленное # TODO: разобраться с удалением устаревшего # NEED: разобраться с частичной загрузкой — большие проекты грузятся недопустимо долго # возможно, стоит запараллелить обработку - request = Request::read(request.id).first + request = Entity::Request::read(request.id).first end end # TODO: разобраться, где тупня sql, sql_args = db_where - result = Observation::from_db_rows(DB.execute("SELECT * FROM observations o#{ sql.empty? && '' || ' WHERE ' }#{ sql };", *sql_args)) + result = Entity::Observation::from_db_rows(DB.execute("SELECT * FROM observations o#{ sql.empty? && '' || ' WHERE ' }#{ sql };", *sql_args)) if !@r_match.empty? result = result.filter { |o| self.match?(o) } end if request != nil request.update do