Friday 24 July 2020

Deleting Documents from Azure CosmosDB using Python

I had a hell of a time trying to delete documents from an Azure Cosmos DB using the Azure Cosmos library in PyPI today. Thought I'd write down what I did to get it working.

The problem occured because the database in question doesn't any partitions defined. Although I could successfully query the database and get the document, I couldn't delete it. The fix was to specify NonePartionKeyValue as the partitiion key argument to delete_item() . I didn't find any documentation on this, and clearly it's a bit of a hack, but it worked!

So here's what worked:

from azure.cosmos.partition_key import NonePartitionKeyValue
from azure.cosmos import exceptions, CosmosClient, PartitionKey
import config #my stuff

guid = #the id of the document I'm trying to delete
db_name = #the id of the database
db_coll = #the name of the database collection

url = config.COSMOS_URL
key = config.COSMOS_KEY
client = CosmosClient(url, credential=key)

database = client.get_database_client(db_name)

container = database.get_container_client(db_coll)

for item in container.query_items(query='select * from o where o.id = \''+ guid + '\'', enable_cross_partition_query=True):
    container.delete_item(item, NonePartitionKeyValue)

Wednesday 2 January 2013

Stuart 10V Steam Engine

I bought a set of castings for a Stuart 10V Steam Engine, to see if I could do it. Although I didn't take as many photos as I should have, because I was more concerned with actually doing it than with recording the process, there are enough pics to make a reasonable post, I think.

Flattening the top of the base in the 4-jaw chuck:

 Facing the soleplate, using a couple of spare cutters to hold things firmly:

Milling out the slots for the main bearings using a vertical slide on the lathe. Just nibbled away in little steps to get the approximate shape, and filed by hand to get the final shape:

Test-fitting the bit of extruded brass I'll use to make the bearings:

We skip unceremoniously to the standard now, facing the feet:

I shaped the soft jaws of the chuck to hold the standard closely, and supported it further with a brass rod stuck in a lump of Sugru, that most excellent of silicone sticky stuffs:

Test-fitting to see if things go together:

Preparing to drill the holes in the standard's feet. The 3-jaw chuck is mounted on the vertical slide.

....and another test fit....

...and another....

Boring the standard. Clamping the standard to the faceplate was a bit tedious. Took a lot of tapping and measuring and more tapping and more measuring:


Preparing the bearings. I used a stub mandrel to hold the piece while turning in very tiny cuts. Here I'm using a height gauge to mark the final diameter:

Test fit. Satisfying.

Things coming together quite nicely now!

Drilling the steam ports in the cylinder. This was scary, since I had to bore the cylinder a little wider than specified in order to get past a casting flaw. So I needed to recaclulate the angles of the steam ports. I started with a center drill...

 ...then milled to the correct depth, leaving a pip where I needed to drill at an angle...

Using a protractor to set the cylinder at the right angle in the lathe:

...and about a week later, here's where we're at:

I made little lids for the oil cups:

Preparing the big end for drilling:

Finished crank webs beside one I messed up earlier (drill bit broke!), but it shows how I did it: I superglued two bits of steel together, and marked them out, and drilled them out, very carefully, in one piece. Then a bit of heat separated the two parts:

Dry-fitting everything to see if stuff lines up ok:

"The crankshaft ready for silver soldering". This was the most pleasant bit of the whole process - I've never silver-soldered before:

After soldering:

Beautiful colours while pickling in vinegar:

After pickling & a bit of emery paper:

And the scary bit: cutting out the crank. Then back to the lathe to clean it all up.

Another trial fit. We're almost there!

Preparing to drill the circle of holes in the cylinder cover. I have a rotary table attached to the vertical slide - really pushing the limits of my Taig lathe here!

Finished. Very satisfying.

Preparing to do the same thing on the standard

Much time passes, and it's all more or less done! Here I've make some decorative steam inlets/outlets using a circle of 12BA bolts.

By accident, I drilled 6 holes in the top cylinder cover instead of the 5 specified. I'm actually glad I did - I think even numbers of holes are nicer!

I modified the standard Stuart drain cocks by adding a steel handle. The handles that come with the purchased drain cocks are way out of scale for an engine this size.




More time passes, and at last the whole thing is fitted together. It runs very smoothly on very little pressure - I can power it quite happily just blowing into it.

And here are some pics of the painted engine. I've attached pipes to the drain cocks so the whole thing looks a bit more, well, enginey:

Some jobs remain - I need to do new steam inlet and outlet pipes and put it on a decent wooden base...

Thanks for watching!






Thursday 16 February 2012

NetDuino - fun with rotary encoders

I'm playing with a Netduino microcontroller with a view to making a digital readout for my lathe (using a linear encoder from machine-dro.co.uk). So I experimented with a couple of rotary controllers I had lying around which were pretty flaky. After quite a bit of googling and poking around, I found the following code gave me the most satisfactory results, so I thought I'd post it in case anybody else found it handy (feel free to suggest improvements):


public class RotaryEncoder
    {
        private InterruptPort PortA;
        private InterruptPort PortB;
        private uint prevA = 0;
        private uint prevB = 0;
        private uint prevPort = 0;

        public int Position{get; private set;}
        
        public RotaryEncoder(Cpu.Pin pinA, Cpu.Pin pinB)
        {

            PortA = new InterruptPort(
                    pinA, 
                    false, 
                    Port.ResistorMode.PullUp, 
                    Port.InterruptMode.InterruptEdgeBoth);

            PortB = new InterruptPort(
                    pinB, 
                    false, 
                    Port.ResistorMode.PullUp, 
                    Port.InterruptMode.InterruptEdgeBoth);

            PortA.OnInterrupt += OnInterrupt;
            PortB.OnInterrupt += OnInterrupt;
        }

        void OnInterrupt(uint port, uint state, DateTime time)
        {
            if (port == prevPort)
                return;

            prevPort = port;

            if (((uint)PortA.Id) == port){
                if (state > 0 && prevB > 0)
                    --Position;
                prevA = state;
            }
            else{
                if (prevA == 0 && state == 0)
                    ++Position;
                prevB = state;
            }    
        }  
    }

Wednesday 15 February 2012

Stuart Steam Oscillator - Part III



The steam engine is finally finished! I was a bit lazy about taking photos so there are a few steps I didn't capture (most notably creating the piston/piston rod/crosshead assembly), but here's what I did...

I used an optical centre punch to punch the centre, then scribed a guideline to help me determine the bore of the cylinder. 


After drilling out, I used a Glanze boring tool to bore the cylinder to its final diameter, using a telescopic bore gauge to check as I went along. The boring tool gave a lovely finish, and I polished it after boring it using a piece of dowel roughly the same diameter as the cylinder covered in Tormek sharpening paste (it's what was to hand, and it gave a mirror finish). 


Drilling the hole for the cylinder stud...


Drilling the steam ports at an angle. Some people recommend drilling them straight and not all the way through, then drilling a hole from the ends of the cylinder to connect it up (there's an excellent series of posts by 'Bogs' on rebuilding a badly-made twin oscillator that's well worth perusing. It's possible that I've made every mistake he describes, but I try not to think about it).

Turning the cylinder covers. The phosphor bronze was an absolute pig to turn. 

I should have left myself a bigger spigot, but I got away with it.

The cover is a nice fit - stays in when you turn it upside down too!

Drilling the holes for the studs that hold the whole cylinder assembly together. I decided to drill the top and bottom covers at the same time to reduce marking errors.

Again, phosphor bronze taking its toll on my drill bits...

Cylinder covers done. Very satisfying considering the covers came from a dirty lump of bronze to start with.

Unfortunately my camera wasn't to hand while I was making the piston. I reckoned it was important to ensure that  the piston and crosshead were exactly concentric with the piston rod. So after roughly turning the piston and crosshead to size, I tapped them and attached them to the piston rod, then finished them off while holding the piston rod in a collet. It all went swimmingly until my cutter snagged the crosshead and bent the end of the piston rod. If I feel inclined, I may make a new piston rod assembly later on (especially since I cocked up drilling through the crosshead), but I decided to press ahead with what I had for now. 


Putting it all together. Amazingly, it all fitted!

Loosely assembled....

Here it is compared to a casting (I bought a second casting in case I messed up, so now I have to make another one!).

Finally I drilled holes for the cylinder lagging screws. And here a word of warning! If you follow the measurements on the plan, you're very likely to end up with the screws overlapping the edge! I was so annoyed! I'll have to find some 7BA screws with a smaller head somewhere, but these will have to do for now.


So here's the finished engine. For such a small thing, it took an enormous amount of time to complete, but I learned a lot in the process, and I have the courage now to tackle something a little more ambitious.




You can see it running (too fast) on compressed air here: