<commit_before>(ns hphelper.live.view
  (:require [hphelper.live.control :as lcon]
            [hphelper.live.api :as lapi]
            [hphelper.shared.sql :as sql]
            [hphelper.shared.saveload :as sl]
            [hphelper.shared.unique :as uni]
            [hphelper.shared.indicies :as indicies]
            ;; For indicies
            [hphelper.scengen.generator :as sgen]
            [taoensso.timbre :as log]

            [hiccup.core :refer :all]

            [hphelper.scengen.print :as sprint]
            [hphelper.chargen.print :as cprint]
            )
  (:gen-class)
  )

(defn- html-print-indicies-table
  "Prints indicies in a table in n columns"
  [inds n]
  [:table
   (map (fn [r] [:tr r])
        (partition-all
          n
          (map (fn [x] [:td x])
               (indicies/html-print-indicies inds))))
   ]
  )

(defn view-game
  "Prints a game view nicely for players"
  [baseURL uid]
  (log/trace "view-game. baseURL:" baseURL "uid:" uid)
  (if-let [game (lcon/get-game uid)]
    (html [:html
           [:head
            [:title "Sector indicies"]
            [:meta {:http-equiv "refresh" :content 5}]
            ]
           [:body
            [:div
             (html-print-indicies-table (first (:indicies game)) 13)
             ]
            [:div
             (map (fn [n] [:div n])
                  (:news game))
             ]
            ]
           ])
    (html [:html [:div "Game not found"]])
    ))

(defn- print-service-group
  "Prints a single service group in a html format"
  [g]
  (html [:div {:class "data"}
         [:h3 (str (:sg_name g) ": " (:owner g))]
         (map (fn [r] [:div (str (:minion_name r)
                                 " -- " (:minion_clearance r)
                                 (if (:minion_cost r)
                                   (str " -- " (:minion_cost r))
                                   "")
                                 (if (:mskills r)
                                   (str " -- " (:mskills r))
                                   "")
                                 )])
              (:minions g)
              )
         ]
        )
  )


(defn view-game-player
  "Prints a game view nicely for a *single* player. Includes live view, session sheet, and player sheets. Reads from a livescenario, not a normal scenario"
  [baseURL guid uuid]
  (log/trace "view-game-player." baseURL guid uuid)
  (if-let [g (lcon/get-game guid)]
    (let [u (get-in g [:hps uuid])]
      (log/trace "view-game-player. HP name is:" (get u :name))
      (html [:html
             [:head
              [:title "Sector View"]
              [:meta {:http-equiv "refresh" :content 5}]
              [:link {:rel "stylesheet" :href (str baseURL "/css/style.css")}]
              [:style ".data {background-color: #270140; padding: 10px; border-right: 10px solid black; border-bottom: 5px solid black;}"]
              ]
             [:body
              [:header
               [:h1 "Sector " (:zone g) ": " (indicies/html-print-indicies (first (:indicies g)))
                ]
               ]
              [:table
               [:tr {:style "vertical-align: top;"}
                [:td ;; Left column Begin
                 ;; Moved these to the header
                 ;;[:div [:h3 "Current Sector Indicies"] (html-print-indicies-table (first (:indicies g)) 13) ]
                 [:div {:class "data"}
                  [:h3 "Sector News"]
                  (map (fn [n] [:div n])
                       (:news g))
                  ]
                 [:div {:class "data"}
                  [:h3 "Upcoming cbay auctions"]
                  (map (fn [^String i] [:div i]) (:cbay g))
                  ]
                 ;; Society messages
                 (if-let [missions (:missions (lapi/get-player-society-missions guid uuid))]
                   (do
                     [:div {:class "data"}
                      [:h3 "Private message summary"]
                      (map (fn [{ss_id :ss_id text :ssm_text}]
                             [:div (str (sql/get-ss-by-id ss_id) ": " text)])
                           (sort-by :ss_id missions))
                      ]
                     )
                   )
                 ;; Extra Messages
                 (if-let [messages (:msgs u)]
                   [:div
                    (map (fn [^String msg] [:div msg]) messages)
                    ]
                   )
                 ;; Player Sheet
                 (if u
                   [:div {:class "data"}
                    [:h3 "Character Sheet"]
                    (cprint/html-print-sheet u)]
                   nil
                   )
                 ]
                [:td ;; Right column Begin
                 ;; Minions
                 (map print-service-group (:serviceGroups (lapi/get-minions guid uuid)))
                 ]
                ]
               ]
              ]
             ]
            )
      )
    )
  )

(defn- player-key
  "Returns a string with a game's uid and the player's uid for logging in"
  [baseURL uid player]
  (str "Player: " (:name player)
       ". Player uid: " (:password player)
       ". Player link: " (html [:a {:href (str baseURL "/live/playerview/" uid "/" (:password player) "/")} (:name player)])<commit_msg>Adds styling to additional messages<commit_after>(ns hphelper.live.view
  (:require [hphelper.live.control :as lcon]
            [hphelper.live.api :as lapi]
            [hphelper.shared.sql :as sql]
            [hphelper.shared.saveload :as sl]
            [hphelper.shared.unique :as uni]
            [hphelper.shared.indicies :as indicies]
            ;; For indicies
            [hphelper.scengen.generator :as sgen]
            [taoensso.timbre :as log]

            [hiccup.core :refer :all]

            [hphelper.scengen.print :as sprint]
            [hphelper.chargen.print :as cprint]
            )
  (:gen-class)
  )

(defn- html-print-indicies-table
  "Prints indicies in a table in n columns"
  [inds n]
  [:table
   (map (fn [r] [:tr r])
        (partition-all
          n
          (map (fn [x] [:td x])
               (indicies/html-print-indicies inds))))
   ]
  )

(defn view-game
  "Prints a game view nicely for players"
  [baseURL uid]
  (log/trace "view-game. baseURL:" baseURL "uid:" uid)
  (if-let [game (lcon/get-game uid)]
    (html [:html
           [:head
            [:title "Sector indicies"]
            [:meta {:http-equiv "refresh" :content 5}]
            ]
           [:body
            [:div
             (html-print-indicies-table (first (:indicies game)) 13)
             ]
            [:div
             (map (fn [n] [:div n])
                  (:news game))
             ]
            ]
           ])
    (html [:html [:div "Game not found"]])
    ))

(defn- print-service-group
  "Prints a single service group in a html format"
  [g]
  (html [:div {:class "data"}
         [:h3 (str (:sg_name g) ": " (:owner g))]
         (map (fn [r] [:div (str (:minion_name r)
                                 " -- " (:minion_clearance r)
                                 (if (:minion_cost r)
                                   (str " -- " (:minion_cost r))
                                   "")
                                 (if (:mskills r)
                                   (str " -- " (:mskills r))
                                   "")
                                 )])
              (:minions g)
              )
         ]
        )
  )


(defn view-game-player
  "Prints a game view nicely for a *single* player. Includes live view, session sheet, and player sheets. Reads from a livescenario, not a normal scenario"
  [baseURL guid uuid]
  (log/trace "view-game-player." baseURL guid uuid)
  (if-let [g (lcon/get-game guid)]
    (let [u (get-in g [:hps uuid])]
      (log/trace "view-game-player. HP name is:" (get u :name))
      (html [:html
             [:head
              [:title "Sector View"]
              [:meta {:http-equiv "refresh" :content 5}]
              [:link {:rel "stylesheet" :href (str baseURL "/css/style.css")}]
              [:style ".data {background-color: #270140; padding: 10px; border-right: 10px solid black; border-bottom: 5px solid black;}"]
              ]
             [:body
              [:header
               [:h1 "Sector " (:zone g) ": " (indicies/html-print-indicies (first (:indicies g)))
                ]
               ]
              [:table
               [:tr {:style "vertical-align: top;"}
                [:td ;; Left column Begin
                 ;; Moved these to the header
                 ;;[:div [:h3 "Current Sector Indicies"] (html-print-indicies-table (first (:indicies g)) 13) ]
                 [:div {:class "data"}
                  [:h3 "Sector News"]
                  (map (fn [n] [:div n])
                       (:news g))
                  ]
                 [:div {:class "data"}
                  [:h3 "Upcoming cbay auctions"]
                  (map (fn [^String i] [:div i]) (:cbay g))
                  ]
                 ;; Society messages
                 (if-let [missions (:missions (lapi/get-player-society-missions guid uuid))]
                   (do
                     [:div {:class "data"}
                      [:h3 "Private message summary"]
                      (map (fn [{ss_id :ss_id text :ssm_text}]
                             [:div (str (sql/get-ss-by-id ss_id) ": " text)])
                           (sort-by :ss_id missions))
                      ]
                     )
                   )
                 ;; Extra Messages
                 (if-let [messages (:msgs u)]
                   [:div {:class "data"}
                    [:h3 "Additional Messages"]
                    (map (fn [^String msg] [:div msg]) messages)
                    ]
                   )
                 ;; Player Sheet
                 (if u
                   [:div {:class "data"}
                    [:h3 "Character Sheet"]
                    (cprint/html-print-sheet u)]
                   nil
                   )
                 ]
                [:td ;; Right column Begin
                 ;; Minions
                 (map print-service-group (:serviceGroups (lapi/get-minions guid uuid)))
                 ]
                ]
               ]
              ]
             ]
            )
      )
    )
  )

(defn- player-key
  "Returns a string with a game's uid and the player's uid for logging in"
  [baseURL uid player]
  (str "Player: " (:name player)
       ". Player uid: " (:password player)
       ". Player link: " (html [:a {:href (str baseURL "/live/playerview/" uid "/" (:password player) "/")} (:name player)])
{'fraction_non_alphanumeric': 0.13188051850460267, 'fraction_numerical': 0.004602667668607928, 'mean_word_length': 1.169315403422983, 'pattern_counts': {'":': 6, '<': 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': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3798690', 'n_tokens_mistral': 3252, 'n_tokens_neox': 3018, 'n_words': 846}