Follow-up from "Add deploy frequency to project-level VSA Summary"
The following discussion from !28772 (merged) should be addressed:
-
@splattael started a discussion: (+2 comments) With this
frequency
is returning either a0
(Fixnum
) ifcount == 0
, a"0"
(String
) iffreq == 0
, orfreq
(Fixnum
).Since we are stringfying in the presentation layer, should we just return
Fixnum
here?(count / days(from, to)).round(1)
🤔 @aakriti.gupta wrote:
This was rather tricky.
We need to display a
-
when values are 0, for deploy, commit and issue counts, but not for deployment frequency.e.g. when there has been 1 deployment in 30 days, the deploy count is 1, but the deployment frequency is 0.03, which is rounded off to 0.0 (it is requirement to show frequency only upto 1 decimal point). Now, if we change all zero values to
-
, the deployment frequency would be-
, even though there has been a deployment. So it is best to show the rounded off value.In the FE it is much harder to treat values coming from each of the counts differently, so we're implementing this in the BE.
Even in the BE, we need the check in at least 2 places:
1 - if there were no deploys, the deploy frequency is 0 (number), which will be displayed as
-
(string)2 - if there were deploys but the deploy frequency is 0.0, we want to display
0.0
(string)This is why it is not possible to always return a Fixnum from here.
@splattael wrote:
I see, it's tricky indeed.
I don't like how the presenter logic is scattered across two files: entity and summary helper.
Maybe, we could introduce two presenter objects (say,
NoDeploys
,Frequency
)def frequency(count, from, to) (count / days(from, to)).round(1) return NoDeploys.new if count.zero? freq = (count / days(from, to)).round(1) Frequency.new(freq) end
The presenters:
class NoDeploys def to_s '-' end end Frequency = Struct.new(:value) do def to_s value.zero? ? '0' : value.to_s end end
In app/serializers/analytics_summary_entity.rb:
def value object.value.to_s end
I am sure I've missed a case- but in general this could work.I think more methods need to return
NoDeploy
/Frequency
/?
as well.Anyhow, let's do it in the follow-up
👍