Commit a935f3b3 authored by pcw109550's avatar pcw109550

op-chain-ops: Refactor delta checker to Channel Aggregator

parent d4389749
#!/bin/bash
set -uo pipefail
# Check if a directory path is provided
# Directory must contain the output of batch_decoder's reassemble command, which are channels in json form
if [ -z "${1:-}" ]; then
echo "Usage: $0 /path/to/directory"
exit 1
fi
# Check if jq is installed
if ! command -v jq &> /dev/null; then
echo "Error: jq is not installed"
exit 1
fi
directory_path=$1
# Check if directory exists and is not empty
if [ ! -d "$directory_path" ] || [ -z "$(ls -A "$directory_path")" ]; then
echo "Error: Directory does not exist or is empty"
exit 1
fi
invalid_json_count=0
invalid_jsons=()
not_ready_channel_count=0
not_ready_channels=()
ready_channel_count=0
span_batch_count=0
singular_batch_count=0
channels_with_invalid_batches=()
batch_type_counter_jq_script='reduce .batch_types[] as $batch_type (
{"span_batch_count": 0, "singular_batch_count": 0};
if $batch_type == 1 then
.span_batch_count += 1
else
.singular_batch_count += 1
end) | .span_batch_count, .singular_batch_count'
# Loop over every .json file in the specified directory
for file in "$directory_path"/*.json; do
# check file is valid json
if ! jq empty "$file" 2>/dev/null; then
((invalid_json_count++))
invalid_jsons+=("$file")
continue
fi
# check channels are ready
if [ $(jq -r ".is_ready" "$file") == "false" ] ; then
# not ready channel have no batches so invalid_batches field is always false
((not_ready_channel_count++))
not_ready_channels+=("$file")
continue
else
((ready_channel_count++))
fi
# check channels contain invalid batches
if [ $(jq -r ".invalid_batches" "$file") == "true" ] ; then
channels_with_invalid_batches+=("$file")
fi
# count singular batch count and span batch count
jq_result=$(jq "$batch_type_counter_jq_script" "$file")
read span_batch_count_per_channel singular_batch_count_per_channel <<< $jq_result
span_batch_count=$((span_batch_count+span_batch_count_per_channel))
singular_batch_count=$((singular_batch_count+singular_batch_count_per_channel))
done
# Display the counts
echo "Singular batch count: $singular_batch_count"
echo "Span batch count: $span_batch_count"
echo "Ready channel count: $ready_channel_count"
echo "Not ready channel count: $not_ready_channel_count"
echo "Invalid json count: $invalid_json_count"
# Display the files which are invalid jsons
if [ ${#invalid_jsons[@]} -gt 0 ]; then
echo "Invalid jsons"
printf '[*] %s\n' "${invalid_jsons[@]}"
else
echo "All processed channels are valid jsons."
fi
# Display the files which are channels not ready
if [ ${#not_ready_channels[@]} -gt 0 ]; then
echo "Not ready channels"
printf '[*] %s\n' "${not_ready_channels[@]}"
else
echo "All processed channels are ready."
fi
# Display the files including invalid batches
if [ ${#channels_with_invalid_batches[@]} -gt 0 ]; then
echo "Channels with invalid batches"
printf '[*] %s\n' "${channels_with_invalid_batches[@]}"
else
echo "All processed ready channels contain valid batches."
fi
#!/bin/bash
set -uo pipefail
# Check if a directory path is provided
# Directory must contain the output of batch_decoder's reassemble command
if [ -z "${1:-}" ]; then
echo "Usage: $0 /path/to/directory"
exit 1
fi
# Check if jq is installed
if ! command -v jq &> /dev/null; then
echo "Error: jq is not installed"
exit 1
fi
directory_path=$1
# Check if directory exists and is not empty
if [ ! -d "$directory_path" ] || [ -z "$(ls -A "$directory_path")" ]; then
echo "Error: Directory does not exist or is empty"
exit 1
fi
valid_count=0
invalid_count=0
invalid_channels=()
# Loop over every .json file in the specified directory
for file in "$directory_path"/*.json; do
# If channel is ready, all batches must valid.
# If delta is activated, all batch types must be span batch.
result=$(jq 'if .is_ready then (.invalid_batches == false and all(.batch_types[]; . == 1)) else empty end' "$file" 2>&1)
if [[ $result == "true" ]]; then
((valid_count++))
else
# supplied json is invalid or does not satisfy condition
((invalid_count++))
invalid_channels+=("$file")
fi
done
# Display the counts
echo "Valid count: $valid_count"
echo "Invalid count: $invalid_count"
# Display the files that returned invalid results
if [ ${#invalid_channels[@]} -gt 0 ]; then
echo "Channels with invalid results:"
printf '[*] %s\n' "${invalid_channels[@]}"
else
echo "All processed channels are valid and contains successfully derived span batches."
fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment