Spaces:
Runtime error
Runtime error
Update test script
Browse filesFiles changed (3)
- .gitignore+5-5
- plot_calls.py+65-17
- test_api.sh+25-20
97 unmodified lines989910010110210310410597 unmodified lines.bash_env**/*secret***/*private*/call_history.csv/call_history.txt/output.csv/call_history_bash.csv/call_history_sentiment_bash.csv97 unmodified lines989910010110210310410597 unmodified lines.bash_env**/*secret***/*private*/bad_response.txt/data/call_history_sentiment_1_bash.csv/data/call_history_text2int_1_bash.csv/data/processed_call_history_sentiment_1_bash.csv/data/processed_call_history_text2int_1_bash.csv
1234567891011121314151617181920212223242526272829from datetime import datetimeimport matplotlib.pyplot as pltimport pandas as pd# pd.set_option('display.max_columns', None)# pd.set_option('display.max_rows', None)df = pd.read_csv(filepath_or_buffer='call_history_bash.csv', sep=";")df["elapsed"] = df["finished"].apply(lambda x: datetime.strptime(x, "%Y-%m-%d %H:%M:%S.%f")) - df["started"].apply(lambda x: datetime.strptime(x, "%Y-%m-%d %H:%M:%S.%f"))df["elapsed"] = df["elapsed"].apply(lambda x: x.total_seconds())df.to_csv("output.csv", index=False, sep=";")student_numbers = df['active_students'].unique()plt.figure(figsize=(16, 10))rows = len(student_numbers)for index, student_number in enumerate(student_numbers, 1):data = df[df["active_students"] == student_number]plt.subplot(rows, 2, 2 * index - 1)plt.title("y=seconds, x=active students", x=0.75, y=0.75)plt.boxplot(x=data["elapsed"], labels=[student_number])plt.subplot(rows, 2, 2 * index)plt.title("y=count of seconds, x=seconds", x=0.75, y=0.75)plt.hist(x=data["elapsed"], bins=25, edgecolor='white')plt.show()1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677from datetime import datetimeimport matplotlib.pyplot as pltimport pandas as pdpd.set_option('display.max_columns', None)pd.set_option('display.max_rows', None)log_files = ['call_history_sentiment_1_bash.csv','call_history_text2int_1_bash.csv',]for log_file in log_files:path_ = f"./data/{log_file}"df = pd.read_csv(filepath_or_buffer=path_, sep=";")df["elapsed"] = df["finished"].apply(lambda x: datetime.strptime(x, "%Y-%m-%d %H:%M:%S.%f")) - df["started"].apply(lambda x: datetime.strptime(x, "%Y-%m-%d %H:%M:%S.%f"))df["elapsed"] = df["elapsed"].apply(lambda x: x.total_seconds())df["success"] = df["outputs"].apply(lambda x: 0 if "Time-out" in x else 1)df.to_csv(f"./data/processed_{log_file}", index=False, sep=";")student_numbers = sorted(df['active_students'].unique())result = df.groupby(['active_students', 'success']) \.agg({'elapsed': ['mean', 'median', 'min', 'max'],'success': ['count'],})print(f"Results for {log_file}")print(result, "\n")title = Noneif "sentiment" in log_file.lower():title = "API result for 'sentiment-analysis' endpoint"elif "text2int" in log_file.lower():title = "API result for 'text2int' endpoint"for student_number in student_numbers:try:failed_calls = result.loc[(student_number, 0), 'success'][0]except:failed_calls = 0successful_calls = result.loc[(student_number, 1), 'success'][0]percentage = (successful_calls / (failed_calls + successful_calls)) * 100print(f"Percentage of successful API calls for {student_number} students: {percentage.__round__(2)}")rows = len(student_numbers)# plt.figure(figsize=(16, 10))# for index, student_number in enumerate(student_numbers, 1):# data = df[df["active_students"] == student_number]# fig = plt.subplot(rows, 2, 2 * index - 1)# plt.title("y=seconds, x=active students", x=0.75, y=0.75)# plt.boxplot(x=data["elapsed"], labels=[student_number])# plt.subplot(rows, 2, 2 * index)# plt.title("y=count of seconds, x=seconds", x=0.75, y=0.75)# plt.hist(x=data["elapsed"], bins=25, edgecolor='white')fig, axs = plt.subplots(rows, 2) # (rows, columns)for index, student_number in enumerate(student_numbers):data = df[df["active_students"] == student_number]axs[index][0].boxplot(x=data["elapsed"]) # axs[row][column]# axs[index][0].set_title(f'Boxplot for {student_number} students')axs[index][0].set_xlabel(f'student number {student_number}')axs[index][0].set_ylabel('Elapsed time (s)')axs[index][1].hist(x=data["elapsed"], bins=25) # axs[row][column]# axs[index][1].set_title(f'Histogram for {student_number} students')axs[index][1].set_xlabel('seconds')axs[index][1].set_ylabel('Count of API calls')fig.suptitle(title, fontsize=16)plt.show()
2 unmodified lines34567891011121316 unmodified lines3031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576772 unmodified linesLOG_FILE_NAME="call_history_bash.csv"if [[ ! -f "$LOG_FILE_NAME" ]]; then# Creation of column names if the file does not exitsecho "student_id;active_students;endpoint;inputs;outputs;started;finished" > $LOG_FILE_NAMEfidata_list_1() {responses=("one hundred forty five"16 unmodified linesecho "${responses[$1]}"}# endpoints: "text2int" "text2int-preprocessed" "sentiment-analysis"# selected endpoint to testendpoint="text2int"create_random_delay () {# creates a random delay for given argumentsecho "scale=8; $RANDOM/32768*$1" | bc}simulate_student() {# Student simulator waits randomly between 0-10s after an interaction.# Based on 100 interactions per studentfor i in {1..100}; dostart_=$(date +"%F %T.%6N")url="https://tangibleai-mathtext.hf.space/run/$3"response=$(curl --silent -X POST "$url" -H 'Content-Type: application/json' -d "$4")if [[ "$response" == *"504"* ]]; thenresponse="504 Gateway Time-out"fiend_=$(date +"%F %T.%6N")printf "%s;%s;%s;%s;%s;%s;%s\n" "$1" "$2" "$3" "$4" "$response" "$start_" "$end_" >>$LOG_FILE_NAMEsleep "$(create_random_delay 10)"done}echo "start: $(date)"active_students=250 # the number of students using the system at the same timei=1while [[ "$i" -le "$active_students" ]]dorandom_value=$((RANDOM % 5))text=$(data_list_2 $random_value)data='{"data": ["'$text'"]}'simulate_student "student$i" "$active_students" "$endpoint" "$data" &sleep "$(create_random_delay 1)" # adding a random delay between studentsi=$(( "$i" + 1 ))donewait2 unmodified lines345678910111216 unmodified lines2930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081822 unmodified linesLOG_FILE_NAME="call_history_bash.csv"if [[ ! -f "$LOG_FILE_NAME" ]]; then# Creation of column names if the file does not exitsecho "student_id;active_students;endpoint;inputs;outputs;started;finished" >$LOG_FILE_NAMEfidata_list_1() {responses=("one hundred forty five"16 unmodified linesecho "${responses[$1]}"}# endpoints: "text2int" "sentiment-analysis"# selected endpoint to testendpoint="sentiment-analysis"create_random_delay() {# creates a random delay for given argumentsecho "scale=8; $RANDOM/32768*$1" | bc}simulate_student() {# Student simulator waits randomly between 0-10s after an interaction.# Based on 100 interactions per studentfor i in {1..100}; dorandom_value=$((RANDOM % 5))text=$(data_list_2 $random_value)data='{"data": ["'$text'"]}'start_=$(date +"%F %T.%6N")url="https://tangibleai-mathtext.hf.space/run/$3"response=$(curl --silent --connect-timeout 30 --max-time 30 -X POST "$url" -H 'Content-Type: application/json' -d "$data")if [[ "$response" == *"Time-out"* ]]; thenecho "$response" >>bad_response.txtresponse="504 Gateway Time-out"elif [[ -z "$response" ]]; thenecho "No response" >>bad_response.txtresponse="504 Gateway Time-out"fiend_=$(date +"%F %T.%6N")printf "%s;%s;%s;%s;%s;%s;%s\n" "$1" "$2" "$3" "$data" "$response" "$start_" "$end_" >>$LOG_FILE_NAMEsleep "$(create_random_delay 10)"done}echo "start: $(date)"active_students=250 # the number of students using the system at the same timei=1while [[ "$i" -le "$active_students" ]]; dosimulate_student "student$i" "$active_students" "$endpoint" &sleep "$(create_random_delay 1)" # adding a random delay between studentsi=$(("$i" + 1))donewait
.gitignore+5-5
plot_calls.py+65-17
test_api.sh+25-20