add command line flags
Some checks failed
continuous-integration/drone Build is failing

This commit is contained in:
2024-10-04 14:39:00 +10:00
parent 73eac1d9ea
commit 82811442a4
5 changed files with 142 additions and 2 deletions

37
.drone.sh Normal file
View File

@@ -0,0 +1,37 @@
#!/usr/bin/env bash
# disable CGO for cross-compiling
export CGO_ENABLED=0
commit=$(git rev-parse HEAD)
buildtime=$(TZ=Australia/Sydney date +%Y-%m-%dT%T%z)
git_version=$(git describe --tags --always --long --dirty)
package_name=generate-chart
#platforms=("linux/amd64" "darwin/amd64")
platforms=("linux/amd64", "windows/amd64")
echo Building $package_name with git version: $git_version
for platform in "${platforms[@]}"
do
platform_split=(${platform//\// })
GOOS=${platform_split[0]}
GOARCH=${platform_split[1]}
output_name=$package_name'-'$GOOS'-'$GOARCH
if [ $GOOS = "windows" ]; then
output_name+='.exe'
fi
starttime=$(TZ=Australia/Sydney date +%Y-%m-%dT%T%z)
echo "build commences at $starttime"
env GOOS=$GOOS GOARCH=$GOARCH go build -trimpath -ldflags="-X main.sha1ver=$commit -X main.buildTime=$buildtime" -o $output_name $package
if [ $? -ne 0 ]; then
echo 'An error has occurred! Aborting the script execution...'
exit 1
fi
gzip $output_name
echo "build complete at $buildtime : $output_name"
sha256sum ${output_name}.gz > ${output_name}_checksum.txt
done
ls -lah

32
.drone.yml Normal file
View File

@@ -0,0 +1,32 @@
kind: pipeline
type: docker
name: default
# Docs at https://docs.drone.io/pipeline/exec/overview/
# Also see https://github.com/harness/drone-cli/blob/master/.drone.yml
steps:
- name: build
image: golang
environment:
CGO_ENABLED: 0
commands:
- sh ./.drone.sh
- name: dell-sftp-deploy
image: hypervtechnics/drone-sftp
settings:
host: deft.dell.com
username:
from_secret: DELLFTP_USER
password:
from_secret: DELLFTP_PASS
port: 22
source: ./
filter: generate-chart*
clean: false
target: /
overwrite: true
verbose: true

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
*.json
*.xlsx

64
README.md Normal file
View File

@@ -0,0 +1,64 @@
# Excel Chart Generator
Using the excellent open source [excelize](https://github.com/qax-os/excelize) library, convert json data tracking numbers over time into an excel workbook of graphs.
## Input data
Here is some sample input data. Note that some of these key names are hard coded in the source code in order to reduce complexity.
```json
{
"Tracking": {
"AVG data 1": {
"Low": {
"DC1": {
"September-2024": 17948.94,
"August-2024": 17947.40,
"July-2024": 17470.34,
"June-2024": 17648.02,
"May-2024": 17314.25
},
"DC2": {
"September-2024": 21226.84,
"August-2024": 20956.31,
"July-2024": 20021.72,
"June-2024": 19713.80,
"May-2024": 19945.32
}
},
"Ultra": {
"DC1": {
"September-2024": 4544,
"August-2024": 4544,
"July-2024": 4685.90,
"June-2024": 4741.55,
"May-2024": 4830.26
},
"DC2": {
"September-2024": 5369.58,
"August-2024": 5372,
"July-2024": 5357.38,
"June-2024": 5344.6,
"May-2024": 5306.26
}
}
},
"count 1": {
"DC1": {
"September-2024": 6801.80,
"August-2024": 6804.71,
"July-2024": 6664.03,
"June-2024": 6673.87,
"May-2024": 6656.42
},
"DC2": {
"September-2024": 6751.17,
"August-2024": 6765.42,
"July-2024": 6597.65,
"June-2024": 6510.47,
"May-2024": 6487.19
}
}
}
}
```

View File

@@ -2,6 +2,7 @@ package main
import (
"encoding/json"
"flag"
"fmt"
"io"
"log"
@@ -239,6 +240,10 @@ func AvgChart(f *excelize.File, worksheetName string, location string, avgCpuCol
func main() {
var err error
inputFile := flag.String("input", "input.json", "The filename from which to load historical data")
outputFile := flag.String("output", "book1.xlsx", "The filename to use when writing excel workbook")
flag.Parse()
// Create the workbook
f := excelize.NewFile()
defer func() {
@@ -252,7 +257,7 @@ func main() {
}
// Load the JSON data from file
file, err := os.Open("input.json")
file, err := os.Open(*inputFile)
if err != nil {
log.Fatalf("Failed to open input.json: %v", err)
}
@@ -271,7 +276,7 @@ func main() {
GenerateCharts(f, data.Tracking.VmCount, "VM Count", "N60")
// Save workbook
if err := f.SaveAs("Book1.xlsx"); err != nil {
if err := f.SaveAs(*outputFile); err != nil {
fmt.Println(err)
}
}