Asked by:
Extracting percent difference

General discussion
-
I think you really want:
$day1 = (dir $path |?{$_.LastWriteTime -gt [datetime]::Today.AddDays(-3) -and $_.LastWriteTime -lt [datetime]::Today.AddDays(-2)}).Count
The math is:
$day1/$day2 -gt .25
\_(ツ)_/
It was just a hint, not the solution. :)
Although i must admit, that using calculate property was not necessary there, so my example was not correct (datetime comparison was right though)
Friday, October 19, 2018 7:41 AM
All replies
-
But the hint doesn't work. A hint should be workable.
\_(ツ)_/
Friday, October 19, 2018 7:42 AM -
Well my hint did count the files using datetime criteria .. so it was workable in my point of view (though your example is better).
$day1/$day2 -gt .25 .. this doesnt either .. this doesn't give u required %
Friday, October 19, 2018 7:53 AM -
It gives the answer. If day2 is 25%greater than day1 the expression is rue.
1/($day1/$day2) -1 gt .25 is the percentage as a decimal value.
\_(ツ)_/
- Edited by jrv Friday, October 19, 2018 9:00 AM
Friday, October 19, 2018 7:57 AM -
Oops. My formual should be:
1/($day1/$day2) -1 gt .25
\_(ツ)_/
- Edited by jrv Friday, October 19, 2018 9:00 AM
Friday, October 19, 2018 7:58 AM -
Oops. My formual should be:
1 - ($day1/$day2) -gt .25
\_(ツ)_/
So.. when 1 day is 50logs, second day is 70 logs.. then its .28 => your statement is correct.
What about 1 day 70logs, second 50 logs.. then its -0.4, right? :) Therefore your formula needs some more tweaking as were looking for 25% differency.. no matter if second day count Is higher or lower ..
- Edited by Mekac Friday, October 19, 2018 8:17 AM
Friday, October 19, 2018 8:16 AM -
No. You have to understand the mathematical concept of percent difference. Greater than 25% more means day 2 is more than 1.25.
Look at it this way.
$day2/$day1 -gt 1.25
which is probably a clearer way of stating the question. The result of the left side is alwys greater than 1.25 when day 2 has more than 1.25 times as many files.
note that
$day2/$day1 -eq 1
means that they are equal when it is true.
Another way of saying this is:
if $day2/$day1 is less than 0 or greater than then it is not equal.
The following:
$day2/$day1 -gt 1.25
means that any time day 2 is more than 25% greater the expression is true.
Logic. It is what makes computers work. It is a fundamental pattern in programming.
This is all based on junior high school math so everyone should know it cold. Right?
Of course we can just invert this for more fun.
$day1/$day2 -lt .75
Which is the same test.
1/($day1/$day2) -1 gt .25
$day1/$day2 -lt .75
$day2/$day1 -gt 1.25Are all the same test and are equivalent. They al test for the same condition.
\_(ツ)_/
- Edited by jrv Friday, October 19, 2018 8:59 AM
Friday, October 19, 2018 8:45 AM -
Opps again.
The correct formula should be
1/($day1/$day2) -1
Getting late and I forgot that little bit.
\_(ツ)_/
Friday, October 19, 2018 8:59 AM -
I should explain.
1/($day1/$day2)
This gets the inverse of the ratio.
1/($day1/$day2) -1 gt .25
subtract one to get the match to normalize at .25.
When $day2 is greater than $day the result is always positive. When $day1 is greater than 2 time $day2 the result is always negative.
This is why this formula is easier to use and understand as well as its variation (-1).
$day2/$day1 -gt 1.25
Note that a percent is not a numeric type but are a convenience added for display and obtained by multiplying by 100 and adding %.
\_(ツ)_/
- Edited by jrv Friday, October 19, 2018 9:08 AM
Friday, October 19, 2018 9:05 AM -
Moving to OFF-TOPIC posts because split thread doesn't make much sense by itself.
\_(ツ)_/
Friday, October 19, 2018 9:26 AM