data structures for the new timesheet reports are created and the parsing logic should be okay. still need to test for typos/bugs

master
dtookey 3 years ago
parent 8e6a2f376d
commit b6d9f3e9fd

@ -18,7 +18,7 @@ type (
FilePath string
Records *[][]string
SkipFirstRow bool
ReportLines *[]*HourReportLine
ReportLines *[]*HourReportLineLegacy
}
HourReportLoadTask struct {
@ -26,7 +26,8 @@ type (
Err error
}
HourReportLine struct {
// HourReportLineLegacy Container for the first iteration of the timesheet reports
HourReportLineLegacy struct {
PayGroup string
LName string
FName string
@ -42,6 +43,32 @@ type (
Service float64
Total float64
}
// HourReportLine Container struct for the new version of the hour report
//
// Badge #,Brv,Hol,OT,Reg,Service,Sick,Total
HourReportLine struct {
EEid int
Bereavement float64
Holiday float64
Overtime float64
Regular float64
Service float64
Sick float64
Total float64
WeekEnding string
}
// DirectoryReportLine Container struct for employee directory information
// Paygroup,Last Name,First Name,EEId,Department Name,Manager
DirectoryReportLine struct {
Paygroup string
LName string
FName string
EEId int
DepartmentName string
Manager string
}
)
var namePattern = regexp.MustCompile("^\\d{1,2}.\\d{1,2}.\\d{2}-(\\d{1,2}.\\d{1,2}.\\d{2}).*csv$")
@ -70,7 +97,7 @@ func UpdateTimesheetReport(pathlike string) {
connector.ExecuteSqlScript(tableWipe)
for _, hourReport := range *reports {
log.Printf("Updating database\n")
db.BlockUpdate[HourReportLine](connector, db.MercuryDatabaseName, "update-mercury-hrTimesheets.sql", hourReport.ReportLines)
db.BlockUpdate[HourReportLineLegacy](connector, db.MercuryDatabaseName, "update-mercury-hrTimesheets.sql", hourReport.ReportLines)
log.Printf("Updates finished.\n")
}
@ -102,8 +129,8 @@ func NewHourReport(pathlike string, skipFirstRow bool) *HourReport {
return &report
}
func processReportToLines(report HourReport) *[]*HourReportLine {
lines := make([]*HourReportLine, 0, 250)
func processReportToLines(report HourReport) *[]*HourReportLineLegacy {
lines := make([]*HourReportLineLegacy, 0, 250)
localTable := *report.Records
headersRaw := (localTable)[0]
headers := make([]string, len(headersRaw), len(headersRaw))
@ -114,7 +141,7 @@ func processReportToLines(report HourReport) *[]*HourReportLine {
for i := 1; i < len(localTable); i++ {
row := localTable[i]
line := newHourReportLineFromRow(headers, row)
line := newHourReportLineLegacyFromRow(headers, row)
line.WeekEnding = fileNameToSQLDate(report.FilePath)
lines = append(lines, &line)
}
@ -131,11 +158,42 @@ func fileNameToSQLDate(fileName string) string {
return fmt.Sprintf("%s-%s-%s", year, month, date)
}
// I hate that this has a ton of hard-coded stuff. I'm not sure if there's a way around it though
func newHourReportLineFromRow(headers []string, row []string) HourReportLine {
line := HourReportLine{}
func newDirectoryReportLine(headers []string, row []string) DirectoryReportLine {
line := DirectoryReportLine{}
if len(headers) != len(row) {
panic("header array and row array are different sizes in newHourReportLineLegacyFromRow")
}
//Paygroup,Last Name,First Name,EEId,Department Name,Manager
for i, header := range headers {
strVal := row[i]
switch header {
case "Paygroup":
line.Paygroup = strVal
case "Last Name":
line.LName = strVal
case "First Name":
line.FName = strVal
case "EEId":
v, err := strconv.Atoi(strVal)
if err != nil {
v = 0
}
line.EEId = v
case "Department Name":
line.DepartmentName = strVal
case "Manager":
line.Manager = strVal
}
}
return line
}
// I hate that this has a ton of hard-coded stuff. I'm not sure if there's a better way, though
func newHourReportLineLegacyFromRow(headers []string, row []string) HourReportLineLegacy {
line := HourReportLineLegacy{}
if len(headers) != len(row) {
panic("header array and row array are different sizes in newHourReportLineFromRow")
panic("header array and row array are different sizes in newHourReportLineLegacyFromRow")
}
//"Paygroup", "Last Name", "First Name", "Home Department", "Manager Name", "Worked DeptName", "OT", "Reg", "Sick", "Vac", "Total"
@ -162,7 +220,6 @@ func newHourReportLineFromRow(headers []string, row []string) HourReportLine {
line.Overtime = v
case "Reg":
v, err := strconv.ParseFloat(strVal, 64)
if err != nil {
v = 0
@ -170,7 +227,6 @@ func newHourReportLineFromRow(headers []string, row []string) HourReportLine {
line.Regular = v
case "Sick":
v, err := strconv.ParseFloat(strVal, 64)
if err != nil {
v = 0
@ -178,7 +234,6 @@ func newHourReportLineFromRow(headers []string, row []string) HourReportLine {
line.Sick = v
case "Vac":
v, err := strconv.ParseFloat(strVal, 64)
if err != nil {
v = 0
@ -186,7 +241,6 @@ func newHourReportLineFromRow(headers []string, row []string) HourReportLine {
line.Vacation = v
case "Total":
v, err := strconv.ParseFloat(strVal, 64)
if err != nil {
v = 0
@ -199,6 +253,72 @@ func newHourReportLineFromRow(headers []string, row []string) HourReportLine {
return line
}
// I hate that this has a ton of hard-coded stuff. I'm not sure if there's a better way, though
func newHourReportLineFromRow(headers []string, row []string) HourReportLine {
line := HourReportLine{}
if len(headers) != len(row) {
panic("header array and row array are different sizes in newHourReportLineLegacyFromRow")
}
// Badge #,Brv,Hol,OT,Reg,Service,Sick,Total
for i, header := range headers {
strVal := row[i]
switch header {
case "Badge #":
v, err := strconv.Atoi(strVal)
if err != nil {
v = 0
}
line.EEid = v
case "Brv":
v, err := strconv.ParseFloat(strVal, 64)
if err != nil {
v = 0
}
line.Bereavement = v
case "Hol":
v, err := strconv.ParseFloat(strVal, 64)
if err != nil {
v = 0
}
line.Holiday = v
case "OT":
v, err := strconv.ParseFloat(strVal, 64)
if err != nil {
v = 0
}
line.Overtime = v
case "Reg":
v, err := strconv.ParseFloat(strVal, 64)
if err != nil {
v = 0
}
line.Regular = v
case "Service":
v, err := strconv.ParseFloat(strVal, 64)
if err != nil {
v = 0
}
line.Service = v
case "Sick":
v, err := strconv.ParseFloat(strVal, 64)
if err != nil {
v = 0
}
line.Sick = v
case "Total":
v, err := strconv.ParseFloat(strVal, 64)
if err != nil {
v = 0
}
line.Total = v
}
}
return line
}
func loadTimeSheet(pathlike string, asyncChan chan<- *HourReportLoadTask) {
f, err := os.OpenFile(pathlike, os.O_RDONLY, 0755)
if err != nil {
@ -221,7 +341,7 @@ func loadTimeSheet(pathlike string, asyncChan chan<- *HourReportLoadTask) {
close(asyncChan)
}
func (line HourReportLine) ToQueryBlock() string {
func (line HourReportLineLegacy) ToQueryBlock() string {
return fmt.Sprintf(
"('%s','%s','%s','%s','%s','%s','%d','%f','%f','%f','%f','%f','%f','%f')",
line.PayGroup,

Loading…
Cancel
Save