<commit_before>(ns conference-rating.db-handler
  (:require [monger.core :as mg]
            [monger.collection :as mc]
            [schema.core :as s]
            [conference-rating.schemas :as schemas]
            [schema.utils :as schema-utils]
            [conference-rating.aggregator :as ag])
  (:import (org.bson.types ObjectId)))

(def mongolab-uri (System/getenv "MONGOLAB_URI"))

(defn clear-id-in-doc [doc]
  (assoc doc :_id (.toHexString (:_id doc))))

(defn connect []
  (if mongolab-uri
    (:db (mg/connect-via-uri mongolab-uri))
    (mg/get-db (mg/connect {:host "127.0.0.1" :port 27017}) "crdb")))

(defn add-conference [conference db]
  (let [document (assoc conference :_id (ObjectId.))]
    (mc/insert db "conferences" document)
    (clear-id-in-doc document)))

(s/defn add-rating [rating :- schemas/Rating db]
  (let [document (assoc rating :_id (ObjectId.))]
    (mc/insert db "ratings" document)
    (clear-id-in-doc document)))

(defn get-conferences-list [db]
  (let [list (mc/find-maps db "conferences")]
    (map clear-id-in-doc list)))

(defn get-conference [id db]
  (let [item (mc/find-one-as-map db "conferences" {:_id (ObjectId. ^String id)})]
    (println item)
    (clear-id-in-doc item)))

(defn- only-valid [rating]
  (let [valid (not (schema-utils/error? rating))]
    (if-not valid
      (println "ignoring " rating))<commit_msg>is/sr/ts| convert series to uppercase before storing in db<commit_after>(ns conference-rating.db-handler
  (:require [monger.core :as mg]
            [monger.collection :as mc]
            [schema.core :as s]
            [conference-rating.schemas :as schemas]
            [schema.utils :as schema-utils]
            [conference-rating.aggregator :as ag])
  (:import (org.bson.types ObjectId)))

(def mongolab-uri (System/getenv "MONGOLAB_URI"))

(defn clear-id-in-doc [doc]
  (assoc doc :_id (.toHexString (:_id doc))))

(defn connect []
  (if mongolab-uri
    (:db (mg/connect-via-uri mongolab-uri))
    (mg/get-db (mg/connect {:host "127.0.0.1" :port 27017}) "crdb")))

(defn add-conference [conference db]
  (let [series (:series conference)
        upper-case-series (if series (.toUpperCase series) "")
        document (assoc conference :_id (ObjectId.) :series upper-case-series)]
    (mc/insert db "conferences" document)
    (clear-id-in-doc document)))

(s/defn add-rating [rating :- schemas/Rating db]
  (let [document (assoc rating :_id (ObjectId.))]
    (mc/insert db "ratings" document)
    (clear-id-in-doc document)))

(defn get-conferences-list [db]
  (let [list (mc/find-maps db "conferences")]
    (map clear-id-in-doc list)))

(defn get-conference [id db]
  (let [item (mc/find-one-as-map db "conferences" {:_id (ObjectId. ^String id)})]
    (clear-id-in-doc item)))

(defn- only-valid [rating]
  (let [valid (not (schema-utils/error? rating))]
    (if-not valid
      (println "ignoring " rating))
{'fraction_non_alphanumeric': 0.1655697956356079, 'fraction_numerical': 0.007620367163145133, 'mean_word_length': 3.1915820029027575, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '2636905', 'n_tokens_mistral': 1080, 'n_tokens_neox': 1044, 'n_words': 265}