From bdd97bcae9fdc3fcd440d59ffbed8b943c6befb8 Mon Sep 17 00:00:00 2001 From: dtookey Date: Wed, 19 Jul 2023 08:55:52 -0400 Subject: [PATCH] updated data structures to hopefully match clarity --- src/db/database-primitives.go | 2 +- src/hr/timesheets.go | 12 +++-- src/mercury.go | 2 +- src/sql/0-run-first/all_projects.sql | 68 +++--------------------- src/sql/0-run-first/contributions.sql | 4 +- src/sql/0-run-first/lifecycle.sql | 4 +- src/sql/read-clarity-allProjects.sql | 2 +- src/sql/read-clarity-billingProjects.sql | 4 +- 8 files changed, 22 insertions(+), 76 deletions(-) diff --git a/src/db/database-primitives.go b/src/db/database-primitives.go index eaaa597..5576f34 100644 --- a/src/db/database-primitives.go +++ b/src/db/database-primitives.go @@ -13,7 +13,7 @@ import ( const ( dbCredsEnvName = "DB_CREDS" dbCredsHostName = "DB_HOST" - dsnTemplate = "clarity:%s@tcp(%s)/%s?parseTime=true" + dsnTemplate = "dtookey:%s@tcp(%s)/%s?parseTime=true" ClarityDatabaseName = "projects" InsightDatabaseName = "insight" diff --git a/src/hr/timesheets.go b/src/hr/timesheets.go index d8017f9..9e4956d 100644 --- a/src/hr/timesheets.go +++ b/src/hr/timesheets.go @@ -256,9 +256,7 @@ func fileNameToSQLDate(fileName string) string { year := parts[0][:4] month := parts[0][4:6] date := parts[0][6:8] - if fileName == "/home/dtookey/work/clarity-reporting/paycor/20230205_Paycor_W5.csv" { - fmt.Printf("woops") - } + return fmt.Sprintf("%s-%s-%s", year, month, date) } @@ -284,7 +282,13 @@ func newDirectoryReportLine(headers []string, row []string) DirectoryReportLine } line.EEId = v case "Department": - line.DepartmentName = strVal + parts := strings.Split(strVal, "- ") + if len(parts) > 1{ + line.DepartmentName = parts[1] + }else{ + line.DepartmentName = strVal + } + case "Manager": line.Manager = strVal default: diff --git a/src/mercury.go b/src/mercury.go index 27c84cc..6f94a57 100644 --- a/src/mercury.go +++ b/src/mercury.go @@ -37,7 +37,7 @@ func updateTelecom() { } func updateTimesheets() { - hr.UpdateEmployeeDirectory(path.Join("/home/dtookey/work/clarity-reporting/paycor_dir", "20221108_Paycor_Employee Roster.csv")) + hr.UpdateEmployeeDirectory(path.Join("/home/dtookey/work/clarity-reporting/paycor_dir", "20230710_Paycor_Employee Roster.csv")) hr.UpdateTimesheetReport("/home/dtookey/work/clarity-reporting/paycor") } diff --git a/src/sql/0-run-first/all_projects.sql b/src/sql/0-run-first/all_projects.sql index 8e5c3a0..da96dd9 100644 --- a/src/sql/0-run-first/all_projects.sql +++ b/src/sql/0-run-first/all_projects.sql @@ -1,70 +1,14 @@ -DROP VIEW IF EXISTS all_projects; -DROP TABLE IF EXISTS all_projects; +CREATE OR REPLACE UNIQUE INDEX ref_num ON projects (refnum); +CREATE OR REPLACE INDEX project_flavor ON projects (proj_type); -#todo we have to find out how to generate this from the info on tablemetadata -CREATE TABLE all_projects AS -SELECT * -FROM CLT2019 -UNION -SELECT * -FROM CLT2020 -UNION -SELECT * -FROM CLT2021 -UNION -SELECT * -FROM CLT2022 -UNION -SELECT * -FROM CLT2023 -UNION -SELECT * -FROM RDU2019 -UNION -SELECT * -FROM RDU2020 -UNION -SELECT * -FROM RDU2021 -UNION -SELECT * -FROM RDU2022 -UNION -SELECT * -FROM RDU2023 -UNION -SELECT * -FROM ENV2020 -UNION -SELECT * -FROM ENV2021 -UNION -SELECT * -FROM ENV2022 -UNION -SELECT * -FROM SRV2020 -UNION -SELECT * -FROM SRV2021 -UNION -SELECT * -FROM WIL2022 -UNION -SELECT * -FROM WIL2023; -CREATE UNIQUE INDEX ref_num ON all_projects (refnum); -CREATE INDEX project_flavor ON all_projects (proj_type); - - -UPDATE all_projects +UPDATE projects SET description = TRIM(BOTH ' ' FROM description) WHERE description RLIKE '^ ' OR description RLIKE ' $'; -UPDATE all_projects +UPDATE projects SET description = 'Soil/Footings' WHERE description IN ( @@ -74,14 +18,14 @@ WHERE description IN 'Soils/Footings - Revisit #1' ); -UPDATE all_projects +UPDATE projects SET description = 'Framing Items' WHERE description IN ( 'Framing Item' ); -UPDATE all_projects +UPDATE projects SET description = '3rd Party Footing Inspection' WHERE description IN ( diff --git a/src/sql/0-run-first/contributions.sql b/src/sql/0-run-first/contributions.sql index d987ce2..d6b29b9 100644 --- a/src/sql/0-run-first/contributions.sql +++ b/src/sql/0-run-first/contributions.sql @@ -1,5 +1,3 @@ -CREATE INDEX IF NOT EXISTS new_value_idx ON project_lifecycle (new_value); - DROP TABLE IF EXISTS engineer_contributions; #########################Engineer Contributions######################################################################## @@ -17,7 +15,7 @@ SELECT CONCAT(users.lname, ', ', users.fname) AS `Eng ap.description AS `Description` FROM users INNER JOIN project_lifecycle ON pkey = modifier - INNER JOIN all_projects ap on project_lifecycle.project_number = ap.refnum + INNER JOIN projects ap on project_lifecycle.project_number = ap.refnum INNER JOIN contacts on ap.contact_fkey = contacts.pkey INNER JOIN clients on contacts.cl_fkey = clients.pkey WHERE project_lifecycle.new_value IN ('+SEALED') diff --git a/src/sql/0-run-first/lifecycle.sql b/src/sql/0-run-first/lifecycle.sql index 10ca2f0..21fa6c1 100644 --- a/src/sql/0-run-first/lifecycle.sql +++ b/src/sql/0-run-first/lifecycle.sql @@ -2,8 +2,8 @@ DROP TABLE IF EXISTS event_counts; CREATE TABLE event_counts AS SELECT DATE(timestamp) AS event_date, - all_projects.proj_type AS division_raw, - SUBSTRING(all_projects.refnum, 1, 3) AS prefix, + projects.proj_type AS division_raw, + SUBSTRING(projects.refnum, 1, 3) AS prefix, if(SUBSTRING(new_value, 1, 1) = '+', 1, -1) AS event_count, SUBSTRING(`new_value` FROM 2) AS flag FROM project_lifecycle diff --git a/src/sql/read-clarity-allProjects.sql b/src/sql/read-clarity-allProjects.sql index d90ebb9..9a13696 100644 --- a/src/sql/read-clarity-allProjects.sql +++ b/src/sql/read-clarity-allProjects.sql @@ -1 +1 @@ -SELECT * FROM projects.all_projects; \ No newline at end of file +SELECT * FROM projects.projects; \ No newline at end of file diff --git a/src/sql/read-clarity-billingProjects.sql b/src/sql/read-clarity-billingProjects.sql index f94095d..9e3921c 100644 --- a/src/sql/read-clarity-billingProjects.sql +++ b/src/sql/read-clarity-billingProjects.sql @@ -1,3 +1,3 @@ SELECT refnum, location, IF(price_override = 1, override_price, default_price) as fee -FROM projects.all_projects - inner join billing b on all_projects.refnum = b.refNumber; \ No newline at end of file +FROM projects.projects + inner join billing b on projects.refnum = b.refNumber; \ No newline at end of file