### Project #3: Facemash Clone

I did this small project on a summer weekend in 2015. I just saw the movie “the Social Network” where Marc had  this idea of rating girls using an algorithm called ELO which is actually used for rating chess players based on their wins and losses against other players.

Personally, I think rating girls is disgusting. But rating Bananas and Apples is fine. An I’m more interested in the theory and the Algorithm itself. So I thought, hm, how hard could it be to implement a system like this – turns out: not that hard.

#### Short theory of the ELO algorithm:

The ELO Algorithm is a very simple, but effective rating algorithm. Assume that we are in the world of fantasy curling players. Naturally there are good players out there with a high reputation and a high chance of winning, and not-so-good players wich are less likely to win a game against the big fishes.  Let’s also assume you are a medium level player with a ELO number of 30. The best player has a ELO number of 70. Today is the big day and you will play a match against Player 2 with a rating number of 61. The rank list right now looks like this:

1. Player 1: 70
2. Player 2: 61
3. Player 3: 32
4. You:           30
5. Player 5: 10
6. Player 6:   2

According to the rules of fantasy curling, there has to be a winner and a looser – a remi is not allowed. At the end of the day, you either won or lost. The outcome of the match will affect both players ELO ratings. The more unlikely the win is, the more impact on the overall rating table this match will have. Let’s have a look at both possibilities.

##### Option 1 – You will loose

To calculate the new ElO ratings, you have to understand how the Algorithm works. You only need to calculate the expected point difference of one player, because of the simple fact that

R_A and R_B are the current “pre-match” ELO ratings of Player A and Player B.

E_A is a value between 1 and 0. The 400 you see here is a historic value chosen by a guy named Arpad Elo and is since used for the chess rating system. Surprisingly, fantasy curling uses the same value ;-). But feel free to modify it.

So you lost against Player 2 with a rating of 61, which leads to the E_A value for you of 0.4555054269169921. (This is close to 0.5 wich would mean that the parameter 400 is not idea, but works for our example. I would suggest choosing a smaller value if you working with ELO ratings that close to each other.) According to the rule, your opponent has an E_B of 0.544494573083008.

How does that value generate the new ELO rating?

This is actually even simpler:

Your new ELO number will be your current rating (30) plus a factor k (assumed 10) multiplied by the difference of the S_A value (0 , because you lost, 1 otherwise, 0.5 for a draw, which does not exist here) and your just calculated E_B value:  25.444945730830078.

Player 2 now has a new ELO number of 65.55505426916991.

The k factor defines the impact of the match on the game. The higher the k is, the more impact it has. You can also fine-tune here.

##### Option 2 – You win:

for the unlikely case of a win against one of the leaders of the list, we will result in the following ELO numbers:

Player 2: 55.55505426916992

You : 34.55505426916992

The impact of the match on the table is defined by the constants k, the constant value 400 and the point difference of the opponents (which is variable). The whole systems is based on the simple assumption that games between a higher rated player and a low rated player are more important and have a greater impact on the result. This allows new players wich usually start with an average value to climb up the ladder very fast.

#### Facemash

Similar to our example, Facemash also some kind of system with rounds where 2 opponents can either win or loose a match. Every element starts with a basic value of 2500 rating points. As a user, you now decide who wins the round and the ELO algorithm decides the new value.

Matchmaking is implemented to be random.

It’s a very simple way to get elements in some kind of order. I was actually surprised how well it works.

The face mash clone is written in Python and uses Flask as underlaying framework.

Check out the project on my GitHub – it’s open source.

### Project #2: Secret Santa

the Secret Santa Project was one of my favourites during the time at university. It’s a kiosk-like service for sending anonymous SMS messages with the goal to surprise your friends with a chocolate santa. The chocolate part makes it even better.

### Background and motivation:

At university, I was a volunteer at our local UNICEF university group. In winter semester 2013, we had the task of doing a project that has something to do with Christmas – and in the group we came up with a little game: The original intention was to create a kiosk like interface, which students can use to send anonymous messages to a fellow student and inform them, that he or she just received a little present (we got some chocolate form our sponsor).

### Idea:

1. Go to the UNICEF stand in the hallway, say hello to the people in the unicef shirts and type in the kiosk system:
• the name of the lucky recipient
• the mobile-number or email address
• a short message
2. Check the checkbox if you want to add a personal message pinned to the Chocolate-Santa
3. Be kind and maybe donate some coins you found in your pocket (because there will always be change for the bar visit the night before and who puts change back in the wallet anyway)
4. Every message will be logged in a database, but only be marked as ‘sent’ when we know the message was sent out successfully.
5. She will receive the message via SMS or email including a pickup code! This message is anonymous and will not contain the name field. Even if you entered your name in the sender-field.
6. She will pick up her present at the UNICEF stand in the hallway. Therefore she tells the people in the blue UNICEF shirts her pickup ID (It’s the last 4 digits of the SMS)
7. They will then type the ID in the searchfield and set the checkbox ‘delivered’. TADAAAA: you just sent an anonymous secret chocolate santa!

Every message sent out contains a 4 digit pickup code (the lenght is configurable btw).

The Management view of the system looks like this: not a s pretty, but practical:

The search is implemented in JavaScript wich makes this fuzzy search field very fast and useful.

As a little gimmick, I recently added a small dashboard to keep the motivation of the group at the stand up and tracks their progress with 2 simple values:

We now did this project a couple times and It was totally worth it – besides It was a great learning experience, we had a lot of fun planning the events.

If you like this project, give it  a star on GitHub 🙂

https://github.com/c7h/SMS_Web

### Project #1: Student Timetable

THI Timetable is the inofficial Timetable for Students of Technische Hochschule Ingolstadt. It brings your schedule to any device via iCal without having to install an App – you can use your native calendar application!

### Background and motivation

Although the university provides a working system, it lacks important features like export or sync functionality. Additionally, the usability is poor: It is written with JSP, making it slow. Another Problem is the layout, which is not optimized for mobile devices. The most annoying aspect of this system is, having you to sign in each time you want to check your timetable.

### How:

First I had to analyze the original page. A great tool to look under the hood of a webapp is a browserextension like Firebug. The first step was to reverse engineer the login process to obtain a valid session-id. The prototype of the autenication method looked like this:

https://gist.github.com/c7h/5526802

Next step is to feed it with username and password and it will send a request to the hiplan-app, parse the result using a regular expression and return the session-id. Now we are logged in, we can dig a little deeper. The hiplan-app uses Ajax to load background-data which turned out to be valid JSON. Fancy! Next we have to parse it. We just transformed the event-jsons to objects, so we can use them to export to any format we want – in this case iCalendar-Format. There is a nice python-library called icalendar which gets the job done. So – next step is to combine all these results and create a first version as a commandline tool. It is available on Github. Just have a look at the examples.

https://gist.github.com/c7h/55399f00a956260a30cb

Since the goal is to make this tool accessible to the masses and considering the fact that nobody uses python command line tools, we need a better looking, user-friendly interface. There are several options:

• stay on the commandline-way: small user-base
• Native Apps: Need support for iOS and Android and Windows Phone (just kidding – windows phone was already doomed to fail back in 2014 when I started the project)
• Webapp: Need only one Version for multiple devices / easy to maintain

So I decided for the Webapp. I hosted this service on Googles AppEngine, since it includes everyhing I need: a Python-Webframework called webapp2 that comes with a jinja2-like template system, a data storage which is needed to hold the user data and last but not least probably the most important part: A cron-service to schedule tasks. The system is build on a polling mechanism to scrape the calendar data from the hijacked api, therefore I needed the cron-service to schedule the update-tasks.

If you signed up successfully with your university credentials, your calendar gets parsed for the first time. You will see a success message and a copy-paste text field with a unique url that contains a long, random looking number. This url will point to your calendar in ICAL-Format – a Format which is readable by most native calendar software like google mail, Apple iCalendar, Android etc.. You simply need to pass this link to your calendar software and it will sync on a regular basis. If everything worked as expected, you should see something like this:

You’re welcome.

The service is online! check it out