-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathgenerate.pl
executable file
·81 lines (71 loc) · 1.9 KB
/
generate.pl
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
#!/usr/bin/perl
use strict;
use warnings;
# This script is used to generate example tables similar to the one in
# setup.sql
print "CREATE TABLE person(id INT PRIMARY KEY, name TEXT NOT NULL, date_of_birth DATE, height SMALLINT);\n";
print "CREATE TABLE room(id INT PRIMARY KEY, name TEXT NOT NULL, area SMALLINT);\n";
print "CREATE TABLE sightings(time TIME NOT NULL, person INT REFERENCES person(id) NOT NULL, room INT REFERENCES room(id) NOT NULL, witness INT REFERENCES person(id));\n";
print "CREATE TABLE reliability(person INT REFERENCES person(id) PRIMARY KEY,score float NOT NULL);\n";
my @names=qw(
Titus
Norah
Ginny
Demetra
Sheri
Karleen
Daisey
Audrey
Alaine
Edwin
Shelli
Santina
Bart
Harriette
Jody
Theodora
Roman
Jack
Daphine
Kyra
);
foreach(my $i=0;$i<@names;++$i) {
my $year=int(rand(60))+1950;
my $month=int(rand(12))+1;
my $day=int(rand(28))+1;
$month="0$month" if $month<10;
$day="0$day" if $day<10;
my $height=rand(50)+160;
my $reliability=rand()/2+0.5;
print "INSERT INTO person VALUES($i,'$names[$i]','$year-$month-$day',$height);\n";
print "INSERT INTO reliability VALUES($i,$reliability);\n";
}
my @rooms=(
"Dining room",
"Blue bedroom",
"Red bedroom",
"Yellow bedroom",
"Green bedroom",
"Living room",
"Kitchen",
"First bathroom",
"Second bathroom",
"Library"
);
foreach(my $j=0;$j<@rooms;++$j) {
my $area=int(rand(30))+8;
print "INSERT INTO room VALUES($j,'$rooms[$j]',$area);\n"
}
foreach(my $i=0;$i<@names;++$i) {
my $nb_observations=int(rand()*20)+1;
foreach(my $k=0;$k<$nb_observations;++$k) {
my $time=int(rand()*48);
$time=sprintf("%02d",$time/2).":".($time%2?"30":"00");
my $person;
do {
$person=int(rand()*@names);
} while($person==$i);
my $room=int(rand()*@rooms);
print "INSERT INTO sightings VALUES('$time',$person,$room,$i);\n";
}
}