Clojure Problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; | |
; This file is intellectual property of Dmitrii Pisarenko (dp@dpisarenko.com). | |
; | |
; Copyright (c) 2020-2021. Dmitrii Pisarenko. | |
; | |
; All rights reserved. | |
; | |
(ns lit-universe.process.v1.export-scene-list-test | |
(:require [clojure.test :refer :all]) | |
(:require [lit-universe.process.v1.export-scene-list | |
:refer [findSeqIdsBySceneId, | |
compose-scene-seqs, | |
compose-unstructured-tuple-list]]) | |
(:require [lit-universe.works.white-ns.lesson12.sceneList2 :refer [перечень-сцен2]]) | |
(:require [lit-universe.works.white-ns.lesson12.seq07 :refer [seq07]]) | |
(:require [clojure.set :as set]) | |
) | |
(deftest findSeqIdsBySceneId-test | |
(is (= ["seq07"] | |
(findSeqIdsBySceneId "sc026" [{ | |
:SceneId "sc026" | |
:SeqId "seq07" | |
}]) | |
) | |
) | |
(is (= ["seq07", "seq06"] | |
(findSeqIdsBySceneId "sc026" [{ | |
:SceneId "sc026" | |
:SeqId "seq07" | |
} | |
{ | |
:SceneId "sc026" | |
:SeqId "seq06" | |
} | |
]) | |
) | |
) | |
) | |
(deftest compose-scene-seqs-test | |
(is (= [["seq07"]] | |
(let | |
[ | |
scene-list [{:sceneId "sc026"}] | |
seq-tuples [ | |
{ | |
:SceneId "sc026" | |
:SeqId "seq07" | |
} | |
] | |
] | |
(compose-scene-seqs scene-list seq-tuples) | |
) | |
)) | |
) | |
(deftest compose-scene-seqs-test2 | |
(is (= [["seq07"] []] | |
(let | |
[ | |
scene-list [ | |
{:sceneId "sc026"} | |
{:sceneId "sc027"} | |
] | |
seq-tuples [ | |
{ | |
:SceneId "sc026" | |
:SeqId "seq07" | |
} | |
] | |
] | |
(compose-scene-seqs scene-list seq-tuples) | |
) | |
)) | |
) | |
(deftest compose-scene-seqs-test3 | |
(is (= [[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] ["seq07"] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []] | |
(let | |
[ | |
scene-list перечень-сцен2 | |
seq-tuples [ | |
{ | |
:SceneId "sc026" | |
:SeqId "seq07" | |
} | |
] | |
] | |
(compose-scene-seqs scene-list seq-tuples) | |
) | |
) | |
) | |
) | |
(deftest compose-scene-seqs-test4 | |
(is (= [[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] ["seq07"] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []] | |
(let | |
[ | |
scene-list (filter some? перечень-сцен2) | |
unstructured-seqs [seq07] | |
unstructured-seq-tuples (compose-unstructured-tuple-list unstructured-seqs) | |
seq-tuples (set/union unstructured-seq-tuples []) | |
] | |
(compose-scene-seqs scene-list seq-tuples) | |
) | |
) | |
) | |
) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; | |
; This file is intellectual property of Dmitrii Pisarenko (dp@dpisarenko.com). | |
; | |
; Copyright (c) 2020-2021. Dmitrii Pisarenko. | |
; | |
; All rights reserved. | |
; | |
(ns lit-universe.process.v1.export-scene-list | |
(:require [lit-universe.core.newline-to-br :refer [newline-to-br]]) | |
(:require [lit-universe.process.v1.locations :refer [generate-location-details-report]]) | |
(:require [lit-universe.works.white-ns.common :refer [russian-character-names]]) | |
(:require [lit-universe.process.v1.utils | |
:refer [ | |
render-with-h4 | |
render-with-h5 | |
]]) | |
(:require [lit-universe.core.seq-html :refer [seq-list-to-html]]) | |
(:require [lit-universe.process.v1.time :refer [ | |
translate-date-time-to-russian, | |
extract-statements, | |
extract-constraints | |
] | |
] | |
) | |
(:require [hiccup.core :refer [html]]) | |
(:require [hiccup.table :refer [to-table1d]] | |
[clojure.set :as set]) | |
) | |
;; Supporting functions (start) | |
(defn create-row | |
([nr id участники событие-сцены время места арки] | |
(create-row nr id участники событие-сцены "td" время места арки) | |
) | |
( | |
[nr id участники событие-сцены tag время места арки] | |
(let [ | |
opening-tag (str "<" tag ">") | |
closing-tag (str "</" tag ">") | |
location (if (= "td" tag) | |
(apply str | |
(interpose ", " | |
(map (fn [cur-location] | |
(let | |
[ | |
location-id (get cur-location :LocationId) | |
location-desc (get cur-location :Desc) | |
] | |
(format "<a href='#%s'>%s</a>" location-id location-desc) | |
) | |
) | |
места | |
) | |
) | |
) | |
"Места" | |
) | |
] | |
(str "<tr>" | |
opening-tag | |
nr | |
closing-tag | |
opening-tag | |
id | |
closing-tag | |
opening-tag | |
участники | |
closing-tag | |
opening-tag | |
событие-сцены | |
closing-tag | |
opening-tag | |
время | |
closing-tag | |
opening-tag | |
location | |
closing-tag | |
opening-tag | |
арки | |
closing-tag | |
"</tr>\n") | |
) | |
) | |
) | |
(defn create-toc | |
[] | |
(let [] | |
(html [:div | |
[:h2 "Содержание"] | |
[:ol | |
[:li [:a {:href "#scene-overview"} "Перечень сцен"]] | |
[:li [:a {:href "#seqs"} "Перечень арок"]] | |
[:li [:a {:href "#time-details"} "Детали по времени сцен"]] | |
[:li [:a {:href "#time-constraints"} "Ограничения по времени сцен"]] | |
[:li [:a {:href "#location-details"} "Места"]] | |
[:li [:a {:href "#scene-details"} "Детальное описание сцен"]] | |
] | |
] | |
) | |
) | |
) | |
(defn scene-characters-to-string | |
[scene] | |
(let [ | |
participants (get scene :participants) | |
russianCharacterNames (map | |
(fn [character] | |
(let [charId (get character :newId) | |
russianCharacterName (get russian-character-names charId) | |
] | |
russianCharacterName | |
) | |
) | |
participants) | |
comma-separated-characters (clojure.string/join ", " russianCharacterNames) | |
] | |
comma-separated-characters) | |
) | |
(defn create-scene-link | |
[scene-id] | |
(str | |
"<a href=\"#" scene-id "\">" | |
scene-id | |
"</a>" | |
) | |
) | |
(defn scene-overview-row | |
[nr cur-scene datetime seqs] | |
(let [scene-nr (str (+ nr 1)) | |
scene-id (get cur-scene :sceneId) | |
link-to-details (create-scene-link scene-id) | |
seqs-str (apply str seqs) | |
] | |
(create-row scene-nr | |
link-to-details | |
(scene-characters-to-string cur-scene) | |
(get cur-scene :summary) | |
datetime | |
(get cur-scene :Locations) | |
seqs-str | |
) | |
) | |
) | |
(defn findSeqIdsBySceneId | |
[scene-id seq-tuples] | |
(let | |
[ | |
scene-tuples (filter (fn [cur-tuple] | |
(let [cur-tuple-scene-id (get cur-tuple :SceneId)] | |
(= scene-id cur-tuple-scene-id)) | |
) | |
seq-tuples | |
) | |
seqs (map (fn [cur-tuple] | |
(get cur-tuple :SeqId) | |
) | |
scene-tuples | |
) | |
] | |
seqs | |
) | |
) | |
(defn compose-unstructured-tuple-list | |
[unstructured-seqs] | |
(into [] | |
(map | |
(fn [cur-seq] | |
(let | |
[ | |
scenes (get cur-seq :Scenes) | |
seqId (get cur-seq :SeqId) | |
scene-seq-tuples (into [] | |
(map | |
(fn [cur-scene] | |
(let [scene-id (get cur-scene :sceneId)] | |
{ | |
:SceneId scene-id | |
:SeqId seqId | |
} | |
) | |
) | |
scenes | |
) | |
) | |
] | |
scene-seq-tuples | |
) | |
) | |
) | |
unstructured-seqs | |
) | |
) | |
(defn compose-scene-seqs | |
[scene-list seq-tuples] | |
(into [] (map (fn [cur-scene] | |
(let | |
[scene-id (get cur-scene :sceneId)] | |
(findSeqIdsBySceneId scene-id seq-tuples) | |
) | |
) | |
scene-list | |
) | |
) | |
) | |
(defn- generate-scene-overview | |
[scene-list time-info seqs] | |
(let [ | |
header "<h2 id='scene-overview'>Обзор</h2>" | |
top-anchor "<a name=\"top\"></a>" | |
table-header (str "<table border=1 cellspacing=0 bordercolor=black>\n" | |
(create-row "№" | |
"Ид." | |
"Участники" | |
"Событие сцены" | |
"th" | |
"Время" | |
"Места" | |
"Арки")) | |
scene-count (count scene-list) | |
scene-numbers (range 0 scene-count) | |
scene-times (into [] (map (fn [scene] | |
(let | |
[ | |
scene-id (get scene :sceneId) | |
eng-time (get time-info scene-id) | |
ru-time (translate-date-time-to-russian eng-time) | |
] | |
ru-time | |
) | |
) | |
scene-list | |
) | |
) | |
;; TODO: Create a map with scene ID as key and sequences as values | |
;; TODO: Create a map with scene ID as key and an empty list of sequences as value | |
structured-seqs (filter | |
(fn [cur-seq] | |
(let | |
[scenes (get cur-seq :Scenes)] | |
(empty? scenes) | |
) | |
) | |
seqs) | |
unstructured-seqs (filter | |
(fn [cur-seq] | |
(let | |
[scenes (get cur-seq :Scenes)] | |
(not (empty? scenes)) | |
) | |
) | |
seqs) | |
structured-seq-tuples [] | |
;; TODO: Convert scenes from unstructured sequences into tuples {sceneId, seqId} | |
unstructured-seq-tuples (compose-unstructured-tuple-list unstructured-seqs) | |
seq-tuples (set/union unstructured-seq-tuples structured-seq-tuples) | |
;; TODO: Does the error occur with only unstructured-seq-tuples? | |
scene-seqs (compose-scene-seqs scene-list seq-tuples) | |
;; TODO: Find out why scene-seqs only contains empty sequences | |
table-body (apply str | |
(map | |
scene-overview-row | |
scene-numbers | |
scene-list | |
scene-times | |
scene-seqs | |
) | |
) | |
notes "<h3>Примечания</h3> | |
<ul>\n | |
<li><b>№</b> = Порядковый номер (в тексте главы будут идти в этом порядке)</li>\n | |
<li><b>Ид.</b> = Идентификатор</li>\n | |
</ul>\n" | |
table-footer "</table>"] | |
(str header | |
top-anchor | |
table-header | |
table-body | |
table-footer | |
notes | |
) | |
) | |
) | |
(defn ii-type-to-string | |
[ii-type] | |
(if (= ii-type :Causal) | |
"Результат активного выбора (causal)" | |
"Совпадение или случайность или нечто неожиданное (coincidental)")) | |
(defn with-tag | |
[tag text] | |
(str | |
"<" tag ">" | |
text | |
"</" tag ">" | |
) | |
) | |
(defn render-inciting-incident | |
[ii] | |
(let [ | |
type (get ii :Type) | |
type-body (str (ii-type-to-string type)) | |
type-html (render-with-h5 "Тип" type-body) | |
desc (newline-to-br (get ii :Desc)) | |
desc-html (with-tag "p" desc) | |
high-concept (newline-to-br (get ii :HighConceptOfTheScene)) | |
high-concept-html (render-with-h5 "Является ли это запускающее событие high concept сцены? Если да, что является high concept этой сцены?" high-concept) | |
arouse-reaction-by-protagonist (newline-to-br (get ii :DoesItArouseAReactionByProtagonist?)) | |
arouse-reaction-by-protagonist-html (render-with-h5 "Вызывает ли этот инцидент сильные чувства у главного героя сцены?" arouse-reaction-by-protagonist) | |
comment (newline-to-br (get ii :Comment)) | |
comment-html (render-with-h5 "Комментарии" comment) | |
footer "<hr>"] | |
(str desc-html | |
type-html | |
high-concept-html | |
arouse-reaction-by-protagonist-html | |
comment-html | |
footer | |
) | |
) | |
) | |
(defn render-single-progressive-complication | |
[nr total-number-of-complications prog-compl] | |
(let [ | |
pc-nr (+ 1 nr) | |
header (str | |
"Сложность № " | |
pc-nr | |
" из " | |
total-number-of-complications | |
) | |
desc (newline-to-br (get prog-compl :Desc)) | |
] | |
(render-with-h5 header desc) | |
) | |
) | |
(defn render-progressive-complications | |
[prog-compls] | |
(let [ | |
complications-count (count prog-compls) | |
complication-numbers (range 0 complications-count) | |
total-number-of-complications (repeat complications-count) | |
body (apply str | |
(map render-single-progressive-complication | |
complication-numbers | |
total-number-of-complications | |
prog-compls)) | |
] | |
(str body "<hr>")) | |
) | |
(defn render-crisis | |
[crisis] | |
(let [ | |
desc (newline-to-br (get crisis :Desc)) | |
desc-html (with-tag "p" desc) | |
choices-or-question (newline-to-br (get crisis :ChoicesOrQuestion)) | |
choices-or-question-html (render-with-h5 "Вопрос или варианты действий" choices-or-question) | |
type (get crisis :Type) | |
type-txt (if (= type :IrreconcilableGoods) | |
"Выбор из 2 несовместимых добр (irreconcilable goods)" | |
"Лучший из нескольких плохих вариантов (best bad choice)" | |
) | |
type-html (render-with-h5 "Тип" type-txt) | |
type-comment (newline-to-br (get crisis :TypeComment)) | |
type-comment-html (render-with-h5 "Комментарий к типу" type-comment) | |
] | |
(str desc-html | |
choices-or-question-html | |
type-html | |
type-comment-html | |
"<hr>" | |
) | |
) | |
) | |
(defn render-climax | |
[climax] | |
(let [ | |
desc (newline-to-br (get climax :Desc)) | |
desc-html (with-tag "p" desc) | |
body (str desc-html "<hr>") | |
] | |
body | |
) | |
) | |
(defn render-resolution-beat | |
[nr total-beats beat] | |
(let [ | |
nr-txt (+ nr 1) | |
title (str "Бит № " nr-txt " из " total-beats) | |
desc (newline-to-br (get beat :Desc)) | |
body (render-with-h5 title desc) | |
] | |
body) | |
) | |
(defn render-resolution | |
[resolution] | |
(let [ | |
beats (get resolution :Beats) | |
beat-count (count beats) | |
beat-count-seq (repeat beat-count) | |
beat-numbers (range 0 beat-count) | |
beats-html (apply str | |
(map render-resolution-beat | |
beat-numbers | |
beat-count-seq | |
beats)) | |
body (str beats-html "<hr>")] | |
body)) | |
(defn render-random-idea | |
[nr total-nr idea] | |
(let [ | |
nr-txt (+ nr 1) | |
title (str "Идея № " nr-txt " из " total-nr) | |
idea (newline-to-br (get idea :Desc)) | |
body (render-with-h5 title idea)] | |
body | |
) | |
) | |
(defn render-random-ideas | |
[random-ideas] | |
(let [ | |
idea-count (count random-ideas) | |
numbers (range 0 idea-count) | |
idea-count-seq (repeat idea-count) | |
body (apply str | |
(map render-random-idea | |
numbers | |
idea-count-seq | |
random-ideas | |
) | |
) | |
] | |
body | |
) | |
) | |
(defn render-turning-point | |
[turning-point] | |
(if (= nil turning-point) | |
"" | |
(let [ | |
header (with-tag "h4" "Поворотный момент") | |
tp-type (get turning-point :Type) | |
type-str (if (= tp-type :CharacterAction) | |
"Действие персонажа (character action)" | |
"Открытие (revelation)" | |
) | |
type-html (render-with-h5 "Тип" type-str) | |
desc (newline-to-br (get turning-point :Desc)) | |
desc-html (with-tag "p" desc) | |
] | |
(str | |
header | |
desc-html | |
type-html | |
) | |
) | |
) | |
) | |
(defn render-scene-details | |
[cur-scene] | |
(let [scene-id (get cur-scene :sceneId) | |
header (str "<h3>" scene-id "</h3>") | |
anchor (str "<a name=\"" scene-id "\"></a>") | |
summary (newline-to-br (get cur-scene :summary)) | |
fivec (get cur-scene :FiveCommandments) | |
inciting-incident (get fivec :IncitingIncident) | |
inciting-incident-body (render-inciting-incident inciting-incident) | |
turning-point (get cur-scene :TurningPoint) | |
turning-point-html (render-turning-point turning-point) | |
progressive-complications (get fivec :ProgressiveComplications) | |
summary-html (render-with-h4 "Событие сцены" summary) | |
participants-html (render-with-h4 "Участники" (scene-characters-to-string cur-scene)) | |
event-id-html (render-with-h4 "Идентификатор события в events.rec" (get cur-scene :eventId)) | |
inciting-incident-html (render-with-h4 | |
"Запускающее событие (Inciting Incident)" | |
inciting-incident-body) | |
progressive-complications-body (render-progressive-complications progressive-complications) | |
progressive-complications-html (render-with-h4 | |
"Усиливающиеся сложности (Progressive Complications)" | |
progressive-complications-body) | |
crisis (get fivec :Crisis) | |
crisis-body (render-crisis crisis) | |
crisis-html (render-with-h4 | |
"Кризис (Crisis)" | |
crisis-body) | |
climax (get fivec :Climax) | |
climax-body (render-climax climax) | |
climax-html (render-with-h4 | |
"Кульминация (Climax)" | |
climax-body) | |
resolution (get fivec :Resolution) | |
resolution-body (render-resolution resolution) | |
resolution-html (render-with-h4 | |
"Развязка (Resolution)" | |
resolution-body) | |
random-ideas (get cur-scene :RandomIdeas) | |
random-ideas-body (render-random-ideas random-ideas) | |
random-ideas-html (render-with-h4 "Разные идеи" random-ideas-body) | |
end-marker (str | |
"<hr><p>** Описание сцены " | |
scene-id | |
" заканчивается здесь. **</p>" | |
"<a href=\"#top\">Наверх</a>" | |
) | |
] | |
(str header | |
anchor | |
summary-html | |
participants-html | |
event-id-html | |
inciting-incident-html | |
turning-point-html | |
progressive-complications-html | |
crisis-html | |
climax-html | |
resolution-html | |
random-ideas-html | |
end-marker | |
) | |
) | |
) | |
(defn create-progress-report-row | |
([nr scene-count-entry] | |
(let [ | |
nri (+ nr 1) | |
scene-count (get scene-count-entry :Count) | |
scene-html (with-tag "center" scene-count) | |
datetime (get scene-count-entry :DateTime) | |
] | |
(create-progress-report-row | |
nri datetime scene-html "td") | |
) | |
) | |
([nr datetime scene-count tag] | |
(let [ | |
opening-tag (str "<" tag ">") | |
closing-tag (str "</" tag ">") | |
] | |
(str | |
"<tr>" | |
opening-tag | |
nr | |
closing-tag | |
opening-tag | |
datetime | |
closing-tag | |
opening-tag | |
scene-count | |
closing-tag | |
"</tr>" | |
) | |
) | |
) | |
) | |
(defn generate-progress-report | |
[progress-data] | |
(let [header (with-tag "h2" "Прогресс") | |
table-header (str "<table border=1 cellspacing=0 bordercolor=black>\n" | |
(create-progress-report-row | |
"№" | |
"Дата и время" | |
"Количество готовых сцен" "th") | |
) | |
table-footer (str "</table>") | |
entries-count (count progress-data) | |
nr-seq (range 0 entries-count) | |
table-body (apply str | |
(map | |
create-progress-report-row | |
nr-seq | |
progress-data | |
) | |
) | |
] | |
(if (> entries-count 0) | |
(str header | |
table-header | |
table-body | |
table-footer | |
"<hr>" | |
) | |
"" | |
) | |
) | |
) | |
(defn- generate-scene-details-view | |
[scene-list] | |
(let [scene-details (apply str | |
(map | |
render-scene-details | |
scene-list | |
) | |
) | |
] | |
(str "<h2 id='scene-details'>Подробности</h2>" scene-details) | |
) | |
) | |
(defn create-stmts-by-scene-ids | |
[stmts] | |
(into {} | |
(map | |
(fn [stmt] | |
(let [ | |
scene-id (get stmt :SceneId) | |
] | |
{ | |
scene-id stmt | |
} | |
) | |
) | |
stmts | |
) | |
) | |
) | |
(defn occurs-on-day-to-string | |
[stmt] | |
(let [ | |
day (get stmt :Day) | |
comment (get stmt :Comment) | |
comment-txt (if (clojure.string/blank? comment) | |
"" | |
(format " Комментарий: %s" comment)) | |
] | |
(format "Происходит в день %s.%s" day comment-txt) | |
) | |
) | |
(defn ends-on-day-to-string | |
[stmt] | |
(let [ | |
day (get stmt :Day) | |
comment (get stmt :Comment) | |
comment-txt (if (clojure.string/blank? comment) | |
"" | |
(format " Комментарий: %s" comment)) | |
] | |
(format "Заканчивается в день %s.%s" day comment-txt) | |
) | |
) | |
(defn occurs-at-time-to-string | |
[stmt] | |
(let [ | |
day (get stmt :Day) | |
comment (get stmt :Comment) | |
comment-txt (if (clojure.string/blank? comment) | |
"" | |
(format " Комментарий: %s" comment)) | |
] | |
(format "Происходит во время %s.%s" day comment-txt) | |
) | |
) | |
(defn ends-at-time-to-string | |
[stmt] | |
(let [ | |
day (get stmt :Day) | |
comment (get stmt :Comment) | |
comment-txt (if (clojure.string/blank? comment) | |
"" | |
(format " Комментарий: %s" comment)) | |
] | |
(format "Заканчивается во время %s.%s" day comment-txt) | |
) | |
) | |
(defn time-statement-to-string | |
[stmt] | |
(let | |
[fine-type (get stmt :FineType)] | |
(case fine-type | |
:OccursOnDay (occurs-on-day-to-string stmt) | |
:EndsOnDay (ends-on-day-to-string stmt) | |
:OccursAtTime (occurs-at-time-to-string stmt) | |
:EndsAtTime (ends-at-time-to-string stmt) | |
"Error" | |
) | |
) | |
) | |
(defn compose-table-body | |
[time-statements-by-scene-id scene-list] | |
(let | |
[ | |
scene-count (count scene-list) | |
counter-seq (range 1 (+ scene-count 1)) | |
] | |
(map | |
(fn [scene, scene-nr] | |
(let [ | |
scene-id (get scene :sceneId) | |
scene-summary (get scene :summary) | |
cur-scene-time-info (get time-statements-by-scene-id scene-id) | |
cur-scene-time-info-txt (time-statement-to-string cur-scene-time-info) | |
] | |
{ | |
:nr scene-nr | |
:scene-id [ | |
:a {:href | |
(str "#" scene-id) | |
} | |
scene-id | |
] | |
:scene-name scene-summary | |
:time cur-scene-time-info-txt | |
} | |
) | |
) | |
scene-list | |
counter-seq | |
) | |
) | |
) | |
(defn generate-time-report-html | |
[time-info scene-list] | |
(let [ | |
stmts (extract-statements time-info) | |
time-statements-by-scene-id (create-stmts-by-scene-ids stmts) | |
table-body (compose-table-body time-statements-by-scene-id scene-list) | |
hiccups-table-attrs { | |
:table-attrs { | |
:border 1 | |
:cellspacing 0 | |
:bordercolor "black" | |
} | |
} | |
hiccups-table (hiccup.table/to-table1d table-body | |
[:nr "№" :scene-id "Ид. Сцены" :scene-name "Описание сцены" :time "Время"] | |
hiccups-table-attrs | |
) | |
hiccups [:h2 {:id "time-details"} "Детали по времени сцен"] | |
] | |
(str (html hiccups hiccups-table)) | |
) | |
) | |
(defn extract-first-scene-id | |
[constraint] | |
(let [fine-type (get constraint :FineType)] | |
(case fine-type | |
:MustHappenBetween (get constraint :SceneId) | |
:MustHappenNDaysAfter (get constraint :FirstSceneId) | |
:MustHappenOnBusinessDay (get constraint :SceneId) | |
:MustHappenDuringWeekend (get constraint :SceneId) | |
:MustNotHappenOn (get constraint :SceneId) | |
:MustHappenAfter (get constraint :FirstSceneId) | |
:MustHappenOnSameDay (get constraint :FirstSceneId) | |
nil | |
) | |
) | |
) | |
(defn extract-second-scene-id | |
[constraint] | |
(let [fine-type (get constraint :FineType)] | |
(case fine-type | |
:MustHappenBetween nil | |
:MustHappenNDaysAfter (get constraint :SecondSceneId) | |
:MustHappenOnBusinessDay nil | |
:MustHappenDuringWeekend nil | |
:MustNotHappenOn nil | |
:MustHappenAfter (get constraint :SecondSceneId) | |
:MustHappenOnSameDay (get constraint :SecondSceneId) | |
nil | |
) | |
) | |
) | |
(defn ccd-MustHappenBetween | |
[constraint] | |
(let [ | |
scene-id (get constraint :SceneId) | |
start (get constraint :Start) | |
end (get constraint :End) | |
] | |
(format "Сцена %s должна произойти между %s и %s." | |
scene-id | |
start | |
end | |
) | |
) | |
) | |
(defn ccd-MustHappenNDaysAfter | |
[constraint] | |
(let | |
[ | |
first-scene-id (get constraint :FirstSceneId) | |
second-scene-id (get constraint :SecondSceneId) | |
days (get constraint :Days) | |
] | |
(format "Сцена %s должна прозойти спустя %d дней после сцены %s." | |
second-scene-id | |
days | |
first-scene-id) | |
) | |
) | |
(defn ccd-MustHappenOnBusinessDay | |
[constraint] | |
(let | |
[ | |
scene-id (get constraint :SceneId) | |
] | |
(format "Сцена %s должна происходить в будний/рабочий день." | |
scene-id) | |
) | |
) | |
(defn ccd-MustHappenDuringWeekend | |
[constraint] | |
(let | |
[scene-id (get constraint :SceneId)] | |
(format "Сцена %s должна происходить в выходные." scene-id) | |
) | |
) | |
(defn ccd-MustHappenAfter | |
[constraint] | |
(let | |
[ | |
first-scene-id (get constraint :FirstSceneId) | |
second-scene-id (get constraint :SecondSceneId) | |
] | |
(format "Сцена %s должна произойти после сцены %s." | |
second-scene-id | |
first-scene-id) | |
) | |
) | |
(defn ccd-MustHappenOnSameDay | |
[constraint] | |
(let | |
[ | |
first-scene-id (get constraint :FirstSceneId) | |
second-scene-id (get constraint :SecondSceneId) | |
] | |
(format "Сцены %s и %s должны произойти в один день." | |
first-scene-id | |
second-scene-id) | |
) | |
) | |
(defn ccd-MustNotHappenOn | |
[constraint] | |
(let | |
[ | |
scene-id (get constraint :SceneId) | |
day (get constraint :Day) | |
] | |
(format "Сцена %s не может происходить в день %s." | |
scene-id | |
day) | |
) | |
) | |
(defn compose-constraint-description | |
[constraint] | |
(let | |
[fine-type (get constraint :FineType)] | |
(case fine-type | |
:MustHappenBetween (ccd-MustHappenBetween constraint) | |
:MustHappenNDaysAfter (ccd-MustHappenNDaysAfter constraint) | |
:MustHappenOnBusinessDay (ccd-MustHappenOnBusinessDay constraint) | |
:MustHappenDuringWeekend (ccd-MustHappenDuringWeekend constraint) | |
:MustNotHappenOn (ccd-MustNotHappenOn constraint) | |
:MustHappenAfter (ccd-MustHappenAfter constraint) | |
:MustHappenOnSameDay (ccd-MustHappenOnSameDay constraint) | |
nil | |
) | |
) | |
) | |
(defn generate-constraints-table-body | |
[constraints sceneList] | |
(let | |
[ | |
constraints-count (count constraints) | |
constraints-count-seq (range 1 (+ constraints-count 1)) | |
scenes-by-ids (into {} | |
(map (fn [scene] | |
(let [ | |
scene-id (get scene :sceneId) | |
] | |
{ | |
scene-id scene | |
} | |
) | |
) | |
sceneList | |
) | |
) | |
] | |
(map (fn | |
[ | |
constraint constraint-nr | |
] | |
(let [ | |
constraint-id (get constraint :ConstraintName) | |
scene1-id (extract-first-scene-id constraint) | |
scene2-id (extract-second-scene-id constraint) | |
comment (get constraint :Comment) | |
scene1 (get scenes-by-ids scene1-id) | |
scene1-summary (get scene1 :summary) | |
scene2 (get scenes-by-ids scene2-id) | |
scene2-summary (get scene2 :summary) | |
constraint-desc (compose-constraint-description constraint) | |
scene1-link (create-scene-link scene1-id) | |
scene2-link (create-scene-link scene2-id) | |
] | |
{ | |
:nr constraint-nr | |
:id constraint-id | |
:scene1Id scene1-link | |
:scene2Id scene2-link | |
:scene1Desc scene1-summary | |
:scene2Desc scene2-summary | |
:constraintDesc constraint-desc | |
:comment comment | |
} | |
) | |
) | |
constraints | |
constraints-count-seq | |
) | |
) | |
) | |
(defn generate-time-constraints-report | |
[complete-time-info sceneList] | |
(let | |
[ | |
constraints (extract-constraints complete-time-info) | |
table-body (generate-constraints-table-body constraints sceneList) | |
hiccups-table-attrs { | |
:table-attrs { | |
:border 1 | |
:cellspacing 0 | |
:bordercolor "black" | |
} | |
} | |
hiccups-table (hiccup.table/to-table1d | |
table-body | |
[:nr "№" | |
:id "Ид." | |
:scene1Id "Ид. первой сцены" :scene1Desc "Описание первой сцены" :scene2Id "Ид. второй сцены" :scene2Desc "Описание второй сцены" :constraintDesc "Описание ограничения" | |
:comment "Примечания" | |
] | |
hiccups-table-attrs | |
) | |
] | |
(str | |
(html [:h2 {:id "time-constraints"} "Ограничения по времени сцен"]) | |
(html [:p "Если время той или иной сцены изменится, нужно проверить, выполняются ли все приведенные ниже ограничения." hiccups-table] | |
) | |
) | |
) | |
) | |
;; Supporting functions (end) | |
;; Main function (start) | |
(defn export-scene-list | |
[scene-list seq-list-par target-file progress-data title] | |
(let [sceneList (filter some? scene-list) | |
seq-list seq-list-par | |
globalHeader "<html>\n<meta charset=\"UTF-8\"> | |
<style>\n | |
* { | |
font-family: Courier Prime, Courier; | |
}\n</style>\n | |
<body>" | |
header-note "<p>Этот файл был создан с помощью lit-universe.works.white-ns.lesson12/generate-scene-overview.</p>" | |
scene-overview (generate-scene-overview sceneList {} seq-list-par) | |
progress-report (generate-progress-report progress-data) | |
scene-details (generate-scene-details-view sceneList) | |
globalFooter "</body></html>" | |
arcs-html (seq-list-to-html seq-list) | |
fileContents (str globalHeader | |
"<h1>" | |
title | |
"</h1>" | |
header-note | |
scene-overview | |
arcs-html | |
progress-report | |
scene-details | |
globalFooter | |
) | |
] | |
(spit target-file fileContents) | |
) | |
) | |
(defn export-scene-list-with-time | |
[scene-list | |
seq-list-par | |
target-file | |
progress-data | |
title | |
approximate-time-info-by-scene | |
complete-time-info] | |
(let [sceneList (filter some? scene-list) | |
seq-list seq-list-par | |
globalHeader "<html>\n<meta charset=\"UTF-8\"> | |
<style>\n | |
* { | |
font-family: Courier Prime, Courier; | |
}\n</style>\n | |
<body>" | |
header-note "<p>Этот файл был создан с помощью lit-universe.works.white-ns.lesson12/generate-scene-overview.</p>" | |
scene-overview (generate-scene-overview sceneList approximate-time-info-by-scene seq-list-par) | |
progress-report (generate-progress-report progress-data) | |
scene-details (generate-scene-details-view sceneList) | |
globalFooter "</body></html>" | |
arcs-html (seq-list-to-html seq-list) | |
time-report-html (generate-time-report-html complete-time-info sceneList) | |
time-constraints-report (generate-time-constraints-report complete-time-info sceneList) | |
location-details-report (generate-location-details-report []) | |
fileContents (str globalHeader | |
"<h1>" | |
title | |
"</h1>" | |
header-note | |
scene-overview | |
arcs-html | |
progress-report | |
time-report-html | |
time-constraints-report | |
location-details-report | |
scene-details | |
globalFooter | |
) | |
] | |
(spit target-file fileContents) | |
) | |
) | |
(defn export-scene-list-with-time-and-locations | |
[scene-list | |
seq-list-par | |
target-file | |
progress-data | |
title | |
approximate-time-info-by-scene | |
complete-time-info | |
all-locations | |
] | |
(let [sceneList (filter some? scene-list) | |
seq-list seq-list-par | |
globalHeader "<html>\n<meta charset=\"UTF-8\"> | |
<style>\n | |
* { | |
font-family: Courier Prime, Courier; | |
}\n</style>\n | |
<body>" | |
header-note "<p>Этот файл был создан с помощью lit-universe.process.v1.export-scene-list/export-scene-list-with-time-and-locations.</p>" | |
scene-overview (generate-scene-overview sceneList approximate-time-info-by-scene seq-list-par) | |
progress-report (generate-progress-report progress-data) | |
scene-details (generate-scene-details-view sceneList) | |
globalFooter "</body></html>" | |
arcs-html (seq-list-to-html seq-list) | |
time-report-html (generate-time-report-html complete-time-info sceneList) | |
time-constraints-report (generate-time-constraints-report complete-time-info sceneList) | |
location-details-report (generate-location-details-report all-locations) | |
toc (create-toc) | |
fileContents (str globalHeader | |
"<h1>" | |
title | |
"</h1>" | |
header-note | |
toc | |
scene-overview | |
arcs-html | |
progress-report | |
time-report-html | |
time-constraints-report | |
location-details-report | |
scene-details | |
globalFooter | |
) | |
] | |
(spit target-file fileContents) | |
) | |
) | |
;; Main function (end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment