# My “Today's Template” using Mathematica?

GROUPS:
 Brian Woytovich 1 Vote Is there a way to recreate what I’m currently doing in Microsoft Word everyday, using the Wolfram Langue and/OR Mathematica to a CDF Printable Format? It’s fairly simple and strait forward. It is a template I use and print for a magnetic whiteboard I use to do videos. The first number is the year month day displayed in an single eight digit number, the second area is the day of the year / days left in the year, the third is the week number with the day of the week following the ISO standard, the fourth and middle area is the day of the week, month and day, and the year, the fifth is the season and the number of days in that season/ and the days remaining (with the week of that season), the sixth is the current quarter and the days in that quarter / and the days remaining (with the week of that quarter). This “todays template” works as Monday being the first day of the week.For obvious reasons I would like to have it be generated automatically, for less obvious reasons I would like it to be formatted and displayed as in the image (if I am able to successfully upload/share it to the Wolfram Community site).Now I’m sure this is a simple thing to accomplish but as someone trying to depend less upon Microsoft technologies and more upon Wolfram’s I would greatly appreciate any direction. while this is something I will be attempting to recreate on my own eventually, as I become more accomplished in Mathematica and more specifically the wolfram language, and because the Computable Document Format is just that, computable, would it be possible to have the calculations automatically update within this document format itself triggered from the system clock on my computer?Or is there some other method someone could suggest? Something that possibly I have not yet considered like doing the calculations in Mathematica or wolfram alfa and having and them just share the data itself to be displayed in template that I've already created on some other document type.
2 years ago
15 Replies
 Hi Brian,Pretty much all the pieces of text can be generated using DateString. For the remaining dates of the year/quarter I suggest you use DateDifference. You can use a Grid construct to format it like you have above. It can contain anything and you can set the background to White/Black as you have, also you can merge the cells using SpanFromLeft. You can use Style to style the various colors. If I have some more time, I can give it a try.--SH
2 years ago
 Sander Huisman 2 Votes Hi Brian,I made a good start: ClearAll[StNdRd,CreateTemplate] StNdRd[n_String]:=If[IntegerQ[ToExpression[n]],StNdRd[ToExpression[n]],""] StNdRd[n_Integer]:=If[3week,Red,Bold],Style["-"<>dayofweek,Bold]}]}; top={Row[top," | "],SpanFromLeft}; ordinal=StNdRd[DateValue[t,"Day"]]; middle={Style[DateString[t,{"DayName", ", ","MonthName"," ","DayShort",ordinal,", ","Year"}],White],SpanFromLeft}; Quarterstart=Take[DateList[t],2]; Quarterstart={First[Quarterstart],Floor[Last[Quarterstart]-1,3]+1,1}; Quarterend=Quarterstart; Quarterend[[2]]+=3; Quarterend=DateList[Quarterend]; daysinquarter=QuantityMagnitude[DateDifference[Quarterstart,Quarterend],"Day"]; dayofquarter=QuantityMagnitude[DateDifference[Quarterstart,t,"Day"],"Day"]+1; bottom2=Column[{Row[{DateString[t,{"Quarter"}]<> StNdRd[DateValue[t,"Quarter"]]<>" Quarter ",dayofquarter,"/",daysinquarter-dayofquarter}],Row[{"(",daysinquarter," Days"," / 13 Weeks)"}]},"Center"]; Grid[{top,middle,{Null,bottom2}},Frame->All,Background->{None,{None,Black,None}}] ] To try out: CreateTemplate[] CreateTemplate[{2016, 4, 18}] CreateTemplate[{1987, 7, 2}] Giving:I will leave you with implementation the seasons part, the font-choices, sizes, colors, and exact styling...
1 year ago
 Thank you, Sander Huisman! Now just to let you know, I am new to the Wolfram Language and I am currently reading; “An Elementary Introduction to the Wolfram Language.” I am extremely impressed with the speed of this community to produce the code requested. Using the code you have provided, I get the following output…As you can see, the output is different from what you have displayed in you last message. Is there a way to convert it to what you show or am I doing something wrong? Again, I apologize that I’m so green at this! The members in this community have been outstanding with respect to the four questions I have asked to date.It’s going to be a learning curve for me and my friends as we now try to move our ideas to the Wolfram Cloud while we slowly create each of the solutions we need using the Wolfram Language.This template is just one of many components of a greater project that I have been working on for over two decades. When I see the code you have written, I am better able to deconstruct it as I learn the language and apply it to other parts of our ongoing project. This question, as it relates to a template for our white board, will move us more towards Wolfram technologies and away from products such as Word, Excel and PowerPoint.These are probably simple problems for many in this community. I have read some of the impressive profiles of members but for those of us working on our own projects with little background in the Wolfram Language it seems a bit daunting, but we are in this for the long haul! Thank you,Brian
1 year ago
 I'm pretty sure you have an older version of Mathematica. I assumed the newest. 2 options: update or change the code...
1 year ago
1 year ago
 Hans Michel 1 Vote Brian:I don't have much time to give a proper solution; so as time is ticking I will put what I have so far. SetSystemOptions["DataOptions" -> "ReturnQuantities" -> False]; ISOWeek[x_] := Module[{d2}, d2 = DateList[{ToExpression[ DateString[ DatePlus[ x, {(-(Flatten[ Position[{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}, DateString[DatePlus[x, {-1, "Day"}], {"DayName"}], 1]])[[1]] + 4), "Day"}], "Year"]], 1, 3, 0, 0, 0}]; IntegerPart[(DateDifference[d2, x] + Flatten[Position[{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}, DateString[d2, {"DayName"}], 1]][[1]] + 5)/7]]; ISODay = Function[{date}, Flatten[Position[{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}, DateString[date, {"DayNameShort"}], 1]][[1]]]; Grid[{ { Item[Style[ DateString[DateList[], {"Year", "", "Month", "", "Day"}], FontFamily -> "Arial Black", FontWeight -> "Black", FontSize -> 32], Alignment -> Center], Item[Style[ StringJoin[ ToString[ IntegerPart[DateDifference[{First[DateList[]]}, DateList[]]]], " / ", ToString[IntegerPart[ DateDifference[ DateList[], {Plus[First[DateList[]], 1]}]]]], FontSize -> 28, FontFamily -> "Arial", FontWeight -> Bold], Alignment -> Center], Item[Style[ Row[{Style[StringJoin["WK", ToString[ISOWeek[DateList[]]]], Red], Style[StringJoin["-", ToString[ NumberForm[ISODay[DateList[]], NumberPadding -> {"0", ""}]]], Black]}], FontSize -> 30, FontFamily -> "Arial Black", FontWeight -> Bold], Alignment -> Center] }, { Item[Style[ DateString[ DateList[], {"DayName", ", ", "MonthName", " ", "Day", "th, ", "Year"}], FontSize -> 40, FontFamily -> "Calibri", FontWeight -> Bold, FontColor -> White, Background -> Black], Alignment -> Center, Background -> Black], SpanFromLeft, SpanFromLeft }, { Row[ { Item[ Style["Spring 30/63 (2nd)", FontSize -> 24, FontFamily -> "Arial", FontWeight -> Bold], Alignment -> Center], Spacer[50], Item[Style[ StringJoin[DateString[DateList[], "Quarter"], "nd", " Quarter ", "18/73 (3rd)"], FontSize -> 24, FontFamily -> "Arial", FontWeight -> Bold], Alignment -> Center] }, Alignment -> Center , Frame -> False ], SpanFromLeft, SpanFromLeft} }, Frame -> True, FrameStyle -> Thickness[5], Spacings -> {2, 5}] Which would giveThe Seasons, Quarters, and dividers need more work. I had a version with Overlay[Grid[]...]. But that was unstable interns of screen resizing. There used to be a package that calculated Seasons see Scientific Astronomer http://library.wolfram.com/infocenter/Conferences/372/ I attempted to get as close to your original fonts. It would be easier to explicitly state them. My font matching skills are rusty. I'll come back to this later.
1 year ago
 This is great! Thank you both Sander and Brain and to whomever else joins in the assistance with creating this template. I did not expect so much help but only maybe some direction, but this is great! Actually I was already answering Sander by the time Brian had written in but had posted it many hours later before I had a chance to look at yours Brian, the formatting and placement looks great. I'll have to look at the code more closely, and because I am so new it will take me a while, but I like the different approaches so i can better learn this language. Have not yet looked at it in detail but in both cases I am at least getting a better idea. And if anyone else wants to improve upon this even more, it will be welcomed :). Thanks so much for the community's help on this!So, currently every day I figure out the numbers by looking at my calendar and adding or subtracting by hand, and only continue to do this because it's become the way I have always done it up to this point. Obviously even if I just have Mathematica give me the numbers each day it would be easier than doing it all myself, and I could even put it myself in a template, but I like the direction that the those who have answered are taking. To keep us on track with what the numbers should be, as of today, I updated what it should read for TODAY (noticing the first image I think was off a bit) figuring it out myself, and I know even using Wolfram Alpha probably would be easier then counting but like I said, you know how you get into the habit of things :(. Anyway, TODAY's template I think should read the following numbers and also this time included a line through what would be nice but not necessary and what I think my be difficult because of my unique way of calculating this as a "week", but all the other numbers should be exact and easy to calculate each and every day updated, automatically.
1 year ago
 Now with the new version 11.1 could I get help from the community with my daily template I have been trying to recreate it using Mathematica and Wolfram Language for about a year now. At first I thought I might be having trouble because I did not have the latest version but even now that I have upgraded to 11.1 I’m still having trouble with the two examples given to me, but I must say they got me a lot closer in a short time then I ever thought was possible so quickly, but since then I have been in a stand still.Would someone look at the following two examples and see what could be tweaked to give me a complete template as shown in my original example from using word, which I have been having to reenter by hand every time I want to reuse it, and see how it can be completed possibly using some of the newest code from Mathematica 11.1 and do we have anything that can work with seasons?Example by Sander Huisman, when I use it from 11.1 ClearAll[StNdRd, CreateTemplate] StNdRd[n_String] := If[IntegerQ[ToExpression[n]], StNdRd[ToExpression[n]], ""] StNdRd[n_Integer] := If[3 < n < 21, "th", Switch[Mod[n, 10], 1, "st", 2, "nd", 3, "rd", _, "th"]] CreateTemplate[time_: Now] := Module[{t, top, middle, dayofyear, totaldays, week, dayofweek, ordinal, bottom2, Quarterstart, dayofquarter, Quarterend, daysinquarter}, t = Take[DateList[time], 3]; dayofyear = DateValue[t, "ISOYearDay"]; totaldays = If[LeapYearQ[t], 366, 365]; week = DateString[t, "WeekShort"]; dayofweek = DateString[t, "ISOWeekDay"]; top = {Style[DateString[t, {"Year", "Month", "Day"}], Bold], Row[{ToString[dayofyear], "/", ToString[totaldays - dayofyear]}], Row[{Style["WK" <> week, Red, Bold], Style["-" <> dayofweek, Bold]}]}; top = {Row[top, " | "], SpanFromLeft}; ordinal = StNdRd[DateValue[t, "Day"]]; middle = {Style[ DateString[ t, {"DayName", ", ", "MonthName", " ", "DayShort", ordinal, ", ", "Year"}], White], SpanFromLeft}; Quarterstart = Take[DateList[t], 2]; Quarterstart = {First[Quarterstart], Floor[Last[Quarterstart] - 1, 3] + 1, 1}; Quarterend = Quarterstart; Quarterend[[2]] += 3; Quarterend = DateList[Quarterend]; daysinquarter = QuantityMagnitude[DateDifference[Quarterstart, Quarterend], "Day"]; dayofquarter = QuantityMagnitude[DateDifference[Quarterstart, t, "Day"], "Day"] + 1; bottom2 = Column[{Row[{DateString[t, {"Quarter"}] <> StNdRd[DateValue[t, "Quarter"]] <> " Quarter ", dayofquarter, "/", daysinquarter - dayofquarter}], Row[{"(", daysinquarter, " Days", " / 13 Weeks)"}]}, "Center"]; Grid[{top, middle, {Null, bottom2}}, Frame -> All, Background -> {None, {None, Black, None}}]] CreateTemplate[] CreateTemplate[{2016, 4, 18}] CreateTemplate[{1987, 7, 2}] Which gives me the example for today as... Example by Hans Michel, when I use it from 11.1 SetSystemOptions["DataOptions" -> "ReturnQuantities" -> False]; ISOWeek[x_] := Module[{d2}, d2 = DateList[{ToExpression[ DateString[ DatePlus[ x, {(-(Flatten[ Position[{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}, DateString[DatePlus[x, {-1, "Day"}], {"DayName"}], 1]])[[1]] + 4), "Day"}], "Year"]], 1, 3, 0, 0, 0}]; IntegerPart[(DateDifference[d2, x] + Flatten[Position[{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}, DateString[d2, {"DayName"}], 1]][[1]] + 5)/7]]; ISODay = Function[{date}, Flatten[Position[{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}, DateString[date, {"DayNameShort"}], 1]][[1]]]; Grid[{{Item[ Style[DateString[DateList[], {"Year", "", "Month", "", "Day"}], FontFamily -> "Arial Black", FontWeight -> "Black", FontSize -> 32], Alignment -> Center], Item[Style[ StringJoin[ ToString[ IntegerPart[DateDifference[{First[DateList[]]}, DateList[]]]], " / ", ToString[ IntegerPart[ DateDifference[DateList[], {Plus[First[DateList[]], 1]}]]]], FontSize -> 28, FontFamily -> "Arial", FontWeight -> Bold], Alignment -> Center], Item[Style[ Row[{Style[StringJoin["WK", ToString[ISOWeek[DateList[]]]], Red], Style[StringJoin["-", ToString[ NumberForm[ISODay[DateList[]], NumberPadding -> {"0", ""}]]], Black]}], FontSize -> 30, FontFamily -> "Arial Black", FontWeight -> Bold], Alignment -> Center]}, {Item[ Style[DateString[ DateList[], {"DayName", ", ", "MonthName", " ", "Day", "th, ", "Year"}], FontSize -> 40, FontFamily -> "Calibri", FontWeight -> Bold, FontColor -> White, Background -> Black], Alignment -> Center, Background -> Black], SpanFromLeft, SpanFromLeft}, {Row[{Item[ Style["Spring 30/63 (2nd)", FontSize -> 24, FontFamily -> "Arial", FontWeight -> Bold], Alignment -> Center], Spacer[50], Item[Style[ StringJoin[DateString[DateList[], "Quarter"], "nd", " Quarter ", "18/73 (3rd)"], FontSize -> 24, FontFamily -> "Arial", FontWeight -> Bold], Alignment -> Center]}, Alignment -> Center, Frame -> False], SpanFromLeft, SpanFromLeft}}, Frame -> True, FrameStyle -> Thickness[5], Spacings -> {2, 5}] Which gives me the example for today as... This is what I have been wondering, because I am not sure what will be the most efficient way to create the most accurate templet possible, using the wolfram language, but after reading the most recent post by Stephen Wolfram "The R&D Pipeline Continues: Launching Version 11.1" and updates made to "DateObject" function and granular dates could we use the same thing, or is there something similar for seasons, for timing a season precisely, which as you can see from the two examples we have not yet been able to accomplish. Yet with a more precise time period wouldn't we be able to have the season start and end precisely when spring, in this case starts and ends. Yet in the two examples we could not get the season to work, and personally I would not have a clue how to best accomplish this without a more precise function. This and a more accurate frame as shown in my original post is all that is standing in the way of using the Wolfram Langue over the way I have been doing it for years in word, and would save me a tremendous amount of time and frustration.Thanks in advance, for any help from the community.
1 year ago
 Sander Huisman 1 Vote If I execute my code in 11.1 it executes without any errors, make sure you have a fresh kernel without old definitions still in memory or such...How do you define the seasons? there are multiple definitions in the world, and some that even change per year... without a definition it is gonna be hard...
1 year ago
 Ok, thanks Sander, I will take a look at this further, thanks for the feedback!
1 year ago
 Brian: I did not think the partial solution was neing used. I had continued some work on your question, did not post. Currently don't have access to that code. When I find it I will post from where I stopped work.But I had same or similar questions as Sander. And the seasons cross years. Depends on where on Earth so to work every where your code would need location if not accessible then set a default location.
1 year ago
 One big challenge for this template is calculating the seasons because Wolfram Language doesn't have this built-in. That said, WL does have functions that can be used to get a very good estimate for season starts. I used SunPosition for my function. I also considered using Sunrise[] and Sunset[], but the granularity of those functions isn't sufficient to find winter and summer start dates.The following method seems pretty good for the dates I checked, but it is likely not 100% accurate. Here is my code: estSeason[year_,month_]:=UnixTime[DateObject[{year,month,21}]] sunAngle[x_?NumericQ]:= QuantityMagnitude[Last[SunPosition[GeoPosition[{0,0}],FromUnixTime[x],CelestialSystem->"Equatorial"]]] transitionDate[year_,3]:= Module[{res}, res=FindRoot[sunAngle[x]==0,{x,estSeason[year,3]}]; FromUnixTime[x/. res] ] transitionDate[year_,6]:= Module[{res}, res = FindMaximum[sunAngle[x],{x,estSeason[year,6]}]; FromUnixTime[x/. Last@res] ] transitionDate[year_,9]:= Module[{res}, res=FindRoot[sunAngle[x]==0,{x,estSeason[year,9]}]; FromUnixTime[x/. res] ] transitionDate[year_,12]:= Module[{res}, res = FindMinimum[sunAngle[x],{x,estSeason[year,12]}]; FromUnixTime[x/. Last@res] ] findNearestTransition[year_,month_,date_DateObject]:= Module[{possibleDates,candidates}, possibleDates = Join[DateObject[{year,#,19}]&/@{3,6,9,12}, DateObject[{year-1,#,19}]&/@{3,6,9,12}]; candidates=SortBy[{#,Abs[date -#]} &/@ possibleDates,Last][[;;3]]; First /@ SortBy[candidates,Last] ] findSeasonsStart[date_DateObject: Today]:= Module[{year,month,nearestTransitions,seasonChanges,seasonStart,seasonsDef = <|3->"Spring",6->"Summer",9->"Fall",12->"Winter"|>,seasonI,nextSeasonStart}, {year,month}=DateList[date][[;;2]]; nearestTransitions = findNearestTransition[year,month,date]; seasonChanges = Sort[Quiet[transitionDate@@# &/@ (DateList[#][[;;2]]& /@ nearestTransitions)]]; Which[ QuantityMagnitude[date-DateObject[DateList[First[seasonChanges]][[;;3]]] ]>=0 && QuantityMagnitude[date-DateObject[DateList[seasonChanges[[2]]][[;;3]]] ]<0, seasonI=1, QuantityMagnitude[date-DateObject[DateList[seasonChanges[[2]]][[;;3]]] ]>=0 && QuantityMagnitude[date-DateObject[DateList[seasonChanges[[3]]][[;;3]]] ]<0, seasonI=2, QuantityMagnitude[date-DateObject[DateList[Last[seasonChanges]][[;;3]]] ]>=0, seasonI=3 ]; seasonStart = seasonChanges[[seasonI]]; nextSeasonStart = seasonChanges[[seasonI+1]]; {seasonsDef[DateList[seasonStart][[2]]], ToString[Round@QuantityMagnitude[UnitConvert[date-DateObject[DateList[seasonStart][[;;3]]],"Days"]]+1], ToString[Round@QuantityMagnitude[UnitConvert[DateObject[DateList[nextSeasonStart][[;;3]]]-date,"Days"]]-1], DateObject[DateList[seasonStart][[;;3]]],DateObject[DateList[nextSeasonStart][[;;3]]]} ] Some evaluations: In[17]:= (* used Today as default *) findSeasonsStart[] Out[17]= {Spring,36,56,Day: Mon 20 Mar 2017,Day: Tue 20 Jun 2017} In[33]:= (* select a day with DateObject *) findSeasonsStart[DateObject[{2017,4,29}]] Out[33]= {Spring,41,51,Day: Mon 20 Mar 2017,Day: Tue 20 Jun 2017} I stuffed this code into Sander's code, but this post is getting long enough already. I'll email that to you separately.
 For some reason i am having difficulty copying all the code over correctly, so the email worked, somewhat - will explain, but the code above does not, and i am still getting it a day off, even from the email. For instance today when i put in the date to run the template, i get the following results but according to my calculations its actually the 47th day of spring and 45 days until Summer. and this seems to be the same on websites or even apps you download. they all give me the same results. or some just run a clock and you can round it to the nearest day, but i am not sure how to do this in the wolfram language, to get it accurate to at least the day, not necessarily the minute or hour, just the day. CreateTemplate[{2017, 5, 6}] Again, is there anyway you can copy all the code in here so more people can help with it because for some reason i am having difficulty getting all the code copied over. IT's hard to believe this template has been so difficult to create, when someone can download an app today and get all the data, i wounder how they are figuring it, and i would suggest that Wolfram include a season function eventually to make things like this easier. I do truly appreciate everyone's help with this, i never would have guessed that of all things i am tying to do this one would prove to be one of more difficult tasks for us. In fact i have even had trouble making the template a larger size, with an included boarder around the whole thing without other portions being distorted. I do not suppose there is a way to use the manipulate function, or what function could you use, in order to use a slide bar to make the template larger or smaller depending upon what I am using it for. Is that even possible? In fact eventually during what we call our "Seasonal Migration Cycles" that is the period of time when the season begins but before the next Quarter. we would like the dark background to switch from the Date "Saturday, May 6th, 2017" to the section that will read "Summer 01/??", until which time we enter into the 3rd quarter on the first day of July. and then it would revert back to the same format as before. I just did not want to bring this up at first because its not as necessary, and i though it would confuse the issue, but now that we have gotten this far, i think i will just at least through this out there.Again I am not sure why the code is not working here, but it dose from my email, so if the whole of the code could be shared that would be great. And maybe eventually with more people chiming in we will eventually accomplish this task, its only been two years attempting it, so i guess i can be patient :)Thank again for everyone's help.
 Chad Knutson 1 Vote The first day of spring (according to google) was March 20, which is the same date that my code returns. If I number the days since then, I see this: In[38]:= days=DateRange[DateObject["March 20, 2017"],DateObject["May 6, 2017"]]; numDay = Range[1,Length[days]]; list=Transpose[{numDay,days}]; In[42]:= list[[#]]&/@ {1,2,3,47,48} // TableForm Out[42]//TableForm= 1 Day: Mon 20 Mar 2017 2 Day: Tue 21 Mar 2017 3 Day: Wed 22 Mar 2017 47 Day: Fri 5 May 2017 48 Day: Sat 6 May 2017 I guess you define the first day of spring as day 0? If that's the case, then editing my code is a trivial task. Just offset by the day