Skip to content

Instantly share code, notes, and snippets.

@tr4n2uil
Last active August 29, 2015 14:13
Show Gist options
  • Save tr4n2uil/8be402c20aa99cfcccd2 to your computer and use it in GitHub Desktop.
Save tr4n2uil/8be402c20aa99cfcccd2 to your computer and use it in GitHub Desktop.
(with-db "20150123"
(def reconnects (get-sessions {:message {$in ["client_reconnecting", "client_reconnecting_with_data"]} "json_data.clientBrowser" "chrome"}))
(defn msg-counter [msgs collections] (map (fn [sid] (hash-map :s sid :rc (count-occurances {:message {$in msgs}} sid))) collections))
(defn reconnects-n [n] (map :s (filter #(= 1 (:rc %)) (msg-counter ["client_reconnecting", "client_reconnecting_with_data"] reconnects))))
(def reconnects-1 (reconnects-n 1))
(def old-sessions (filter
(partial any?
{:message {$in ["client_reconnecting", "client_reconnecting_with_data"]}
"json_data.xhr_failure" {$exists false}
}) reconnects-1))
(def new-sessions (filter
(partial any?
{:message {$in ["client_reconnecting", "client_reconnecting_with_data"]}
"json_data.xhr_failure" {$exists true}
"json_data.report" {$exists false}
}) reconnects-1))
(def no-internet (filter
(partial any?
{:message {$in ["client_reconnecting", "client_reconnecting_with_data"]}
"json_data.xhr_failure" {$gt 0.0}
"json_data.report" {$exists false}
}) reconnects-1))
(def no-report-on-reconnect (filter
(partial any?
{:message {$in ["client_reconnecting", "client_reconnecting_with_data"]}
"json_data.xhr_failure" 0.0
"json_data.report" {$exists false}
"json_data.speed" {$exists false}
"json_data.packetsReceived" {$exists false}
}) reconnects-1))
(def undefined-speed (filter
(partial any?
{:message {$in ["client_reconnecting", "client_reconnecting_with_data"]}
"json_data.xhr_failure" 0.0
"json_data.report" {$exists false}
"json_data.speed" {$exists false}
"json_data.packetsReceived" {$exists true}
}) reconnects-1))
(def zero-speed-open-dataChannel (filter
(partial any?
{:message {$in ["client_reconnecting", "client_reconnecting_with_data"]}
"json_data.xhr_failure" 0.0
"json_data.report" {$exists false}
"json_data.speed" "0.00"
"json_data.data_channel_state" "open"
}) reconnects-1))
(def zero-speed-null-dataChannel (filter
(partial any?
{:message {$in ["client_reconnecting", "client_reconnecting_with_data"]}
"json_data.xhr_failure" 0.0
"json_data.report" {$exists false}
"json_data.speed" "0.00"
"json_data.data_channel_state" "null"
}) reconnects-1))
(def zero-speed-closed-dataChannel-ice-connected (filter
(partial any?
{:message {$in ["client_reconnecting", "client_reconnecting_with_data"]}
"json_data.xhr_failure" 0.0
"json_data.report" {$exists false}
"json_data.speed" "0.00"
"json_data.data_channel_state" "closed"
"json_data.ice_connection_state" "connected"
}) reconnects-1))
(def zero-speed-closed-dataChannel-ice-disconnected (filter
(partial any?
{:message {$in ["client_reconnecting", "client_reconnecting_with_data"]}
"json_data.xhr_failure" 0.0
"json_data.report" {$exists false}
"json_data.speed" "0.00"
"json_data.data_channel_state" "closed"
"json_data.ice_connection_state" "disconnected"
}) reconnects-1))
(def zero-speed-closed-dataChannel-ice-closed (filter
(partial any?
{:message {$in ["client_reconnecting", "client_reconnecting_with_data"]}
"json_data.xhr_failure" 0.0
"json_data.report" {$exists false}
"json_data.speed" "0.00"
"json_data.data_channel_state" "closed"
"json_data.ice_connection_state" "closed"
}) reconnects-1))
(def nonzero-speed-null-dataChannel (filter
(partial any?
{:message {$in ["client_reconnecting", "client_reconnecting_with_data"]}
"json_data.xhr_failure" 0.0
"json_data.report" {$exists false}
"json_data.speed" {$ne "0.00" $exists true}
"json_data.data_channel_state" "null"
}) reconnects-1))
(def nonzero-speed-closed-dataChannel (filter
(partial any?
{:message {$in ["client_reconnecting", "client_reconnecting_with_data"]}
"json_data.xhr_failure" 0.0
"json_data.report" {$exists false}
"json_data.speed" {$ne "0.00" $exists true}
"json_data.data_channel_state" "closed"
}) reconnects-1))
(def nonzero-speed-open-dataChannel (filter
(partial any?
{:message {$in ["client_reconnecting", "client_reconnecting_with_data"]}
"json_data.xhr_failure" 0.0
"json_data.report" {$exists false}
"json_data.speed" {$ne "0.00" $exists true}
"json_data.data_channel_state" "open"
}) reconnects-1))
(defn lp [n s] (vector s n (/ (* 100.00 n) (count new-sessions))))
(def results {
:total_reconnect_sessions (count reconnects)
:reconnect_1_sessions (count reconnects-1)
:old-sessions (count old-sessions)
:new-sessions (count new-sessions)
})
(def buckets {
:undefined-speed (lp (count undefined-speed) "stats api issue")
:zero-speed-open-dataChannel (lp (count zero-speed-open-dataChannel) "video speed zero after dataChannel opened")
:zero-speed-null-dataChannel (lp (count zero-speed-null-dataChannel) "no ssrc in stats")
:zero-speed-closed-dataChannel-ice-connected (lp (count zero-speed-closed-dataChannel-ice-connected) "")
:zero-speed-closed-dataChannel-ice-disconnected (lp (count zero-speed-closed-dataChannel-ice-disconnected) "ice disconnected by socketio reconnect")
:zero-speed-closed-dataChannel-ice-closed (lp (count zero-speed-closed-dataChannel-ice-closed) "ice closed abruptly")
:nonzero-speed-null-dataChannel (lp (count nonzero-speed-null-dataChannel) "no dataChannel opened but video working")
:nonzero-speed-closed-dataChannel (lp (count nonzero-speed-closed-dataChannel) "closed dataChannel but video working")
:nonzero-speed-open-dataChannel (lp (count nonzero-speed-open-dataChannel) "reconnect after internet failure")
:no-internet (lp (count no-internet) "internet disconnected")
:no-report-on-reconnect (lp (count no-report-on-reconnect) "null report data on reconnect")
})
(defn tabulate [] (table/table-view (conj (vec (cons [:reason, :sessions, :percent] (reverse (sort-by second (vals buckets))))) [:total (reduce + (map second (vals buckets))) (reduce + (map #(nth % 2) (vals buckets)))])))
(pprint results)
(print "\n")
(pprint buckets)
(print "\n")
(pprint (str "Total " (reduce + (map second (vals buckets))) " " (results :new-sessions)))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment