                             (str/join ", " (take 10 bad-plots))
                             "]"))))
     (when-let [assigned-plots (assign-user-plots plots design-settings)]
-      (p-insert-rows! "assigned_plots" assigned-plots))))
+      (p-insert-rows! "assigned_plots" (assign-qaqc assigned-plots design-settings)))))
 
 (defn- create-project-plots! [project-id
                               lon-min

;;; Create project
;;;

(defn- add-users-to-plots [user-id users-plots]
  (map (fn [{:keys [plot_id]}]
         {:plot_rid plot_id
          :user_rid user-id})
       users-plots))

(defn- assign-user-plots
  "Assigns users to plots. The two assignment options are:

  (let [{:keys [user-method users percents]} (:user-assignment design-settings)
        plot-count (count plots)]
    (case user-method
      "equal"   (equally-assign-users plots users :plot_id)
      "percent" (loop [rem-users    users
                       rem-percents percents
                       rem-plots    plots
                       user-plots   []]
                  (if (= 1 (count rem-users))
                    (concat user-plots
                            (add-users-to-plots (first rem-users) rem-plots :plot_id))
                    (let [num-plots (ceil-percent plot-count (first rem-percents))]
                      (recur (rest rem-users)
                             (rest rem-percents)
                             (drop num-plots rem-plots)
                             (concat user-plots (add-users-to-plots (first rem-users)
                                                                    (take num-plots rem-plots)
                                                                    :plot_id))))))
      nil)))

(defn- assign-qaqc [assigned-plots design-settings]
  (when (seq assigned-plots)
    (let [{:keys [qaqc-method percent smes]} (:qaqc-assignment design-settings)
          {:keys [users]}                    (:user-assignment design-settings)]
      (concat assigned-plots
              (->> assigned-plots
                   (group-by :user_rid)
                   (map (fn [[user-id user-plots]]
                          [user-id (take (ceil-percent (count user-plots) percent)
                                         user-plots)]))
                   (reduce (fn [acc [user-id user-plots]]
                             (let [other-users (case qaqc-method
                                                 "overlap" (remove #(= user-id %) users)
                                                 "sme"     smes
                                                 nil)]
                               (concat acc (equally-assign-users user-plots
                                                                 other-users
                                                                 :plot_rid))))
                           []))))))

(defn- create-project-samples! [project-id
                                plot-shape
