Skip to content

Commit

Permalink
feat: drop internal time, and next tasks because of 2024 changes in t…
Browse files Browse the repository at this point in the history
…he reporting policy
  • Loading branch information
senior-sigan committed Jan 10, 2024
1 parent 1b3318f commit 02c3865
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 75 deletions.
6 changes: 0 additions & 6 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,12 @@ nonpaid_project_tasks = "entry.714539999"
nonpaid_project_hours = "entry.52836812_hour"
nonpaid_project_minutes = "entry.52836812_minute"
nonpaid_project_seconds = "entry.52836812_second"
next_tasks = "entry.1462603973"
report_year = "entry.1783131858_year"
report_month = "entry.1783131858_month"
report_day = "entry.1783131858_day"
internal_tasks = "entry.20657743"
internal_hours = "entry.2061354997_hour"
internal_minutes = "entry.2061354997_minute"
internal_seconds = "entry.2061354997_second"

[forms.google.params]
url = "https://docs.google.com/forms/d/e/GOOGLE_FORM_KEY/viewform"
internal = "internal"

[reporter]
project_time_precision = 300 # in seconds
Expand Down
79 changes: 15 additions & 64 deletions forms/forms.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,9 @@ type GoogleFormFieldsMapping struct {
NonpaidProjectHours string `toml:"nonpaid_project_hours"`
NonpaidProjectMinutes string `toml:"nonpaid_project_minutes"`
NonpaidProjectSeconds string `toml:"nonpaid_project_seconds"`
NextTasks string `toml:"next_tasks"`
ReportYear string `toml:"report_year"`
ReportMonth string `toml:"report_month"`
ReportDay string `toml:"report_day"`
InternalTasks string `toml:"internal_tasks"`
InternalHours string `toml:"internal_hours"`
InternalMinutes string `toml:"internal_minutes"`
InternalSeconds string `toml:"internal_seconds"`
}

type GoogleFormData struct {
Expand All @@ -37,14 +32,9 @@ type GoogleFormData struct {
NonpaidProjectHours int
NonpaidProjectMinutes int
NonpaidProjectSeconds int
NextTasks string
ReportYear int
ReportMonth int
ReportDay int
InternalTasks string
InternalHours int
InternalMinutes int
InternalSeconds int
}

type GoogleFormGenerator struct {
Expand All @@ -56,52 +46,21 @@ type GoogleFormGenerator struct {

func (gen *GoogleFormGenerator) ConvertReportToFormsData(report report.Report) map[string]GoogleFormData {
formData := make(map[string]GoogleFormData)
var internalProjectData *GoogleFormData

var projectWithInternal string

for _, project := range report.Projects {
if project.Name == gen.InternalProjectName {
internalProjectData = &GoogleFormData{
ProjectName: gen.InternalProjectName,
InternalTasks: gen.Formatter.Format(project.Paid.Tasks),
InternalHours: utils.Hours(project.Paid.Duration),
InternalMinutes: utils.Minutes(project.Paid.Duration),
InternalSeconds: utils.Seconds(project.Paid.Duration),
ReportYear: report.At.Year(),
ReportMonth: int(report.At.Month()),
ReportDay: report.At.Day(),
}
} else {
projectWithInternal = project.Name
formData[project.Name] = GoogleFormData{
ProjectName: project.Name,
ProjectTasks: gen.Formatter.Format(project.Paid.Tasks),
ProjectHours: utils.Hours(project.Paid.Duration),
ProjectMinutes: utils.Minutes(project.Paid.Duration),
ProjectSeconds: utils.Seconds(project.Paid.Duration),
NonpaidProjectTasks: gen.Formatter.Format(project.NonPaid.Tasks),
NonpaidProjectHours: utils.Hours(project.NonPaid.Duration),
NonpaidProjectMinutes: utils.Minutes(project.NonPaid.Duration),
NonpaidProjectSeconds: utils.Seconds(project.NonPaid.Duration),
ReportYear: report.At.Year(),
ReportMonth: int(report.At.Month()),
ReportDay: report.At.Day(),
}
}
}

if internalProjectData != nil {
data, ok := formData[projectWithInternal]
if projectWithInternal != "" && ok {
data.InternalTasks = internalProjectData.InternalTasks
data.InternalHours = internalProjectData.InternalHours
data.InternalMinutes = internalProjectData.InternalMinutes
data.InternalSeconds = internalProjectData.InternalSeconds

formData[projectWithInternal] = data
} else {
formData[internalProjectData.ProjectName] = *internalProjectData
formData[project.Name] = GoogleFormData{
ProjectName: project.Name,
ProjectTasks: gen.Formatter.Format(project.Paid.Tasks),
ProjectHours: utils.Hours(project.Paid.Duration),
ProjectMinutes: utils.Minutes(project.Paid.Duration),
ProjectSeconds: utils.Seconds(project.Paid.Duration),
NonpaidProjectTasks: gen.Formatter.Format(project.NonPaid.Tasks),
NonpaidProjectHours: utils.Hours(project.NonPaid.Duration),
NonpaidProjectMinutes: utils.Minutes(project.NonPaid.Duration),
NonpaidProjectSeconds: utils.Seconds(project.NonPaid.Duration),
ReportYear: report.At.Year(),
ReportMonth: int(report.At.Month()),
ReportDay: report.At.Day(),
}
}

Expand All @@ -128,8 +87,8 @@ func (gen *GoogleFormGenerator) ConvertReportToForms(report report.Report) map[s
func (gen *GoogleFormGenerator) encode(form GoogleFormData) string {
query := url.Values{}
query.Set(gen.Mapping.ProjectName, form.ProjectName)
if (form.ProjectTasks != "") {

if form.ProjectTasks != "" {
query.Set(gen.Mapping.ProjectTasks, form.ProjectTasks)
} else {
query.Set(gen.Mapping.ProjectTasks, "-")
Expand All @@ -143,17 +102,9 @@ func (gen *GoogleFormGenerator) encode(form GoogleFormData) string {
query.Set(gen.Mapping.NonpaidProjectMinutes, strconv.Itoa(form.NonpaidProjectMinutes))
query.Set(gen.Mapping.NonpaidProjectSeconds, strconv.Itoa(form.NonpaidProjectSeconds))

if form.NextTasks != "" {
query.Set(gen.Mapping.NextTasks, form.NextTasks)
}
query.Set(gen.Mapping.ReportYear, strconv.Itoa(form.ReportYear))
query.Set(gen.Mapping.ReportMonth, strconv.Itoa(form.ReportMonth))
query.Set(gen.Mapping.ReportDay, strconv.Itoa(form.ReportDay))

query.Set(gen.Mapping.InternalTasks, form.InternalTasks)
query.Set(gen.Mapping.InternalHours, strconv.Itoa(form.InternalHours))
query.Set(gen.Mapping.InternalMinutes, strconv.Itoa(form.InternalMinutes))
query.Set(gen.Mapping.InternalSeconds, strconv.Itoa(form.InternalSeconds))

return query.Encode()
}
5 changes: 0 additions & 5 deletions forms/forms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,9 @@ func GenTestMapping() GoogleFormFieldsMapping {
NonpaidProjectHours: "entry.52836812_hour",
NonpaidProjectMinutes: "entry.52836812_minute",
NonpaidProjectSeconds: "entry.52836812_second",
NextTasks: "entry.1462603973",
ReportYear: "entry.1783131858_year",
ReportMonth: "entry.1783131858_month",
ReportDay: "entry.1783131858_day",
InternalTasks: "entry.20657743",
InternalHours: "entry.2061354997_hour",
InternalMinutes: "entry.2061354997_minute",
InternalSeconds: "entry.2061354997_second",
}
}

Expand Down

0 comments on commit 02c3865

Please sign in to comment.