Skip to content
This repository has been archived by the owner on Jun 1, 2021. It is now read-only.

Commit

Permalink
Add ratio buckets' aggregate analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
joelpurra committed Feb 2, 2015
1 parent 521c575 commit 939f205
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/one-shot/questions.sh
Expand Up @@ -15,6 +15,8 @@ set -e
<"domains.parts.expanded.public-suffix.classified.disconnect.json" "${BASH_SOURCE%/*}/../util/parallel-chunks.sh" "${BASH_SOURCE%/*}/../questions/ratio-buckets.sh" > "ratio-buckets.json"
# TODO: parallelize question aggregation?
<"ratio-buckets.json" "${BASH_SOURCE%/*}/../questions/ratio-buckets.aggregate.sh" > "ratio-buckets.aggregate.json"
# TODO: parallelize question analysis?
<"ratio-buckets.aggregate.json" "${BASH_SOURCE%/*}/../questions/ratio-buckets.aggregate.analysis.sh" > "ratio-buckets.aggregate.analysis.json"

# Regroup disconnect's categories and organizations
<"aggregates.analysis.json" "${BASH_SOURCE%/*}/../questions/disconnect.categories.organizations.sh" "prepared.disconnect.services.json" > "aggregate.disconnect.categories.organizations.json"
57 changes: 57 additions & 0 deletions src/questions/ratio-buckets.aggregate.analysis.sh
@@ -0,0 +1,57 @@
#!/usr/bin/env bash
set -e

read -d '' getRatioBucketAggregateAnalysis <<-'EOF' || true
def averageIndices:
. as $array
| reduce range(0; length) as $index(
[];
. + [
{
index: $index,
value: $array[$index]
}
]
)
| map(
.diff = (
.value - 0.5
| if . < 0 then . * -1 else . end
)
)
| (map(.diff) | min) as $min
| map(select(.diff == $min))
| map(.index);
def averageIndexMinimum:
0 as $min
| .[$min];
def averageIndexMiddle:
(((length - 1) / 2) | floor) as $mid
| .[$mid];
def averageIndexMaximum:
(length - 1) as $max
| .[$max];
def getAverageIndiceRange:
averageIndices
| {
minimum: averageIndexMinimum,
middle: averageIndexMiddle,
maximum: averageIndexMaximum,
};
def getAverageIndiceRanges:
with_entries(
.value.analysis = {}
| .value.analysis.index = {}
| .value.analysis.index.average = (.value.normalized.cumulative | getAverageIndiceRange)
);
.ratios |= getAverageIndiceRanges
| .occurrences |= getAverageIndiceRanges
EOF

jq "$getRatioBucketAggregateAnalysis"

0 comments on commit 939f205

Please sign in to comment.