Change Project مشروع التغيير الحضاري - بالانجليزية
swb-schema-sql
1. -- swb-tables.schema
-- schema for switchboard, call home, call friend, and polyphone
-- George Zipperlen
-- 19-Mar-1996 sparse version of swb_availability
-- 26-Mar-1996 minor changes to bring tables and views closer to db2 version
-- 1-Apr add ANI to call_stats
-- 4-Apr change call_subjects zip -> 10, comments -> 200 chars
-- 8-Apr change swb_availability.day_of_week to varchar2(9)
-- 8-Apr change call_stats.conn_duration to varchar2(8)
-- 8-Apr change call_stats.talk_duration to varchar2(8)
-- 8-Apr change call_stats.record_duration to varchar2(8)
-- 8-Apr add substr to active_pins.recruit_date
-- 8-Apr change column order in call_stats_index
-- 8-Apr add call_subject.held_by_line
-- 9-Apr change varchar to varchar2 in all tables
-- 9-Apr change start_time and end_time to varchar2(5) in
-- swb_availability
-- 9-Apr remove call_subject.held_by_line
-- 9-Apr add end_date,calls_recvd to active_pins view
-- 9-Apr add tel_line to swb_candidates
-- 9-Apr add view available_callees
-- 9-Apr replace time_last_tried with skip_until_time in call_subjects
-- 9-Apr make end_date,calls_recvd not null in call_subjects and
-- add index on end_date,calls_recvd. This will cause
-- available_callees view to return rows with proper ranking.
-- 9-Apr add index on call_stats.callee_pin
-- RobotOperator applications
create table iv_appl (
appl_num number(1) not null primary key,
appl_name varchar2(12)
);
-- RobotOperator prompt languages
create table iv_lang (
lang_num number(2) not null primary key,
lang_name varchar2(12)
);
-- possible call results
create table iv_stat_types (
res_num number(2) not null primary key,
res_name varchar2(20)
);
-- organizations, e.g. fraternity, PTA, interest group
create table orgs (
org_abbr varchar2(12) not null primary key,
org_name varchar2(32)
);
-- locations, typically university
create table locs (
loc_abbr varchar2(12) not null primary key,
loc_name varchar2(32)
);
-- subject group affiliation, e.g. habitat_hum @ u_penn
create table subject_groups (
group_org varchar2(12) not null,
group_loc varchar2(12) not null,
contact varchar2(32),
address varchar2(64),
2. phone varchar2(12),
num_members number(3),
foreign key (group_org) references orgs(org_abbr),
foreign key (group_loc) references locs(loc_abbr)
);
create unique index subject_groups_index on subject_groups(
group_org,
group_loc
);
-- central location for all scalar info about subjects in any project
create table call_subjects (
PIN varchar2(8) not null,
project number(1), -- cf, ch, polyphone, swb ...
lang number(2), -- language for prompts
language varchar2(12), -- subject's language
subj_org varchar2(12), -- e.g. campus crusade for cthulhu
subj_loc varchar2(12), -- e.g. university of pennsylvania
last_name varchar2(32),
first_name varchar2(16),
apt varchar2(32),
street varchar2(40),
city varchar2(16),
state varchar2(12),
zip varchar2(10),
home_phone varchar2(12),
work_phone varchar2(12),
fax varchar2(12),
email varchar2(40),
gender char(1),
age number(2),
edu number(2),
birth_country varchar2(16),
where_raised varchar2(40),
active number(1), -- true or false
assigned_by varchar2(12), -- LDC, or recruiter
assigned_date date,
reg_date date, -- date of online registration (if used)
end_date date not null, -- last date subject available
skip_until_time date, -- skip this callee until this time
-- the following fields are redundant, but easier to store here
-- than construct from complex select statements
-- calls_made, calls_recvd, last_status
calls_made number(2), -- derived from call_status
calls_recvd number(2) not null, -- derived from call_status
last_status number(2), -- busy, no ans, not avail, etc
-- derived from call_status
reg_line number(2), -- line used for online registration
notified varchar2(12), -- phone, mail, email, ...
payment varchar2(24),
comments varchar2(200),
primary key (PIN),
foreign key (project) references iv_appl(appl_num),
foreign key (lang) references iv_lang(lang_num),
foreign key (subj_org) references orgs(org_abbr),
foreign key (subj_loc) references locs(loc_abbr)
);
-- This index is used by available_callees view to rank candidates
create index callee_ranking_ix on call_subjects(end_date,calls_recvd);
-- sparse table indexed by day_of_week and start_time within day
create table swb_availability (
3. PINa varchar2(8) not null,
day_of_week varchar2(9) not null,
start_time varchar2(5) not null, -- start of availability period
end_time varchar2(5) not null, -- end of availability period
phone_a varchar2(12), -- phone to call during available period
num_handsets number(1),
foreign key (PINa) references call_subjects(PIN)
);
create unique index swb_availability_index on swb_availability (
PINa,
day_of_week,
start_time
);
create table topics (
topic_num number(3) not null primary key,
description varchar2(80)
);
-- list of topics subject is interested in
create table subject_topics (
tPIN varchar2(8) not null,
topicp number(3),
foreign key (tPIN) references call_subjects(PIN),
foreign key (topicp) references topics(topic_num)
);
create unique index subject_topics_index on subject_topics(
tPIN,
topicp
);
-- record of all calls, including attempts
create table call_stats (
call_date_time date,
appl_s number(1),
lang_s number(2),
caller_PIN varchar2(8) not null,
callee_PIN varchar2(8) not null,
caller_ani varchar2(12), -- caller ID from ANI, if available
caller_phone varchar2(12), -- caller ID keyed in by caller
callee_phone varchar2(12),
topic number(3),
conn_duration varchar2(8), -- total duration of call
talk_duration varchar2(8), -- duration after connection to callee
record_duration varchar2(8), -- duration recorded to disk
call_status number(2),
line number(2), -- DS0, for debugging
primary key (call_date_time),
foreign key (caller_PIN) references call_subjects(PIN),
foreign key (callee_PIN) references call_subjects(PIN)
);
create unique index call_stats_index on call_stats(
caller_PIN,
callee_PIN,
call_date_time
);
create index call_stats_callee_ix on call_stats(callee_pin);
-- list of selected candidate callees available now
create table swb_candidates (
PIN varchar2(8) not null,
4. phone varchar2(12) not null,
tel_line number(2) not null
);
create unique index candidate_idx on swb_candidates(pin);
-- equivalent to PIN table in old call_home / call_friend
create view active_pins (
PIN,
appl,
lang,
recruit_date,
PIN_usage,
calls_recvd,
end_date
)
as select
PIN,
project appl,
lang,
substr(to_char(assigned_date,'MM/DD/YY'),1,8) recruit_date,
calls_made PIN_usage,
calls_recvd,
end_date
from call_subjects
where call_subjects.active = 1
;
create view registration (
PIN,
appl,
language,
gender,
age,
school,
phone_number,
reg_date
)
as select PIN,project,lang,gender,age,edu,home_phone,reg_date
from call_subjects
;
create view swb_talked (
caller_PIN,
callee_PIN
)
as select caller_PIN,callee_PIN
from call_stats
where call_stats.call_status = 0
;
create view switchboard_stats (
call_date,
caller_PIN,
callee_PIN,
caller_number,
callee_number
)
as select call_date_time,caller_pin,callee_pin,caller_phone,callee_phone
from call_stats
where call_stats.appl_s = 3
and call_stats.call_status = 0
5. ;
-- this view returns candidates available now ranked by desirability
-- ranking requires end_date,calls_recvd to be not null and indexed
-- add where clause to selects from this view:
-- caller <> pin
-- caller,callee not in switchboard_stats
create view available_callees (
pin,
phone) as
select cs.pin,sa.phone_a
from call_subjects cs,swb_availability sa
where cs.pin not in (
select st.callee_pin
from call_stats st
where trunc(st.call_date_time) = trunc(sysdate)
and st.callee_pin = cs.pin
and st.call_status = 0)
and cs.pin not in (
select sc.pin
from swb_candidates sc)
and to_number(to_char(sysdate,'sssss'))
between to_number(to_char(to_date(sa.start_time,'hh24:mi'),'sssss'))
and to_number(to_char(to_date(sa.end_time,'hh24:mi'),'sssss'))
and sa.day_of_week = rtrim(to_char(sysdate,'Day'))
and cs.pin||'' = sa.pina
and nvl(cs.skip_until_time,sysdate) <= sysdate
and cs.active = 1
and cs.end_date >= trunc(sysdate)
and cs.calls_recvd >= 0
;
6. ;
-- this view returns candidates available now ranked by desirability
-- ranking requires end_date,calls_recvd to be not null and indexed
-- add where clause to selects from this view:
-- caller <> pin
-- caller,callee not in switchboard_stats
create view available_callees (
pin,
phone) as
select cs.pin,sa.phone_a
from call_subjects cs,swb_availability sa
where cs.pin not in (
select st.callee_pin
from call_stats st
where trunc(st.call_date_time) = trunc(sysdate)
and st.callee_pin = cs.pin
and st.call_status = 0)
and cs.pin not in (
select sc.pin
from swb_candidates sc)
and to_number(to_char(sysdate,'sssss'))
between to_number(to_char(to_date(sa.start_time,'hh24:mi'),'sssss'))
and to_number(to_char(to_date(sa.end_time,'hh24:mi'),'sssss'))
and sa.day_of_week = rtrim(to_char(sysdate,'Day'))
and cs.pin||'' = sa.pina
and nvl(cs.skip_until_time,sysdate) <= sysdate
and cs.active = 1
and cs.end_date >= trunc(sysdate)
and cs.calls_recvd >= 0
;