<commit_before>(ns viewer.controller.web
  (:require [compojure.core :refer [defroutes GET]]
            [clojure.data.json :as json]
            [clojure.xml :as xml]
            [viewer.model.mastery :as mastery]
            [viewer.model.ship :as ship]
            [viewer.view.mastery :as mastery-view]))

(def xml-filename-pattern #"(\S+) - (\S+).xml")

(defn parse-xml-filename [fn]
  (rest (re-find xml-filename-pattern fn)))

(defn xml-response [content]
  {:status 200
   :headers {"Content-Type" "application/xml"}
   :body content})

;;; ["/user/:id", :id #"[0-9]+"]
(defroutes routes
  (GET ["/masteries/:typeid", :typeid #"[0-9]+"] [typeid]
       (mastery-view/render (ship/ship-info (read-string typeid))
                            (mastery/all (read-string typeid))))
  (GET ["/masteries/:shipname", :shipname #"[a-zA-Z ]+"] [shipname]
       (let [ship-info (ship/ship-info shipname)]
         (mastery-view/render ship-info
                              (mastery/all (:typeid ship-info)))))
  (GET "/masteries/xml/:filename" [filename]
       (let [[ship level] (parse-xml-filename filename)]
         (xml-response (with-out-str (xml/emit-element (mastery/as-xml ship level)))))))
<commit_msg>Return 404 for non existing ships.<commit_after>(ns viewer.controller.web
  (:require [compojure.core :refer [defroutes GET]]
            [clojure.data.json :as json]
            [clojure.xml :as xml]
            [viewer.model.mastery :as mastery]
            [viewer.model.ship :as ship]
            [viewer.view.mastery :as mastery-view]))

(def xml-filename-pattern #"(\S+) - (\S+).xml")

(defn parse-xml-filename [fn]
  (rest (re-find xml-filename-pattern fn)))

(defn xml-response [filename content]
  {:status 200
   :headers {"Content-Type" "application/xml"
             "Content-Disposition" (format "attachment; filename=\"%s\"" filename)}
   :body content})

;;; ["/user/:id", :id #"[0-9]+"]
(defroutes routes
  (GET ["/masteries/:typeid", :typeid #"[0-9]+"] [typeid]
       (mastery-view/render (ship/ship-info (read-string typeid))
                            (mastery/all (read-string typeid))))
  (GET "/masteries/:shipname" [shipname]
       (let [ship-info (ship/ship-info shipname)]
         (when ship-info
           (mastery-view/render ship-info
                                (mastery/all (:typeid ship-info))))))
  (GET "/masteries/xml/:filename" [filename]
       (let [[ship level] (parse-xml-filename filename)]
         (xml-response filename (with-out-str (xml/emit-element (mastery/as-xml ship level)))))))

{'fraction_non_alphanumeric': 0.17796942375539004, 'fraction_numerical': 0.006664053312426499, 'mean_word_length': 2.599435825105783, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 26}, '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': '4713540', 'n_tokens_mistral': 872, 'n_tokens_neox': 853, 'n_words': 188}