<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/"><channel><title>2017-02 on Funky Si's Test</title><link>https://blog-test.funkysi1701.com/2017/02/</link><description>Recent content in 2017-02 on Funky Si's Test</description><generator>Hugo -- gohugo.io</generator><language>en-gb</language><managingEditor>funkysi1701@gmail.com (Simon Foster)</managingEditor><webMaster>funkysi1701@gmail.com (Simon Foster)</webMaster><lastBuildDate>Mon, 27 Feb 2017 20:00:45 +0000</lastBuildDate><atom:link href="https://blog-test.funkysi1701.com/2017/02/index.xml" rel="self" type="application/rss+xml"/><item><title>Learning R</title><link>https://blog-test.funkysi1701.com/posts/2017/learning-r/</link><author>funkysi1701@gmail.com (funkysi1701)</author><pubDate>Mon, 27 Feb 2017 20:00:45 +0000</pubDate><guid>https://blog-test.funkysi1701.com/posts/2017/learning-r/</guid><category term="ExchangeRates">ExchangeRates</category><category term="R">R</category><media:content medium="image" type="image/jpeg" url="https://blog-test.funkysi1701.com/images/2017/Exchange-Rate-Calculator.jpg"/><description>&lt;p&gt;
&lt;img class="img-fluid" alt="R" src="https://blog-test.funkysi1701.com/images/2017/Exchange-Rate-Calculator.jpg" loading="lazy"
width="1024" height="689"
/&gt;
Today I spent some time learning the R language.&lt;/p&gt;
&lt;p&gt;The problem I was trying to solve was to convert local prices of some items into Euros. I had been using a fixed exchange rate for all data, but as exchange rates fluctuate so much this is incorrect.&lt;/p&gt;
&lt;p&gt;My first though was to find a free API that I could query to get the values I wanted. The first API I found didn’t cover all the currencies, the next one I found I burnt through the free allowance in one pass.&lt;/p&gt;
&lt;p&gt;A colleague of mine mentioned using R to solve this, he sent me some links and I set out to write my first piece of R code.&lt;/p&gt;
&lt;p&gt;My finished code can be found on &lt;a href="https://github.com/funkysi1701/ExchangeRate/blob/master/script.R" target="_blank" rel="noopener noreferrer"&gt;github&lt;/a&gt;
and I will attempt to explain some of it.&lt;/p&gt;
&lt;p&gt;R defines functions fairly simply&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-r" data-lang="r"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;nameoffunction &lt;span style="color:#f92672"&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;function&lt;/span&gt;(arg1, arg2)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; arg1 &lt;span style="color:#f92672"&gt;*&lt;/span&gt; arg2
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I have created a function that takes 2 parameters date and currency. I know I have about 10 different currencies that I want to get currencies for and I want to loop through each day so I will need to pass in a date.&lt;/p&gt;
&lt;p&gt;The source of my exchange rate information is the &lt;a href="https://www.xe.com" target="_blank" rel="noopener noreferrer"&gt;www.xe.com&lt;/a&gt;
website, its historical exchange rate page passes currency and date into the query string so I should be able to build up a string containing all the different elements.&lt;/p&gt;
&lt;p&gt;All programming language can concatenate strings and R is no different. R uses paste()&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-r" data-lang="r"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;var &lt;span style="color:#f92672"&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;paste&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;Hello&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;World&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;However R has an annoying feature in this function. I would expect that var in the above example would contain &amp;ldquo;HelloWorld&amp;rdquo;, it doesn’t it contains &amp;ldquo;Hello World&amp;rdquo;. Why it automatically adds a space I don’t know?&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-r" data-lang="r"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;var &lt;span style="color:#f92672"&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;paste&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;Hello&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;World&amp;#34;&lt;/span&gt;, sep&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I am not entirely sure what all of the code does but I can take a good guess.&lt;/p&gt;
&lt;p&gt;read_html() I would guess loads a html page, html_nodes() finds all the html tags of a certain type on the page, in my case &amp;lt;table&amp;gt;, html_table() reads the first table it finds.&lt;/p&gt;
&lt;p&gt;table1[2] selects the second column, and head() selects a specific number of rows. I want the first row and second column so I combine these two as head(table1[2],1)&lt;/p&gt;
&lt;p&gt;Now that I have found my exchange rate what do I do with it? R can read and write to SQL Server so why not store this info in a SQL lookup table. I can then use this data in a stored procedure when I process my data.&lt;/p&gt;
&lt;p&gt;To query sql you can use sqlQuery(), it has two parameters, a sql connection and a TSQL command (eg a SELECT, INSERT, UPDATE statement)&lt;/p&gt;
&lt;p&gt;I use a while loop to loop through every day between 1st October 2016 and today and look up the exchange rate for each currency.&lt;/p&gt;
&lt;p&gt;For now I am manually running this R script, however there are ways to run R directly from SQL Server which I may well investigate. I could then have a SQL job to run this on a schedule, maybe once a day to get the latest exchange rates. I also would like to do something a bit cleverer like only getting exchange rates for the days that I need them by querying existing database tables.&lt;/p&gt;</description></item><item><title>Side Project – Connect 4</title><link>https://blog-test.funkysi1701.com/posts/2017/side-project-connect-4/</link><author>funkysi1701@gmail.com (funkysi1701)</author><pubDate>Mon, 06 Feb 2017 20:00:45 +0000</pubDate><guid>https://blog-test.funkysi1701.com/posts/2017/side-project-connect-4/</guid><category term="Connect4">Connect4</category><category term="PWA">PWA</category><category term="Website">Website</category><description>&lt;p&gt;Hello?&lt;/p&gt;
&lt;p&gt;You have probably like me almost forgotten about this blog. Life has got in the way over the last few months, but lets see if I can restart my blogging habit.&lt;/p&gt;
&lt;p&gt;
&lt;img class="img-fluid" alt="Connect 4 board game" src="https://blog-test.funkysi1701.com/images/2017/Connect4.png" loading="lazy"
width="639" height="553"
/&gt;
&lt;/p&gt;
&lt;p&gt;In 2017 I want to start a side project for a few reasons. I want to improve my coding skills and look at things I wouldn’t normally during my day job.&lt;/p&gt;
&lt;p&gt;I have been trying to decide what to build. The actual project doesn’t matter too much, it is the techniques I use during build that matters the most. I would like something that I can start off as a windows app and then extend onto the web or mobile apps.&lt;/p&gt;
&lt;p&gt;I started off thinking about a Rubik’s cube app, however my initial coding has lead me to believe it is probably too complex for my first app.&lt;/p&gt;
&lt;p&gt;Last year I spent an evening looking at Connect 4 during a &lt;a href="https://yorkcodedojo.github.io/" target="_blank" rel="noopener noreferrer"&gt;York Code Dojo&lt;/a&gt;
session. I think this should be complex enough that I can code some logic to efficiently solve the game, however not too complex I get defeated before building too much.&lt;/p&gt;
&lt;p&gt;So far I have built a console app that displays via Console.Write() commands, a grid to represent the game, with 0 meaning empty, 1 red and 2 yellow etc. I am currently working on the logic to solve the game, once I have that in a good state I can extend into a winforms app, into a web (MVC most likely) app and finally a mobile app (I have no knowledge about how to do this yet, but something I would like to try one day).&lt;/p&gt;
&lt;p&gt;Over the last few days I listened to .NetRocks where they discussed &lt;a href="https://www.dotnetrocks.com/?show=1396" target="_blank" rel="noopener noreferrer"&gt;Progressive Web Apps&lt;/a&gt;
. This sounds like a great challenge for me to aim for. A progressive Web App is a website that automatically detects various properties to give you an app that runs well whatever the state of your internet connection and whatever browser you are in.&lt;/p&gt;
&lt;p&gt;I have lots to learn but I can split it down into small sections and I can build something that demonstrates some of my skills.&lt;/p&gt;</description></item></channel></rss>