未验证 提交 049a6c4d 编写于 作者: P Phodal Huang

feat: add basic evaluate summary

上级 ed05faea
......@@ -306,16 +306,49 @@ coca evaluate
```
```
custom [customKeyGenerator customCacheManager]
throw [throwUnchecked throwCheckedSync throwUncheckedSync throwChecked]
evict [evictWithException evictAllEarly evictAll evict evictEarly]
multi [multiCacheAndEvict multiCache multiUpdate multiEvict multiConditionalCacheAndEvict]
conditional [conditional conditionalUpdate conditionalSync]
unknown [unknownCustomCacheManager unknownCustomKeyGenerator]
throw [throwException throwCheckedException]
put [putWithException put]
early [earlyRemoveWithException earlyRemoveAllWithException earlyRemoveAll earlyPut earlyPutWithException earlyRemove]
evict [evictAll evictWithException evict evictEarly evictAllEarly]
+------------------------+-------+--------+-------+-------+
| TYPE | COUNT | LEVEL | TOTAL | RATE |
+------------------------+-------+--------+-------+-------+
| Nullable / Return Null | 8 | Method | 161 | 4.97% |
| Utils | 1 | Class | 64 | 1.56% |
| Static Method | 19 | Method | 19 | 0.62% |
+------------------------+-------+--------+-------+-------+
```
Evaluate.json examples
```json
{
"Nullable": {
"Items": [
"nonnull.Name.testNull",
"nonnull.Name.orElseNull",
"org.ofbiz.base.util.UtilURL.fromResource",
"org.ofbiz.base.util.UtilURL.getOfbizHomeRelativeLocationFromFilePath",
"study.huhao.demo.adapters.outbound.persistence.blog.BlogPO.toDomainModel",
"study.huhao.demo.adapters.outbound.persistence.blog.BlogPO.toDomainModel",
"study.huhao.demo.adapters.outbound.persistence.blog.BlogPO.of",
"study.huhao.demo.infrastructure.persistence.blog.BlogPO.convertDomain"
]
},
"ServiceSummary": {
"LifecycleMap": null,
"ReturnTypeMap": {
"BookRepresentaion": [
"com.phodal.pholedge.book.BookService.getBookById",
"com.phodal.pholedge.book.BookService.updateBook"
]
},
"RelatedMethod": null
},
"UtilsSummary": {},
"Summary": {
"UtilsCount": 1,
"ClassCount": 64,
"MethodCount": 161,
"StaticMethodCount": 19
}
}
```
### Todo
......
......@@ -3,12 +3,15 @@ package cmd
import (
"encoding/json"
"fmt"
"github.com/olekukonko/tablewriter"
"github.com/phodal/coca/config"
"github.com/phodal/coca/core/domain/evaluate"
"github.com/phodal/coca/core/models"
. "github.com/phodal/coca/core/support"
"github.com/spf13/cobra"
"log"
"os"
"strconv"
)
type EvaluateConfig struct {
......@@ -43,16 +46,30 @@ var evaluateCmd = &cobra.Command{
cModel, _ := json.MarshalIndent(result, "", "\t")
WriteToCocaFile("evaluate.json", string(cModel))
fmt.Println(" ----- same type in service ------ ")
fmt.Println(result.ServiceSummary.ReturnTypeMap)
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Type", "Count", "Level", "Total", "Rate"})
fmt.Println("-------- Null -------- Method")
for _, nullItem := range result.Nullable.Items {
fmt.Println(nullItem)
}
classCount := result.Summary.ClassCount
methodCount := result.Summary.MethodCount
nullItemsLength := len(result.Nullable.Items)
table.Append([]string{"Nullable / Return Null", strconv.Itoa(nullItemsLength), "Method", strconv.Itoa(methodCount), Percent(nullItemsLength, methodCount)})
utilsCount := result.Summary.UtilsCount
table.Append([]string{"Utils", strconv.Itoa(utilsCount), "Class", strconv.Itoa(classCount), Percent(utilsCount, classCount)})
staticCount := result.Summary.StaticMethodCount
table.Append([]string{"Static Method", strconv.Itoa(staticCount), "Method", strconv.Itoa(methodCount), Percent(utilsCount, methodCount)})
table.Render()
},
}
func Percent(pcent int, all int) string {
percent := 100.0 * float64(pcent) / float64(all)
return fmt.Sprintf("%3.2f%%", percent)
}
func init() {
rootCmd.AddCommand(evaluateCmd)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册