<commit_before>(ns braid.server.identicons
  (:require [braid.server.digest :refer [sha256-digest]])
  (:import (java.awt.image BufferedImage AffineTransformOp)
           (java.awt.geom AffineTransform)
           (java.io ByteArrayOutputStream)
           (org.apache.commons.codec.binary Base64OutputStream)
           (java.awt Color)
           (javax.imageio ImageIO)))

;; General creating icons
(defn new-icon
  "Create a new BufferedImage to draw an icon"
  [w h]
  (BufferedImage. w h BufferedImage/TYPE_INT_RGB))

(defn icon-context
  "Get the graphics context from an icon"
  [icon]
  (.createGraphics icon))

(defmulti draw-identicon (fn [icn-type nums ctx] icn-type))

;; Default-style identicon

(defmethod draw-identicon :default
  [_ [w h] nums]
  (let [img (new-icon w h)
        ctx (icon-context img)
        tiles-per-side 5
        tile-size (quot (min w h) tiles-per-side)
        tiles-count (/ (* tiles-per-side tiles-per-side) 2) ; / 2 b/c we mirror pixels
        mirror-vert? (even? (last nums))
        in-row (fn [pos] (quot pos (/ tiles-per-side 2)))
        in-col (fn [pos] (rem pos (/ tiles-per-side 2)))
        draw-tile (fn [pos]<commit_msg>clean up java imports in identicons<commit_after>(ns braid.server.identicons
  (:require [braid.server.digest :refer [sha256-digest]])
  (:import (java.awt.image BufferedImage
                           AffineTransformOp)
           java.awt.geom.AffineTransform
           java.io.ByteArrayOutputStream
           org.apache.commons.codec.binary.Base64OutputStream
           java.awt.Color
           javax.imageio.ImageIO))

;; General creating icons
(defn new-icon
  "Create a new BufferedImage to draw an icon"
  [w h]
  (BufferedImage. w h BufferedImage/TYPE_INT_RGB))

(defn icon-context
  "Get the graphics context from an icon"
  [icon]
  (.createGraphics icon))

(defmulti draw-identicon (fn [icn-type nums ctx] icn-type))

;; Default-style identicon

(defmethod draw-identicon :default
  [_ [w h] nums]
  (let [img (new-icon w h)
        ctx (icon-context img)
        tiles-per-side 5
        tile-size (quot (min w h) tiles-per-side)
        tiles-count (/ (* tiles-per-side tiles-per-side) 2) ; / 2 b/c we mirror pixels
        mirror-vert? (even? (last nums))
        in-row (fn [pos] (quot pos (/ tiles-per-side 2)))
        in-col (fn [pos] (rem pos (/ tiles-per-side 2)))
        draw-tile (fn [pos]
{'fraction_non_alphanumeric': 0.12484342379958246, 'fraction_numerical': 0.008350730688935281, 'mean_word_length': 2.6138763197586727, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2467469', 'n_tokens_mistral': 821, 'n_tokens_neox': 796, 'n_words': 223}