Skip to content

Commit

Permalink
start to add in requisite methods
Browse files Browse the repository at this point in the history
  • Loading branch information
boyter committed Aug 1, 2023
1 parent 2462818 commit c5ddd28
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cmd/badges/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import re
import string

import boto3
# import boto3

from datetime import datetime, timedelta
import time
import math

s3 = boto3.client('s3')
# s3 = boto3.client('s3')
bucket_name = 'sloccloccode'

def lambda_handler(event, context):
Expand Down
43 changes: 43 additions & 0 deletions cmd/badges/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"errors"
"fmt"
"math"
"net/http"
"strings"
)
Expand Down Expand Up @@ -42,3 +43,45 @@ func processPath(path string) (location, error) {

return location{}, nil
}

func formatCount(count float64) string {
//ranges = [
// (1e18, 'E'),
// (1e15, 'P'),
// (1e12, 'T'),
// (1e9, 'G'),
// (1e6, 'M'),
// (1e3, 'k'),
//]
//
//for x, y in ranges:
// if count >= x:
// t = str(round(count / x, 1))
// if len(t) > 3:
// t = t[:t.find('.')]
// return t + y
//
//return str(round(count, 1))

type r struct {
val float64
sym string
}
ranges := []r{
{1e18, "E"},
{1e15, "P"},
{1e12, "T"},
{1e9, "G"},
{1e6, "M"},
{1e3, "k"},
}

for _, v := range ranges {
if count >= v.val {
t := math.Round(count / v.val)
return fmt.Sprintf("%v%v", t, v.sym)
}
}

return fmt.Sprintf("%v", math.Round(count))
}
40 changes: 40 additions & 0 deletions cmd/badges/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,43 @@ func Test_processPath(t *testing.T) {
})
}
}

func Test_formatCount(t *testing.T) {
type args struct {
count float64
}
tests := []struct {
name string
args args
want string
}{
{
name: "",
args: args{
count: 100,
},
want: "100",
},
{
name: "",
args: args{
count: 1000,
},
want: "1.0k",
},
{
name: "",
args: args{
count: 2500,
},
want: "2.5k",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := formatCount(tt.args.count); got != tt.want {
t.Errorf("formatCount() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit c5ddd28

Please sign in to comment.