Cattle counter based on events log
My understanding of your requirements: For each event calculate a number based on the prior events (including the current one).
That is indeed possible by using a window function:

SELECT id, event, addend, SUM(addend) OVER (ORDER BY id ASC) AS count FROM (
  SELECT id, event, 
  CASE WHEN event = 'entry' THEN 1 WHEN event = 'exit' THEN -1 ELSE 0 END AS addend 
  FROM events
) AS events_with_addend


The type of event does not contain any information we can use in the aggregate sum, so we have to provide it (in the inner query).

Instead it is preferred to create a separate table event_types containing the name of the event as well as the change applied to count by it, then referencing event_typesfrom events (look up database normalization) and losing the inner query.

The actual window function then just sums up the addends of each row until (including) the current one (the window frame).

It is very possible this approach might lead to performance problems depending on the (growing) count of rows. If it does, have a look into materialized views