#!/bin/bash

function check(){
  F=$1
  MEASURED=$(grep Continue $F|cut -d ":" -f 3 | cut -d "a" -f 1)
  REPORTED=$(grep "File creation" $F| cut -d ":" -f 2|cut -b -20)
  START=$(grep -- "-- started at" $F | cut -b 25-33| sed "s/:/*3600+/" | sed "s/:/*60+/"|bc)
  END=$(grep -- "-- finished at" $F  | cut -b 27-35| sed "s/:/*3600+/" | sed "s/:/*60+/"|bc)
  DELTA=$(($END - $START))
  TASKS=$(grep "tasks, .* files" $F | awk '{print $1}')
  FILES=$(grep "tasks, .* files" $F | awk '{print $3}')

  EXPECTED_RATE=$(echo "$MEASURED * $TASKS / $DELTA" | bc)
  REPORTED_RATE=$(echo "$FILES / $DELTA" | bc)
  echo "$F => Corrected rate: $EXPECTED_RATE ; currently reported rate: $REPORTED_RATE"
}

function checkValue(){
  check $1/mdtest_easy_write.txt
  check $1/mdtest_hard_write.txt
}

checkValue "$1"
