Message Boards Message Boards

HackUPC: BarcelonaTech's Hackathon

Awesome. That's my one-word summary of HackUPC this past weekend. Seeing 400 international students take the initiative to turn dreams into reality was an inspiring experience for me and my twin brother @Jofre Espigule.

enter image description here

Friday's night opening ceremony at the Sports Pavilion of Universitat Politècnica de Catalunya.

Opening Talk

Hack UPC took place in UPC's North Campus in sunny Barcelona. And it was made possible thanks to Miquel Llobet (founder of Hack UPC), the Major League Hacking, the sponsors (Wolfram, Skyscanner, Everis,...), and an amazing team of volunteers. Here are the TravelDirections to Hack UPC:

HackUPC venue

Jofre and I got some cool Wolfram swag to give away. We also demoed a bunch of code examples to people interested in the the Wolfram Language. And we helped several teams that came to us with great ideas. Below is one of the hacks I demoed there, a "Weather Station in a Snap" similar to @Arnoud Buzing Arduino Yún weather station but using the new Sense HAT for the Raspberry Pi.

hat = DeviceOpen["SenseHAT"];
bin = CreateDatabin[];
RunScheduledTask[DatabinAdd[bin,<|"temp" -> DeviceRead[hat, "Temperature"], "hum" -> DeviceRead[hat, "Humidity"], "pres" -> DeviceRead[hat, "Pressure"]|>], 120]

Weather Station

Temperature, humidity and pressure measurements were being added in a regular basis at this databin: https://wolfr.am/aDkxtY91.

Now let's take a look at some great Wolfram projects done by students at Hack UPC. The first project that I want to share with you was about cryptography. And it was carried out by two students, Xavier Perranau and Arnau Bordas. Right after signing in to WOLFRAM DEVELOPMENT PLATFORM they got familiarized with functions covered in the WLanguage Guide about Cryptographic Number Theory. Their next step consisted in developing a cloud service to allow users send encrypted messages. And after some trial and errors, they ended up adapting the example Hide Secret Messages in Images from the WL Code Gallery. They called their project Steganography a la Wolfram which allows users to drag and drop an image in two cloud-deployed FormFunction to wether hide a text message on it or decipher a message previously inserted in the image.

Here is how it works. A function called InsertSecretMessage is defined to insert a string into a photo:

InsertSecretMessage[carrierImage_Image, mesg_] := 
  Block[{carrierBytes, pixelChannels, secretBits, secretBytes}, 
   carrierBytes = BitAnd[ImageData[carrierImage, "Byte"], 254];secretBits = Flatten[IntegerDigits[ToCharacterCode[ToString[mesg, InputForm, CharacterEncoding -> "ASCII"]], 2, 8]]; 
    secretBytes = Fold[Partition, PadRight[Join[IntegerDigits[Length[secretBits], 2, 48], secretBits], Times @@ Dimensions[carrierBytes]], 
      Reverse[Rest[Dimensions[carrierBytes]]]]; Image[carrierBytes + secretBytes, "Byte"]]

Then, an advanced FormFunction with four fields named "Message","Image","ByEmail" and "SendTo" is cloud-deployed with the InsertSecretMessage function added inside a conditional to see if the user wants to send the image by email with SendMail or just generate it on the Wolfram Cloud:

 CloudDeploy[FormFunction[{"Message"->"String","Image"->"Image","ByEmail"->{True,False}, 
"SendTo"-><|"Interpreter"->"EmailAddress","Input"->"nomail@exemple.com"|>},
If[#ByEmail==True,SendMail[#SendTo,{"Email from Wolfram",InsertSecretMessage[#Image,#Message]}],InsertSecretMessage[#Image,#Message]]&,
AppearanceRules-><|"Title"->"Wolfram Steganography Insertion","Description"->"Insert your plaintext message here and we will add it to the image of your choice."|>,
FormTheme->"Black"],"insert",Permissions->"Public"]

https://www.wolframcloud.com/objects/user-bb7ad2a9-a624-45e5-a867-8da9c0832887/insert

insert

To get back the previously given string, an ExtractSecretMessage function is declared and inserted in the following simple FormFunction.

ExtractSecretMessage[img_Image] :=Block[{secretData, messageLength},
  secretData = Flatten[BitAnd[ImageData[img, "Byte"], 1]];
  messageLength = FromDigits[Take[secretData, 48], 2];
  secretData = Partition[Drop[secretData, 48], 8];
  ToExpression[ FromCharacterCode[FromDigits[#, 2] & /@ Take[secretData, messageLength]]] ]

CloudDeploy[FormFunction["Image"->"Image",ExtractSecretMessage[#Image]&,
AppearanceRules-><|"Title"->"Wolfram Steganography Extraction","Description"->"Insert your image here and you will get the Text"|>, 
FormTheme->"Black"],"extract",Permissions->"Public" ]

https://www.wolframcloud.com/objects/user-bb7ad2a9-a624-45e5-a867-8da9c0832887/extract

extract

The project awarded with the Skyscanner Prize was GrooveScanner: quality events on a budget because planning just got easy. A project developed by a group of polish students that consisted in building a service that searches for cheapest most convenient flight and nearest accommodation to the venue requested. What makes it unique is the combination of Skyscanner API and Wolfram Alpha API for Transportation.

GrooveScanner WA airports

Finally, the project that won the Best Use of Wolfram Tech Award was .... DriveFlyTeleport! Sightseeing: The Smart Way. Given three main constrains which are: time, money and the topics a person is interested in, the system determines which places in the area (museums, monuments, places of interest in general) are the best fit. It uses a Wolfram Cloud API and a twitter handle of any given user to get the text content from his timeline and analyze it to see which of the travel options may fit him best: https://github.com/adamszewe/HackUPC-Wolfram

DriveFlyTeleport

Congratulations to all HackUPC participants for coming up with such amazing projects!

http://hackupc2016.devpost.com/submissions

POSTED BY: Bernat Espigulé
3 Replies

Most developers in HackUPC were not familiar with the Wolfram Language and they were using other programming languages (i.e. Python, JavaScritpt, ...). And of course, they were not aware that the Wolfram Language can be fully integrated into their projects.

So, I started by showing them how easy is to embed WL code into other programming languages using the EmbedCode Function. I created an APIFunction using ImageIdentify as an example:

APIFunction[{"image" -> "Image"}, ImageIdentify[#image] &]

Then I deployed to the Wolfram cloud with CloudDeploy and finally I specified the programming language to which embed the WL code (Python in this particular case):

EmbedCode[ CloudDeploy[APIFunction[{"image" -> "Image"}, ImageIdentify[#image] &], Permissions -> "Public"], "Python"] 

The result is the following Python code:

from urllib import urlencode
from urllib2 import urlopen

class WolframCloud:

    def wolfram_cloud_call(self, **args):
        arguments = dict([(key, arg) for key, arg in args.iteritems()])
        result = urlopen("http://www.wolframcloud.com/objects/e9a0e41f-120a-4d54-925a-835108932f", urlencode(arguments))
        return result.read()

    def call(self, image):
        textresult =  self.wolfram_cloud_call(image=image)
        return textresult

And now the API can be called easily using Python, for example sending the following picture of a dog to our API gives a "Labrador retriever" as a result:

a = WolframCloud()
result = a.call('https://www.petfinder.com/wp-content/uploads/2012/11/dog-how-to-select-your-new-best-friend-thinkstock99062463.jpg')
print(result)

After explaining how to do this it was straightforward for the HackUPC teams to implement the Wolfram Language into their projects. For example the team winning the Best Use of Wolfram Tech Award: DriveFlyTeleport! Sightseeing: The Smart Way used the Wolfram Language to get data from Wikipedia with WikipediaData Function of the most touristic places in Barcelona and then create Jaccard Indices with the Wikipedia data and the user twitter account text information, in order to guess the preference of the user on what to visit first:

 jaccard[a_, b_] := ( c = Length[Union[a, b]]; d = Length[Intersection[a, b]]; d / c )

    listOfWords[topic_] := (    
        wikipediaData = WikipediaData[topic];
        wikiList = StringSplit[wikipediaData, Except[WordCharacter]..];
        wikiListLower = Map[ToLowerCase, wikiList];
        stopWords = WordData[All, "Stopwords"];
        lowerNoStopWords = Select[wikiListLower, Not[MemberQ[stopWords, #]] &];
        lowerNoStopWords
    )

    cleanWords[s_] := (
        wikiList = StringSplit[s, Except[WordCharacter]..];
        listLower = Map[ToLowerCase, wikiList];
        stopWords = WordData[All, "Stopwords"];
        lowerNoStopWords = Select[listLower, Not[MemberQ[stopWords, #]] &];
        lowerNoStopWords
    )


twitterJaccard[txt_] := (
    twitterWords = cleanWords[txt];

    wordsSagradaFamilia = listOfWords["Sagrada Familia"];
    wordsMuseuPicasso = listOfWords["Museu Picasso"];
    wordsParkGuell = listOfWords["Park Güell"];
    wordsHardRockCafe = listOfWords["Hard Rock Cafe"];
    wordsCampNou = listOfWords["Camp Nou"];


    jaccardSagradaFamilia = jaccard[twitterWords, wordsSagradaFamilia];
    jaccardMuseuPicasso = jaccard[twitterWords, wordsMuseuPicasso];
    jaccardParkGuell = jaccard[twitterWords, wordsParkGuell];
    jaccardHardRockCafe = jaccard[twitterWords, wordsHardRockCafe];
    jaccardCampNou = jaccard[twitterWords, wordsCampNou];

    jaccardIndices = {
        jaccardSagradaFamilia,
        jaccardMuseuPicasso, 
        jaccardParkGuell, 
        jaccardHardRockCafe,
        jaccardCampNou 
    }


)

Note that they created a function called jaccard which I think it is equivalent to the built in function called JaccardDissimilarity.

Finally they embedded the code in Python as I showed earlier with EmbedCode function.

class WolframCloud:

    def wolfram_cloud_call(self, **args):
        arguments = dict([(key, arg) for key, arg in args.iteritems()])
        result = urlopen("http://www.wolframcloud.com/objects/e41033e5-9612-4e54-b523-ad886925f1e", urlencode(arguments))
        return result.read()

    def call(self, text):
        textresult =  self.wolfram_cloud_call(text=text)
        return textresult

For more details you can find the source code in Github here: https://github.com/adamszewe/HackUPC-Wolfram

Adding here some HackUPC top projects that could had been done with Wolfram but were NOT:

Menjadora: device to schedule feeding times for pets using the Raspberry Pi. (3rd prize winner).

Menjadora

n-Snake: an up to 5-dimensional version of the classic game. Select a dimension to get a projection of a square, cube, or a 4-, 5-, or 6-dimensional hypercube. Rotate the projection and try some of the random projections.Try it out http://n-dimensional.nifty.ninja/. (2nd prize winner).

4-snake

Want more? Go to the Wolfram Demonstration Project and try to play Billiard in a 4D Hypercube.

TEXsavvy: generating beautiful LaTeX CVs and websites from Linkedin. (1st prize winner).

TeXsavvy

HackEyes: a Raspberry Pi robot controlled by air gesture and VR.

Hack Eyes

Starduino: a happy little Arduino who wants to stargaze with you. Selected celestial objects get pointed by a red-light laser using servomotors controlled by an Arduino.

Starduino

If you are interested in doing something similar with the Raspberry Pi and the WL, take a look @Tom Sherlock's Serial Interface Control of Astronomical Telescopes.

Happy Hacking!

POSTED BY: Bernat Espigulé

enter image description here -- you have earned Featured Contributor Badge enter image description here Your exceptional post has been selected for our editorial column Staff Picks http://wolfr.am/StaffPicks and Your Profile is now distinguished by a Featured Contributor Badge and is displayed on the Featured Contributor Board. Thank you!

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

Group Abstract Group Abstract