Bläddra i källkod

Support sequential option for Belarus case study

Vecna 7 månader sedan
förälder
incheckning
86a7a56a41
2 ändrade filer med 57 tillägg och 4 borttagningar
  1. 6 1
      run.sh
  2. 51 3
      scripts/belarus.sh

+ 6 - 1
run.sh

@@ -1,12 +1,15 @@
 #!/bin/bash
 
 fast=false
+sequential=false
 ncpus=""
 cpurange=""
 
 while [ -n "$1" ]; do
     if [ "$1" == "--fast" ]; then
         fast=true
+    elif [ "$1" == "-s" ]; then
+        sequential=true
     elif [ "$1" == "-n" ]; then
         ncpus="$2"
         shift
@@ -73,8 +76,10 @@ if [[ ! -f appendix-a-results.pdf || ! -f section-3-results ]]; then
     # Clean up any remnants of previous attempts and try again
     rm -f appendix-a-results.{pdf,tex} section-3-results
 
-    if [ "$1" == "--fast" ]; then
+    if [ "$fast" == "true" ]; then
         ./scripts/belarus.sh --fast || abort "belarus"
+    elif [ "$sequential" == "true" ]; then
+        ./scripts/belarus.sh -s || abort "belarus"
     else
         ./scripts/belarus.sh || abort "belarus"
     fi

+ 51 - 3
scripts/belarus.sh

@@ -1,13 +1,61 @@
 #!/bin/bash
 
-docker run --name "tp-belarus" --rm -d -i tp-analysis:latest || exit 1
+# Populate array of months we care about
+months=()
+# 2020
+for i in {7..12}; do
+    months+=( 2020-$(printf %02d $i) )
+done
+# 2021
+for i in {1..4}; do
+    months+=( 2021-$(printf %02d $i) )
+done
+
+cd belarus-2020-2021
 
 if [ "$1" == "--fast" ]; then
-    docker exec tp-belarus sh -c "cd /home/analysis/belarus-2020-2021 && ./run.sh --fast" | tee section-3-results
+    echo "Repacking some pre-processed data for the next step..."
+    ./scripts/repack-preprocessed-data.sh
+    #docker exec tp-belarus sh -c "cd /home/analysis/belarus-2020-2021 && ./run.sh --fast" | tee section-3-results
 else
-    docker exec tp-belarus sh -c "cd /home/analysis/belarus-2020-2021 && ./run.sh" | tee section-3-results
+    #docker run --name "tp-belarus-process-data" --rm -d -i tp-analysis:latest || exit 1
+    echo "Downloading data from the Tor Project..."
+    ./scripts/download-bridge-data.sh
+
+    if [ "$1" == "-s" ]; then
+        # Do this step sequentially
+        for i in ${months[@]}; do
+            docker run --name "tp-belarus-${i}" --rm -d -i tp-analysis:latest || exit 1
+            docker exec tp-belarus-${i} sh -c "cd /home/analysis/belarus-2020-2021 && ./scripts/extract-extra-infos-archive.sh bridge-extra-infos-${i}.tar.xz"
+            docker cp tp-belarus-${i}:/home/analysis/belarus-2020-2021/data/bridge_data/bridge-extra-infos-${i}_processed.tar.xz . && docker stop tp-belarus-${i}
+        done
+    else
+        # Do this step in parallel
+        for i in ${months[@]}: do
+            docker run --name "tp-belarus-${i}" --rm -d -i tp-analysis:latest || exit 1
+            docker exec tp-belarus-${i} sh -c "cd /home/analysis/belarus-2020-2021 && ./scripts/extract-extra-infos-archive.sh bridge-extra-infos-${i}.tar.xz" &
+        done
+        wait
+        for i in ${months[@]}; do
+            docker cp tp-belarus-${i}:/home/analysis/belarus-2020-2021/data/bridge_data/bridge-extra-infos-${i}_processed.tar.xz . && docker stop tp-belarus-${i}
+        done
+    fi
 fi
 
+docker run --name "tp-belarus" --rm -d -i tp-analysis:latest || exit 1
+docker exec tp-belarus sh -c "mkdir -p /home/analysis/belarus-2020-2021/data/bridge_data"
+
+# Copy archives to docker
+for i in data/*_processed.tar.xz; do
+    docker cp "${i}" tp-belarus:/home/analysis/belarus-2020-2021/data/bridge_data/
+done
+
+# Return to artifact root
+cd ..
+
+# Process the data
+docker exec tp-belarus sh -c "cd /home/analysis/belarus-2020-2021 && ./scripts/get-email-bridges.sh && ./scripts/clean-bridge-data.sh" && \
+docker exec tp-belarus sh -c "cd /home/analysis/belarus-2020-2021 && ./scripts/get-stats.sh" | tee section-3-results
 docker cp tp-belarus:/home/analysis/belarus-2020-2021/appendix-a-results.tex . && \
 docker cp tp-belarus:/home/analysis/belarus-2020-2021/appendix-a-results.pdf . && \
 docker stop tp-belarus