using System.Globalization;
public static void Main()
var eventId = "M4882207200740428651";
var timestamp = DateTimeOffset.ParseExact(eventId[4..19], "yyMMddHHmmssfff", new CultureInfo("hu-HU")).ToUnixTimeMilliseconds();
Console.WriteLine($"DELETE FROM traffic.events WHERE pkey = {GetEventPartitionKey(eventId)} AND eventcreatedat = '{timestamp}' AND eventid = '{eventId}'");
Console.WriteLine($"DELETE FROM traffic.images WHERE pkey = {GetImagePartitionKey(eventId)} AND eventid = '{eventId}'");
private static int GetEventPartitionKey(string eventId)
const string timeSpanFormat = "mmss";
const long ticksPerHalfHour = TimeSpan.TicksPerMinute * 30;
const long ticksPerPartition = ticksPerHalfHour / 100;
const int dateOffset = 1000;
var timeSpan = TimeSpan.ParseExact(eventId[12..16], timeSpanFormat, new CultureInfo("hu-HU"));
var eventPartition = (int)((timeSpan.Ticks % ticksPerHalfHour) / ticksPerPartition);
return (int.Parse(eventId[4..10]) * dateOffset) + eventPartition;
private static long GetImagePartitionKey(string eventId)
const int partitionMultiplier = 4;
var hourPartition = int.Parse(eventId[10..12]) % partitionMultiplier;
return (((long)GetEventPartitionKey(eventId)) * 10) + hourPartition;