Skip to content

Commit

Permalink
dashboard/app: add coverage->subsystems heatmap
Browse files Browse the repository at this point in the history
  • Loading branch information
tarasmadan committed Jul 22, 2024
1 parent 0f4c05d commit 5fce04a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 45 deletions.
4 changes: 3 additions & 1 deletion dashboard/app/templates/templates.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ <h1><a href="/{{$.Namespace}}">syzbot</a></h1>
<a class="navigation_tab{{if eq .URLPath (printf "/%v/graph/coverage" $.Namespace)}}_selected{{end}}"
href="/{{$.Namespace}}/graph/coverage">Total</a>
<a class="navigation_tab{{if eq .URLPath (printf "/%v/graph/coverage_heatmap" $.Namespace)}}_selected{{end}}"
href="/{{$.Namespace}}/graph/coverage_heatmap">Heatmap</a>
href="/{{$.Namespace}}/graph/coverage_heatmap">Repo Heatmap</a>
<a class="navigation_tab{{if eq .URLPath (printf "/%v/graph/coverage_subsystems_heatmap" $.Namespace)}}_selected{{end}}"
href="/{{$.Namespace}}/graph/coverage_subsystems_heatmap">Subsystems Heatmap</a>
</div>
</div>
{{end}}
Expand Down
78 changes: 34 additions & 44 deletions pkg/cover/heatmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,61 +173,63 @@ where
return res, nil
}

func DoDirHeatMap(w io.Writer, projectID, ns string, dateFrom, dateTo civil.Date) error {
return DoHeatMap(w, projectID, ns, dateFrom, dateTo, "dir")
type styleBodyJS struct {
Style template.CSS
Body template.HTML
JS template.HTML
}

func DoSubsystemsHeatMap(w io.Writer, projectID, ns string, dateFrom, dateTo civil.Date) error {
return DoHeatMap(w, projectID, ns, dateFrom, dateTo, "subsystems")
func DoDirHeatMap(w io.Writer, projectID, ns string, dateFrom, dateTo civil.Date) error {

Check failure on line 182 in pkg/cover/heatmap.go

View workflow job for this annotation

GitHub Actions / build

182-192 lines are duplicate of `pkg/cover/heatmap.go:194-204` (dupl)
style, body, js, err := DoHeatMapStyleBodyJS(projectID, ns, dateFrom, dateTo)
if err != nil {
return fmt.Errorf("failed to DoHeatMapStyleBodyJS() %w", err)
}
return heatmapTemplate.Execute(w, &styleBodyJS{
Style: style,
Body: body,
JS: js,
})
}

func DoHeatMap(w io.Writer, projectID, ns string, dateFrom, dateTo civil.Date, hmType string) error {
var style template.CSS
var body, js template.HTML
var err error
f := DoHeatMapStyleBodyJS
switch hmType {
case "dir":
case "subsystems":
f = DoSubsystemsHeatMapStyleBodyJS
}
style, body, js, err = f(projectID, ns, dateFrom, dateTo)
func DoSubsystemsHeatMap(w io.Writer, projectID, ns string, dateFrom, dateTo civil.Date) error {

Check failure on line 194 in pkg/cover/heatmap.go

View workflow job for this annotation

GitHub Actions / build

194-204 lines are duplicate of `pkg/cover/heatmap.go:182-192` (dupl)
style, body, js, err := DoSubsystemsHeatMapStyleBodyJS(projectID, ns, dateFrom, dateTo)
if err != nil {
return fmt.Errorf("failed to get heatMapStyleBodyJS() %w", err)
return fmt.Errorf("failed to DoSubsystemsHeatMapStyleBodyJS() %w", err)
}
return heatmapTemplate.Execute(w, struct {
Style template.CSS
Body template.HTML
JS template.HTML
}{
return heatmapTemplate.Execute(w, &styleBodyJS{
Style: style,
Body: body,
JS: js,
})
}

func DoHeatMapStyleBodyJS(projectID, ns string, dateFrom, dateTo civil.Date,
func stylesBodyJSTemplate(templData *templateHeatmap,
) (template.CSS, template.HTML, template.HTML, error) {
covAndDates, err := filesCoverageWithDetails(context.Background(), projectID, ns, dateFrom, dateTo)
if err != nil {
return "", "", "", fmt.Errorf("failed to filesCoverageWithDetails: %w", err)
}
templateData := filesCoverageToTemplateData(covAndDates)
var styles, body, js bytes.Buffer
if err := heatmapTemplate.ExecuteTemplate(&styles, "style", templateData); err != nil {
if err := heatmapTemplate.ExecuteTemplate(&styles, "style", templData); err != nil {
return "", "", "", fmt.Errorf("failed to get styles: %w", err)
}
if err := heatmapTemplate.ExecuteTemplate(&body, "body", templateData); err != nil {
if err := heatmapTemplate.ExecuteTemplate(&body, "body", templData); err != nil {
return "", "", "", fmt.Errorf("failed to get body: %w", err)
}
if err := heatmapTemplate.ExecuteTemplate(&js, "js", templateData); err != nil {
if err := heatmapTemplate.ExecuteTemplate(&js, "js", templData); err != nil {
return "", "", "", fmt.Errorf("failed to get js: %w", err)
}
return template.CSS(styles.String()),
template.HTML(body.String()),
template.HTML(js.Bytes()), nil
}

func DoHeatMapStyleBodyJS(projectID, ns string, dateFrom, dateTo civil.Date,
) (template.CSS, template.HTML, template.HTML, error) {
covAndDates, err := filesCoverageWithDetails(context.Background(), projectID, ns, dateFrom, dateTo)
if err != nil {
return "", "", "", fmt.Errorf("failed to filesCoverageWithDetails: %w", err)
}
templData := filesCoverageToTemplateData(covAndDates)
return stylesBodyJSTemplate(templData)
}

func DoSubsystemsHeatMapStyleBodyJS(projectID, ns string, dateFrom, dateTo civil.Date,
) (template.CSS, template.HTML, template.HTML, error) {
covWithDetails, err := filesCoverageWithDetails(context.Background(), projectID, ns, dateFrom, dateTo)
Expand All @@ -246,20 +248,8 @@ func DoSubsystemsHeatMapStyleBodyJS(projectID, ns string, dateFrom, dateTo civil
ssCovAndDates = append(ssCovAndDates, &newRecord)
}
}
templateData := filesCoverageToTemplateData(ssCovAndDates)
var styles, body, js bytes.Buffer
if err := heatmapTemplate.ExecuteTemplate(&styles, "style", templateData); err != nil {
return "", "", "", fmt.Errorf("failed to get styles: %w", err)
}
if err := heatmapTemplate.ExecuteTemplate(&body, "body", templateData); err != nil {
return "", "", "", fmt.Errorf("failed to get body: %w", err)
}
if err := heatmapTemplate.ExecuteTemplate(&js, "js", templateData); err != nil {
return "", "", "", fmt.Errorf("failed to get js: %w", err)
}
return template.CSS(styles.String()),
template.HTML(body.String()),
template.HTML(js.Bytes()), nil
templData := filesCoverageToTemplateData(ssCovAndDates)
return stylesBodyJSTemplate(templData)
}

func approximateInstrumented(points int64) string {
Expand Down

0 comments on commit 5fce04a

Please sign in to comment.