SQL and the (newly discovered) OVER operator

I have a tool that takes a range of ids and processes each document with an id within that range. I wanted to run this tool in parallel with each instance processing 100,000 documents. The problem is that document ids are not contiguous. There are gaps. So a simple criteria of document id + offset is not sufficient. I needed an SQL statement that detailed contiguous range of 100,000 document ids.

As with most ostensibly complicated SQL the solution is in creating a virtual table (ie inner select) from an existing table. My virtual table needed to be sorted on document id and a sequence number given for each row. To do that I needed to use this in the column selection of the virtual table.

ROW_NUMBER() OVER( ORDER BY document_id ) - 1 row_number

I had never heard of the OVER operator. It applies a function to a row of an ordered relation. So the ROW_NUMBER() function gives the first row a value 1, the second 2, etc. Since I would be grouping using division I need the row numbers to start from 0 and so the subtraction of 1.

Now that I have row numbers and rows ordered by document id I needed to find within groups of 100,000 rows the minimum and maximum document ids. I used a simple group by row_number / 100,000 to get the row groupings. Then used MIN(document_id) to get the group's minimum document id. Same for maximum document id. The final SQL is as follows and it runs fast enough for the 50M records I needed to use it with

SELECT
  FLOOR( y.row_number / 100000 ),
  MIN( y.document_id ),
  MAX( y.document_id ),
  COUNT( * )
FROM
  (
    SELECT
      x.*,
      ROW_NUMBER() OVER( ORDER BY document_id ) - 1 row_number
    FROM
      documents x
  ) y
GROUP BY
  FLOOR( y.row_number / 100000 )
ORDER BY
  MIN( y.document_id )

With the data I can use a bash script to read it and produce a series of commands that are feed to xargs for parallel execution.

superglue + baby powder = gap filling putty

I bought some of Games Workshop's liquid green stuff and have been waiting to use it to clean up some plastic kits I am currently working on (well, next in line). Today, however, I found out about the superglue + baby powder putty. Dries rock hard and can be filed to shape.

Viking and Anglo-Saxon army painting saga concludes

If you had any interest in my 6mm Viking and Anglo-Saxon army painting saga then, well, first, you need to get out more and meet people, but, second, I sold them to a nice chap in Australia. Who then sent them to a nice chap in Scotland to paint them! Perhaps I should have done that.

What scale are scale buildings?

In response to the question "When gaming a city fight, do you all try to match the scale/size of the scenery to your miniature troops:"

A true scale creates overpowering buildings and the combatants are very greatly diminished. So a smaller scale for buildings with regard to their volume, but not their floor plan, removes this diminishment. I have not tried this, but you could use the Disney World trick of reducing the height of each floor above the ground floor. See Forced Perspective.

No one man or woman can fix this broken country

I plan to read none of your postings about 2016 Presidential candidates. Let's be rational, no one man or woman can fix this broken country. The US has run its course. Only a revolution to replace it will work. A revolution by those with the wisdom, knowledge, principles, and diplomacy of the Founding Fathers. Not the loudest. Not the richest.



Why are tires so expensive?

Where can you buy 15mm and 28mm wheels for military vehicles? I looked around today and found several suppliers, but with outrageous prices at ~$2/tire. Langley Models have better prices, but still high. For some reason I had expected to be able to buy a 100 for $10.

Keiichi Matsuda's Hyper-Realty

Keiichi Matsuda has updated his 2010 haunting vision of an augmented reality with his new Hyper-Realty. Worth watching and, be advised, it is a horrible place.

Sobriety is an unwelcome form of adulthood

'Nuf said.

"Flat" terrain feature example

I like adding features to an otherwise flat terrain board. This includes features like swales, outcroppings, or a bunch of logs. Anything that might get in the way of gameplay's terrain is put at the edges of the game board. Here is constructive set of photographs showing the progression of a flagstone and well terrain feature by Firedragon Games

How to start gaming a scenario?

I am working on a scenario and I am looking for advise. I have imagined a setting in the future where inadequate water supplies has lead to national governments and international corporations buying land in other countries to claim water rights. The water is then transported back home -- as water or as foods, eg wheat, rice, etc -- or sell it to the highest bidder. This lead to armed insurrection by the locals even though the water claims are legal. The insurrections have now devolved into multi-party factional/clan warfare. All factions have advanced military equipment (mechs!), but some factions have better supply lines and maintenance facilities than others.

The environment is harsh. Dust storms of national and global scale have made long distance wireless communications unreliable. So, despite the advanced equipment the factions continue to rely on scouting (human and autonomous drones) and runners to convey situation awareness and instructions between units. Even long range targeting and retargeting takes significant time, but once established is accurate. Some factions rely on well planned actions with strict adherence to the plan by the discrete units. Other factions rely on discrete units making local decisions stemming from the unit's overall purpose.

The scenario I am working on is a tanker truck needs to be driven to the coast (ie, off board) by its corporate owners. A rival faction wants to divert the trunk to its own facilities for local distribution (ie, driven off the other side of the board). It is a stalemate to have the trunk not reach either of these destinations before N rounds of play. It is a defeat for both sides if the tanker trunk is destroyed.

My initial plan was to use the Horizon Wars rules as I played an early edition of them from a few years ago. The rules are basic, but do make for a quick game. However, I am not wedded to them so am open to suggestions for other suitable rules.

My first question is how to start gaming a scenario? Is there an approach to determining the units needed? Or is it ad hoc, ie just play a game with a guess at unit composition and respond to the results? Or something else all together?

Update: The working document for this is at "A setting for near-future wargames."

Weekend workbench 2016-05-14

Finally made the cubby to hold my modeling tools, materials, and stuff. Still need to paint it, but that might happen in another life.


Update: It is beginning to fill up.

Meeting room geek lights

I have been giving more thought to the meeting room occupancy display. Right now I am considering what would be a minimal presentation. There are 2 reasons for this. The first is that the problem is not about showing details of who has reserved the room, but, instead, is the room free for squatting and, if so, for how long? The second problem is a technical one and that is the display device should run for weeks on a single battery charge. (I am assuming no mains electricity.)

So here is the new display.

⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤

Each light, red and green, represents 10 minutes of time. The display shows a total of 2 hours of time. The above display indicates that the room is reserved for another 40 minutes, free for the following 60 minutes. and then occupied for at least 20 minutes -- it could be more, but the display can't indicate for how much more.

⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤

Here the room is free for another 20 minutes, then reserved for 30 minutes, and the free again for at last 70 minutes.

The more I look at this the more I think that this is the solution.

Update 2025-03-17: The Japanese stationery manufacturer King Jim has created a similar product, the Visual Time Bar (VBT10). When I wrote the original post I had not considered the cultural situation of reading the display from left-to-right or right-to-left. The VBT10 is read right-to-left.

The spotter stood still ...

The spotter stood still bracing himself against in the swirling sands of the desert winds. It was not sight but sound that caught his attention first. Once again, the people of the Rough needed to defend themselves against the Coppers. The Rough had only a ruined city and salvaged armaments to defend with. The Coppers had everything else ... except the will to never give up.

A setting for an Horizon Wars miniatures wargame.

Meeting room occupancy project

We have an issue with staff not reserving meeting rooms. You know the situation, team High-Strung did reserve the room, but when they arrive they find that team Anarchist has squatted and are well into their arguments discussions. I don't include myself in the "we," by the way. I am happy to meet sitting on the floor with a big pad of paper between the participants. Anyway, it got me thinking about how technology can be used to exasperate this problem. For example, a display at the door to each meeting room that told folks if the room was reserved, for how much longer, who was using the room next, and lastly a list of reservations for today and tomorrow. Or, better yet, some ambient situation awareness device like Illumigami.

Before reinventing the wheel I did look around for a tool like this. What I found was a market of crazy, obese, gold plated implementations that actually cost money and often often lots of it. I don't object to making money from software, but not from something so simple as this, that is something that requires hardly more than a single web page. And so the development began.

The webapp is in its very early stages of development. I have just touched the surface of the Google Calendar API and its use within a HTML/JS page. At this point I am only concerned with the mechanics and so have made little attempt to make the UI useable. My goal with the UI is to have a tablet by each meeting room running a browser in "kiosk" mode and only showing the meeting room page. The page will show the events for a user who has authorized and selected a calendar.

If you want a side project and are interested in working on this with me to complete it the project is at https://github.com/andrewgilmartin/meeting-room-occupancy. A live version is running at http://andrewgilmartin.com/meetingroom/.

An unfortunate choice of title

There is a new dark ages set of wargame rules out called Blood Eagle. While I know that I play a game that represents an immoral, cruel, and bloody human activity, but to name a game after one of its more heinous acts were the warrior
would have their spine column exposed and then their ribs severed from the spine and pulled open (to resemble wings). Finally the lungs were exposed (and in some instances covered in salt) to complete the torture and lead to the death of the prisoner. (source)
is too much for me. I won't be playing that game.

DNS records for site split between Blogger and colocation server

This posting is mostly here to remind me how to configure the DNS records for a site where the www subdomain's content is hosted by Blogger and other subdomains are hosted by my colocation server.

DNS A record

Host Points To TTL
@ 111.222.333.444 1 hour

DNS CNAME records

Host Points To TTL
* @ 1 hour
www ghs.google.com 1 hour
X Y.googlehosted.com 1 hour

Where X and Y are given by Google/Blogger.

When I figure out the MX records I will update this page!

"Splinters"

In a previous posting I wrote about using "splinters" to represent the kind of deadfall you find in the woods and bogs. I spent more energy that I care to admit settling on a source for the splinters: block planer shavings, chainsaw chunks, drill bit waste, ... In the end I used the dried up branches one drives over time and again on the driveway. A hand full of this material will spread out to a square foot of forest floor. Just split off a chunk, flatten it a few times with a hammer, and then pull it apart.

Preparing two more tables for May's Great Swamp Wargamers game night

Preparing two more tables tops for May's Great Swamp Wargamers game night. The table tops are 4'×3' hardboard glued and nailed on a framework made from 2"×1" pine boards. The edges are blue-taped to keep them clean until the terraforming is done. The terraforming is a simple process of

  1. Glue down any surface features. In this case, I am using "splinters" to give the appearance of deadfall found in a bog or forest floor.
  2. Paint the whole surface with an earth brown.
  3. Paint the surface features as needed. In this case a "wet" brown.
The remaining surface features are added in reverse order. That is, if you want daisies then put down the yellow flowers first, then add the grass, and finally add the dirt. The goal is that the items added first will absorb most of the glue so that when you get to step 8 what is on top will fall off.
  1. Using a spray bottle coat the entire surface with watered-down white glue -- about 1 part glue to 3 parts water. Use a spray bottle rather than a brush as it will apply a more even coating. A brush tends to leave ridges.
  2. Using a sieve apply a pattern of grass. When using Woodland Scenics's fine turf add some coarse turf to the sieve to slow the casting of the fine turf. If you don't do this then you tend to get mounds of turf rather than an even application. 
  3. Using a sieve apply to the remaining (non-grass) areas dirt. I use dirt from my yard that has been baked for an hour at 400° F to kill off the microbes. 
  4. When dry, turn the tabletop upside down and tap to remove excess grass and dirt.
  5. Finish with several applications of watered-down white glue or spray clear coat to fix the grass and dirt and make it resilient to playing on. I use a pressurized hand sprayer that is normally used for spraying insecticide. It can apply an even coat of the glue. The tabletop is noticeably wet after each spraying, but I do this outside on a warm day so that the glue drys before penetrating the hardboard.

Java 8 is not Java

Java 8 is not Java. Java 8 is a good tool. Java's shift towards being a functional language is unstoppable. Java, however, as a principled, strongly typed, object-oriented, imperative programing language is no more. I have heard the argument that as a developer I can stick with Java 7 syntax using -source 7, but this is not practical. Libraries will evolve to use use functional practices. Old bugs will only be fixed in these evolved libraries. As functional practices becomes ever more rooted in the libraries their use from Java 7's syntax will become ever more cumbersome and perhaps impossible. If you want to continue developing in Java then you and your team will have to evolve with it.

So these days I am thinking ever more about what language to move to. I think the perspective of my employer would be to remain with a language targeting the JVM. I haven't asked, but I know well enough its conservative approach to solutions. The software architect in me would like to pick a language that is more aligned with a fail fast approach to service runtime and its corollary of needing to start fast.

Lots of folks at this week's O'Reilly Software Architecture conference in NYC are favoring Go (commonly called "golang" to make the conversation clearer and searchable). That it compiles to a binary (and even a statically linked binary) for direct execution on the host is a significant boost to start fast. Starting slow would be your architect's fault: Too much in-process preparation and not enough just in time initialization or not enough externalization of functionality into a service. I will look at Go and its libraries. I do worry that is the new black, like Ruby was several years ago.

Its handheld not handsheld, people.

Finally, a sane design for a handheld device! The Kindle Oasis. Hopefully it rotates for lefties and for righties when writing notes on paper.