Getting to grips with unit testing Cordova applications

I have really enjoyed using Cordova to build Android apps because I can knock things up quick and easy. I do have a problem though, sometimes I knock something up quickly and decide that I want to take it further, I then wish that I had thought harder at the start of the project about things such as how I am going to structure and test my code.

One of the problems I have with my latest project, Trivia Quizzes, is that it is a basically bits of code I have pulled out of other projects while getting to grips with Cordova. I quite like Trivia Quizzes and want to go on to expand on it a little; I’m thinking it would be a good base project to learn some new Cordova techniques, I’m thinking of extending it to include Google Play Services scoreboards and achievements. Before I’ed expand I decided to go back and restructure the project properly.

The restructuring was not an easy task. I would move things around in the project only for them to break. I would remove code I thought was redundant only to notice quite quickly that it wasn’t. Since I am writing my application in Javascript I would forget that some things that work on a desktop don’t work so well on a Mobile Phone and I quite often reintroduce bugs in to the code; I think that the programming gods call this a regression. After a bit of searching I found that the the way to fight these is to add little tests to your code to check that units of code still work despite you fiddling with stuff, these tests, believe it or not are called Unit Tests.

Unit Testing in Cordova
I have heard of Unit Testing before, in fact a whole ago I had read ‘The art of Unit Testing‘ by Roy Osherove. I just hadn’t really implemented many tests in to my code. My experiences with Cordova, especially my reorganisation of the Trivia Quizzes project has taught me a lesson.  I’m also hoping it will help with my debugging as I have to admit that debugging in Cordova is not going well for me.  While I have been reading up on debugging on a mobile device or simulator device it is difficult to synchronize breakpoints or retrieve stack traces. Since Cordova is basically HTML/CSS/Javascript it can be debugged in a desktop web browser, but I have found that things such as JavaScript Performance and the phone API availability are difficult things to emulate in the browser. There are a few projects that attempt to get around that, projects such as emulate and gapdebug but it is hard to know what to go with.

I’ve had a poke around different frameworks for unit testing and debugging in Javascript and have come up with a way forward. I am going to create a series of unit tests that I can access from within both the application and when debugging on the desktop. I’m not sure how I am going to write tests for Phone specific activities, like accessing parts of the Phone API, but I am going use unit testing as a way of evaluating the debugging tools.

Creating the testing infrastructure

As far as unit testing in Javascript goes, I like the sound of QUnit as it appears to be regularly updated and as part of the hugely popular JQuery suite has a large user base. JQuery also seems quite simple to set; I created a new folder in my project that with an HTML page, this included QUnits CSS/JS files and  two div’s with specific ID’s in the page. I also included the javascript file that I wanted to start creating tests for (functions.js) and an empty file I was going to plonk my tests in (tests.js):

Heading to that page now gives you a rundown of your tests:

Screen Shot 2014-10-13 at 10.54.16

With that the framework all you need to do is write the tests, QUnit documentation has some great examples. The first thing that went through my head when writing the Unit tests was ‘What exactly is a Unit?’. While it sounds like a silly question ut I found it a great place to start as it makes you think about how your code is structured. This is particularly useful for somebody like me who likes to knock up ideas with bits of code from previous projects I’ve been working on, projects where I may have structured my code slightly differently between them. My first test simply checks that a string is returned from one of my functions:

The key thing I’m taking from this at present isn’t that the Unit Tests check if my code works, but it is making me think about how my code is structured. I was hoping at this point to be writing more tests, but the exercise has made me think about restructuring my code again. I’m going to give it a go and I am hoping that it will be easier this time I have Qunit to help me.


Posted in Uncategorized

New LAK dataset

I’ve been informed by Davide Taibi that the LAK dataset has been updated, this update includes some paper text that I reported on, but also has lots more data. As described by Davide:

This version includes papers from:
- EDM conferences (2008-2014)
- LAK conferences (2011-2014, 2014 only abstract since we are waiting for ACM agreement)
- Journal of Learning Analytics (2014)
- Journal of Educational Data Mining (2009 – 2014)
- Lak data challenge (2013-2014)
- Special Issue of JETS on Learning Analytics (2012)

In total we have 697 papers, 1214 distinct authors and 365 institutions represented in the Dataset.

Moreover, we have added interlinks with Semantic Web Dog Food, DBLP and DBpedia. The number of interlinks will be improved furthermore.

Sounds great!

You can download the RDF and NT dumps here dataset here . If you want the data in R format, you are best downloading the RDF and converting it yourself, this is because the R format hosted on crunch uses an old LAK dump. It is really easy to convert to R using a script I checked in to the LACE project github. I made a video of the process, this was recorded with the old dataset, but I have tried it with the latest one and it works fine.

Posted in Data Analytics Tagged with: , ,

My first mobile app –built with Cordova

I’ve been contemplating getting started with mobile development for a while. On the one hand it feels like there is something very powerful about writing software for portable devices, on the other hand it just felt like there were too many barriers in the way. Cost was always major issue for me and because I am not in the business of writing Apps for a living I hate the idea of paying Apple £100 a year for the privilege of writing applications for a device which costs way more than it should in the first place. When the first Android devices started trickling out I don’t think there was anybody who doubted that it’s market share would soon leave iOS in the dust, I was excited and with the cost being so much lower I thought that I was going to start developing applications for it as soon as I could.

As soon as I got my hands on an Android phone I poked about the development kit… and came to the conclusion that I couldn’t be bothered. I thought it would be nice to knock something up for my phone, but I’ve always been the sort of person to knock out lots of personal projects quickly rather than have my head stuck in a project for 6 months. Despite already knowing my way around Eclipse, the learning curve just seemed to steep for somebody wanting to knock things out quickly. Plus, why should I learn how to do something for Android when it will be different for iOS/Windows Phone/Web?

It annoyed me somewhat that I couldn’t just do it with web technologies with some sort of special middleware that could somehow allow me to access the phones features that a regular native application would do and also allow me to get around some of the issues of hosting software on the web. Particularly since Google is clearly headed towards a world of HTML and Javascript applications/

This apparently annoyed a lot of people and it wasn’t long before a project surfaced that was basically that. Cordova is a set of APIs that allow developers to build phone applications and access the functions of the phone using html/css/javascript. I believe the original project was called PhoneGap but this has since been purchased by Adobe, the underlying functionality is still nice and safe in an Apache project, so you can develop using tjat with your soul in tact.

It’s taken me a few hours of throwing stuff together here and there to get a very basic application together. While it is not a very good application, I’m amazed that I can get something on to the Google play store in a few hours. Here are some thoughts:

It is not quite as simple as ‘make a website, stick it on your phone’. If like me, you have some web development experience but no mobile development experience then the hardest bit will be working out how to package up your application for the different platforms. I have only used Android which lets you self sign your applications making it not too hard, I suspect that publishing to iPhone will be harder as I think you’ll need to sign with a certificate you get from Apple (I’m guessing that’s what the £100 a year buys you). Adobe runs a service that will do the packaging for you, but it only seems to support certain plugins. I wrote some notes about the bits that tripped me up.

Plugin support is amazing. You will need a plugin for anything that is using your mobile phones features. Core functionality is provided by the Cordova project, but there are lots of plugins on Github that extend functionality future, although you will have to be careful they are up to date and the developer wants to continue with them.

You learn a lot about Android development, despite your app being written with web technologies.
I’ve had to go in and fix a few plugins or configuration problems which have helped me to understand the Android way of thinking.

It took me a while to work out how I wanted my configuration. You are using web technologies this is tied to bits of Java. Even though you may not be interested in the Java, the compiler will be, so do you use a Java IDE with web support, or forget the Java and pray the command line Cordova tools just work? At first I used Cordova at the command line mixed with a eclipse with web tools. I then decided to use Eclipse with the android development kit integrated with Cordova.

Most of all, it is fun and you can throw things up quickly. I’ve enjoyed using Unity too, but that is for another post.

My app is very much just a test case, but I like the fact that Cordova supports the idea of just creating ‘test cases’. The Android play store also seems to support the philosophy of letting people play without hassle since it only takes a few hours from submission of something before it appears on the play. I’m not charging for my app or in app purchases and Google seem to be lighter on those kind of apps.

If you are interested, the app currently lives here and is very much in beta.

Posted in Mobile Development

Unexpected Creativity

In gaming circles a ‘shit crayon’ is a term used when a user creates something amazing despite the barriers that have been put in front of them. The term was coined by popular game developer and writer Ian Bogost and draws from the concept of the magic crayon by Chaim Gingold in his thesis. You may have heard of the idea that a magic crayon, a tool that boosts creativity in such a way that the produced artifact would not be possible without the tool. But Bogost suggests that sometimes people create barriers that also boost creativity but are not magic crayons.

‘ the despots who confined Soyinka until he shit poetry onto toilet paper, because he had to do or else go mad in isolation.’

I’m not sure that the story about Wole Soyinka is entirely true, but you get the gist. In gaming circles a discussion about magic vs shit crayons is a discussion around the barriers that a user has found themselves up against. A Magic Crayon is a game that creates barriers or has a ruleset that boosts creativity in some way, a shit crayon is a game that creates barriers or rules that makes life hell for the player, but sometimes they create anyway because it is a game to them.

No developer wants to be accused of handing out the shit crayons. In gaming circles it is somewhat of a joke to do something creative in an awful environment, to draw something brilliant out of the shit crayons. The gamers are not a daft bunch, they know when they have been handed a magic crayon and when they have been handed a shit one, while the art of being creative with a shit crayon may be praised the tool itself is not. The creativity of anything made with a shit crayon is seen as something of a joke, ‘they did it because they could do it, despite the tool. The message to the developer is then mixed, ‘are people using my games to be creative because I am enabling them or because they are mocking me?’.

I think education often hands out the shit crayons. There has been a lot of discussions in the department about learning outcomes this week. I’m not sure where I stand on learning outcomes at the moment, and I am saving it for another post after I have had a chance to think things through. They do sound a lot like the shit crayons to me. When I was teaching at my institution I felt like the confused games developer, the feedback that I was getting back from the students was hard to decipher, are they being creative with shit crayons to spite me or because of the incentive of the piece of paper they need at the end. It would be nice to think they were being creative because of magic. Just how can we tell which crayons we are handing out?

Posted in Technology

The audit of every thought and word

I recently read this great post on Sheila MacNeill’s Blog, one of the many reasons I thought it was a great post being that it was so open and honest. My favourite posts give an insight in to what was going on in the person’s head as their fingers hit the keyboard. Sheila explains that her feelings on the subject made her to write an article in a certain vein, but she couldn’t, the subject of the post interweaved with her own feelings about commenting on the subject.

I told her via twitter that I enjoyed the post because I thought it was honest, which made it an enjoyable read for me. I followed up by saying that I thought an open practitioner is not somebody who just posts stuff online so people can read it, but can really open up about how they feel about a subject and their position in reporting on it.

At the same time as I was tweeting Sheila, Scottish comedian Rob Florence tweeted something:

This Tweet, I guess, was about the recent Kanye West news article, whatever people may think of Kanye West I think the point that Rob is making is still a good one. An open practitioner is expected to put work and thoughts in places where they can be critiqued. Thinking about this and Rob’s Tweet made me feel kind of bad for my suggestion that we may only be called open practitioners if we aim to be honest. While I think that there is something to be said for being honest in your blog post it feels a bit hypocritical of me to type that while I sit here with a folder of half written blog posts on TOR and Tails. Do I go back and delete the Tweet? How honest is that? In a thread on Reddit around the idea of TOR and Tails I recently commented that there are things you may want to hide from your computer usage that do not make you a bad person for wanting to hide.

An age where we are encouraged to pump out consistent honesty through 160 characters is quite a scary one. As Rob points out, how would we survive if all these thoughts and feelings get analysed, sometimes to the extent that they become BBC headlines. The hot topics for me at the moment are honesty and privacy. Honestly, I feel really torn between them.

Posted in Uncategorized

Age of Strategy Android

On booting up Age of Strategy the first thing that you will notice is the sheer amount of content. From the menu you have access to lots of content, the core of which is a series of campaigns, these are a collections of maps that are linked together with a short text story. There are loads of campaigns to play through, most are fictional battles but some are based on historical events. It seems that some of the campaigns are fan built and that this content is added to the game regularly; I was intrigued by the ‘History of Hungary’ section that seems to be filling up with battles based around the Hungarian empire. Perhaps the developer is Hungarian or there is an Hungarian fan of the game submitting content, whatever the case it is interesting that this level of detail is what the developer is aiming for.

Aside from campaigns you can play one off maps or a random game. One off maps are maps that have been designed by fans. Some are pretty cool ideas, for example one is a battle on a chess board, while some are more are serious battles that will make you think about every move. Random mode is like a skirmish game where you can battle a number of AI’s. I like to unbalance things and set up or match in 2v2v1 with an AI on my team or 2v2v1 on my own. You can also play multiplayer online, but I haven’t had a chance to jump in a game yet.

On a first play it seems comparable to Advance Wars, you have units that you move around a battlefield and bases that you can capture to produce more units. There are also worker units that can build different buildings such as attack towers or barracks. It has been a long time since I’ve played AW but there seems to be a wider range of units and buildings in Age of Strategy. The AI is simplistic but seems to be under constant tinkering by the developer. I enjoy the simplicity of the AI because I like strategy games where the human has an upper hand simply because they can work out what the AI will do. Those who find it too easy might want to join a multiplayer game or make the game harder by giving the AI an advantage like setting the game as 2 vs 1.

The length of a game can be quick or long depending on the size of the map and the number of players. On a large map with a lot of players it can start to take a long time for the CPU to take it’s turn, but fortunately there is a ‘skip’ button that hides the animation. Still, on very large maps it started to take a few minutes to wait for every team to have their go.

Unlike many indie strategy games the game never feels too difficult to progress, campaign maps get harder but never feel frustrating. There is also an option to skip a level at the cost of a gem. Gems are the games upgrade system but this is not Candy Crush style robbery and you do not have to buy gems to put yourself on par with other players. Gems are unlocked by completing campaign missions in a certain amount of turns. There are plenty of gems to get very easily and a good reward system to keep you playing. Unlike most Android games multiplayer games can turn the ability to use gems off so that nobody has an advantage. If you do decide you do want to buy gems then there is no official system in place to pay through the Android store, instead he will give out a decent amount of gems to anybody who promotes the game on Twitter and the such. There is a donate button if you feel like you want to give some money back.

This massive battle on a world map was on a 2v2v1 game. It was taking a few minutes for the computer to have it's turn but was really fun.

This massive battle on a world map was on a 2v2v1 game. It was taking a few minutes for the computer to have it’s turn but was really fun. My team mate is fighting the yellows on the African continent. I am building towers and a bridge from Asia downwards to attack the greens (out of the screenshot).

The game is self-described as having ‘limited graphics’, but if graphics are your thing then you properly won’t be looking for a turn-based strategy on Android. Personally I think they are more than adequate, images of units make it quite obvious what they are supposed, a man on a horse with a bow looks suitably different than the man on a horse without a bow. I presume that keeping the graphics ‘limited’ also means that the download is smaller. The only gripe I have is that sometimes it is hard to tell which team a unit is on, this might be because the units were quite small on my phone and some units such as the knight were hard to tell what team they belonged to. You can click a unit to find out if you can move it or not though and on a larger tablet it might be more obvious. I had no other problems playing it on a phone, you can zoom in and out and it never had a problem working out what I was pressing. It did seem to make my battery run flat quite a bit faster, but still much less than any of the top graphic heavy games on the store.

Age of Strategy is a game that represents what I hoped the play store would become about. An independent title by somebody who clearly cares about the game they are making. The game doesn’t feel finished, not because there is content missing or bugs but because the developer seems to constantly tweaking and updating, it feels more like the game is forever growing. The ‘Gems’ system does not affect the gameplay one in any negative sense and is simply a way to give back to the developer for his time if you so wish. There is a forum where you can give feedback and it is taken on board and discussed. It is upsetting to think this is what the store could be about, we need more of this and less ‘pay to win’ EA style games.

This is currently my favourite game on the Android Play Store, I’m starting to lurk about the forum and see what is up and coming next. I’ve recorded a video of myself playing it which you can see below. The game engine works very well and I wonder if it could be used as the basis for a Civilization style game, something which I think hasn’t been done well on the market place.

Posted in Computer Games Tagged with: ,

We were promised jetpacks

Going off very little research except a quick skim read of the Wikipedia page for Education Technology I have discovered that an Educational Technology is something that is ‘improving performance’ in the education system. The page has a few technologies listed as examples; these examples are a mix of both physical and software related things that could be used to improve organisation or connectivity in some way. Criticisms on the page were generally around cost and lack of research in to return on investment.

The reason I was on the Educational Technology Wikipedia page was to see what it said about technologies or criticisms related to privacy. This is because, as the rambling nonsensical nature of my blog presumably reveals, I am very confused about what Education Technology actually is, or whom it is to benefit. One thing I do know is that I have been very interested in privacy recently and since I have job in Educational Technology I presumed the two might be related, so as all students hoping for a quick answer do, I checked Wikipedia.

I know many students who feel trapped by the system because they have to play this weird game of submitting the right sort of data to a particular data entry point in the right format. If they can please the right people with the right assignment type/survey response/loan repayment then they will get through. It feels like an outright bribe might be easier. So, I guess this is why I am interested in privacy and education, because it feels like education system became this skilled manipulator that commands a network of informants against its students. Wikipedia didn’t have anything about these informants or how the system can manipulate students in the EdTech page, but I feel like it should have something about technologies or initiatives that can help the student avoid being caught in the trap and to help them better decisions for themselves.

A colleague last year said that 2013 felt like 2002 to him, there were lots of cool exciting technologies in the pipeline and in a few years the best would be victorious. I pictured that we would be living the dream, presumably flying around the classroom in our jet packs, paid for with Google AdSense revenue. I did not dream that the technologies where mass users are the product will be victorious, I wonder why Facebook purchased the Oculus Rift.

I find it interesting that both privacy and analytics technologies are double-edged swords. Do we employ Learning Analytics as the informant against the student or to empower the student in his decision maing process? What if the best thing for the student is to leave us behind? Does TOR give people the freedom to educate themselves on subjects without censorship or the power to purchase drugs at dirt-cheap Bitcoin prices.

Posted in Education

No Going Back

The survivors huddled around the fire, times had not been easy since The Incident. The group had been on the road for two years already and were getting tired of their endless struggle; they had heard the rumour that up north the city of Graduation was a full of food, jobs and warmth. Many felt that Graduation was their only hope and at their current pace only about a year of travel away. It would be a hard year, but the survivors were no strangers to hardship. In fact, they had really only survived on their journey because of the skills of their leader, Veronica Tutor, an ex software engineer who always carried a small black box with her everywhere she went. Veronica was had a strange attachment to the box, which she affectionately called Pulse, and would sneak a look at it when she thought nobody was looking. Pulse’s purpose was unknown to the rest of the group but would measurement, collection, analyse the status of the survivors and report stats on them back to Veronica. Using this information she would know which survivors would and wouldn’t make it to Graduation, she would leave those with no hope behind and give those who needed it a push to carry on. This would mean that precious resources would not be wasted on the doomed.

The death of David earlier in the week had come as a shock to the group. He had gone out looking for food with Veronica and didn’t come back. Veronica who was usually calm in these situations had been visibly shaken all week.

“That bloody box!”

Screamed Veronica, throwing it in to the fire.

“I dragged David across three counties and every morning he’d say he wasn’t getting up. I would check Pulse, and it would say he could make it, that he had it in him to get to Graduation. Knowing that he could do it I’d convince him. Or push him. Or I’d carry him, if I had to. Until that day, while looting for food in an abandoned computer lab a few Java assignments caught us unaware and cornered us. They forced us to the roof. And when they kept coming… I… I couldn’t make him jump. I couldn’t throw him. So I tried something else. I told him he could have what he bloody wanted and I left him there as I jumped to the next building over by myself. I left him to fail those bloody assignments when I knew he could make it. Its been killing me all week, Pulse told me he could survive and I let him go. But I finally realised that I’d put him on a forced march through hell, when all he really wanted was for me to let him go.”

Posted in Education Tagged with:

House Bolton

House Bolton was one of the lessor of the noble house in the land, only in recent history had it even been acknowledged to be a house by the ruling powers. The last few years for the house had been particularly rocky, but due to a three point strategy of clever accounting, overseas trade missions and the beheading of anybody suspected of being a spy, the house managed to keep itself in check with enough gold in the coffers to avoid the the wrath of Shah Greg IV of the Empire. The Duke had also made several attempts to ally or merge with older and more powerful houses, all of which unsuccessful.

While at least having some money would keep an invasion of Shah Greg troops at bay the Duke still knew that his subjects were being snatched by rival houses. Fewer subjects would mean less income which would led to depleted coffers. The Duke feared this would make Shah Greg remove Bolton’s house status and with an alliance with greater houses now not looking hopeful the Duke knew that something had to be done. A successful kidnapping led to the skills of a great advisor from House East London being acquired to tackle  the problem. While the great advisor may have been shackled to his desk, he was still given unlimited access to the coffers and on his advice two job ravens were dispatched from the citadel; they were tasked with sending a message to the local taverns. House Bolton was looking for a suitable Senior Information Engineer and Data Assistant to be given peerage.

Upon their arrival the Senior Information Engineer set to work creating a drug, the ingredients of which acquired by sending the data assistant in to the forest at night to pick wild herbs. The assistant could not identify all the herbs, but he did a good job of picking the things he thought looked correct. It was, of course, harder at night to tell a Moodle Log Mushroom from a Keycard Swipe Timestamp. After a year of development, against the advice of the Senior Information Engineer, the Duke decided the drug was ready and started to the program of a complete one-pill, once-daily drug regimen taken on an empty stomach at bedtime to minimize dizziness, drowsiness and impaired concentration.

The next day the Duke awoke with extrasensory perception that gave a glimpse in to the future. In front of his eyes he could see many paths. From this day forward, before the duke made any type of physical movement he could see which path the movement would take him on.

The Duke ran to the operations room and hovered his hands over the buttons and studied the paths. He put his hand over the big red button square button, he could see the path before him, a path of millions and millions of subjects, lots of income and the recognition of being a major house. He pressed the button. He moved his hand over all the buttons, evaluated the path and kept pressing. After he had finished he waited for weeks, time passed but the results were not as expected, no more subjects came.

The Senior Information Engineer had warned the king that the drug was not ready, this was because an important ingredient was missing. This was of course bark of a Tweet, available only from House Twitter from the Land of Social Media. So House Bolton paid the large fee demanded by House Twitter for the bark, the Duke doubled his dose, headed back to the operations room and pressed his buttons, a few months later and again nothing had changed. The Senior Information Engineer explained that the drug was missing petals from the Coursera flower found in the gardens of House Ng in the land of For Profit Standford Projects and House Bolton Paid.

The process repeated itself every few months until the money was gone. There was nothing to do but prepare for war. House Bolton was ready for fellow nobles looking for an easy acquisition to come and gobble them up, but nobody did come. It would appear they had also emptied their wallets to foreign lands who were amassing their own armies. All the nobles of the land could do now was wait.

update: I wasn’t aware that there is actually already a House Bolton in Game of Thrones, as this was supposed to be a riff off Dune. Bolton are described my friend Mark Power on Twitter as ‘complete and utter psychos.’ and in GoT wiki as ‘The Boltons are known for their practice of flaying their enemies. ‘   Damn. George R. R. Martin beat me to it.


Posted in Education Tagged with: , ,

Haiku from the Learning Analytics and Educational Data Mining communities

There is a bot on Reddit that crawls through comments and looks for haiku in the text, I like the bot because everything has more of an emotional impact when it’s written as a haiku, even Reddit comments. Inspired by this I had a look online and it turns out there are a few python libraries that will find haiku in text files for you. I opened my LAK14 R workspace, which contains both stats and the contents of papers from various learning analytic conferences and wrote the contents of those papers to a text file (papers$content if you follow the method of grabbing LAK data in the link). I then  ran the python script to pick out a haiku or two and it turns out the learning analytics community are a poetic bunch. These haiku have have been generated from the LAK dataset, they were found using a special dictionary file that contains the number of syllables a word has and therefore will have missed any words unique to the community. The script doesn’t look for seasons in the text either although I’m not sure if haiku actually have to mention a season or not, I’ll ask my Japanese cultural expert @wilm. It picked up hundreds of haiku, but here are some of the best:

A quick answer is
that there is more room to grow
for harder items.

The node is hidden,
so its value cannot be
observed directly.

Within the network
they indicate the people
they interact with.

What modalities
of learning can stimulate.
Learner engagement?

Thus, our model will
retain its ability
to detect “aha!”

Code size, time between
compilations and errors,
for Luca’s logfiles

I wonder if as
a 45 year old I
will feel differently.

My  favourite perhaps sums up educational datamining:

Are a few key words
enough to understand what
students are saying?

Posted in Data Analytics, Education Tagged with: , , , ,