diff --git a/app/controllers/ranking_snapshots_controller.rb b/app/controllers/ranking_snapshots_controller.rb index 3f8d638..f858d4d 100644 --- a/app/controllers/ranking_snapshots_controller.rb +++ b/app/controllers/ranking_snapshots_controller.rb @@ -24,15 +24,17 @@ def get_24hr_tickers @symbols = @daily_ranking.map{|r| [r["symbol"], r["source"]] } @three_days_duration = $redis.get('three_days_duration') || 12 @three_days_select = $redis.get('three_days_select').to_i - @three_days_ranking = JSON.parse($redis.get("get_three_days_tickers")) rescue [] + @three_days_ranking = JSON.parse($redis.get("get_three_days_tickers_#{@three_days_duration}_#{@three_days_select}")) rescue [] @weekly_duration = $redis.get('weekly_duration') || 12 @weekly_select = $redis.get('weekly_select').to_i - @weekly_ranking = JSON.parse($redis.get("get_one_week_tickers")) rescue [] + @weekly_ranking = JSON.parse($redis.get("get_one_week_tickers_#{@weekly_duration}_#{@weekly_select}")) rescue [] end def refresh_tickers data_type = params[:data_type] - RefreshRankingSnapshotsJob.perform_later(params[:three_days_duration], params[:three_days_select], data_type) + duration = params[:three_days_duration] || params[:weekly_duration] + rank = params[:three_days_select] || params[:weekly_select] + RefreshRankingSnapshotsJob.perform_later(duration, rank, data_type) redirect_to get_24hr_tickers_ranking_snapshots_path(anchor: get_anchor(data_type)), notice: "正在更新,请稍等刷新查看最新排名..." end diff --git a/app/models/ranking_snapshot.rb b/app/models/ranking_snapshot.rb index 0e87574..70a9cf6 100644 --- a/app/models/ranking_snapshot.rb +++ b/app/models/ranking_snapshot.rb @@ -18,7 +18,19 @@ def self.get_daily_rankings end def self.get_rankings(duration: 12, rank: nil, data_type: nil) - redis_key = data_type == 'weekly' ? 'get_one_week_tickers' : 'get_three_days_tickers' + if data_type == 'weekly' + duration_key = 'weekly_duration' + rank_key = 'weekly_select' + redis_key = "get_one_week_tickers_#{duration}_#{rank}" + else + duration_key = 'three_days_duration' + rank_key = 'three_days_select' + redis_key = "get_three_days_tickers_#{duration}_#{rank}" + end + + $redis.set(duration_key, duration) + $redis.set(rank_key, rank) + result = JSON.parse($redis.get(redis_key)) rescue nil if result.nil? result = RankingSnapshot.order(event_date: :asc).group_by{|snapshot| [snapshot.symbol, snapshot.source]}.map do |key, data| diff --git a/app/services/sync_futures_ticker_service.rb b/app/services/sync_futures_ticker_service.rb index 765c207..24fb3cd 100644 --- a/app/services/sync_futures_ticker_service.rb +++ b/app/services/sync_futures_ticker_service.rb @@ -37,7 +37,7 @@ def get_24hr_tickers(bottom_select, top_select, duration, data_type) last_price = ticker["last"].to_f margin = ticker["high24h"].to_f - ticker["low24h"].to_f price_change = (ticker["last"].to_f - open_price) / open_price - price_ratio = get_price_ratio(from_symbol, last_price, rank, price_type, duration) + price_ratio = get_price_ratio(from_symbol, last_price, rank, duration) { "symbol" => from_symbol + to_symbol, "instId" => ticker["instId"],