lexbailey / giant_led_cube

Other
2 stars 0 forks source link

log data in clickhouse #5

Closed lexbailey closed 2 years ago

lexbailey commented 2 years ago

spit out all the info to the cloud and make it do all the thinking about twitter etc

46bit commented 2 years ago

@danieljabailey 👋🏻 I'm more-or-less ready to implement this. Haven't immediately figured out the implementation though.

I want to log button presses (e.g. which button was used, which way it was moved up/down), some sort of ID for the current solve attempt, successful solves (and their time taken.) Basically lots of interesting metadata for grafana :)

It'll probably just be an async call using the reqwest library. Which bit of hardware should I do it on? And is all that info available there?

46bit commented 2 years ago

There's more info on the product at https://blog.cloudflare.com/workers-analytics-engine/ if you're interested, or I can give you a demo sometime :)

lexbailey commented 2 years ago

Awesome! The place to implement this will be in the service executable, which runs on the RasPi4 inside the cube. It already spawns a bunch of threads for various things, so I think the thing to do is spawn another one to handle all your network stuff. IDK if you've used rust's MPSC channels before, but you can see in the code some examples of creating channels to pass events between threads.

Currently there's no unique solve ID, but you could use the started field in GameState to derive a unique ID based on the time the game was started. https://github.com/danieljabailey/giant_led_cube/blob/main/service/src/main.rs#L79 of if that's not suitable then I'm sure you can add something in there. You might need to hack the code a bit to test this, currently there's no way to pretend a cube is attached to try things out while developing, you'll have to implement that to be able to test it (probably just make a thing that implements all the same things as the serial port device, and have a command line option to swap that in for the cube serial stream).

As for the events you want: you won't get raw button presses. The hardware can't actually distinguish between some of the switches anyway since various groups of buttons do the same things. What you can easily get though is the name of the twist the player requested in standard rubik's cube notation: https://ruwix.com/the-rubiks-cube/notation/ (see the Twist type in cube_model: https://github.com/danieljabailey/giant_led_cube/blob/main/cube_model/src/lib.rs#L122)

The events coming from the cube device are handled here: https://github.com/danieljabailey/giant_led_cube/blob/main/service/src/main.rs#L604 This is the twist event and the solved event. The timing is calculated there, but I haven't actually tested the timing code properly yet, that's first on my list once I have the new hardware working.

Good luck, and do ask questions :)

46bit commented 2 years ago

https://github.com/danieljabailey/giant_led_cube/pull/10

46bit commented 2 years ago

13 will get us much closer to being ready

46bit commented 2 years ago

Gonna close this now #21 is done 🎉