[Tux4kids-commits] r397 - in tuxmath/trunk: doc src

tholy-guest at alioth.debian.org tholy-guest at alioth.debian.org
Mon Dec 31 11:54:08 UTC 2007


Author: tholy-guest
Date: 2007-12-31 11:54:08 +0000 (Mon, 31 Dec 2007)
New Revision: 397

Modified:
   tuxmath/trunk/doc/changelog
   tuxmath/trunk/src/fileops.c
   tuxmath/trunk/src/mathcards.c
Log:
Add some additional reporting about student progress: a log.csv file
that contains a brief (one-line) summary of every game played.  This
file organization is chosen to make it easy to import the data into a
spreadsheet program.


Modified: tuxmath/trunk/doc/changelog
===================================================================
--- tuxmath/trunk/doc/changelog	2007-12-30 13:00:46 UTC (rev 396)
+++ tuxmath/trunk/doc/changelog	2007-12-31 11:54:08 UTC (rev 397)
@@ -1,3 +1,30 @@
+2007.Dec.31 (svn.debian.org/tux4kids - revision 397)
+      Code:
+	Add some additional reporting about student progress: a log.csv
+	file that contains a brief (one-line) summary of every game
+	played.  This file organization is chosen to make it easy to
+	import the data into a spreadsheet program.
+
+      Tim Holy <holy at wustl.edu>
+
+2007.Dec.30 (svn.debian.org/tux4kids - revision 396)
+    Bug fixes:
+      fileops.c: homedir setting in read_config_file lacked a closedir,
+        resulting in a memory leak.
+      fileops.c: write_postgame_summary did not close the file after
+        appending, resulting in the summary sometimes never being
+        "flushed" (some summary files have just been truncated).
+      mathcards.c: new_randomize_list did not set the "previous" field of
+        each node, resulting in memory corruption & drawing glitches
+      mathcards.c: free tmp_vect (fixes memory leak)
+
+    New feature:
+      mathcards & game & fileops: collect data on the amount of time each
+        problem is on the screen, and report the median in the game
+        summary files.
+
+      Tim Holy <holy at wustl.edu>
+	
 2007.Dec.26 (svn.debian.org/tux4kids - revision 394)
     Code:
       * More bugfixing in the new login system: now the system seems to

Modified: tuxmath/trunk/src/fileops.c
===================================================================
--- tuxmath/trunk/src/fileops.c	2007-12-30 13:00:46 UTC (rev 396)
+++ tuxmath/trunk/src/fileops.c	2007-12-31 11:54:08 UTC (rev 397)
@@ -173,9 +173,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
+#include <time.h>
 
 
-
 /* Used by both write_pregame_summary() and */
 /* write_postgame_summary() so defined with */
 /* file scope:                              */
@@ -211,6 +211,7 @@
 static int read_lines_from_file(FILE *fp,char ***lines);
 static void dirname_up(char *dirname);
 static char* get_user_name(void);
+static char* get_file_name(char *fullpath);
 
 
 /* fix HOME on windows */
@@ -425,6 +426,9 @@
 static int add_subdir = 1;
 static char* high_scores_file_path = NULL;
 
+/* A variable for storing the "current" config filename */
+static char* last_config_file_name = NULL;
+
 char *get_user_data_dir ()
 { 
   if (! user_data_dir)
@@ -535,6 +539,10 @@
   /* Make compiler happy: */
   const char* filename = (const char*)fn;
 
+  if (last_config_file_name != NULL)
+    free(last_config_file_name);
+  last_config_file_name = strdup(filename);
+
   #ifdef TUXMATH_DEBUG
   printf("\nIn read_named_config_file() filename is: = %s\n", filename);
   #endif
@@ -2680,6 +2688,8 @@
       fprintf(fp, "\nPlayer: %s\n", get_user_name());
     }
 
+    fprintf(fp, "\nMission: %s\n", last_config_file_name);
+
     /* Write question list:  */
     fprintf(fp, "\nStarting Question List:");
     MC_PrintQuestionList(fp);
@@ -2696,13 +2706,23 @@
 
 int write_postgame_summary(void)
 {
-  FILE* fp;
+  FILE *fp;
   char filepath1[PATH_MAX];
   int total_answered;
+  float median_time;
+  int success = 1;
+  int write_column_names = 0;
+  time_t filetime;
+  struct stat filestat;
+  struct tm datetime;
+  char *mission_name;
 
   get_user_data_dir_with_subdir(filepath1);
   strcat(filepath1, summary_filenames[0]);
 
+  total_answered = MC_NumAnsweredCorrectly() + MC_NumNotAnsweredCorrectly();
+  median_time = MC_MedianTimePerQuestion();
+
   fp = fopen(filepath1, "a"); /* "a" means append to end of file */
   if (fp)
   {
@@ -2713,7 +2733,6 @@
                 MC_WrongListLength());
 
     /* Write post-game statistics:     */
-    total_answered = MC_NumAnsweredCorrectly() + MC_NumNotAnsweredCorrectly();
 
     fprintf(fp, "\n\nSummary:\n");
     fprintf(fp, "Questions Answered:\t%d\n", total_answered);
@@ -2730,7 +2749,7 @@
     else
       fprintf(fp, "Percent Correct: (not applicable)\n");
 
-    fprintf(fp,"Median Time/Question:\t%g\n",MC_MedianTimePerQuestion());
+    fprintf(fp,"Median Time/Question:\t%g\n",median_time);
 
     fprintf(fp, "Mission Accomplished:\t");
     if (MC_MissionAccomplished())
@@ -2743,13 +2762,53 @@
     }
 
     fclose(fp);
-    return 1;
   }
   else /* Couldn't write file for some reason: */
   {
     fprintf(stderr,"Summary not written.\n");
-    return 0;
+    success = 0;
   }
+
+  /* Append brief summary to log */
+  if (total_answered > 0) {
+    /* We're going to want to write the date.  Use the filetime  */
+    /* rather than calling "time" directly, because "time"       */
+    /* returns the time according to whatever computer is        */
+    /* running tuxmath, and in a server/client mode it's likely  */
+    /* that some of the clients' clocks may be wrong. Use      */
+    /* instead the time according to the server on which the     */
+    /* accounts are stored, which can be extracted from the      */
+    /* modification time of the summary we just wrote.           */
+    if (stat(filepath1,&filestat) == 0) {
+      filetime = filestat.st_mtime;
+    } else {
+      filetime = time(NULL);
+    }
+    localtime_r(&filetime,&datetime); /* generate broken-down time */
+
+    get_user_data_dir_with_subdir(filepath1);
+    strcat(filepath1, "log.csv");
+    /* See whether the log file already exists; if not, write */
+    /* the column names */
+    fp = fopen(filepath1, "r");
+    if (fp == NULL)
+      write_column_names = 1;
+    else
+      fclose(fp);
+    
+    fp = fopen(filepath1, "a"); /* "a" means append to end of file */
+    if (fp) {
+      if (write_column_names) {
+	fprintf(fp,"\"User\",\"Mission\",\"Date\",\"Completed?\",\"Percent correct\",\"Time per question\"\n");
+      }
+      mission_name = strdup(last_config_file_name);
+      fprintf(fp,"\"%s\",\"%s\",%d/%d/%d,%d,%d,%g\n", get_user_name(), get_file_name(mission_name), datetime.tm_year+1900, datetime.tm_mon+1, datetime.tm_mday, MC_MissionAccomplished(), ((MC_NumAnsweredCorrectly() * 100)/ total_answered), median_time);
+      fclose(fp);
+      free(mission_name);
+    } else
+      success = 0;
+  }
+  return success;
 }
 
 
@@ -2908,20 +2967,27 @@
 static char* get_user_name(void)
 {
   char filepath2[PATH_MAX];
-  char *username;
 
   get_user_data_dir_with_subdir(filepath2);
-  username = &filepath2[strlen(filepath2)-1];
+  return get_file_name(filepath2);
+}
+
+/* Extract the last "field" in a full pathname */
+static char* get_file_name(char *fullpath)
+{
+  char *file_name;
+
+  file_name = &fullpath[strlen(fullpath)-1];
   /* Chop off trailing "/" */
-  while (username > &filepath2[0] && *username == '/') {
-    *username = '\0';
-    username--;
+  while (file_name > &fullpath[0] && *file_name == '/') {
+    *file_name = '\0';
+    file_name--;
   }
   /* Back up to the next "/" */
-  while (username > &filepath2[0] && *username != '/')
-    username--;
+  while (file_name > &fullpath[0] && *file_name != '/')
+    file_name--;
 
-  return username;
+  return ++file_name;
 }
 
 

Modified: tuxmath/trunk/src/mathcards.c
===================================================================
--- tuxmath/trunk/src/mathcards.c	2007-12-30 13:00:46 UTC (rev 396)
+++ tuxmath/trunk/src/mathcards.c	2007-12-31 11:54:08 UTC (rev 397)
@@ -2812,7 +2812,7 @@
     return;
   }
 
-  fprintf(fp, "%s\t", ptr->card.formula_string);
+  fprintf(fp, "%s\n", ptr->card.formula_string);
   /*fprintf(fp, "randomizer = %d\n", ptr->randomizer);*/
 }  
 




More information about the Tux4kids-commits mailing list