From 2fc5291952a1ab1f627155514fe6f86d73a385f7 Mon Sep 17 00:00:00 2001 From: Ben Boyter Date: Thu, 3 Aug 2023 17:41:31 +1000 Subject: [PATCH] add in cocomo --- cmd/badges/main.go | 103 ++++++++++++++++++++++++++++----------------- 1 file changed, 65 insertions(+), 38 deletions(-) diff --git a/cmd/badges/main.go b/cmd/badges/main.go index 98063c4a..46018a19 100644 --- a/cmd/badges/main.go +++ b/cmd/badges/main.go @@ -49,44 +49,7 @@ func main() { category := strings.TrimSpace(strings.ToLower(r.URL.Query().Get("category"))) - title := "" - var value int64 - - switch category { - case "codes": - fallthrough - case "code": - title = "Code lines" - for _, x := range res { - value += x.Code - } - case "blank": - fallthrough - case "blanks": - title = "Blank lines" - for _, x := range res { - value += x.Blank - } - case "comment": - fallthrough - case "comments": - title = "Comments" - for _, x := range res { - value += x.Comment - } - case "cocomo": - title = "COCOMO $" - case "lines": // lines is the default - fallthrough - case "line": // lines is the default - fallthrough - default: - // - title = "Total lines" - for _, x := range res { - value += x.Lines - } - } + title, value := calculate(category, res) textLength := "250" s := formatCount(float64(value)) @@ -103,6 +66,62 @@ func main() { http.ListenAndServe(":8080", nil).Error() } +func calculate(category string, res []processor.LanguageSummary) (string, int64) { + title := "" + var value int64 + + switch category { + case "codes": + fallthrough + case "code": + title = "Code lines" + for _, x := range res { + value += x.Code + } + case "blank": + fallthrough + case "blanks": + title = "Blank lines" + for _, x := range res { + value += x.Blank + } + case "comment": + fallthrough + case "comments": + title = "Comments" + for _, x := range res { + value += x.Comment + } + case "cocomo": + title = "COCOMO $" + for _, x := range res { + value += x.Code + } + + wage := 56286 + //if 'avg-wage' in event['queryStringParameters']: + //wage = event['queryStringParameters']['avg-wage'] + + value = int64(estimateCost(value, wage)) + //if wage.isdigit(): + //s = format_count(estimate_cost(sum([x['Code'] for x in j]), int(wage))) + //else: + //s = format_count(estimate_cost(sum([x['Code'] for x in j]))) + + case "lines": // lines is the default + fallthrough + case "line": // lines is the default + fallthrough + default: + // + title = "Total lines" + for _, x := range res { + value += x.Lines + } + } + return title, value +} + type location struct { Provider string User string @@ -290,3 +309,11 @@ func cleanString(s string) string { return processedString } + +func estimateEffort(codeCount int64) float64 { + return 3.2 * math.Pow(float64(codeCount)/1000, 1.05) * 1 +} + +func estimateCost(codeCount int64, averageWage int) float64 { + return estimateEffort(codeCount) * (float64(averageWage) / 12) * 1.8 +}