Wednesday, June 30, 2010

Music and lyrics

I've noticed that some of the blog entries have started to have coloured backgrounds which weren't intended. Manually editing the html code only seems to make things worse, so I'm going to write this entry without changing the colour of the text in the hope that this will prevent problems.

I saw the Hugh Grant/Drew Barrymore film "Music and lyrics" again over the weekend. This is a great rom-com and really speaks to me, presumably because Hugh Grant is a has-been musician who has difficulty in writing songs and records in a home studio.

I saw this film in a cinema with my daughter several years ago and even then I was aware that the editing (or continuity) was somewhat suspect - especially the scene which takes place in a diner. Drew Barrymore also manages to change clothes even though she's spending time in Grant's flat and brought no clothes with her. Minor carping aside, Grant and Barrymore could have been the romantic couple of the decade had they made more films together, in the same way that Woody Allen and Diane Keaton defined (for me) the romantic couple of the 70s, and Meg Ryan/Tom Hanks the couple of the 90s.

I am always peeved by this film that the song 'Way back into love' is never performed in its entirety. Grant and Barrymore perform the first two verses when they're recording the demo, but there's talking in between the verses. Grant and Hayley Bennett (playing the part of Cora Corman) sing the first two verses and the middle eight in the concert, but the first verse is talked over. Bennett sings the third verse in the studio but the recording peters out as Grant is surprised by the lyrics.

So I decided to try and create a composite version and make a complete song. I played the different parts of the film on my computer's dvd player and recorded the soundtrack. I needed to record four parts:
  1. The Indian intro (recorded at Bennett's studio) - no singing
  2. Opening verse by Drew Barrymore (recorded at Grant's studio)
  3. Second half of first verse and onto the middle eight and instrumental - concert
  4. Final verse by Bennett
Most of the editing went well, although it turns out that Drew Barrymore's first verse is in a different key to the concert version, although the final verse is in the same key as the concert version. In order to complete the song, I looped the chorus and middle eight from the concert. I feel like Phil Spector artificially lengthening one of the final Beatles' songs because it was too short ("I me mine", if I remember correctly). The finished version sounds ok but not astounding.

I find it interesting that Drew Barrymore apparently sings the opening verses. When she appeared in Woody Allen's musical "Everyone says I love you", she was the only actor not to sing, because her voice was so bad.

The In-basket: the initial stages of designing a computerised exam

The occupational psychologist for whom I work (let's call her OP from now on) unveiled her latest project for me a few days ago - computerising the 'In-basket' exam. Although I've never heard of such an exam before, it turns out that it's a well known exercise in management and there are even complete books written about it, such as In-Basket Examination: Test Preparation Study Guide, Questions & Answers. There are many references to this kind of exam on the Internet, but most seem to be connected with branches of the American police. Here's a complete example which has nothing to do with the police.

I feel a little like Jim Graves (or whatever his name was, in "Mission Impossible"): your mission, should you decide to accept it, is to convert this text-only exercise into a computerised simulation.

The original brief which I received very briefly on Friday morning was that the user is presented with a series of emails with which she has to deal. During the course of the exam, more emails appear, and even a secretary enters the room to give details of current events. Apparently the scenario which the OP uses is based on events which happened (or supposedly happened) fifteen to twenty years ago in the chair manufacturing factory in which I work (so I doubt that there is an event in which the secretary rushes in to announce that the factory is on fire).

When considering how to program the simulation, it became clear that the program would need a timer which fulfills the following functions (dig that alliteration!):
  • show the user how much time is left to complete the exam
  • check every minute whether there are new events/emails to be displayed
  • provide a time stamp for actions that the user has taken, so that afterwards her actions can be analysed according to the order in which they were performed
Originally I had assumed that it would be necessary to fake an email application in which some mails are already present, new mails get added during the course of the exam, and others are deleted after they are handled. In order to program this, I used a TListView. It also became clear that the program would have to use the MDI model in order to display all the opened emails, instead of working one email at a time. These are all techniques which I have used in the past few months, so I didn't have any technical problems in programming; the problems which I did have were in designing the interface, or more accurately, determining how the application should be presented to the user, what she would need to do in order to undertake the exam, what actions she would need to take and how these would be represented.

I wrote a pilot version of the exam before I had even seen the Internet material. Upon reading this, I extended the pilot version until I had something interesting - but also somewhat unwieldy.
My method of working was to think hard about how I wanted to implement something (not in the programming sense of implementation, eg how to implement quick sort) and then try and get the program to do what I wanted it to do. The programming per se wasn't hard although at times it was tricky and sometimes I did get bogged down on minor details (for example, in a MDI application, the 'OnKeyPress' event does not work - the solution is to use the TApplicationEvents component).

At this point, I contacted the OP and asked some pertinent questions about the direction of the program - should all the emails be presented at once (as per the example which I gave above) so that they could be prioritised, or should they be presented via the clock, which would make the prioritising much harder. How should the email replies be dealt with? One idea which I saw was to allow the user to 'make' phone calls - how could this be represented?

One idea which I had considered was to show the user's priorities by allowing her to sort the emails in the listview via drag and drop. Whilst waiting for an answer from the OP, I actually implemented this in a small test application. Her reply stated that the priorities would come from the order in which the emails were replied to and thus there was no need for drag and drop.
Once I had her reply, I thought a little more about what was needed, especially about how the user would reply to the emails. I had originally designed a simple dialog box (displayed as a non-modal mdi child form) which displayed the original email text in a memo along with two memo boxes connected to a database table in which the user would write his reply and attempt to explain her reasons for replying in this manner. At the bottom of the form were, as usual, two buttons: pressing the OK button would insert the user's answers into the database and would close the form whereas pressing the Cancel button would discard the user's answers and close the form. I had conceptual problems about editing - should the user be allowed to answer the same email twice (or at least edit the original answer)? What would happen to the time stamp in such a situation?

I utilised the time otherwise wasted whilst driving home from work in order to think about the new program structure. I realised that the OK button should initially be disabled; it should only be enabled after the user actually types something in the reply field. Then I considered the fact that if there was no need for drag and drop on the listview, there was no real need for the listview at all. New emails could simply be displayed on the desktop as mdi child forms. To prevent the user from closing the forms without replying (and without the listview, there would be no way of redisplaying the forms), I realised that the Cancel button should be removed!

I dropped the idea of 'recording phone messages' as these seemed to be identical to the 'instant messages', the equivalent of the secretary entering the office and announcing that the workers had gone home on strike. The 'instant messages' were virtually the same as the 'email messages' - the only difference (at the moment) being that the emails were 'sent' by somebody whereas the instant ones weren't. This meant that I could use one database table to store all the messages and display them in the same form (hiding the 'from' field if it were empty).

Upon getting home, I set about writing a new version of the demo exam. The database structure had simplified, so I deleted the original database file and defined a new one. This new version of the exam is - from a programming point of view - much simpler. Apart from a form which is displayed modally at the beginning of the exam in which the user enters her personal data, the program consists of one MDI main form with a timer; every minute, the program executes a query which determines whether there are any messages to be displayed. If so, a call is made to display an MDI child form as described earlier. There is only one button on the form - OK - which is initially disabled. If the user wishes not to act upon the form, it simply stays open on the desktop to be handled at a later stage. If the user types something into the form, pressing the OK button will save the data (along with the time stamp) and remove the form from the desktop - forever.

Now all I need to do is input the scenario  - the messages and when they appear - and the exam, at least in its initial stage, is complete. I am sure that there will be many changes, but most of them will be minor now that the architecture is in place. Of course, I could have misunderstood the OP's intentions.....

Sunday, June 27, 2010

LASIK surgery

My daughter underwent LASIK surgery on Thursday evening; she's been wearing glasses since the age of 12 and she is now 22. Actually, most of the time she wears contact lenses rather than glasses; the former look better although require more maintenance.

She decided a few weeks ago to undergo the operation and began researching the market. There are several places which offer the operation in Jerusalem, which meant that her eyes were thoroughly examined twice (each clinic has to judge for itself whether the patient's problem is correctable) before she could get to the stage of comparing price quotations and suitability. As it happens, she chose a more expensive clinic, but as my wife would say, one doesn't skimp on health.

The chosen clinic was on the tenth (and top floor) of a building near the entrance to Jerusalem; the expansive windows allowed a panoramic view of the city at night. Even at 7pm, the clinic was full; it's more like a conveyor belt operation than personal attention, as each operation takes only a few minutes. But as there were many patients waiting, it took some time before my daughter's turn came, and we only left the clinic after 9pm, she wearing protective goggles over her eyes.

The next morning we had to return for a brief check-up; as we waited in the building's lobby for the lift, we saw people walking around with sunglasses (it was only 7:30 in the morning). I joked that it was like a scene from 'The Matrix' and that I was wearing sunglasses in order to identify with all the other patients (my eyes are sensitive to light so I wear sunglasses very often). The check-up was fine, and on the way back home, we were having competitions on who could see the better. 

The procedure was miraculous: in a few minutes, her sight problems were corrected and now it seems that she can see better than I can (my eye muscles are tired)!

Wednesday, June 23, 2010

The Israelis are becoming like the British

The Israelis are becoming like the British - always talking about the weather. Normally the climate is like southern California and hot, hot, hot! every day. But the last few days have been extra-ordinary: yesterday morning at 5:30am, the temperature was 32.5 degrees Celsius outside the house, and by 8am it was over 40 degrees (that's 104 Fahrenheit). Apparently at around 10am, cold winds started to blow, slowly taking the temperature down to a more reasonable 30 degrees at 5pm. This morning, it was about 21 degrees outside - but 27 degrees inside! More power to the air-conditioners! According to the television news, the electricity company was supplying 99.98% of its capacity.

Most people are glued to their televisions at the moment watching the World Cup (or Mondial, as it is known here) but I couldn't care less. I have never been interested in football, even as a child (well, maybe I was slightly interested then), although I was a passionate rugby football fan during my school years. 

I have discovered that an obscure television station broadcasting from Cyprus has begun showing 'Star Trek: The next generation', beginning with the first series. I haven't seen these episodes for years (they were originally broadcast over 20 years ago) and am enjoying the trip down memory lane. The acting and plots are a bit clunky, but as I recall, the series improved greatly by the time of the third season. I wonder whether this station is going to show all the episodes.

During the 1990s, this programme acted as my bible for organisational behaviour, although I didn't know the term at the time. I admired how Captain Picard would assemble his officers in the briefing room in order to hold what would be in business terms a management meeting. There was no flapping about: everybody would bring pertinent information to the table and a decision would be reached quickly. If only real life were like that.... Instead, people talk about things which they know little about and conceal or reveal their ambitions. 

Later I always wondered how come the bridge is always manned by the senior staff. Was the concept of 'watches' or shift duty unknown to them?  Actually, I have a dim memory of one episode which is narrated by Data, which starts by him commanding the night shift. Maybe he doesn't have to sleep but surely the others do. Of course, such realities wouldn't make for a very good television series.

Sunday, June 20, 2010

Sunday morning

In western countries, the weekend is Saturday and Sunday, but in Israel it's Friday and Saturday. There are plenty of people who work on Fridays (normally until 1 or 2pm) but there are also plenty of people who don't. A five day work week was instituted maybe ten years ago, adding an hour to every work day. For those who do work on Fridays (my bank, for example), there is usually one weekday when they don't work (the bank is closed today). If one works on an hourly basis (as does my wife), then it's better to work during the week and not work on a Friday as one works more hours this way and so gets paid more. 

The point of this over-elaborate introduction is that two phrases which are resonant in western society ("I don't like Mondays" - the Boomtown Rats, "Someone's got a case of the Mondays" - the film "Office Space") don't really make much sense here. Instead, one could say "someone's got a case of the Sundays", but I've never heard anyone say that. There is definitely a sense of transition, although for religious Jews, this occurs on Saturday night when Shabbat "goes out"; there is a small ceremony held, called "Havdala" (difference) in which this transition is marked.
For me, the first ten minutes on a Sunday are slightly difficult as my head is normally full of the programming which I've done over the weekend, and now I have to clear my head instantly and take on a different set of responsibilities. I'm going to write here about the fun and games of the weekend, and not the fun and games of the day job.

The occupational psychologist for whom I work developed a questionnaire whose results indicate which profession is suitable for the person sitting the exam. The target population for this exam is mainly pre-university youngsters although there are elder populations for whom the questionnaire is applicable. I computerised the questionnaire several months ago; this was fairly routine. Even the program which reads the raw data and "calculates" the suggested profession is fairly routine, although we did spend a large amount of time designing and programming the output in order to make it user friendly.

As we intend this questionnaire to be distributed "in the wild", there are certain aspects which are unique to the program suite (there are four or five programs involved). 
  • People will have to pay in order to get their results, which means that there has to be a mechanism for issuing and distributing licenses. 
  • The raw data has to be sent from the client's computer to our server, the results have to be calculated and the output file has to be returned.
The first point was fairly simple to implement: I added a 'licenses' table to the database, which has fields for username, email, license code, counter and multi-user. If the license is defined as multi-user, then the same code can be used many times (this is intended for external establishments, who presumably will pay according to the license counter, which is incremented every time a licensed data file is received). For a normal user, the license is good for one time only.

In order to implement the second point, I added to the distributed questionnaire program a code snippet which automatically sends by email the raw results file to a specific email address. I then wrote a program which polls this email address every five minutes and downloads any letter which has certain characteristics (it's not going to download spam!). The program extracts the attached data file from the email and passes it to the calculation and output stages of the results program and then returns the output file by email. How does it know where to send the email? Because output files are sent only to registered users and the email of the registered user is known. So even if someone bothers enough to fake a registration code, they won't get the results.

The previous paragraph glossed over several points which actually took me quite a time to get right. Finding a free email server which handles POP3 was surprisingly difficult and took several attempts before I found one whose mail I could download successfully. I had never written a program which downloads email before, so I had to learn how to do the ins and outs of this as well. Checking the license and the multi-user status of the license was tricky but not difficult.

There were several little parsing errors which needed to be solved, but on Friday night, the occupational psychologist's son (who is in the target population) was roving the kibbutz with a mobile computer and the computerised questionnaire, getting all his friends to complete the questionnaire and getting the results back by email. Well, not quite: there was a problem with the file returning code. I woke up at 6am with a possible solution to the problem; it wasn't the correct solution, but did help pave the way.

This mobile computer was a pain in the neck by itself. I had programmed the display for a normal computer screen, but this mobile was one of the new breed of notebook computers with an aspect ratio sufficiently different from a standard screen to cause problems. The normal screen displays instructions at the top and five questions; on the notebook, the screen was truncated and only one or two questions were being displayed - and there were no scrollbars visible which would have enabled the user to scroll the display in order to see the missing questions.

I spent a few hours on Friday afternoon solving this problem. The other son of the occupational psychologist had done some design work with me on the program, resulting in an aesthetically pleasing display. His design called for the questions to be displayed in a dialog box with no borders - and it transpires that such a dialog box cannot have scrollbars. After knocking my head against a brick wall for some time, I found a compromise solution in which the dialog box has no caption but has a minimal border. This allowed the vertical scrollbar to appear (I fiddled with the width of the dialog in order to prevent a horizontal scrollbar from appearing).

There was another wish which I had been avoiding for the time being: the output file should be a PDF file and not a Word file. I know that Word 2007 has a 'save to PDF' option but we are using Word 2003 and upgrading solely for this ability seemed non-proportional. Yes, I know that Open Office can save to pdf, but then I would have to learn how to automate Open Office, a task which seems somewhat daunting at the moment, especially considering the lack of documentation. I tried a command line program which sort of did the job, but it seemed very slow, required most of the computer's cpu time whilst converting and was not free. 

After a brief nap on Saturday afternoon, I contemplated the pdf problem again. The program which I had tried automatically invoked Word and instructed it to send the file as output to a printer driver which the program had installed. This is when the light went on over my head: we already have a pdf printer driver! I had erroneously assumed that it couldn't help us as it always asks where to save the file and then invokes a pdf reader after the file has been created. Wrong! The printer driver has settings which enable the user to avoid the 'file save' dialog and not invoke the pdf reader. After five minutes work, I had a test program which wrote to a Word file via automation and then converted that file to pdf. 

I still had to install the pdf printer driver on the server, sets its definitions and add the necessary few lines to the output program, but these tasks were trivial. Now the automatic downloader/dispatcher program will send a pdf file back to the questionnee! (This is yet to be tested as no more data files have been received since I added this, but I am confident of the results).

In conclusion: I now have to switch off the part of my brain which has been operating on finding solutions for the problems posed by this questionnaire suite, and reprogram it in order to meet the challenges provided by the day job (for example, show where the differences in inventory value for examples in the last two months come from).

Thursday, June 10, 2010


I wrote a few weeks ago about our attempts to take the output from an external program and feed it into our ERP program. The external program is known as MTD (although I think that this is the name of the company and not the program itself) and the ERP program is called Priority; hence my program is called (with great imagination) MTD2Prio.

The previous installment of this saga had the team realising that the glue program needed to more than simply parse one of MTD's output files. I developed a simple quasi-database program (utilising a clientdatabaseset) which would display lines read from the file as well as lines added by the user. With no small amount of effort, I wrote code which would output five different files for import into Priority, one file for each table in Priority. Not all lines (parts) displayed on the screen are in each of the different files, so this part was more than tricky.

Once I had the five files (and originally I thought that I would need only three), I started on the work of importing those files into Priority and substituting parts in the given order with the parts in the files. Most of this work was achieved without difficulty, although it became apparent that I needed more data than I had originally planned (which is why the number of files increased). In a moment of inspiration, I also figured out how the program could use standard parts - a problem which had occupied us in a previous meeting and had been ignored since.

After displaying this new, improved version, some bright spark asked what would happen if the same part designed in the external program appeared more than once in the user's order. This could happen if the order was split up into sections, each section representing a different room in the customer's office; the same special table could be in each room. Obviously, the part would have to be designed only once, but the problem became mine: how could the user show that the part would have to be inserted into lines 1, 5 and 7 (for example) in the customer's order without defining three parts?

I figured out how to do most of the work as a mental exercise whilst driving back from Tel Aviv after the final economics lecture on Friday, but hadn't wanted to devote any time to implementing this new feature until after the exam. Today I had the time and space to devote to solving the problem, so solve it I did. I probably spent more time on parsing the input file than I did on the mechanics of the substitution in Priority. I wouldn't necessarily say that the work was overly complicated, but it demanded a certain finesse.

Anyway, that problem has been solved, leaving only one more problem of which I am aware, which is concerned with raw materials handling. As this is solely a Priority issue, I'm not expecting too much difficulty, but I'm leaving it for the moment in order to allow the solution to mature in my brain.

Of course, the users will probably have several issues which haven't been considered yet. These will probably be interface problems which won't necessitate any changes in the Priority code.

Wednesday, June 09, 2010

Post mortem on my Economics exam

Today was held the examination in Economics, the third course which I have taken for my MBA degree. As opposed to the previous exams which had been held in the Exhibition grounds of Tel Aviv, this exam was held in a posh hotel on the sea front. As I understand, this is going to be the new home for all future exams. For me, getting to the location was more problematic than before; in the past, I would take a train to the Tel Aviv University station and walk a few hundred metres. Yesterday, I took a train to an earlier Tel Aviv station, took a bus from there - and had to walk more than a few hundred metres. Coming back, I took a slightly different route which involved less walking. 

Obviously the conditions inside the hotel were better than before: both cold and hot drinks were waiting outside the examination room, and there were also adjacent lounges facing the sea, where most of us relaxed for a few minutes before the exam started. But once the exam started, all the external conditions ceased to have any effect as 100% concentration was directed to the exam.

The exam was much harder than I had expected; as part of the preparation process, I had worked on several previous exams, and in the morning even went over once more the two practice exams given in the course's textbook. Maybe it was the familiarity, but none of them were as hard as this one. Our lecturer said that every now and then the exam is very difficult, but with luck we would miss the hard one. Our luck did not hold.

The exam consists of four parts: 30 multiple choice questions (2 marks each), one 'case study', which is normally a numerical exercise in micro-economics (20 marks), one essay on micro-economics (40 marks) and one essay on macro-economics (40 marks). This makes a total of 160 marks and one needs 80 in order to pass. 

The multiple choice questions, as usual, were difficult and it's easy to make mistakes. In about half of the questions, there was a statement and four different answers; these are usually not too difficult to answer as normally two of the potential answers are obviously wrong. But this exam added a new wrinkle: there were several questions in which three statements were made, and then one has to choose (for example) whether the first is right, the second and third are right, all are right or all are wrong. My certainty on this type of question was lower.

Unfortunately, we didn't get, in the case study, a nice numerical question about a fishing company and how many people should go fishing every day. No, we had to get a question about a tennis player who endorses watches (why not tennis racquets?); she wants to get a percentage of the selling price whereas the manufacturers wish to maximise their profits. Write an essay explaining the situation - no numerical data provided. I thought that this section would bring an easy 15-20 marks, but instead I had to sweat in order to achieve maybe 15. 

The micro-economics essay, as expected, was about economic efficiency and 'marginal efficiency conditions', but instead of linking this to market failures as per usual, it was connected to the labour market. This is a combination which we hadn't come across before, and again, a great deal of mental sweat was necessary.

In the macro-economics question, several data about a nation's economy over two years were presented, along with four statements saying that 'if x and y, then z would be expected'. The question was to explain why z did not happen.

I imagine that I passed the exam, but with a lower mark than I might have otherwise expected. I don't know how anyone else felt about the exam because no one left at the same time as I did, and anyway we are now on holiday - until August. Next up is Project Management, which is a subject which will definitely be useful in my daily life.

Tuesday, June 01, 2010

Network card

I'm typing this from a mobile computer whilst sitting in a crowded train travelling from the north of Israel to Tel Aviv. I've had a laptop for some time, but have never been able to use it on trains because I didn't have a network card that connects to a mobile supplier. Finally today I got the long waited card and of course wasted no opportunity to start using it. As the connection is not via the work network (to which I have to connect via VPN), I am free to point my browser at whatever site I want, which is what enables me to write this entry.

There are some train journeys in which the computer is going to prove invaluable - I could have done with it this morning when I received several phone calls on my way up north - but there are also going to be times when using it is impractical. It's not very easy at the moment - the train is more than full, and before there were groups of youngsters walking up and down the aisles and bumping into my elbow.  But even so.... 

We have just arrived at the Binyamina station and it's time to log off.