diff options
author | Markus Uhlin <markus@nifty-networks.net> | 2024-04-04 03:25:44 +0200 |
---|---|---|
committer | Markus Uhlin <markus@nifty-networks.net> | 2024-04-04 03:25:44 +0200 |
commit | 76141fbf611d9e9525a9453b7536ed3d04697364 (patch) | |
tree | 609dce745498dab75f3aa60422a61ba7a7dc4edb | |
parent | bef370167de540740b5293bd3f2616949927a467 (diff) |
Reformatted load_ratings() + enhancements
-rw-r--r-- | FICS/ratings.c | 99 |
1 files changed, 52 insertions, 47 deletions
diff --git a/FICS/ratings.c b/FICS/ratings.c index a1443de..ccce9a3 100644 --- a/FICS/ratings.c +++ b/FICS/ratings.c @@ -267,55 +267,60 @@ PUBLIC void rating_remove(int rating, int type) } } -PRIVATE void load_ratings(void) +PRIVATE void +load_ratings(void) { - FILE *fp; - char fname[MAX_FILENAME_SIZE]; - int i; - - sprintf(fname, "%s/newratingsV%d_data", stats_dir,STATS_VERSION); - fp = fopen(fname, "r"); - if (!fp) { - fprintf(stderr, "FICS: Can't read ratings data!\n"); - return; - } - fscanf(fp, "%lf %lf %lf %d", &Rb_M, &Rb_S, &Rb_total, &Rb_count); - fscanf(fp, "%lf %lf %lf %d", &Rs_M, &Rs_S, &Rs_total, &Rs_count); - fscanf(fp, "%lf %lf %lf %d", &Rw_M, &Rw_S, &Rw_total, &Rw_count); - fscanf(fp, "%lf %lf %lf %d", &Rl_M, &Rl_S, &Rl_total, &Rl_count); + FILE *fp; + char fname[MAX_FILENAME_SIZE] = { '\0' }; - for (i = 0; i < MAXHIST; i++) { - fscanf(fp, "%d %d %d %d", &sHist[i], &bHist[i], &wHist[i], &lHist[i]); - } - fclose(fp); - if (Rs_count) { - Ratings_S_StdDev = sqrt(Rs_S / Rs_count); - Ratings_S_Average = Rs_total / (double) Rs_count; - } else { - Ratings_S_StdDev = 0; - Ratings_S_Average = 0; - } - if (Rb_count) { - Ratings_B_StdDev = sqrt(Rb_S / Rb_count); - Ratings_B_Average = Rb_total / (double) Rb_count; - } else { - Ratings_B_StdDev = 0; - Ratings_B_Average = 0; - } - if (Rw_count) { - Ratings_W_StdDev = sqrt(Rw_S / Rw_count); - Ratings_W_Average = Rw_total / (double) Rw_count; - } else { - Ratings_W_StdDev = 0; - Ratings_W_Average = 0; - } - if (Rl_count) { - Ratings_L_StdDev = sqrt(Rl_S / Rl_count); - Ratings_L_Average = Rl_total / (double) Rl_count; - } else { - Ratings_L_StdDev = 0; - Ratings_L_Average = 0; - } + snprintf(fname, sizeof fname, "%s/newratingsV%d_data", stats_dir, + STATS_VERSION); + + if ((fp = fopen(fname, "r")) == NULL) { + fprintf(stderr, "FICS: Can't read ratings data!\n"); + return; + } + + fscanf(fp, "%lf %lf %lf %d", &Rb_M, &Rb_S, &Rb_total, &Rb_count); + fscanf(fp, "%lf %lf %lf %d", &Rs_M, &Rs_S, &Rs_total, &Rs_count); + fscanf(fp, "%lf %lf %lf %d", &Rw_M, &Rw_S, &Rw_total, &Rw_count); + fscanf(fp, "%lf %lf %lf %d", &Rl_M, &Rl_S, &Rl_total, &Rl_count); + + for (int i = 0; i < MAXHIST; i++) { + fscanf(fp, "%d %d %d %d", &sHist[i], &bHist[i], &wHist[i], + &lHist[i]); + } + + fclose(fp); + + if (Rs_count) { + Ratings_S_StdDev = sqrt(Rs_S / Rs_count); + Ratings_S_Average = (Rs_total / (double)Rs_count); + } else { + Ratings_S_StdDev = 0; + Ratings_S_Average = 0; + } + if (Rb_count) { + Ratings_B_StdDev = sqrt(Rb_S / Rb_count); + Ratings_B_Average = (Rb_total / (double)Rb_count); + } else { + Ratings_B_StdDev = 0; + Ratings_B_Average = 0; + } + if (Rw_count) { + Ratings_W_StdDev = sqrt(Rw_S / Rw_count); + Ratings_W_Average = (Rw_total / (double)Rw_count); + } else { + Ratings_W_StdDev = 0; + Ratings_W_Average = 0; + } + if (Rl_count) { + Ratings_L_StdDev = sqrt(Rl_S / Rl_count); + Ratings_L_Average = (Rl_total / (double)Rl_count); + } else { + Ratings_L_StdDev = 0; + Ratings_L_Average = 0; + } } PUBLIC void |