• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / tigerdata-app / 49abd256-27e3-45e4-a672-bbe75194bd67

04 Jun 2025 08:10PM UTC coverage: 85.735% (-0.2%) from 85.904%
49abd256-27e3-45e4-a672-bbe75194bd67

Pull #1538

circleci

bess
Configure database for CI
Pull Request #1538: Deploy to ci server

4 of 4 branches covered (100.0%)

2891 of 3372 relevant lines covered (85.74%)

495.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.25
/app/presenters/project_show_presenter.rb
1
# frozen_string_literal: true
2
class ProjectShowPresenter
1✔
3
  delegate "id", "in_mediaflux?", "mediaflux_id", "pending?", "status", "title", to: :project
1✔
4
  delegate "description", "project_id", "storage_performance_expectations", "project_purpose", to: :project_metadata
1✔
5

6
  attr_reader :project, :project_metadata
1✔
7

8
  # @return [Class] The presenter class for building XML Documents from Projects
9
  def self.xml_presenter_class
1✔
10
    ProjectXmlPresenter
4✔
11
  end
12

13
  def initialize(project)
1✔
14
    @project = project
303✔
15
    @project_metadata = @project.metadata_model
303✔
16
  end
17

18
  # @return [String] the XML for the project Document 
19
  def to_xml
1✔
20
    xml_document.to_xml
3✔
21
  end
22

23
  # @return [Nokogiri::XML::Document] the XML Document for the Project
24
  def xml_document
1✔
25
    @xml_document ||= xml_presenter.document
4✔
26
  end
27

28
  def created
1✔
29
    @project.created_at.strftime("%b %e, %Y %l:%M %p")
57✔
30
  end
31

32
  def updated
1✔
33
    @project.updated_at.strftime("%b %e, %Y %l:%M %p")
57✔
34
  end
35

36
  def data_sponsor
1✔
37
    User.find_by(uid: @project.metadata["data_sponsor"]).uid
57✔
38
  end
39

40
  def data_manager
1✔
41
    User.find_by(uid: @project.metadata["data_manager"]).uid
57✔
42
  end
43

44
  # used to hide the project root that is not visible to the end user
45
  def project_directory
1✔
46
    project.project_directory.gsub(Mediaflux::Connection.hidden_root, "")
31✔
47
  end
48

49
  # This assumed that the storage usage is recorded in the same units as the units specified in the StorageCapacity metadata
50
  def storage_usage(session_id:)
1✔
51
    persisted = project.storage_usage_raw(session_id: session_id)
×
52
    value = persisted.to_f
×
53

54
    value*default_usage_divisor
×
55
  end
56

57
  def storage_capacity(session_id: nil)
1✔
58
    return project_metadata.storage_capacity if session_id.nil?
103✔
59

60
    persisted = project.storage_capacity_raw(session_id: session_id)
57✔
61
    value = persisted.to_f
57✔
62

63
    value*default_capacity_divisor
57✔
64
  end
65

66
  def formatted_storage_capacity(session_id:)
1✔
67
    value = storage_capacity(session_id: session_id)
57✔
68
    format("%.3f", value)
57✔
69
  end
70

71
  def formatted_quota_percentage(session_id:)
1✔
72
    value = quota_percentage(session_id:)
57✔
73
    format("%.3f", value)
57✔
74
  end
75

76
  def quota_usage(session_id:)
1✔
77
    if project.pending?
193✔
78
      quota_usage = "0 KB out of 0 GB used"
172✔
79
    else
80
      quota_usage = "#{project.storage_usage(session_id:)} out of #{project.storage_capacity(session_id:)} used"
21✔
81
    end
82
    quota_usage
193✔
83
  end
84

85
  def quota_percentage(session_id:)
1✔
86
    return 0 if project.pending? || project.storage_capacity_raw(session_id:).zero?
182✔
87
    
88
   (project.storage_usage_raw(session_id:).to_f / project.storage_capacity_raw(session_id:).to_f) * 100
4✔
89
  end  
90

91
  private
1✔
92

93
    def default_usage_divisor
1✔
94
      1.0/(1000.0**1)
×
95
    end
96

97
    # Capacity is in bytes
98
    def default_capacity_divisor
1✔
99
      1.0/(1000.0**3)
57✔
100
    end
101

102
    def storage_remaining(session_id:)
1✔
103
      capacity = storage_capacity(session_id: session_id)
×
104
      return 0.0 if capacity.zero?
×
105

106
      usage = storage_usage(session_id: session_id)
×
107

108
      remaining = (capacity/default_capacity_divisor) - usage
×
109
      remaining*default_capacity_divisor
×
110
    end
111

112
    def xml_presenter_args
1✔
113
      project
4✔
114
    end
115

116
    def xml_presenter
1✔
117
      @xml_presenter ||= self.class.xml_presenter_class.new(xml_presenter_args)
4✔
118
    end
119
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc