diff --git a/src/insight/insight-connect.go b/src/insight/insight-connect.go index 43bebff..66dda2c 100644 --- a/src/insight/insight-connect.go +++ b/src/insight/insight-connect.go @@ -17,7 +17,7 @@ const ( projectEndpoint = "" projectListEndpoint = "project/list?ids=" - timeEntryForUserInRangeEndpoint = "time-entry/user-date-range?startDate=2020-01-01&endDate=%s&userId=%s" + timeEntryForUserInRangeEndpoint = "time-entry/user-date-range?modelProperties=ActualHours,Date,Description,Project_Id,Task_Id,TimeSheet_Id,User_Id&startDate=2020-01-01&endDate=%s&userId=%s" userEndpoint = "user/list-active?modelProperties=Id,FirstName,LastName,EmailAddress" ) @@ -79,22 +79,13 @@ type ( } TimeEntry struct { - ActualHours float64 - ActualHoursFormattedString string - ActualTimeString string - ActualTotal float64 - BillableHours float64 - BillableHoursFormattedString string - BillableTimeString string - BillableTotal float64 - TimeEntryDate string `json:"Date,omitempty"` - TimeEntryDescription string `json:"Description,omitempty"` - ProjectId string `json:"Project_Id,omitempty"` - RateBill float64 - RateBurden float64 - TaskId string `json:"Task_Id,omitempty"` - TimeSheetId string `json:"TimeSheet_Id,omitempty"` - UserId string `json:"User_Id,omitempty"` + ActualHours float64 + TimeEntryDate string `json:"Date,omitempty"` + TimeEntryDescription string `json:"Description,omitempty"` + ProjectId string `json:"Project_Id,omitempty"` + TaskId string `json:"Task_Id,omitempty"` + TimeSheetId string `json:"TimeSheet_Id,omitempty"` + UserId string `json:"User_Id,omitempty"` } User struct { @@ -128,11 +119,21 @@ func (ic *Interconnect) UpdateUsers() { func (ic *Interconnect) UpdateTimeEntries() { users := ic.DBConnector.FetchEngineerUsers() + entryChan := make(chan *[]*TimeEntry) + coroutineCount := 0 for _, userPtr := range *users { - user := *userPtr - entries := ic.Client.GetTimeAllTimeEntriesForUserThroughDate(user.Id, "2022-04-28") + go ic.Client.GetTimeAllTimeEntriesForUserThroughDate(userPtr.Id, "2022-04-28", entryChan) + coroutineCount++ + } + + log.Printf("Currently working goroutines: %d\n", coroutineCount) + for coroutineCount > 0 { + entries := <-entryChan ic.DBConnector.UpdateTimeEntries(entries) + coroutineCount-- + log.Printf("Currently working goroutines: %d\n", coroutineCount) } + ic.DBConnector.ExecuteSqlScript("insight", "create-insight-contribution-table.sql") } // @@ -151,7 +152,7 @@ func NewIClient() *IClient { return &c } -func (iClient *IClient) GetTimeAllTimeEntriesForUserThroughDate(userId string, endDate string) *[]*TimeEntry { +func (iClient *IClient) GetTimeAllTimeEntriesForUserThroughDate(userId string, endDate string, returnChan chan<- *[]*TimeEntry) { urlString := fmt.Sprintf(timeEntryForUserInRangeEndpoint, endDate, userId) log.Println(urlString) req := iClient.createRequest(urlString, insightTokenFile) @@ -161,7 +162,7 @@ func (iClient *IClient) GetTimeAllTimeEntriesForUserThroughDate(userId string, e if err != nil { log.Fatal(err) } - return &container + returnChan <- &container } func (iClient *IClient) GetProjectsInList(projectIds []string) *[]Project { diff --git a/src/insight/insight-database.go b/src/insight/insight-database.go index 5eb3145..069ca9d 100644 --- a/src/insight/insight-database.go +++ b/src/insight/insight-database.go @@ -44,18 +44,9 @@ func (c *DBConnector) UpdateTimeEntries(entries *[]*TimeEntry) { } for _, ent := range *entries { _, err = s.Exec(ent.ActualHours, - ent.ActualHoursFormattedString, - ent.ActualTimeString, - ent.ActualTotal, - ent.BillableHours, - ent.BillableHoursFormattedString, - ent.BillableTimeString, - ent.BillableTotal, ent.TimeEntryDate, ent.TimeEntryDescription, ent.ProjectId, - ent.RateBill, - ent.RateBurden, ent.TaskId, ent.TimeSheetId, ent.UserId) diff --git a/src/mercury.go b/src/mercury.go index 5f4c9a5..7d0b146 100644 --- a/src/mercury.go +++ b/src/mercury.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "log" "mercury/src/insight" "mercury/src/mercury" @@ -12,6 +11,9 @@ import ( func main() { s := time.Now() + //icx := insight.NewInsightConnect() + //icx.DBConnector.ExecuteSqlScript("insight", "create-insight-contribution-table.sql") + //processQbBilling() test() //fetchInsightData() @@ -36,20 +38,3 @@ func processQbBilling() { mercury.ProcessTrialBalances(reportBase, "./test.csv") } - -func fetchInsightData() { - //jcrouch id = e779e0a9-0e56-4dbe-98dd-e8d0048d109f - //id := "e779e0a9-0e56-4dbe-98dd-e8d0048d109f" - client := insight.NewIClient() - users := client.GetUsers() - for _, user := range *users { - - if user.EmailAddress == "jcrouch@jdsconsulting.net" { - fmt.Println(user.EmailAddress) - timeEntries := client.GetTimeAllTimeEntriesForUserThroughDate(user.Id, "2022-04-22") - for _, entry := range *timeEntries { - fmt.Printf("%#v\n", entry) - } - } - } -} diff --git a/src/sql/create-insight-contribution-table.sql b/src/sql/create-insight-contribution-table.sql new file mode 100644 index 0000000..e7c184c --- /dev/null +++ b/src/sql/create-insight-contribution-table.sql @@ -0,0 +1,14 @@ +DROP TABLE IF EXISTS insight_engineering_contributions; + +CREATE TABLE insight_engineering_contributions AS +SELECT email, + CONCAT(insight.users.LastName, ', ', insight.users.FirstName) as Engineer, + ProjectId, + ActualHours, + TimeEntryDate, + TimeEntryDescription +FROM projects.users + INNER JOIN insight.users ON projects.users.email = insight.users.EmailAddress + INNER JOIN insight.timeentry ON insight.users.Id = insight.timeentry.UserId +WHERE projects.users.priv & POW(2, 25) > 0 +; \ No newline at end of file diff --git a/src/sql/create-timeentry-table.sql b/src/sql/create-timeentry-table.sql index f370cd0..4f7a2f4 100644 --- a/src/sql/create-timeentry-table.sql +++ b/src/sql/create-timeentry-table.sql @@ -3,18 +3,9 @@ DROP TABLE IF EXISTS insight.timeentry; CREATE TABLE insight.timeentry ( ActualHours REAL, - ActualHoursFormattedString varchar(30), - ActualTimeString VARCHAR(30), - ActualTotal REAL, - BillableHours REAL, - BillableHoursFormattedString VARCHAR(30), - BillableTimeString VARCHAR(30), - BillableTotal REAL, TimeEntryDate VARCHAR(30), TimeEntryDescription VARCHAR(4096), ProjectId VARCHAR(50), - RateBill REAL, - RateBurden REAL, TaskId VARCHAR(50), TimeSheetId VARCHAR(50), UserId VARCHAR(50) diff --git a/src/sql/update-timeentry.sql b/src/sql/update-timeentry.sql index 19c01c7..b3ca986 100644 --- a/src/sql/update-timeentry.sql +++ b/src/sql/update-timeentry.sql @@ -1,17 +1,8 @@ INSERT INTO insight.timeentry (ActualHours, - ActualHoursFormattedString, - ActualTimeString, - ActualTotal, - BillableHours, - BillableHoursFormattedString, - BillableTimeString, - BillableTotal, TimeEntryDate, TimeEntryDescription, ProjectId, - RateBill, - RateBurden, TaskId, TimeSheetId, UserId) -VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); \ No newline at end of file +VALUES (?, ?, ?, ?, ?, ?, ?); \ No newline at end of file