Tuesday 18 June 2013

WiseMove: a HTML5 Mobile App - full example with source - Part 1

In this small series of posts I will introduce a HTML5 Mobile App named WiseMove, and the technologies and tools used to build it.

The app is available on-line (in form suitable for desktop) at the following location: wisemove.ppettit.net

The app can be packaged for mobile using Cordova and full source code is available at http://github.com/phillp/WiseMove



The app is intended to serve a real, albeit small purpose.  WiseMove is aimed at assisting a person moving house to evaluate locations.  The user is able to place pins on a map that represent locations the user is considering moving to, or locations the user will visit.   The user is able to score locations by any measure they define.  The app also looks up route information from google to determine likely travel times.



The subjective scores and travel times are displayed in charts and tabular forms.



There are a very large number of frameworks and libraries in which this application could have been successfully built.  The libraries I used were:

  • JQuery Mobile
  • Knockout JS
  • Google Maps
  • Flot charts
  • QUnit JS  
The development environment included:
  • Ubuntu
  • WebStorm
  • Ripple Emulator
  • NodeJS (as static content server)
In the next post I'll dig into the way the libraries were used in detail.

Friday 7 June 2013

NSimulate: a discrete-event simulation library for .NET

This is the first post in my blog in which I plan to talk about software development topics or announce details of some of the projects (usually open-source) that I work on from time to time.

One of my recent projects has been the development of an event simulation library for .NET.  The library is open-source (MIT style license) and available on github:  http://phillp.github.io/NSimulate/

My aim for the project was to produce a flexible library that is extensible and supports simulation of processes, activities, resources and event notifications.

Some inspiration for this comes from the Simpy (python) simulation package.

There are several examples included with the library in which I have tried to demonstrate the various usage patterns.  These examples are the fairly typical set for this kind of thing, but (I hope) are implemented in a concise way.

Examples include:

  • Workshop with unreliable machines
  • Call-center with call escalation
  • Order delivery with warehouse reorder
  • Alarm Clock

Each simulation runs until an end-condition (specified as a delegate) is met.

The simulation is single-thread, and processes are implemented as iterators using the c# yield statement (so that process logic can be written cleanly and without the need for callbacks).  When a process yields a result, the process logic is paused until some condition (indicated by the yield result) is met; this may be the availability of a resource, the occurrence of a specified event, or simply the passing of a certain amount of simulation time.

One example implementation of a process is shown below.

// while the simulation is running
while(true){
 // check if the queue for this machine is empty
 if (JobQueue.Count == 0){
  // if it is, wait until there is something in the queue
  yield return new WaitConditionInstruction(()=>JobQueue.Count > 0);
 }
 else{
  // take a job from the queue
  var jobToProcess = JobQueue.Dequeue();

  // simulate processing the job
  // which takes time
  yield return new WaitInstruction(jobToProcess.ProcessingTimeRequiredByJobQueue[JobQueue]);

  // use the reliability indicator to determine if the machine is broken down
  if (CheckForRandomBreakdown()){
   // the machine has broken down
   // add the job it was processing back to the queue
   JobQueue.Enqueue(jobToProcess);

   // obtain a repair person
   var allocateInstruction =  new AllocateInstruction<RepairPerson>(1);
   yield return allocateInstruction;

   // and wait for the machine to be fixed
   yield return new WaitInstruction(RepairTimeRequired);

   // then release the repair person resource
   yield return new ReleaseInstruction<RepairPerson>(allocateInstruction);
  }
  else{
   // record the fact that the job has been processed by this machine type
   jobToProcess.ProcessingTimeRequiredByJobQueue.Remove(JobQueue);

   // if the job still requires other processing
   if (jobToProcess.RequiresMoreWork){
    // add it to the next queue
    jobToProcess.ProcessingTimeRequiredByJobQueue.Keys.First().Enqueue(jobToProcess);
   }
   else{
    // otherwise remove it from the all unprocessed jobs list
    _unprocessedJobsList.Remove(jobToProcess);
   }
  }
 }
}
All feedback is welcome and thanks for reading.

http://phillp.github.io/NSimulate/