Quick, Fun, Hacky Side Projects with WL and Cloud

Bob Sandheinrich, Wolfram Research

(RowDefault[, (Spacer1), , (Spacer1), ])  #WolframTechConf

ABSTRACT

Quickly turn fun ideas into products that mostly work

Note: This presentation contains jokes. If I get no feedback from the audience I will assume they were all bad jokes. As a dad, I will proceed undeterred.

Introduction

I spend a lot of time using the Wolfram Language. This has side effects.

I dream of computational sheep

Notebooks for grocery lists (paper is so passe)

Ideas yearn to become code

The Wolfram Language is highly automated. This has benefits.

30 minute hacks create real results

Discover that dead ends before it is too late

Wolfram Cloud makes deployment easy. This has consequences.

My hacky products are in the world

Code-less friends are wildly impressed

This presentation is a quick, fun, hacky rundown, of a few quick, fun, hacky side projects (QFHSPs) I have done.

Pi Slices Daily

The story of a QFHSP in four parts.

Digits of Pi

Every year at Wolfram we get a spike of traffic on mypiday.com ». Getting arbitrary digits of Pi is easy!

SliceOfPi[n_,start_]:=FromDigits@First@RealDigits[Pi,10,n,-start]

SliceOfPi[15,20]

N[Pi,35]

+ Twitter

ServiceConnect allows you to use Twitter from within WL.

twitter=ServiceConnect["Twitter","New"]

Get some tweets:

ServiceExecute[twitter,"TweetList","Username"->"@WolframResearch"]

Make a tweet:

ServiceExecute[twitter,"Tweet",{"Message"->"My Next Tweet, Sent From "<>$MachineName<>" at "<>DateString[]<>" using Wolfram Language"}]

+ Cloud Tasks

I also routinely work with ScheduledTask in cloud

CloudDeploy[ScheduledTask[PutAppend[Now->AirTemperatureData[(Entity["Saint Louis", Entity["City",{"SaintLouis","Missouri","UnitedStates"}], "Entity[\"City\", {\"SaintLouis\", \"Missouri\", \"UnitedStates\"}]", "city"])]-AirTemperatureData[(Entity["Champaign", Entity["City",{"Champaign","Illinois","UnitedStates"}], "Entity[\"City\", {\"Champaign\", \"Illinois\", \"UnitedStates\"}]", "city"])],CloudObject@"STLvsChambanaTempLog"],Quantity[6,"Hours"]],"STLvsChampaignTempTask"]

ReadList@CloudObject["STLvsChambanaTempLog"]

DateListPlot[List@@@%]

= PiSlicesDaily

The most important webpage on the planet @PiSlicesDaily

Github: PiSlicesDaily

Random Haiku generator

About a year ago WordSyllables was published by Mark Greenberg in the Wolfram Function Repository. It undoubtedly represents a lot of work and expertise to create good solution to a hard problem. I quickly decided to use it for something stupid RandomEnglishHaiku.

ResourceFunction["RandomEnglishHaiku"][TextWords[First[ResourceData["State of the Union Addresses"]]["Text"]]]

A bit of web stuff

makeHaikuHTML[Global`lines_List]:=StringJoin["\n<html style=\"height: 100%;\">
  <head>
    <title>a very good haiku</title>
    <link      href=\"https://fonts.googleapis.com/css?family=Dancing+Script&amp;display=swap\"
      rel=\"stylesheet\"
    />
 </head>
  <body
    style=\"
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  margin: 0;
  height: 100%;
\"
  >
    <main
      style=\"
  font: 6vw 'Dancing Script', cursive;
  line-height: 1.5;
\">", StringRiffle[Global`lines, "<br>"], "</main>
  </body>
</html>"]

A webpage completes the QFHSP

CloudDeploy[Delayed[With[{str = ResourceFunction["RandomEnglishHaiku"][]}, If[StringQ[str], ExportForm[makeHaikuHTML[StringSplit[str, "\n"]], {"String", "HTML"}], "Oops"]]],
"Haiku/Random",Permissions->"Public"]

Baseball Reference Player Graph

I am a baseball fan. Baseball is a rich playground for data and statistics. In order to play around with the data I made a scraper for some of the pages on baseball-reference.com. The code for this QFHSP is also in Github.

<<"/Users/bobs/Documents/Bob/BobPersonal/BR-Graph/BRGraph.wl";

Web Scraping

Determining all the teams and their urls:

teams=BRPlayerGraph`TeamList[]

Finding the years a team has been active:

teamyears=BRPlayerGraph`TeamYears[RandomChoice[teams]]

Graph Construction

Scraping players from the rosters of all teams over a time span and creating a Graph were vertices are players and edges represent teammates.

AbsoluteTiming[graph=BRPlayerGraph`TeamYearPlayersGraph[,1980,1981]]

GraphPlot[graph]

Finding paths between players is fast and easy

{firstplayer, secondplayer}=RandomChoice[VertexList[graph],2]

path=FindShortestPath[graph,firstplayer,secondplayer]

AnnotationValue[{graph,path},"Player"]

Cloud Deployment

Export the raw graph

CloudExport[graph,"MX","WTCDemo/MLBPlayerGraph.mx"]

Create a webpage in Wolfram Cloud that imports the graph and writes a random story

CloudDeploy[Delayed[ExportForm[BRPlayerGraph`RandomStory[Import["WTCDemo/MLBPlayerGraph.mx"]],"HTMLCloudCDF"]],"WTCDemo/MLBPlayerStory",Permissions->"Public"]

Baseball Reference Player Graph Results

My story teller with 120+ years of data creates endless computational joy

Notes on the final graph

17669 vertices (players)

2035808 edges (teammates)

GraphDiameter of 9

Minnie Miñoso is the Bacon/Erdős of Major League Baseball.

1388 players are connected to all players in 5 degrees

Top 20 BetweennessCentrality players:

There are many people with Bacon/Miñoso numbers

There may not be anyone with a Miñoso/Erdős number (this requires further study)

Old-timey baseball nicknames are great. A possible QFHSP is to try to quantify the downfall of the great baseball nickname

Typical example

COVID-19 Tools

A QFHSP begins to grow up.

COVID-19 Paclet Code

(* <<COVID19` *)

chambanacovid=COVID19`MetroData[GeoNearest["USCounty",(Entity["Champaign", Entity["City",{"Champaign","Illinois","UnitedStates"}], "Entity[\"City\", {\"Champaign\", \"Illinois\", \"UnitedStates\"}]", "city"]),7],"MetroName"->"Chambana ","MinimumDeaths"->5]

COVID19`DeployMetroData[{"STL",(Entity["Missouri, United States", Entity["AdministrativeDivision",{"Missouri","UnitedStates"}], "Entity[\"AdministrativeDivision\", {\"Missouri\", \"UnitedStates\"}]", "administrative division"])},"COVID19/STLMetro/TimelineGridAndDataTable","MetroName"->"St. Louis ","MinimumCases"->1000]

Thank you

Bob Sandheinrich - Development Manager - Deployed Products and Services

(@bobohilario Inventor of #HashtagsAsCode and @HandlesAsCode)

Too Much Time Left? KanJam Leaderboard