Skip to content

Instantly share code, notes, and snippets.

@velll
Last active May 16, 2016 11:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save velll/9092333 to your computer and use it in GitHub Desktop.
Save velll/9092333 to your computer and use it in GitHub Desktop.
Issue estimation
-- estimation storage table
CREATE TABLE ISSUE_ESTIMATION(
N_ESTIMATION_ID NUMBER,
VC_PREDICTOR VARCHAR2(64) NOT NULL,
VC_ISSUE VARCHAR2(64) NOT NULL,
N_ESTIMATION NUMBER NOT NULL,
D_ESTIMATION DATE NOT NULL);
ALTER TABLE ISSUE_ESTIMATION
add constraint PK_ISSUE_ESTIMATION primary key (N_ESTIMATION_ID);
-- global procedure for estimation
CREATE OR REPLACE PROCEDURE ESTIMATE_ISSUE(
vch_VC_ISSUE IN ISSUE_ESTIMATION.VC_ISSUE%TYPE,
num_N_ESTIMATION IN ISSUE_ESTIMATION.N_ESTIMATION%TYPE)
IS
vch_VC_PREDICTOR VARCHAR2(64);
num_N_ESTIMATION_ID NUMBER;
BEGIN
dbms_application_info.read_client_info(vch_VC_PREDICTOR);
BEGIN
SELECT N_ESTIMATION_ID
INTO num_N_ESTIMATION_ID
FROM ISSUE_ESTIMATION
WHERE VC_PREDICTOR = vch_VC_PREDICTOR
AND VC_ISSUE = vch_VC_ISSUE;
EXCEPTION WHEN no_data_found THEN
num_N_ESTIMATION_ID := NULL;
END;
IF num_N_ESTIMATION_ID IS NULL THEN
num_N_ESTIMATION_ID := MAIN.GET_LOG_AUTO_NUMBER;
INSERT INTO ISSUE_ESTIMATION(
N_ESTIMATION_ID,
VC_PREDICTOR,
VC_ISSUE,
N_ESTIMATION,
D_ESTIMATION)
VALUES(
num_N_ESTIMATION_ID,
vch_VC_PREDICTOR,
vch_VC_ISSUE,
num_N_ESTIMATION,
SYSDATE);
ELSE
UPDATE ISSUE_ESTIMATION
SET N_ESTIMATION = num_N_ESTIMATION
WHERE N_ESTIMATION_ID = num_N_ESTIMATION_ID;
END IF;
COMMIT;
END ESTIMATE_ISSUE;
-- estimation process
-- execute once for a session so that you avoid passing predictor name everytime
exec dbms_application_info.set_client_info('vela');
-- estimation in hours
exec ESTIMATE_ISSUE('AIS-3774', 3)
-- diverging estimations
SELECT *
FROM ISSUE_ESTIMATION
WHERE VC_ISSUE IN (
SELECT VC_ISSUE
FROM (
SELECT VC_ISSUE,
MAX(N_ESTIMATION) N_MAX_ESTIMATION,
MIN(N_ESTIMATION) N_MIN_ESTIMATION
FROM ISSUE_ESTIMATION
GROUP BY VC_ISSUE)
WHERE ABS(N_MAX_ESTIMATION - N_MIN_ESTIMATION) >= 0.5)
ORDER BY VC_ISSUE, N_ESTIMATION DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment