Skip to content

Commit

Permalink
Mostly completed
Browse files Browse the repository at this point in the history
  • Loading branch information
ucayalifish committed Feb 11, 2018
1 parent ab0f60f commit f537cb5
Show file tree
Hide file tree
Showing 22 changed files with 1,010 additions and 29 deletions.
293 changes: 281 additions & 12 deletions console.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
DROP TABLE raw_data;

DROP TABLE summary;

CREATE TABLE raw_data
(
ssoid TEXT,
Expand All @@ -16,6 +18,12 @@ CREATE TABLE raw_data
ymdh TEXT
);

CREATE TABLE summary
(
total BIGINT,
selected BIGINT
);

COPY raw_data (ssoid, ts, grp, atype, asubtype, url, orgid, formid, code, ltpa, sudirresponse, ymdh)
FROM '/var/test_case.csv'
DELIMITER ';' CSV HEADER;
Expand Down Expand Up @@ -52,6 +60,47 @@ ORDER BY ssoid, ts;
SELECT DISTINCT grp
FROM raw_data;

SELECT
grp,
formid
FROM raw_data
WHERE ssoid <> 'Unauthorized'
AND ssoid IS NOT NULL
AND ssoid <> ''
AND formid IS NOT NULL
AND formid <> 'null'
AND formid <> ''
GROUP BY grp, formid
ORDER BY grp;

WITH services AS (
SELECT
grp,
formid
FROM raw_data
WHERE ssoid <> 'Unauthorized'
AND ssoid IS NOT NULL
AND ssoid <> ''
AND formid IS NOT NULL
AND formid <> 'null'
AND formid <> ''
GROUP BY grp, formid
ORDER BY grp
)
SELECT
ssoid,
raw_data.grp,
raw_data.formid,
atype,
asubtype,
ts
FROM raw_data
INNER JOIN services
ON raw_data.grp = services.grp
AND raw_data.formid = services.formid
ORDER BY ssoid, raw_data.ts;


SELECT
ssoid,
grp,
Expand All @@ -76,7 +125,8 @@ SELECT to_timestamp(1499765675);
SELECT DISTINCT ssoid
FROM raw_data
WHERE ssoid <> 'Unauthorized'
AND ssoid IS NOT NULL;
AND ssoid IS NOT NULL
AND ssoid <> '';

SELECT DISTINCT ymdh
FROM raw_data;
Expand Down Expand Up @@ -124,38 +174,49 @@ GROUP BY formid
ORDER BY form_count DESC
LIMIT 5;

-- топ-5 форм?
WITH form_counter AS (
SELECT
ssoid,
grp,
formid
FROM raw_data
WHERE ssoid <> 'Unauthorized'
AND ssoid IS NOT NULL
AND ssoid <> ''
AND formid IS NOT NULL
AND formid <> 'null'
AND formid <> ''
GROUP BY ssoid, formid
ORDER BY formid
GROUP BY ssoid, grp, formid
ORDER BY grp, formid
)
SELECT
grp,
formid,
count(formid) AS fc
FROM form_counter
GROUP BY formid
GROUP BY grp, formid
ORDER BY fc DESC
LIMIT 5;

SELECT
ssoid,
formid
FROM raw_data
WHERE ssoid <> 'Unauthorized'
WHERE ssoid NOT LIKE 'Unauthorized%'
AND ssoid IS NOT NULL
AND formid IS NOT NULL
AND formid <> 'null'
AND formid <> ''
ORDER BY ssoid, formid;

-- данные по использованию форм пользователями
SELECT
ssoid,
formid
FROM raw_data
GROUP BY ssoid, formid
ORDER BY formid;
ORDER BY ssoid;

WITH form_counter AS (
SELECT
Expand All @@ -166,16 +227,224 @@ WITH form_counter AS (
AND ssoid IS NOT NULL
AND formid IS NOT NULL
AND formid <> 'null'
AND formid <> ''
ORDER BY ssoid, formid
) SELECT
ssoid,
formid
FROM form_counter
GROUP BY ssoid, formid
ORDER BY ssoid;

SELECT ssoid
FROM raw_data
GROUP BY ssoid;

SELECT
ssoid,
formid,
atype,
asubtype,
ts
FROM raw_data
WHERE ssoid NOT LIKE 'Unauthorized%'
AND ssoid IS NOT NULL
AND formid IS NOT NULL
AND formid <> 'null'
AND formid <> ''
AND formid = '51001'
ORDER BY ssoid, ts;

WITH form_steps AS (
SELECT
ssoid,
formid,
atype,
asubtype,
ts
FROM raw_data
WHERE ssoid NOT LIKE 'Unauthorized%'
AND ssoid IS NOT NULL
AND formid IS NOT NULL
AND formid <> 'null'
AND formid <> ''
ORDER BY ssoid, ts
), usage_maximazer AS (
SELECT
ssoid,
formid,
count(*) AS usage_count
FROM form_steps
GROUP BY ssoid, formid
ORDER BY formid
)

SELECT
formid,
max(usage_count)
FROM usage_maximazer
GROUP BY formid;

SELECT
ssoid,
formid
FROM form_counter
GROUP BY ssoid, formid
grp,
formid,
atype,
asubtype,
ts
FROM raw_data
ORDER BY ssoid, grp, formid, atype, asubtype, ts;

WITH success_history AS (
SELECT
ssoid,
grp,
formid,
atype,
asubtype,
ts
FROM raw_data
WHERE grp LIKE 'dszn_%'
AND asubtype = 'send'
ORDER BY ssoid, grp, formid, atype, asubtype, ts
) SELECT
ssoid,
grp,
formid,
min(ts) AS started,
max(ts) AS completed,
max(ts :: INTEGER) - min(ts :: INTEGER) AS duration,
count(*) AS number_of_steps
FROM success_history
GROUP BY ssoid, grp, formid;

-- успехи
SELECT
ssoid
FROM raw_data
WHERE grp LIKE 'dszn_%'
AND asubtype = 'send'
ORDER BY ssoid;

SELECT ssoid
WITH history AS (
SELECT
ssoid,
grp,
formid,
atype,
asubtype,
ts
FROM raw_data
WHERE grp LIKE 'dszn_%'
ORDER BY ssoid, grp, formid, atype, asubtype, ts
) SELECT
ssoid,
grp,
formid,
min(ts) AS started,
max(ts) AS completed,
max(ts :: INTEGER) - min(ts :: INTEGER) AS duration,
count(*) AS number_of_steps
FROM history
GROUP BY ssoid, grp, formid;

SELECT ssoid, grp, formid, max(ts::BIGINT) as completed
FROM raw_data
GROUP BY ssoid;
WHERE grp LIKE 'dszn_%'
GROUP BY ssoid, grp, formid
ORDER BY ssoid;

SELECT ssoid, grp, formid, atype, asubtype
FROM raw_data
WHERE ssoid='0151a322-a1de-4ae1-bdca-566c71626f2a'
AND ts='1499766991';

WITH dszn_history AS (
SELECT
raw_data.ssoid AS ssoid,
grp,
formid,
atype,
asubtype,
ts
FROM raw_data
WHERE grp LIKE 'dszn_%'
ORDER BY raw_data.ssoid, grp, formid, atype, asubtype, ts
) SELECT
dszn_history.ssoid,
grp,
formid,
min(ts) AS started,
max(ts) AS completed,
max(ts :: INTEGER) - min(ts :: INTEGER) AS duration,
count(*) AS number_of_steps
FROM dszn_history
GROUP BY dszn_history.ssoid, grp, formid;

WITH dszn_history AS (
SELECT
ssoid,
grp,
formid,
atype,
asubtype,
ts
FROM raw_data
WHERE grp LIKE 'dszn_%'
ORDER BY ssoid, grp, formid, atype, asubtype, ts
), totals AS (
SELECT
ssoid,
grp,
formid,
min(ts) AS started,
max(ts) AS completed,
max(ts :: INTEGER) - min(ts :: INTEGER) AS duration,
count(*) AS number_of_steps
FROM dszn_history
GROUP BY ssoid, grp, formid
) SELECT sum(number_of_steps)
FROM totals;

SELECT count(*)
FROM raw_data
WHERE grp LIKE 'dszn_%';


SELECT
grp,
formid,
atype,
asubtype,
ts
FROM raw_data
WHERE ssoid = '716da031-92e6-47d7-ad65-ea1337b33b9d'
AND grp = 'dszn_17'
AND formid = '1001'
ORDER BY ts;

SELECT
grp,
formid
FROM raw_data
GROUP BY grp, formid;

SELECT DISTINCT formid
FROM raw_data;

SELECT DISTINCT grp
FROM raw_data;

SELECT
grp,
count(DISTINCT formid)
FROM raw_data
GROUP BY grp;

WITH groups AS (
SELECT
grp,
count(DISTINCT formid) AS form_cnt
FROM raw_data
GROUP BY grp
) SELECT sum(form_cnt)
FROM groups;
4 changes: 3 additions & 1 deletion csvimporter/csvimporter.iml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-logging:1.5.10.RELEASE" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.1.11" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.1.11" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.22" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:jcl-over-slf4j:1.7.25" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:jul-to-slf4j:1.7.25" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:log4j-over-slf4j:1.7.25" level="project" />
Expand All @@ -42,5 +42,7 @@
<orderEntry type="library" name="Maven: org.postgresql:postgresql:42.2.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-csv:1.5" level="project" />
<orderEntry type="module" module-name="datautils" />
<orderEntry type="library" name="Maven: io.vavr:vavr:0.9.2" level="project" />
<orderEntry type="library" name="Maven: io.vavr:vavr-match:0.9.2" level="project" />
</component>
</module>
Loading

0 comments on commit f537cb5

Please sign in to comment.