Tuesday, April 30, 2019

Class diagram

Just a note: the video for this did not record

Background

GW-Basic, Fortran, Cobol, Top to bottom
hard to debug, not reusable Goto
Structured programming c pascal ADA functions
code reuse -- call function, debugging was easier
Objects --break the code into natural groups of functions that
reflect the structure of what you are working with
door(lock), card, scan, user, validation,
Object contains fields and methods
C++, Java, C#, Objective C
Python, php, JScript, ruby

Theory

Abstraction--abstract classes, interfaces
Encapsulation--lego idea-- every class should be self contained,
internal should be private
Inheritance--get all the public fields and
methods from the parent classes
Polymorphism--different behaviors for different environments
Overriding and overloading

Diagrams

User Class

Lock Class

More complete diagram

Tuesday, April 23, 2019

Activity diagram

Manage access activity diagram

Security alert

Security Alert

Forks and Joins

Thursday, April 11, 2019

Use cases

Locks ERD

Here is the link to the use case diagrams

Security Use case

Inheritance

Written Use Case 1

Written Use case 2

Thursday, April 4, 2019

Class Discussion ERD

Security system uses key cards.

People (administrator,students, staff,faculty, Custodial, security)

Departments

Rooms--locks

Security levels--people--rooms--server, computer labs

Smart cards: info is on the card

*Dumb cards--just a number--

Which card has access to which rooms at which times

Grouping of rooms

emergency opening and locking of doors

log every swipe--logging card number and lock

Alert if door open --swipe three times and fail

Here is a a picture of the ERD

here is the link to the ERD in LucidCharts

Systems Beginning

Definition: A System consists of parts that work together to accomplish a task or goal

A car engine, a computer, a body, an economy, or a planet's ecology can be a system

Definition: a sub system is a set of components that work together to accomplish a task or goal which contributes to the larger system.

Examples, the fuel or electrical systems of an engine, the circulatory system, the supply system, the water cycle.

Systems Analysis consists of identifying systems and their purpose, and the identifying--breaking them into--their component parts and determining how those parts interact with the whole.

The idea is to break complex processes into simpler pieces that can be understood and manipulated much more easily than the system as a whole.

The various techniques of systems analysis were developed to aid this process and increase the chances of success.

Most attempts to create and replace systems fail.

Reasons for Analysis

Typically one analyzes a system in order to understand some business process in order to automate it or improve the existing automation

The first steps would be to identify the system to be considered and its outcomes.

Then you would define the requirements of the replacement system

Thirdly you would identify any number of possible solutions that meet those requirements. You would analyze the feasibility of each potential solution financially,temporally , technologically, legally and culturally.

That done, you would choose one and setup a project with the timeline, personnel and resources to complete the project.

Then you test the product, fix any errors and deploy it. After deploying it, you maintain it until such a point as the process needs to start over.

In most contemporary organizations, systems are monitored continuously. Analysis, development, deployment and maintenance are all happening simultaneously.

Tuesday, March 5, 2019

Admin commands

--System queries
Select * from information_Schema.tables
Where table_schema='public';

Select table_schema, table_name, is_updatable
from information_schema.views
Where Not table_schema='pg_catalog'
And not table_schema='information_schema';

Select column_name, data_type, constraint_name, constraint_Type
From information_schema.columns
Join information_schema.table_constraints
on information_schema.columns.table_name=information_schema.table_constraints.table_name
where information_schema.columns.table_name='grantapplication'
Order by column_name;

--index
Create index on Person(personlastname);

Alter index person_personlastname_idx 
rename to idx_lastname;

Select Grantapplicationkey, grantapplicationdate, personlastname, grantapplicationamount
From grantapplication
join person
using (personkey)
Where personlastname = 'Blake';

Create unique index on person(personprimaryphone);

Create index on grantapplication (granttypekey, personkey);

Create index on donation(donationamount)
Where donationamount > 500;

--roles
Create role employeerole;

Grant connect on database communityassistpg to employeerole;
Grant usage on Schema public to employeerole;
Grant SELECT on All Tables in schema public to employeerole;
Grant usage on Schema employeeschema to employeerole;
Grant SELECT on All Tables in schema employeeschema to employeerole;

Create Role janderson with password 'P@ssw0rd1' Login inherit;

Grant employeerole to janderson;

Tuesday, February 26, 2019

Functions and triggers

--functions
Create or replace function myCube(num Integer)
Returns integer
As $$
Begin
RETURN num * num * num;
End;
$$ language plpgsql;



Select myCube(5);

create or replace function employeeschema.donationpercentages
(amount numeric, percentage numeric)
Returns numeric
AS $$
Begin
--semicolons required
Return amount * percentage;
End;
$$ language plpgsql;

select donationkey, donationamount, 
employeeschema.donationpercentages(donationamount, .76)"to charity"
From donation;

select donationkey, donationamount, 
employeeschema.donationpercentages(donationamount, 76)"to charity"
From donation;

create orreplace function employeeschema.donationpercentages
(amount numeric, percentage numeric)
Returns numeric
AS $$
Begin
if percentage > 1
   Then percentage = percentage/100;
end if;
--semicolons required
Return round((amount * percentage),2);
End;
$$ language plpgsql;

Create or replace function makeusername(firstname text, lastname text)
returns text
AS $$
Begin
Return Lower(substring(firstname,1,1)|| lastname); 
end;
$$ language plpgsql;

Select personfirstname, personlastname, 
makeusername(personfirstname, personlastname) as username
From person;

create schema donorschema;

Create or replace function donorschema.getdonations
(donorkey integer)
Returns table
(
  "Date" timestamp,
  amount numeric,
  validation UUID
)
AS $$
BEGIN
Return query
Select donationdate, donationamount, donationvalidation
From donation
Where personkey=donorkey;
End;
$$ language plpgsql;
Select * from donation;

Select * from donorschema.getdonations(6);

Alter table person
add personannouncements boolean default true;

Create or replace function addperson
(
 firstname text,
 lastname text,
 email text,
 phone text,
 announce boolean,
 apartment text,
 street text,
 city text,
 "state" char(2),
 zipcode char(11),
 passwd varchar(50)
) returns void
as $$
Insert into person(
personfirstname, personlastname, personemail,
personprimaryphone, persondateadded, personannouncements)
values(firstname, lastname, email, phone, 
current_timestamp, announce);

Insert into personaddress(personkey, personaddressstreet, 
personaddresscity, personaddressstate, personaddresszipcode,
personaddressapt)
values(currval('person_personkey_seq'), street, city, 
"state",zipcode, apartment);

Insert into logintable(personkey, personusername, personpassword)
Values(currval('person_personkey_seq'), makeusername(firstname, lastname),
createpassword(passwd));
$$ language sql;

Select addperson('Joseph,','Rogers', 'jrogers@gmail.com',
'2065552345', True, '641', '222 8th avenue', 'Seattle', 'WA',
'98100', 'RogersPass');

Select * from person where personkey =138
Select * from personaddress where personkey=138;
Select * from logintable where personkey=138;

Create or replace function updateperson
(
 pkey integer,
 firstname text,
 lastname text,
 email text,
 phone text,
 announce boolean,
 apartment text,
 street text,
 city text,
 "state" char(2),
 zipcode char(11)
 
) returns void
as $$
Update person
set personlastname=lastname,
personfirstname=firstname,
personemail=email,
personprimaryphone=phone,
personannouncements=announce
Where personkey=pkey;

update personaddress
Set personaddressstreet=street,
personaddresscity=city,
personaddressstate="state",
personaddresszipcode=zipcode,
personaddressapt=apartment
where personkey = pkey;

$$ language sql;
      
Select updateperson(138,'Joseph,','Rogers', 'jrogers@gmail.com',
'2065552345', False, '641', '222 8th avenue', 'Bellevue', 'WA',
'98100');

alter table grantapplication
add isflagged boolean default False; 
      
Create or replace function flagrequest()
Returns trigger as
$Body$
Begin
If NEW.grantapplicationamount >
   (Select granttypeonetimemax
    from granttype
    where granttypekey = new.granttypekey)
Then
 Update grantapplication
    Set isflagged =True
    where grantapplicationkey=new.grantapplicationkey;
end if;
Return new;
End;
$Body$ language plpgsql;

Create trigger flag_over_amounts
After Insert
on grantapplication
For each row
Execute procedure flagrequest();
      
Insert into grantapplication(Grantapplicationdate, personkey, granttypekey,
    grantapplicationamount, grantapplicationexplain)
     values(current_timestamp, 138, 1, 150.00, 'hungry');
      
Select * from grantapplication where grantapplicationkey = 
      (select max(grantapplicationkey) from grantapplication);