--- /dev/null
+#! /bin/bash
+# SPDX-License-Identifier: EPL-1.0
+##############################################################################
+# Copyright (c) 2019 The Linux Foundation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+
+set -euf
+
+# This script can be run on a cost file (.csv) to standardize the formats of the
+# uptime, cost & stack_cost fields.
+
+cost_file=$1
+
+while IFS="," read -r job_name build_number date resource uptime cost stack_cost; do
+ [[ $resource == "0" ]] && resource='unknown'
+ printf "%s,%s,%s,%s,%d,%.2f,%.2f\n" "$job_name" "$build_number" "$date" \
+ "$resource" "$uptime" "$cost" "$stack_cost"
+done < "$cost_file"
else
echo "ERROR: Pricing API returned invalid json"
cost=0
- resource=0
+ resource='unknown'
fi
# Archive the cost date
# This format is readable by spreadsheet and is easily sortable
date=$(TZ=GMT date +'%Y-%m-%d %H:%M:%S')
-cat << EOF > "$WORKSPACE/archives/cost.csv"
-$JOB_NAME,$BUILD_NUMBER,$date,$resource,$uptime,$cost,$stack_cost
-EOF
+# Format the uptime, cost & stack_cost fields
+printf "%s,%s,%s,%s,%d,%.2f,%.2f\n" "$JOB_NAME" "$BUILD_NUMBER" "$date" \
+ "$resource" "$uptime" "$cost" "$stack_cost" > "$WORKSPACE/archives/cost.csv"
#
# Each cost file contains one or more CSV records in the following format:
#
-# JobName , BuildNumber , Date , InstanceType , Uptime , Cost1 , Cost2
+# JobName , BuildNumber , Date , InstanceType , Uptime , Cost , StackCost
#
# Date format: '%Y-%m-%d %H:%M:%S'
+# Cost format: '%.2f' (1.29)
#
##############################################################################
#