Thursday, November 11, 2021

The Ice Bucket Challenge (Almost)

Although I'm certainly not as regimented in my thinking as an engineer, I like to think that I have a non-zero ability to look at a simple mechanical process and figure out how it works ("Oh, I see....when you pull on this, that makes this other thing spin which hooks onto that..." etc.). That self-perception was sorely tested during a recent hotel stay. 

I was staying in a very nice room in a conference hotel. When I first got to the room after checking in, I saw that the amenities had been recently upgraded, including a very fancy looking shower setup. Instead of the usual small, round shower head, there was a massive flat square with lots of little water jets. Very posh. Next to that was something that resembled chrome TV remote attached to a flexible tube, which I assumed was a handheld shower extension. In between the two was a large handle that seemed to have three positions, which I took to be off, handheld, and main shower. In my mind's eye, I was already envisioning a refreshing shower the following morning.

But it was not to be. The next morning, I stepped into the shower, turned on the water, grabbed the large handle, and moved it from the 9:00 position to the 12:00 position and waited for the blast of warm water on my face.

And waited.....and waited.....and waited. Water was still flowing out of the faucet, not the shower head.

I moved the lever back to the starting position and tried again, feeling a very distinct click along the way (presumably for the hand held attachment) as I moved the handle from 9:00 to 12:00. Still nothing from the shower head, as water streamed out of the faucet and began filling up the tub.

"Perhaps they were a little too aggressive in their remodeling schedule and forgot to make sure everything works," I thought to myself. I moved the lever back and forth several times, but nothing seemed to divert the water from the faucet. Not wanting to be late for the first conference session, I made do with the water that had collected in the tub to get clean. 

As I was walking back to the hotel after the morning sessions, I asked myself whether it was worth making a fuss to the hotel staff. I know that times have been tough for the service industry due to the pandemic, and didn't want to come across like some entitled jerk. Besides, there is an ice bucket in the hotel room, and I could just use that for my next shower and let them know about the issue when I check out. As I mulled the issue over, I noticed that there was no one in line at the front desk, and decided to just give them a friendly heads up.

I told the woman at the front that there was something wrong with my shower and she said that she would send someone up immediately. It was literally only a few minutes after I got back to my room that I heard a knock at my door and opened it to find a maintenance man saying that he was here to check on a faulty shower.

After letting him in, I retreated to the main part of the bedroom to put on my mask (hotel Covid 19 protocols and all). Seconds later, I could hear the shower running in the bathroom. This led to an exceedingly embarrassing "What seems to be the problem, sir?" moment as I entered the bathroom.  

Long story short, I was right in thinking that the lever controlled which shower head to use. However, it doesn't actually divert the water from the faucet to the shower. On most showers, there is a little handle on top of the faucet that you pull to divert the water. But on this super snazzy posh shower, the diverter handle was actually "hidden" in the curve of the faucet -- you pull on the "elbow" in the faucet to activate the shower. I was so sure that the lever was the main mechanism for the shower, that I neglected to carefully inspect the faucet. 

I thanked the maintenance guy while sheepishly mumbling something about "user error." 

On a positive note, my shower the next morning was much nicer than it would have been with the ice bucket. Live and learn, I suppose.


Friday, October 8, 2021

No More More With Less

When resources get tight, people are often extolled to do "more with less." This is sometimes the result of dips in funding, or perhaps a co-worker leaving suddenly. Whatever the reason, there is now less of what there used to be.

All other things being equal, you can't do more with less. Lots of people would like to believe that you can, but they are just fooling themselves. If you are saying it to others, you are likely really saying "Don't complain, just work harder." If you are saying it to yourself, perhaps you have visions of being "the scrappy team" with the "can do" attitude that impresses the higher ups with their "resourcefulness." That's not a bad attitude, but believing doesn't make it so.

Doing more with less? I don't buy it. 

That said, there are other possibilities.  

You can certainly do less with less. If you lose a team member or have a cutback in resources, you might be able to cut out things that aren't really very useful or efficient. In fact, not doing those might actually be a good thing. Cutting down the number of things you are doing might actually give you time focus on other, more important, things. This might give the illusion of doing more with less, but it is actually doing less with less (or doing different with less, which we'll get to).

It might also be possible to do more with same. If you give yourself a cold, hard look, you might realize that you are not always taking advantage of what is already available in terms of resources to improve performance. This might even include some unlikely candidates, such as taking advantage of sick leave or annual leave to recharge and reset, taking advantage of a training opportunity provided by the company, etc. The resources haven't changed, but you've found a way to make better use of them.   

A final option is to do more with different, and this is the usual result of trying to do more with less. You end up doing less with less, but if you do things differently, it might be an improvement overall. For example, if there is a way to automate a previously manual task, that might free up resources. Getting rid of "zombie" meetings or reports might free up resources. Moving to a different tool or to a managed service might be a net gain in productivity even if team size stays constant or shrinks. 

I like to believe (unless convincing evidence is presented to the contrary) that most people in most workplaces are trying to do an honest day's work. Let's not be dishonest by pretending that it is possible to do more with less.

Thursday, September 23, 2021

The Ice-Cream is Melting

A few months back, I blogged about a project in which the goal was to use an API to grab data from our LMS about which students had completed a particular course, and "reward" completion by means of a free ice cream in the form of credit on their student account. I had written a proof-of-concept Python script to grab the data, which I passed on to others on the project, but not being a software developer or data engineer, I assumed that the project team would put together a more robust solution. Early emails back and forth suggested that everyone had what they needed, so I assumed everything was under control.

Fast-forward to a few days ago (many weeks since the original meetings). Once again, people seemed to be talking about the need to grab LMS data to assess course completion. I had been under the impression that we were already more than a month into a working solution. 

What happened? I don't have any particular insight into who was doing what during the interim, but I can venture as to the general challenge. (I think I first heard these ideas in a presentation years ago by Johanna Rothman.)

Information about a new project is lowest before the project has begun. All we have are assumptions about how long things will take, who will be available to do the work, where the bottlenecks will be (if we even recognize that there will be some), which systems require special permissions, etc. (An exception to this is projects very similar to current or previous work, which can serve as initial estimates of resource requirements and probable timelines.) Our assumptions of how long something will take can easily be off by orders of magnitude if we start from a blank slate. Not just "I thought I could do it in three hours, but it looks like it will take four or five", but rather, "I thought I could do this in an afternoon, but now I realize that it might take several weeks to get it working." 

Because the project scope seemed to be rather small (extract data from a single class), there was likely a shared (and unvoiced) assumption that it should be a relatively trivial task, and there would certainly be no need to prioritize it over the many other, "obviously higher priority" tasks that folks had on their respective plates. By the time people rolled up their sleeves and got to work, unforeseen challenges emerged. 

I would also posit that these assumptions were not just on the IT side, but also on the original concept side. I don't know who was involved in discussions and on what level, but my guess is that IT was not consulted (or the people who might actually be responsible for doing the work were not consulted) before the project was given the green light. 

The moral of the story is that, in a room full of "sure, we can do thats," there is also a need for "has anyone thought abouts?". 


Wednesday, August 11, 2021

Leaves of Three, Let it Be

 Have you ever had one of those minor annoyances that isn't really a big deal in the grand scheme of things, but is just intrusive enough to cast a pall over everything? Like if you step in a puddle of water just before entering a really nice restaurant and can't focus on the juicy steak in front of you because your are distracted by your wet shoe and squishy sock under the table? That's what my last few weeks have been like. My "puddle" was poison ivy.

This series of unfortunate events started one evening. We have a small tree in our front yard surrounding by an "island" of ankle high plants. (I'm sure there's some fancy landscaping term for that arrangement, but you get the idea.) At one edge of the "island" there was some kind of fast-growing "weed" sticking up here and there, creating quite an unsightly mess. As this was right next to where my (newly moved-in) neighbor's yard starts, I thought I'd take advantage of the fact that they were out for the evening and do some quick cleanup. 

I put on a pair of gloves and pulled out anything and everything that was sticking up more than the surroundings. At one point, I stepped onto the "island" to pull some stuff from closer to the interior. The whole job was done in about 15 minutes. 

That happened on a Friday. On Monday, I noticed some raised red scratches or welts on my wrists and arms that were a little itchy. My first thought was mosquito bites or, worse, bedbugs or something. I did briefly consider poison ivy or poison oak, but couldn't recall touching any plants that day. I bought some over-the-counter cream to on my way home from work to help with the itching. 

By Wednesday, it was pretty clear that I was getting a rash that might not go away on its own, so I made a doctor's appointment for that afternoon. That's when I learned that, depending on the person, a poison ivy rash can take several days to appear and, because the plant's oil (which actually causes the reaction) gets on different parts of skin in different amounts, the rash can appear to "spread" as the reaction occurs. 

The doctor prescribed some steroid cream, though I had to wait until Thursday evening for my local drug store to fill the prescription as it was initially out of stock. Even after using the cream twice daily for a few days, the rash still seemed to be slowly "spreading" towards my fingers.

That's when I learned one of those tidbits of information that are kind of scary when you think about them -- the oil from the poison ivy plant can remain active for up to a year after contact, so any oil residue left on clothing, etc., can cause the same kind of reaction as touching the plant, depending on the amount. I had washed the clothes that I had been wearing, but had neglected the shoes! Covid-19 has trained us all to avoid touching our face when we are out and about and to always wash our hands when coming back inside. This made perfect sense as to why I was getting a "spread" to my fingers, but never had anything on my face...

So there was another round of washing (sheets, shoes, pillows, etc.) anything that I might have inadvertently contaminated with poison ivy oil.

Now three weeks on, the rash is finally beginning to subside. I was usually able to resist the urge to scratch, but there were a few days (ironically right at the start of annual leave from work) when the itching between my fingers was quite annoying and frustrating. (It is very hard to avoid moving your fingers if you actually want to do anything.)  

Though dealing with poison ivy is small potatoes compared to so many other problems people are facing these days, it is still a good idea to heed the advice we got as kids, "Leaves of three, let it be." 

    

 

Saturday, July 3, 2021

Proactive Tweaking

 This is the third (and hopefully last) post chronicling my attempts to extract some data from a PDF. While those posts were focused on the challenges, this post is focused a little more on one of the successes. 

To set the stage, I was working with a document that had a chronological list of colleges and universities that had gone to "test optional" for their admissions process. The document was mostly just the list of school names, but occasionally had a date range to the left:

Summer 2011     Bryant University 
                Earlham College 
                Nichols College 
                Anna Maria College

Though this format is quite readable for humans, it is obviously not the most useful format for processing. The me of a few years ago would probably have just saved to text and then gone through the text file manually to pull out the dates. But the current me knew better. I knew that I should do something to make things easier on myself for downstream processing. 

I had a simple idea. I went through the document and prepended the word "DATE:" before each date, then hit return to make sure that the school name was not on the same line. That resulted in, after saving to text, something that looked like this:

DATE:Summer 2011    
Bryant University 
Earlham College 
Nichols College 
Anna Maria College

From there, I could use a simple Python script to loop through each line, ignore blank lines, identify and extract the dates, and create a dataframe that had dates and schools for every row: 

cur_date = ''
results = []
for element in data:
    element = element.strip()
    if not element:
        continue
    if element.startswith("DATE:"):
        new_date = element.split("DATE:",1)[1]
        if (cur_date != new_date):
            cur_date = new_date
            continue
    results.append((cur_date,element)) 

# make dataframe
df = pd.DataFrame(results, columns =['Date_Range', 'Schools'])

 Once I had the data in a dataframe, grouping by date and plotting the count of schools became quite easy.  


Bar chart showing growth in schools with test optional policies over time
 

The moral of this story is that even if you are doing something partially manually, why not add some proactive tweaking to make things easier on yourself down the line. Though this process may not have saved time in terms of making this particular chart (I could have just counted the number of schools in each time period and tracked the results in Excel), I don't consider it a wasted effort. I now have the list of the schools themselves along with the dates for each school in a machine-friendly format for future use, if needed.


Friday, July 2, 2021

Don't Use Cut and Paste

 This is a follow-up to a recent post about regex. The context is trying to take data from a PDF that presented a chronological list of colleges and universities that have adopted a test optional admissions process. As detailed in the previous post, I had tried (and eventually given up trying) to extract data directly from the PDF via a Python program and finally broke down and cut and pasted the contents into a text file from a Word doc that the PDF had been exported to using Adobe Acrobat.

 Now that I had a text file (and a good night's sleep to forget all about regex), I thought that it should be relatively easy to finish up the process. Determined to use Python for at least part of the process, I created a small script to read in the text file that I had created previously, initially printing the results to the screen. 

At first, I noticed that there were a number of blank lines when reading in the file, but I figured I could get rid of those easily enough before saving. But as I looked more carefully at the lines, I noticed the same issue I had run into when reading directly from PDF -- multiple entries on the same line. Huh? How could that happen? 

I don't know for sure, but my best guess is that, whatever the process used to create the original file, not everything that looked like a separate line was actually a separate line. In other words, there was not a line break after everything that looked like a line. (You've probably seen the same behavior at the page level in Word, where things will flow to the next page automatically. You may have even added some additional spaces at the end of a sentence near the bottom of a page to "help" that process along.....)

 The solution was to go back to the exported Word doc (which I had saved, luckily) and, rather than cut and paste, try to save directly to text. Lo and behold, a dialog box popped up asking if I would like to add line breaks. Yes, please! 

With that done, the script correctly read the lines as expected, and I could get on to the business of manipulating the data (which I'll describe in the next post). 

 The moral of the story? Just because something "looks" like columns or lines or whatever in a document, that doesn't mean that it will behave as such programmatically. Be careful when cutting and pasting! 

 

Thursday, July 1, 2021

Now You've Got Two Problems

 According to Wikipedia, regex (short for "regular expression") is "a sequence of characters that specifies a search pattern." There's an old regex joke in coding circles that goes something like this:

You have a problem. You are trying to extract specific information from a string. So you say to yourself, "I know, I'll use regular expressions." Now you have two problems.

This is one of those jokes which makes you laugh and wince at the same time. It's funny because it's true. Here's my story.

 The other day, I came across a chronological list of colleges and universities that have moved to a "test optional" application process. ("Test optional" means that students are not required to submit e.g., SAT or ACT scores as part of their application, a policy which is not new, but became supercharged as Covid-19 wreaked havoc on standardized testing sites and schedules.) Because the list was in PDF format, I thought it might be useful to parse the data to something more amenable to manipulation, such as csv, so that the increase in schools over time could be more easily counted or even plotted. 

The first challenge was trying to initially extract data from the PDF (which is about 17 pages long). Based on some Googling and Stack Overflow posts, I first looked into a Python package called PyPDF2, but that didn't seem to work for me. I knew that I didn't want to spend to much time on this (famous last words), so I tried just exporting to Excel from Adobe Acrobat, but that wasn't much better. I also tried copy/pasting from the "edit" view in Acrobat, but that was also quite frustrating and I quickly gave up. (Seventeen pages is not trivial to cut and paste, and my wrist started complaining pretty quickly.)

 I went back to more pressing tasks for a bit, but had that gnawing desire in the back of my mind to not admit defeat yet. The next time I had a break, I decided to search for alternative Python package and came across another post that had some sample code to extract text from a PDF using the "SimplePDFViewer" module from the pdfreader package. I tweaked the sample code, pointed it at the PDF, and got promising results. Not perfect but any stretch of the imagination (breaks in strange places, empty lines, only one page parsed, etc.), but promising. 

The format of the document is basically a list of colleges (one per line) with occasional date ranges to the left of the names. Most entries also contain some kind of parenthetical material about the details of the test optional process (e.g., "Alfred University (for high school classes of 2021, 2022 and 2023)").  

It took several tries to rewrite the sample code to actually read all seventeen pages of the document and extract the text from each page. I found that using spaces and ignoring the parentheses via regex

 (re.split('\([^()]*\)|\s\s+', page)  

tended to do a relatively decent job of splitting the schools on each page, allowing me to go from something that looked like a single string (to the computer) after the initial extract:

 '  Union College   Franklin & Marshall College (extend optional policy to all)   King’s College   Nazareth College   Mitchell College   Lake Forest College   Salisbury University (3.5 GPA) Summer 2006        Hobart & William Smith Colleges   Providence College Spring 2006  Bennington College     Gustavus Adolphus College   George Mason University (3.5 GPA)   Lebanon Valley College Fall 2005  Knox College     Drew University   Chatham College Spring 2005  Lawrence University   The College of the Holy Cross   St. Lawrence University Winter 2004-2005 Susquehanna University (“Write Option” for all)   Sarah Lawrence College  '   

to something that looked like this (a Python list):

 ['', 'Union College', 'Franklin & Marshall College', '', 'King’s College', 'Nazareth College', 'Mitchell College', 'Lake Forest College', 'Salisbury University', '', 'Summer 2006', 'Hobart & William Smith Colleges', 'Providence College', 'Spring 2006', 'Bennington College', 'Gustavus Adolphus College', 'George Mason University', '', '', 'Lebanon Valley College', 'Fall 2005', 'Knox College', 'Drew University', 'Chatham College', 'Spring 2005', 'Lawrence University', 'The College of the Holy Cross', 'St. Lawrence University', 'Winter 2004-2005', 'Susquehanna University', '', 'Sarah Lawrence College', '']  

But there were still empty strings in the list, as well as elements that didn't parse nearly as well, leading to some multiple entries like: "Illinois State University Illinois Wesleyan University" as a single line in the final processed file.

If regex helped the first time, then of course the answer is "more regex"! So I decided to rewrite the program to read back in the initial processed output, remove blank lines (which worked), and use "regex magic" to split those long, confusing entries into individual schools (which didn't).

At first, things seemed to be going smoothly. I read the file line by line, ignoring the blank lines, and looked for lines that had more than once instance of the word "University" or "College" to identify lines with multiple entries. If no multiple entries were found, the line was saved back to a file. If a multiple entry was found, I would try to parse the line using regex:

 ([\w\s]+(University|College))\s([\w\s]+(University|College))  

which could then extract each of the school names as a regex group before saving. This worked wonderfully, until it didn't. I quickly realized that some schools have "Institute" in the name, though adding "Institute" to the regex was not terribly challenging:

 ([\w\s]+(University|College|Institute))\s([\w\s]+(University|College|Institute))  

The bigger problem was three-fold: The first was that, while most of the troublesome lines contained two entries, some contained many more (like this humdinger: "Indiana Tech Indiana University East Indiana University Kokomo Indiana University Northwest Indiana University Southeast Indiana University South Bend Indiana University of Pennsylvania Indiana Wesleyan University Iowa State University").  I haven't yet been able to successfully modify my query to match "one or more" additional schools on the same line, though I know it is possible in theory (and probably even trivial for someone who works with regex daily).

The second problem was the variation in naming conventions all of which the regex pattern would need to account for. Here are just a couple:

  • <something> College (e.g., Swarthmore College)
  • <something>University (e.g., Harvard University)
  • <something> Institute (e.g., Rensselaer Polytechnic Institute)
  • <something> Institute of <something> (e.g., Massachusetts Institute of Technology)
  • University of <something> (e.g., University of Hawai`i Hilo)
  • College of <something> (e.g., College of Wooster)
  • <something> University <something> (e.g., Loyola University Chicago)

(And don't forget the "false friends" like the string "University of Maryland College Park", which is a single place and not the name of two distinct schools, unlike the "Illinois State University Illinois Wesleyan University" string earlier.)

The third problem was the not insignificant number of typos and similar in the document. This was usually in the form of mismatched brackets (e.g., opening parentheses, but closing brackets; brackets rather than parentheses; doubled opening or closing parentheses; square rather than curly brackets), but such things all would need to be accounted for in the regex. The difference between "Caldwell University {Three-year pilot)" and "Caldwell University (Three-year pilot)" may be trivial and inconsequential for the human reader, but is a world of difference for an automatic parser.  

So, although I had some moments of success along the way, I realized that regex is not going to save the day this time. Maybe this kind of thing is trivial for a regex guru, but I could feel myself getting dragged deeper and deeper into the regex rabbit hole. (There is some email validation regex that runs over 6,000 characters in length! Dealing with all of the edge cases get get pretty hairy.) 

At the end of the day, I gave up, exported the PDF to Word, manually added carriage returns to each date range along with a prepended "DATE:" designation, and copy/pasted everything to text document which I then saved, after using Notepad++ to remove all of the tabs. Maybe tomorrow I'll feel like trying to do something with the file, but regex beat me up pretty good today.