From 68b04c6ef02370d2290d7139306bdabb823143d8 Mon Sep 17 00:00:00 2001 From: Pan Xiong Date: Fri, 10 Nov 2023 20:44:10 +1100 Subject: [PATCH] Update funding fee chart page --- app/controllers/page_controller.rb | 6 ++++-- app/views/layouts/application.html.erb | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/controllers/page_controller.rb b/app/controllers/page_controller.rb index 899d69b..0a1c143 100644 --- a/app/controllers/page_controller.rb +++ b/app/controllers/page_controller.rb @@ -175,16 +175,18 @@ def funding_fee_chart @to_date = Date.parse(params[:to_date]) rescue Date.today @from_date = Date.parse(params[:from_date]) + 1.day rescue @to_date - 3.months - histories = FundingFeeHistory.includes(:snapshot_position).where('funding_fee_histories.user_id is null and funding_fee_histories.event_date >= ? and funding_fee_histories.event_date <= ?', @from_date, @to_date).order(event_date: :asc) + histories = FundingFeeHistory.where('funding_fee_histories.user_id is null and funding_fee_histories.event_date >= ? and funding_fee_histories.event_date <= ?', @from_date, @to_date).order(event_date: :asc) histories = histories.where(origin_symbol: @symbol) if @symbol.present? histories = histories.where(source: @source) if @source.present? @data_summary = histories.data_summary @data = {} total_amount = FundingFeeHistory.where('user_id is null and event_date < ?', @from_date).sum(&:amount) + snapshots = SnapshotPosition.joins(:snapshot_info).where(snapshot_info: {user_id: nil}).available histories.group_by(&:event_date).each do |date, value| amount = value.sum(&:amount) total_amount += amount - @data[date] = { amount: amount, revenue: value.sum(&:revenue), total_amount: total_amount, date: date } + revenue = snapshots.select{|x| x.event_date == date}.sum(&:revenue) + @data[date] = { amount: amount, revenue: revenue, total_amount: total_amount, date: date } end end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 82f9135..e108aec 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -92,12 +92,12 @@ 个人仓位管理