From f6d02b2f5008a833bf8ad60c52b5574690821323 Mon Sep 17 00:00:00 2001 From: "Robert C. Martin" Date: Thu, 22 Jun 2023 10:15:23 -0500 Subject: [PATCH] ::event-counter --- src/more_speech/mem.clj | 5 +++-- src/more_speech/types/event_counter.clj | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 src/more_speech/types/event_counter.clj diff --git a/src/more_speech/mem.clj b/src/more_speech/mem.clj index b2bdcbf..f0b3f44 100644 --- a/src/more_speech/mem.clj +++ b/src/more_speech/mem.clj @@ -3,7 +3,8 @@ [more-speech.types.active-subscription :as subscription-type] [more-speech.types.profile :as profile-type] [more-speech.types.relay :as relay-type] - [more-speech.types.tab :as tab-type]) + [more-speech.types.tab :as tab-type] + [more-speech.types.event-counter :as event-counter-type]) (:import (javax.swing JFrame) (javax.swing.tree DefaultMutableTreeNode))) @@ -74,8 +75,8 @@ ::node-map ::orphaned-replies ::event-history + ::event-counter-type/event-counter - ::event-counter ::back-count ::send-chan ::article-window diff --git a/src/more_speech/types/event_counter.clj b/src/more_speech/types/event_counter.clj new file mode 100644 index 0000000..bffa1f4 --- /dev/null +++ b/src/more_speech/types/event_counter.clj @@ -0,0 +1,16 @@ +(ns more-speech.types.event-counter + (:require [clojure.spec.alpha :as s])) + +(s/def ::relay-url #(re-matches #"ws+://[\w.-]+/?" %)) +(s/def ::total int?) +(s/def ::dups int?) +(s/def ::kinds (s/map-of int? int?)) + +;Counts incoming events and sorts them by relay and kind. Also counts dups. +(s/def ::event-counter (s/and + (s/keys :opt-un [::total + ::dups + ::kinds]) + (s/map-of (s/or :keyword #{:total :dups :kinds} + :url ::relay-url) + some?)))