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

pulibrary / tigerdata-app / cd871925-a1a8-4379-b3a8-4ee1e8486a04

04 Jun 2025 05:06PM UTC coverage: 85.587% (-0.3%) from 85.847%
cd871925-a1a8-4379-b3a8-4ee1e8486a04

Pull #1533

circleci

jrgriffiniii
Implements a route for retrieving the Mediaflux XML document for project metadata
Pull Request #1533: Implements a route for retrieving the Mediaflux XML document for project metadata

4 of 4 branches covered (100.0%)

3 of 14 new or added lines in 2 files covered. (21.43%)

6 existing lines in 2 files now uncovered.

2969 of 3469 relevant lines covered (85.59%)

581.23 hits per line

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

85.71
/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
304✔
15
    @project_metadata = @project.metadata_model
304✔
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")
58✔
30
  end
31

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

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

40
  def data_manager
1✔
41
    User.find_by(uid: @project.metadata["data_manager"]).uid
58✔
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, "")
32✔
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?
106✔
59

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

63
    value*default_capacity_divisor
58✔
64
  end
65

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

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

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

84
  def quota_percentage(session_id:)
1✔
85
    return 0 if project.pending?
184✔
86

87
    storage_capacity = project.storage_capacity_raw(session_id:)
33✔
88
    return 0 if storage_capacity.zero?
33✔
89

90
    storage_usage = project.storage_usage_raw(session_id:)
4✔
91
    (storage_usage.to_f / storage_capacity.to_f) * 100
4✔
92
  end
93

94
  private
1✔
95

96
    def default_usage_divisor
1✔
UNCOV
97
      1.0/(1000.0**1)
×
98
    end
99

100
    # Capacity is in bytes
101
    def default_capacity_divisor
1✔
102
      1.0/(1000.0**3)
58✔
103
    end
104

105
    def storage_remaining(session_id:)
1✔
UNCOV
106
      capacity = storage_capacity(session_id: session_id)
×
UNCOV
107
      return 0.0 if capacity.zero?
×
108

109
      usage = storage_usage(session_id: session_id)
×
110

UNCOV
111
      remaining = (capacity/default_capacity_divisor) - usage
×
112
      remaining*default_capacity_divisor
×
113
    end
114

115
    def xml_presenter_args
1✔
116
      project
4✔
117
    end
118

119
    def xml_presenter
1✔
120
      @xml_presenter ||= self.class.xml_presenter_class.new(xml_presenter_args)
4✔
121
    end
122
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