Skip to content

Commit

Permalink
potree-utils: hierarchy summary - csv format
Browse files Browse the repository at this point in the history
  • Loading branch information
EliCDavis committed Jun 2, 2024
1 parent f5960c1 commit 457b2a3
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion examples/potree-utils/summarize_hierarchy.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package main

import (
"encoding/csv"
"encoding/json"
"fmt"
"io"
"math"
"os"
"strconv"

"github.com/EliCDavis/polyform/formats/potree"
"github.com/urfave/cli/v2"
Expand All @@ -21,6 +23,34 @@ type levelSummary struct {
Spacing float64 `json:"spacing"`
}

func writeSummaryAsCSV(out io.Writer, summaries []levelSummary) {
writer := csv.NewWriter(out)
writer.Write([]string{
"Level",
"Nodes",
"Average",
"Min",
"Max",
"Total",
"Volume",
"Spacing",
})

for i, summary := range summaries {
writer.Write([]string{
strconv.Itoa(i),
strconv.Itoa(summary.Nodes),
strconv.FormatFloat(summary.Average, 'f', -1, 64),
strconv.Itoa(summary.Min),
strconv.Itoa(summary.Max),
strconv.Itoa(summary.Total),
strconv.FormatFloat(summary.Volume, 'f', -1, 64),
strconv.FormatFloat(summary.Spacing, 'f', -1, 64),
})
}
writer.Flush()
}

func writeSummaryAsMarkdown(out io.Writer, summaries []levelSummary) {
fmt.Fprintf(
out,
Expand Down Expand Up @@ -59,7 +89,7 @@ var SummarizeHierarchyCommand = &cli.Command{
hierarchyFlag,
&cli.StringFlag{
Name: "format",
Usage: "format to write summary data too (markdown, json)",
Usage: "format to write summary data too (markdown, json, csv)",
Value: "markdown",
},
&cli.StringFlag{
Expand Down Expand Up @@ -140,6 +170,9 @@ var SummarizeHierarchyCommand = &cli.Command{
_, err = out.Write(data)
return err

case "csv":
writeSummaryAsCSV(out, summaries)

default:
return fmt.Errorf("unrecognized format %s", format)
}
Expand Down

0 comments on commit 457b2a3

Please sign in to comment.