family-tree.lisp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. ;;;; family-tree.lisp
  2. (in-package #:genie)
  3. ;;; "family-tree" goes here. Hacks and glory await!
  4. ;;; Generate nodes for people
  5. (defun generate-person-node (person-id)
  6. (let ((person (first (select :people (where (equal :/person-id person-id)))))
  7. (birth (first (select :births (where (equal :/birth-person person-id)))))
  8. (death (first (select :deaths (where (equal :/death-person person-id))))))
  9. (format nil "person_~a [label = \"~a\", color = ~a, shape = rectangle];"
  10. person-id
  11. (format nil "~a\\\n~a — ~a"
  12. (:/person-name person)
  13. (:/birth-date birth)
  14. (if (not (null death))
  15. (:/death-date death)
  16. "Living"))
  17. (if (string= (:/gender person) "M") "blue" "pink"))))
  18. ;;; Generate edges between people
  19. ;; (defun generate-person-edges (person-id)
  20. ;; (let ((birth (first (select :births (where (equal :/person person-id))))))
  21. ;; (if (or (= 0 (:/father birth))
  22. ;; (= 0 (:/mother birth)))
  23. ;; (if (= 0 (:/mother birth))
  24. ;; (format nil "person_~a -> person_~a;" (:/father birth) person-id)
  25. ;; (if (= 0 (:/father birth))
  26. ;; (format nil "person_~a -> person_~a;" (:/mother birth) person-id)
  27. ;; ""))
  28. ;; (let ((marriage
  29. ;; (first (select :marriages
  30. ;; (where (and (equal :/wife (:/mother birth))
  31. ;; (equal :/husband (:/father birth))))))))
  32. ;; (if (not (null marriage))
  33. ;; (format nil "marriage_~a -> person_~a;"
  34. ;; (:/marriage-id marriage)
  35. ;; person-id)
  36. ;; (format nil "{person_~a, person_~a} -> person_~a"
  37. ;; (:/mother birth)
  38. ;; (:/father birth)
  39. ;; person-id))))))
  40. (defun generate-person-edges (person-id)
  41. (let* ((birth
  42. (first (select :births (where (equal :/person person-id)))))
  43. (mother (:/mother birth))
  44. (father (:/father birth))
  45. (marriage
  46. (first (select :marriages
  47. (where (and (equal :/wife mother)
  48. (equal :/husband father)))))))
  49. (cond
  50. ((= 0 (:/father birth))
  51. )
  52. ((= 0 (:/mother birth))
  53. (format nil "person_~a -> person_~a;" father person-id))
  54. ((null marriage)
  55. (format nil "{person_~a, person_~a} -> person_~a;"
  56. mother
  57. father
  58. person-id))
  59. (t
  60. (format nil "marriage_~a -> person_~a;"
  61. (:/marriage-id marriage)
  62. person-id)))))
  63. (defun generate-person-edges (person-id)
  64. (flet ((unlisted-father (birth-record)
  65. (= 0 (:/father birth-record)))
  66. (unlisted-mother (birth-record)
  67. (= 0 (:/mother birth-record)))
  68. (parent-married-status (birth-record)
  69. (let* ((mother (:/mother birth-record))
  70. (father (:/father birth-record))
  71. (records (select :marriages))
  72. (record (first
  73. (remove-if (lambda (record)
  74. (not (= (:/wife record) mother)))
  75. (remove-if (lambda (record)
  76. (not (= (:/husband record) father)))
  77. records)))))
  78. (values (not (null record)) (:/marriage-id record)))))
  79. (let ((birth (first (select :births
  80. (where (equal :/birth-person person-id))))))
  81. (cond
  82. ((unlisted-father birth)
  83. (format nil "person_~a -> person_~a;" (:/mother birth) person-id))
  84. ((unlisted-mother birth)
  85. (format nil "person_~a -> person_~a;" (:/father birth) person-id))
  86. ((parent-married-status birth)
  87. (multiple-value-bind (bool id)
  88. (parent-married-status birth)
  89. (declare (ignore bool))
  90. (format nil "marriage_~a -> person_~a;"
  91. id
  92. person-id)))
  93. ((not (parent-married-status birth))
  94. (format nil "{person_~a, person_~a} -> person_~a;"
  95. (:/mother birth)
  96. (:/father birth)
  97. person-id))))))
  98. ;;; Generate nodes for weddings
  99. (defun generate-marriage-node (marriage-id)
  100. (let ((marriage (first (select :marriages (where (equal :/marriage-id
  101. marriage-id)))))
  102. (divorce (first (select :divorces (where (equal :/marriage marriage-id))))))
  103. (format nil "marriage_~a [label = \"Married ~a — ~a\", shape = invtrapeseum];"
  104. marriage-id
  105. (:/wedding-date marriage)
  106. (if (not (null divorce))
  107. (if (string= "0" (:/end-date marriage))
  108. "Present"
  109. (:/end-date marriage))
  110. (format nil "Div. ~a" (:/divorce-date divorce))))))
  111. ;;; Generate edges for weddings
  112. (defun generate-marriage-edges (marriage-id)
  113. (let* ((marriage (first (select :marriages
  114. (where (equal :/marriage-id marriage-id)))))
  115. (husband-id (:/husband marriage))
  116. (wife-id (:/wife marriage)))
  117. (format nil "{person_~a, person_~a} -> marriage_~a;"
  118. husband-id
  119. wife-id
  120. marriage-id)))
  121. ;; (defun generate-graph ()
  122. ;; ())