Challenge: Can you use conditionals in calculations?

Or is there a nice way of crossing the midnight line. Yes, that old chestnut.

So, minutes from Sunrise is easy as sunset is before midnight
((((#DH#*60)+#Dm#)-((#WRH#*60)+#WRm#))

But minutes from Sunset won’t work that way just on #DH#.

I did a static int test of (3+($#Da#==AM?12:0$)) and without the internal brackets but it returns nothing making me thing it’s a no-go.

I have a few ideas to try when back from the pub but thought I’d punt it out there as a challenge :wink:

UPDATE:
If you don’t want to read the fluff afterwards then No. You can’t use conditionals inside calculations.
You need to have the whole calculation inside conditionals. The above example is not a good use case but imagine having 150 characters of calculation where only one value needs to be changed instead of just a 3+.
Anyway, you would write that as:
$#Da#==AM?(3+12):(3+0)$)
Or for complex ones where you have multiple equality tests (>3) or multiple required outcomes (>2) you might have:
$#Da#==AM&&#DH#<=5?(3+3):$$#Da#==AM&&#DH#>5?(3+6):$$#Da#==PM?(3+9):$

2 Likes

I find it difficult to calculating with time. I have seen guys using DNOW to calculate things.

But to your question about conditions in calculations:
I do not think it is possible. An approach would be to use nested conditions.

This is an example of what I mean:

$#DOW#=0?SU:$$#DOW#=1?MO:$$#DOW#=2?TU:$$#DOW#=3?WE:$$#DOW#=4?TH:$$#DOW#=5?FR:$$#DOW#=6?SA:$

2 Likes

Used concatenated over nested conditionals so much as they are just easier to noggin and they can’t be repeated in threads enough as useful.

Unfortunately they only seem useful as a display switch and … Well…

OK. I’m going to finish setting up a sample progress bar and text displays for a working SR-SS with Now as % and open it up for a challenge for SS-SR crossing the midnight line.

1 Like

So, The challenge is to fix the second text block and progress bar for time and %complete for time between sunset and now across the midnight line.

I can’t find it on search and I now have to do the thing where you lie down and all the other lives happen. I hope I get one of the levitation ones.

2 Likes

Sorry, I am not sure what are you trying to calculate. After sunset the minutes left before next sunrise?

2 Likes

I think I understood.
The bar is to start at sunrise and end at sunset. I’ll set out what I have come up with so far. Here some assumptions:

  • I will use the width of a rectangle instead of a progress bar, I think it is easier
  • We cannot make a bar that starts at sunset and travels to sunrise. We do not know the sunrise of the next day. So bar width is during the day, from sunrise to sunset.
  • There is no place on earth, where sunrise is past midday, but is not an issue here
  • I will not consider sunset after midnight at this point. This can be the case way up north in summer

So for the bar width to be 0 at sunrise, we need the current time (using 24h as scale) - sunrise time:
(#DWFHS#-15*(#WRH#+(#WRm#/60)))

I used DWFHS for better smooth width progress, hence need to multiply by 15 of the sunrise time

Ok next step is to figure out how to put in the overall daytime in the width of the bar.
For a start we may need the exact daytime. In the example sunrise at 7:14 to sunset at 6:34, is 680 minutes or 11.3333 hours:

(60*(#WSH#-#WRH#)-#WRm#+#WSm#)

So far so good… stay tuned, or someone else can jump in…

3 Likes

Sunrise to sunset is the easy part and that works in the example (which switches SR and sunset as they rotate. When the top text is white the progress works.
I was hoping not to have to swap out progress bars for different calculations but may have to.

Sunset to sunrise is the hard part.

For example, Sunset 18:00 then it’s easy so know that at 23:00 5 hours has passed but what about at 01:00.
So, you can work that out by SR->midnight duration + midnight->now duration but you only use that when now>=00:00 and I can’t work out how to conditionally use one calculation before midnight and another after, or, a single calculation that accounts for both sides of midnight for Now.

With regards to using a rectangle over progress bar, I think that would add complexity. I am already calculating the percentage progress. With a rectangle I would then have to add calculation of that percentage of the total shape length and update the calculation with any shape change.
.75 is always .75 on a progress bar but .75 of 100, 200, 140…

3 Likes

OK. went with serial conditions as the panacea of conditional fallbacks.

Also had to go with shapes as, although the text area of fill ratio shows the correct value on paste of a conditional it does not change with time.
I ended up with:

(Now Minutes minus Rise Minutes)/(Set Minutes minus Rise Minutes)
$#DISDAYTIME#==true?([StartX]+([Length]*((((#DH#*60)+#Dm#)-((#WRH#*60)+#WRm#))/(((#WSH#*60)+#WSm#)-((#WRH#*60)+#WRm#))))):$

(Now Minutes minus Set Minutes)/((Set minutes until midnight)+(Midnight until Rise minutes)
$#DISDAYTIME#==false&&#DH#>=#WSH#?([StartX]+([Length]*(((#DH#*60)+#Dm#)-((#WSH#*60)+#WRm#))/(((((#WSH#-11)*60)-#WSm#)+(((13-#WRH#)*60)+#WRm#))))):$

(Sunset to Midnight plus Midnight to Now)/(Set minutes until midnight )+(Midnight until Rise minutes)
$#DISDAYTIME#==false&&#DH#<=#WRH#?([StartX]+([Length]*((((#WSH#-12)*60)-#WSm#)+((#DH#*60)+#Dm#))/(((((#WSH#-11)*60)-#WSm#)+(((13-#WRH#)*60)+#WRm#))))):$

2 Likes

Another progress bar addendum.
The problem with the bar progress is that it didn’t like an empty if not met on conditionals $true?value:$
Circular progress seem to work fine with it. Why they should be functionally different and not just in shape I haven’t a scooby. maybe @Facer_Official will have one.

If you use $true?value:0$ then the bar version works but has a big pause of the entire face when hitting sunrise as 1 becomes 100 for fill ratio and it has a small fit it needs to recover from.

2 Likes

So is it working now . I must test it . :blush:

1 Like

Dropped you a personalised version for 'AINT

1 Like

Bless . Thank you very much indeed
I hope to publish it again on Sunday without he Watchy refrence .

1 Like

From sunset to sunrise: I guess you can neglect the exact sunrise time, because the value we have is from the current day and not the next day. The difference is less than a minute, depends a bit how close to the equator you are.

2 Likes

I don’t know if SR changes over at SS or not. It’s not testable in designer as the SR and SS are set at page load or time machine refresh and does not update as days, or even months progress. Also the locale is fixed at Los Angeles.

2 Likes

Ha Ha yes . However I see no jump in your Formula . I think +/- two minutes is a good Tolerence on something like this . Varios SR SS tabes I use are often 2 minutes differet . Ther is always the debate about which is sunrise. Disc touching or Half way . Give or take Two minutes . I have 2 spare to witness either .

2 Likes