Group Abstract Group Abstract

Message Boards Message Boards

My “Today's Template” using Mathematica?

POSTED BY: Brian Woytovich
15 Replies
POSTED BY: Chad Knutson
POSTED BY: Brian Woytovich
POSTED BY: Brian Woytovich
Posted 9 years ago
POSTED BY: Updating Name
POSTED BY: Hans Michel

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... Sander Huisman Result Example when I use it from 11.1

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... Hans Michel Result Example when I use it from 11.1

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.

POSTED BY: Brian Woytovich

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...

POSTED BY: Sander Huisman

Ok, thanks Sander, I will take a look at this further, thanks for the feedback!

POSTED BY: Brian Woytovich
POSTED BY: Brian Woytovich
POSTED BY: Hans Michel
POSTED BY: Brian Woytovich

I'm pretty sure you have an older version of Mathematica. I assumed the newest. 2 options: update or change the code...

POSTED BY: Sander Huisman

Sander,

First of all I want to thank you for your time spent on my question for this template. I can see from your profile that you must be very busy and so I do not take it as a light matter that you have taken the time to even help me figure out this code.

Personally, I always want to use the latest version if there is reason, but unfortunately, I do not want to have to spend the extra money for an upgrade if not completely necessary at this time. I first purchased the product, on I believe, November 17th 2014, but have not had the time to use it much after first purchasing it. When I first purchased the product, I thought that it included minor updates.

Could you or someone else confirm that for those of us existing users on Mathematica 10 if upgraded the above code would work moving from 10.0 to the latest 10.4. While I wait for a response I will be trying to learn about the new command differences from 10.0, 10.1, 10.2, 10.3, and 10.4.

Thanks again for your time,

Brian

POSTED BY: Brian Woytovich
POSTED BY: Sander Huisman
POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard