diff --git a/app/controllers/page_controller.rb b/app/controllers/page_controller.rb index ce3938e..6b33f5c 100644 --- a/app/controllers/page_controller.rb +++ b/app/controllers/page_controller.rb @@ -8,6 +8,7 @@ def user_positions sort_type = params[:sort_type].presence || "desc" @symbol = params[:search] histories = UserPosition.available.where(user_id: nil) + @total_summary = histories.total_summary histories = histories.where(origin_symbol: @symbol) if @symbol.present? histories = histories.where(level: params[:level]) if params[:level].present? histories = histories.select{|h| h.amount < @max_amount} if @flag && @max_amount > 0 @@ -15,10 +16,9 @@ def user_positions @histories = parts.last.sort_by{|h| h.send("#{sort}")} + parts.first @histories = @histories.reverse if sort_type == "desc" @histories = Kaminari.paginate_array(@histories).page(params[:page]).per(15) - @total_summary = UserPosition.available.total_summary compare_date = params[:compare_date].presence || Date.yesterday - snapshots = SnapshotPosition.joins(:snapshot_info).where(snapshot_info: {source_type: 'synced', user_id: nil, event_date: compare_date}) - @last_summary = snapshots.last_summary(data: @total_summary) + snapshots = SnapshotInfo.where(source_type: 'synced', user_id: nil, event_date: compare_date).first&.snapshot_positions + @last_summary = snapshots.last_summary(data: @total_summary) rescue {} @snapshots = snapshots.to_a flash[:alert] = "找不到相应的快照" if params[:compare_date].present? && @snapshots.blank? end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6205d07..53a4ae4 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -506,6 +506,7 @@ def get_roi(total_summary) end def last_summary_display(data, is_percent = false) + data = data.to_f c = data > 0 ? 'pos-num' : 'neg-num' if is_percent "(#{data.round(2)}%)".html_safe diff --git a/features/user_positions.feature b/features/user_positions.feature index 0492551..50467e5 100644 --- a/features/user_positions.feature +++ b/features/user_positions.feature @@ -2,15 +2,15 @@ Feature: User Positions pages Background: Given I am a new, authenticated user Given I have 10 user positions with user id - Given I have uploaded snapshot with user id + Given I have synced snapshot with user id @javascript Scenario: Visit User positions page When I visit the '/user_positions' page Then I see '总投入' text - Then I see '(-124.8)' text + Then I see '(307.2)' text Then I see '绝对收益' text - Then I see '(392.55)' text + Then I see '(157.22)' text Then I see 'EOS' text When I select2 "BTCUSDT" from "#search" filter And I click on the button "确定"