Sunday, October 27, 2013

Dates

Did I mention that my daughter is getting married?

She's been working on getting the hall that she wants at a price per head that she is willing to pay (or to put it another way: guests here are expected to cover the cost of their place; if the hall charges 250 NIS, then a couple will be expected to give a 500 NIS present, but of course, no guest knows exactly how much the hall will charge). Once we have a hall at the right price, then we have a date.

She was torn between the hall that she wants (in Modi'in) which is in great demand, which means that it is expensive, and a hall that she doesn't want in Jerusalem which would be cheap. Finally she settled on the hall in Modi'in, with the compromise that the wedding be held in March (prices are cheaper before Pesach, April 2014). We heard this on Friday morning.


A few days ago, I read in an Israeli newspaper that the King Crimson offshoot group, The Crimson ProjeKCt (consisting of three one-time KC members Adrian Belew, Tony Levin and Pat Mastelloto and three others) will be coming to Israel for one concert in March. As this seemed far off in the future, I hadn't bothered yet to check what the actual date will be.

We joked on Friday morning that I would have a tough choice should the Crimson ProjecKCt appear on the same day as the wedding. What should I do? (Of course, there is no real choice whatsoever). There are 31 days in March, I said to myself, so there is a 3% chance that the two events will fall on the same day.

Today I decided to find out when that concert will be. In so doing, I stumbled upon an Israeli site about progressive music, which probably will receive return visits. Anyway, the concert will be held on March 5, 2014.

The date for the wedding? You guessed: Wednesday, March 5, 2014.

So much for the Crimson ProjeKCt....

Tuesday, October 22, 2013

Some DBA thoughts

Despite the malaise from which I seem to have been suffering in the past few weeks due to lack of quality sleep, I am trying to study as much as possible. On the one hand, this means studying all the various statistical tests, whereas on the other hand, I am revisiting the material which I learnt earlier in the year for the exam which I missed (mainly about literature reviews). I am trying as much as possible to study this material dispassionately: trying to learn it as it is presented and not as how it affects my own research.

Even so ... this morning I was asked about one of our business units and why they don't work properly. I didn't give a very clear answer, but thinking about it now, I can explain more clearly (at least to myself!). As far as I am concerned, people who work with Excel (or to be polite, end user computing) in an ERP environment are like programmers who learnt Access and then try to use what they have learnt in an environment which uses SQL: they are using a 'record' way of thinking as opposed to a 'set' way of thinking ('set' as in 'set theory'). This is a common failing of programmers new to SQL.

Specifically: this business unit asked me for data about parts which have been ordered (the users are never precise enough; what they mean is parts which customers have ordered, as opposed to the parts which we need to purchase in order to produce the parts which we will sell to the customers). I gave them totals per part - a 'set' way of thinking - whereas they persist in asking me for part amounts per order - a 'record' way of thinking. I contend that they would be able to do their job better if they left the conception of a record/order behind and started thinking in terms of aggregates (sets).

This is especially important when considering purchasing: there are two types of purchasing approaches, bulk and specific. The purchaser does not need to know for which orders a bulk item is required, just that 10,000 units have to arrive before a specific date so that all the customer orders can be fulfilled. A purchaser does not have to know the purpose of a part which is bought specifically in order to fulfill a given customer order, but it helps. Obviously, parts which are expensive and used only rarely will be purchased specifically whereas parts which are used frequently will be purchased in bulk.

Translating between the terms, bulk purchasing is a 'set' way of thinking whereas specific purchasing is the 'record' way of thinking.

Monday, October 21, 2013

Paul Klee

When I was a teenager, I "fell in love" with the pictures created by artist Paul Klee. My favourite painting of his was one called 'Senecio' (appears on the left); I don't remember now what attracted me to it nor how I discovered who painted it. I suspect that there was a subconscious influence at play: one day (probably in 1973) I discovered that there was a print of this painting hanging on the wall next to the main staircase in my school! This means that I had probably seen this painting at least once a day for several years.

I went through an 'arty' phase when I started at university, and frequently visited an Athena shop, from which I bought a few Klee and Picasso prints. I took these with me when I emigrated to Israel, and I mounted the 'Senecio' print on plywood, so that I could hang it properly. I had this 'painting' on my wall for several years but eventually had to discard it as the colours had faded. I'm not sure where the Picasso is now but this used to hang on a wall at home; when people came to our house, I used to joke by saying that most of the pictures on the walls were drawn by my wife, but this one (the Picasso) was mine.

I see that there is a Klee exhibition running at the Tate Modern at the moment. This reminds me that there was a similar exhibition in Jan/Feb 1975, which I wrote about for my university newspaper. This was the first of several articles which I wrote, although the others were about music or films. Eventually I 'graduated' to writing a personal column, but due to circumstances beyond my control (I spent my second year working outside of the university; the newspaper's editor changed)  I only wrote two personal columns. Unfortunately, all the reviews and columns which I wrote got lost, so I can't quote from them. Probably just as well, as they would seem extremely naive and callow now.

I have at least one book about Klee at home which dates from my period of infatuation, but I think that I haven't looked at it for thirty years. But if I were in London now, I would be making my way to the Tate....

Sunday, October 20, 2013

More health issues

It seems that my joy in cutting down the number of apneic events by increasing the pressure that my CPAP machine provides was short lived: true, I had three days with few events at a pressure of 7.5 cmH2O, but then I had four days with high numbers (back into the realm of 20 incidents per hour). As per my instructions, I increased the pressure to 8 cmH2O. After a week, I checked the results and saw that increasing the pressure had made no difference.

Yesterday, I increased the pressure to 9 cmH2O; presumably as a result of trying to adapt to the higher pressure, I slept very badly and this morning I feel lousy. Hopefully I'll get used to the new pressure and get some sleep, although its quality will be an unknown factor.

In my doctoral studies, I was working on what's called the Mann-Whitney U test, which basically checks whether one series of values is significantly different from another series of values. This test is meant for non-standard distributed values which are independent of each other - exactly like the values I get from the CPAP machine. I checked 24 values from Friday nights against 24 values from Saturday nights, and assuming that I did the maths correctly, I can conclude with a confidence level of 95% that I have more apnea on a Friday night than on a Saturday.

The only good thing that I can find to say about my health is that my weight is fast decreasing. Two weeks ago I was surprised to discover that my weight had ballooned from 82 kg to 85 kg; last week it had decreased to 84.3 kg and this morning I weighed only 83.3 kg. At this rate, in another two weeks I will have lost all the extra weight and will be well placed to make some serious losses.

Which leads me back to sleep apnea: shortly my weight will be the same as it was in April when the machine was set up, which means that I should be using the same pressure as then (7 cmH2O). If there is a significant increase in the number of apneic events (without regard to pressure) then there is some other variable which needs to be taken into account. Maybe there is a problem with the machine or the mask ... or maybe me.

As an aside, I note that despite the fact that a sizeable proportion of the adult population suffers from sleep apnea, I have never seen this (or CPAP machines) mentioned in either films or books. So it was a happy moment when I found the following passage in the opening pages of 'Up in the air'  "Once between Denver and Oklahoma City, I nodded off next to a pulmonary specialist who told me when I woke that I had apnea - a tendency to stop breathing while unconscious. The doctor recommended a machine that pushes air through the nostrils while one sleeps to raise the oxygen level in one's blood."

Sunday, October 13, 2013

Tasks

One of the Occupational Psychologist's team has left and has been replaced by a new person. Fortunately the integration of this new person with my management program is going very smoothly (as opposed to the one who is leaving who tended not to utilise it very well) and I am slowly getting feedback via the OP on new ideas to implement.

Friday's meeting centered around tasks: apparently the new person wanted to insert into the program a reminder to call someone in a few days time. Although in a sense, this capability exists within the program, the existing function was not really meant for this and certainly doesn't display a reminder.

At first, I suggested that they use Outlook to provide the reminder: why re-invent the wheel? But it turns out that they don't use Outlook very much in the office - they use Gmail combined with the management program. So I had to provide capability. The actual idea of tasks didn't seem to be a problem - this can easily be implemented with a database table of tuples consisting of a few fields, including the date and time of when the reminder has to appear - but what seemed problematic was how to pop the reminder up at the correct date and time.

Originally I considered using an external program which would display the reminder; its execution would be triggered by the management program adding an entry to the Windows scheduler. As I'm not familiar with the interface to the scheduler, this idea had to be put to one side. For a while I considered using a separate thread within the program, but later on I realised that this too was overkill. In the end, I implemented a simple scheme with a timer: every five minutes the timer wakes up and checks whether there are any tasks for the current user whose date and time have passed; if so, display the task non-modally. It is true that this means that the program is polling the database, whereas on the surface the Windows scheduler and thread approaches simply 'wake up' at the correct time. After thinking about this, I realised that these approaches too use polling; as far as the user is concerned, there's no polling but the system itself also uses a timer exactly in the same way that I'm doing. In other words, it's implicit polling as opposed to explicit polling.

Surprisingly, the hardest part of implementing tasks was recording for which date and at what time the task was set. I had naively thought that the TDateTimePicker component of Delphi would do this, but it turns out that I needed two such components: one for date and one for time. I also had great difficulty in getting the time from the component into the database as well as reading back a date/time combination into two components. Eventually I used the following code....

Saving the date and time values in one database field (edDate is the component showing the date, edTime is the component showing the time)
decodedate (edDate.Date, y, m, d); s:= inttostr (y) + '-' + inttostr (m) + '-' + inttostr (d) + ' '; decodetime (edTime.Time, y, m, d, ms); s:= s + inttostr (y) + ':' + inttostr (m); qInsert.parambyname ('p3').asstring:= s;
Reading the value back from the database and displaying it in two components
dt:= qGetTask.fieldbyname ('curdate').asdatetime; decodedate (dt, y, m, d); edDate.Date:= encodedate (y, m, d); decodetime (dt, y, m, d, ms); edTime.time:= encodetime (y, m, d, ms);
Once I had developed a method of reliably saving and restoring the date/time combination, I could write the timer code which pops the task up. This was actually very easy. So in the end, the part which most worried me in advance turned out to be easy, and the part which I assumed to be easy turned out to be hard! 

The contents of a task are minimal at the moment; they are sufficient for the purpose, but I have no doubt that additions will be required. Such additions don't bother me as they only affect data insertion and retrieval; they won't affect the date/time parts.

Another germ of an idea which popped up (sorry about the pun!) during our discussion was the possibility of my program actually downloading letters from Gmail! Let's say that we have sent a letter to contact A (the letter was sent from the program so we have the complete text) and contact A replies. The reply would arrive in the Gmail inbox and my program will be blissfully unaware of this. My current idea would be for the program to scan the inbox and download letters which have been sent from addresses which are known to the program. Once downloaded, the contents will be stored in the database and linked to the contact, so we will be able to see the complete conversation. I have written code which accesses Gmail's sent items folder so this part isn't too problematic; I will have to consider how to download letters only once. Should such a program run only once a day and check the previous day's mail? Maybe Gmail assigns each mail in the inbox an id number and I can use this to my advantage.

Whilst I was implementing the 'add task' code, I noticed that there was a routine for loading comboboxes with the contents of a database table that I had written and included in at least ten different forms. It didn't take much to turn this routine into a library procedure and simply call it from all those different forms. This is a minor example of refactoring; every now and then I find such examples in my code and improve them. The management program is a fine example because it is definitely the largest program (by far) that I have ever written, although it's not complicated: it's composed of many simple (and very similar) forms.

Saturday, October 12, 2013

Sleep apnea

I haven't been sleeping well lately; according to the readings of my CPAP machine, there have been nights when there have been over 20 apneae per hour, a number which is far too high. I would like to blame this on all the traveling of the past two weeks, but ironically I get the impression that there are fewer incidents on the days that I travel. After locating my sleep clinic (it has moved from nearby Bet Shemesh to Jerusalem), I made an appointment to have my machine checked last Sunday (meaning another day on which I traveled).

The first question which the technician asked me after downloading results from the machine was whether I had put on weight. As it happens, I had been for a regular checkup in the clinic two days previously, so I was able to state (rather unhappily) that I had put on three kilos of weight in the past few months. This satisfied the technician who explained that such an increase would probably mean that the pressure that the machine was putting out (7 cmH2O) was not high enough anymore. 

He showed me how to increase the pressure (normally the user does not know how to do this)  to 7.5 cmH2O. He said to see what happens over the next week: if the number of incidents decreases but not significantly, then I should increase the pressure to 8 cmH2O and then see what happens. As it happens, the number of incidents dropped dramatically (6.7 per hour on Tuesday, 8.4 on Wednesday and only 4.2 on Thursday), so I'm going to leave the pressure at 7.5 cmH2O for another week and then check the results.

I was in the clinic again yesterday in order to get a flu inoculation. I took the opportunity to weigh myself and was pleased to note that my weight had dropped by nearly one kilo over the week. The most dramatic change in my diet during the past week was cutting the number of milkshakes (milk + powder) from five a day to one or two a day. During the working week, this isn't much of a problem (I just drink a herbal infusion instead) but at home on the weekend, the temptation is greater. I've been drinking more apple flavoured water. I've also cut my two spoonfuls of granola in the morning to only one spoonful, and have cut down on the biscuits.

I hope that next week will show a similar weight loss.

Friday, October 11, 2013

More books

During the last two weeks, I've traveled almost every day (meaning at least two hours traveling in the morning and the same in the evening), meaning that on one hand, I've had very little personal time (I'm too tired in the evening to do much) but on the other hand, I've had the opportunity to read even more books.

Two books were about computers - the autobiography of Steve Wozniak (contrast his life with Jobs'!) and the story of a 21st century hacker who engaged no small amount in credit card crime.

One modern literature book which I found very intriguing and captivating was 'What Alice Forgot' by Liane Moriarty. The book opens with the titular Alice dreaming - as a result of a head injury that she sustained whilst working out in the gym. Alice thinks that she's 29, happily married and expecting her first child whereas in fact she is 39, has three children and has recently separated from her husband. The injury causes her to forget the last ten years of her life, placing her in a completely different 'head space'.

Ignoring the story itself (how she slowly recovers her memory, how she integrates her earlier self with her later self, etc), it is very interesting to try the same exercise out on oneself. If I were to lose the memories of the last ten years, I think that I would still be in a similar 'head space', but if the accident were to happen to me when I was 39, then certainly things would be very different. Aged 29, I was living on one kibbutz with a wife but no children, committed to making a success of that kibbutz, whereas ten years later I was living somewhere else with two children, somewhat embittered at my first kibbutz. Of course, the ten years between 19 and 29 would have even greater changes.

I am currently reading 'Without remorse' by Tom Clancy, probably in recognition of his death last week. This book was written in 1993 but somehow missed my attention. It is very much a prequel to the 'Jack Ryan universe', set in 1968, as its protagonist is someone who will become the John Clark of later books. The penny didn't drop at first, but after the second mention, I realised that one of the policemen mentioned, Lt Emmet Ryan, is the father of Jack Ryan. Maybe the younger Ryan himself appears in the book, although I doubt it.

Whilst displaying none of the global intrigue of the Ryan books (so far most the action takes place in Baltimore although there is a thread about American prisoners of war in Vietnam), Clancy's attention to detail shines all the way through the book. Clark is a very thorough person in what he does.

At least one does not need an MBA to understand this book - it's fairly normal tough guy material, albeit on a very high level.