File: db_summary.ll

package info (click to toggle)
lifelines 3.0.50-2
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 11,140 kB
  • ctags: 6,517
  • sloc: ansic: 57,468; xml: 8,014; sh: 4,255; makefile: 848; yacc: 601; perl: 170; sed: 16
file content (147 lines) | stat: -rw-r--r-- 4,274 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
 * @progname    db_summary.ll
 * @version     1
 * @author      Eggert
 * @category
 * @output      Text
 * @description

This program gives you summary statistics on your database.  It
calculates the number of birth, baptism, marriage, death, and burial
events, and gives the distribution over centuries of birth/baptisms,
death/burials, and marriages.  It tells you how many different names
(given names and surnames separately) there are in the database, and
how many persons have no surname in the database.

db_summary - a LifeLines database summary program
        by Jim Eggert (eggertj@ll.mit.edu)
        Version 1, 29 March    1995  Initial release
*/

proc main() {
    table(surnames)
    table(givens)
    list(bcents)
    list(dcents)
    list(mcents)

    list(namelist)

    set(nsurnames,0)
    set(ngivens,0)
    set(nnosurnames,0)
    set(nnogivens,0)
    set(nemptysurnames,0)
    set(nbirths,0)
    set(nbaptisms,0)
    set(nmarrs,0)
    set(ndeaths,0)
    set(nburials,0)

    print("Collecting individual statistics...")
    forindi(person,pnum) {
/* Do individual event statistics */
        set(by,0)
        if (b,birth(person)) {
            incr(nbirths)
            extractdate(b,bd,bm,by)
        }
        if (b,baptism(person)) {
            incr(nbaptisms)
            if (not(by)) { extractdate(b,bd,bm,by) }
        }
        call increment_century(bcents,by)

        set(dy,0)
        if (d,death(person)) {
            incr(ndeaths)
            extractdate(d,dd,dm,dy)
        }
        if (d,burial(person)) {
            incr(nburials)
            if (not(dy)) { extractdate(d,dd,dm,dy) }
        }
        call increment_century(dcents,dy)

/* Do name statistics */
        extractnames(inode(person),namelist,nnames,isurname)
        if (not(isurname)) { incr(nnosurnames) }
        forlist(namelist,name,nnum) {
            if (eq(nnum,isurname)) {
                if (not(lookup(surnames,name))) {
                    incr(nsurnames)
                    insert(surnames,save(name),save(key(person)))
                }
                if (not(strcmp(name,""))) {
                    incr(nemptysurnames)
                }
                if (not(name)) { incr(nnosurnames) }
            }
            else {
                if (not(lookup(givens,name))) {
                    incr(ngivens)
                    insert(givens,save(name),save(key(person)))
                }
            }
        }
    }

    print("done.\nCollecting family statistics...")
    forfam(family,fnum) {
        set(by,0)
        if (m,marriage(family)) {
            incr(nmarrs)
            extractdate(m,md,mm,my)
            call increment_century(mcents,my)
        }
    }

    print("done.\nGenerating report...")
    "The database " database() " contains:\n"
    d(pnum) " individuals\n"
    d(nsurnames) " unique surnames\n"
    d(ngivens) " unique given names\n"
    d(nemptysurnames) " individuals with empty surnames\n"
    d(nnosurnames) " individuals with no surname\n"
    d(nbirths) " birth events\n"
    d(nbaptisms) " baptism events\n"
    "Birth/baptism events distributed by century as\n"
    call list_centuries(bcents)
    d(ndeaths) " death events\n"
    d(nburials) " burial events\n"
    "Death/burial events distributed by century as\n"
    call list_centuries(dcents)
    "\n"
    d(fnum) " families\n"
    d(nmarrs) " marriage events distributed by century as\n"
    call list_centuries(mcents)
    print("done.\n")
}

proc increment_century(centuries,year) {
    if (year) {
        set(century,div(year,100))
        if (not(length(centuries))) {
            enqueue(centuries,century)
            enqueue(centuries,1)
        }
        else {
            set(first_century,dequeue(centuries))
            while (lt(century,first_century)) {
                requeue(centuries,0)
                set(first_century,sub(first_century,1))
            }
            set(index,add(1,sub(century,first_century)))
            setel(centuries,index,add(getel(centuries,index),1))
            requeue(centuries,first_century)
        }
    }
}

proc list_centuries(centuries) {
    set(century,dequeue(centuries))
    while (count,dequeue(centuries)) {
        "    " d(century) "00s  " d(count) "\n"
        incr(century)
    }
}