@@ -64,6 +64,7 @@ int main(int argc, char **argv) {
6464 tics_font_size = 8 ;
6565 labels_font_size = 8 ;
6666 char * path = NULL ;
67+ char * temp ;
6768
6869 while ((c = getopt (argc , argv , "l:t:nhp:x:y:" )) != -1 ) {
6970 switch (c )
@@ -84,7 +85,12 @@ int main(int argc, char **argv) {
8485 tics_font_size = atoi (optarg );
8586 break ;
8687 case 'p' :
87- path = optarg ;
88+ temp = optarg ;
89+ len = strlen (temp )+ 2 ;
90+ path = malloc (len );
91+ strcpy (path , temp );
92+ path [len - 2 ]= '/' ;
93+ path [len - 1 ]= '\0' ;
8894 break ;
8995 case 'n' :
9096 NOLABELS = 1 ;
@@ -120,8 +126,15 @@ int main(int argc, char **argv) {
120126 return 0 ;
121127}
122128
123- void configure_handle (gnuplot_ctrl * h , int number_of_events , int number_of_elements , unsigned int res_x , unsigned int res_y ){
129+ void configure_handle (gnuplot_ctrl * h , int number_of_events , int number_of_elements ){
124130
131+ gnuplot_cmd (h ,"reset" );
132+
133+ gnuplot_cmd (h , "dx=.7" );
134+ gnuplot_cmd (h , "n=%d" , number_of_events );
135+ gnuplot_cmd (h , "total_box_width_relative=0.3" );
136+ gnuplot_cmd (h , "gap_width_relative=0.1" );
137+ gnuplot_cmd (h , "d_width=(gap_width_relative+total_box_width_relative)*dx/2." );
125138
126139 gnuplot_cmd (h ,"list = ''" );
127140 gnuplot_cmd (h ,"index(w) = words(substr(list, 0, strstrt(list, w)-1))" );
@@ -131,28 +144,27 @@ void configure_handle(gnuplot_ctrl * h, int number_of_events, int number_of_ele
131144 gnuplot_cmd (h , "set xtics rotate by -25" );
132145 gnuplot_cmd (h , "set logscale y" );
133146
147+ gnuplot_cmd (h , "set term png truecolor" );
148+ gnuplot_cmd (h , "set grid" );
149+ gnuplot_cmd (h , "set boxwidth total_box_width_relative/n relative" );
150+ gnuplot_cmd (h , "set style fill transparent solid 0.5 noborder" );
151+
152+
134153 gnuplot_cmd (h , "set term png size %d,%d" , res_x , res_y );
135154
136155 gnuplot_cmd (h , "set ylabel \"Number of occurrences\"" );
137156
138157
139- gnuplot_cmd (h , "dx=0.7" );
140-
141- gnuplot_cmd (h , "n=%d" ,number_of_events );
142- gnuplot_cmd (h , "total_box_width_relative=0.3" );
143- gnuplot_cmd (h , "gap_width_relative=0.1" );
144- gnuplot_cmd (h , "d_width=(gap_width_relative+total_box_width_relative)*dx/2." );
145- gnuplot_cmd (h , "set boxwidth total_box_width_relative/n relative" );
146- gnuplot_cmd (h , "set style fill transparent solid 0.5 noborder" );
147-
158+ /*
148159 gnuplot_cmd(h, "set xrange [-1:%d]", number_of_elements);
149-
160+ */
150161 gnuplot_cmd (h , "set xtics out" );
151162 gnuplot_cmd (h , "set xtics nomirror" );
152163 gnuplot_cmd (h , "set xtics autofreq" );
153164 gnuplot_cmd (h , "set xtics font \"Verdana,%d\"" , tics_font_size );
154165 gnuplot_cmd (h , "set tic scale 0" );
155166 gnuplot_cmd (h , "set grid" );
167+
156168 gnuplot_cmd (h , "set label at character 1,1 \"Generated with Papify\"" );
157169 gnuplot_cmd (h , "set format y \"%%.0se%%S\"" );
158170
@@ -164,7 +176,7 @@ void plot_overall(char* output_path, char *path, int number_of_actors, int numbe
164176 h = gnuplot_init () ;
165177
166178 //int label_rot = 20;
167- configure_handle (h , number_of_events , number_of_actors , res_x , res_y );
179+ configure_handle (h , number_of_events , number_of_actors );
168180 gnuplot_cmd (h , "set output \"%s/papiplot_overall_.png\"" , output_path );
169181 gnuplot_cmd (h , "set title \"Events per actor\"" );
170182 gnuplot_cmd (h , "set xlabel \"Actors\"" );
@@ -230,7 +242,7 @@ void plot(char* output_path, char *path, char* actor_name, int number_of_actions
230242 h = gnuplot_init () ;
231243
232244 //int label_rot = 20;
233- configure_handle (h , number_of_events , number_of_actions , res_x , res_y );
245+ configure_handle (h , number_of_events , number_of_actions );
234246 gnuplot_cmd (h , "set output \"/%s/papiplot_%s.png\"" , output_path , actor_name );
235247 gnuplot_cmd (h , "set title \"Events in actor \\\"%s\\\" per action\"" , actor_name );
236248 gnuplot_cmd (h , "set xlabel \"Actions\"" );
@@ -305,11 +317,12 @@ int get_events_nb(char *path) {
305317
306318 while (token != NULL ){
307319 nb ++ ;
320+ if (strcmp (token ,"\n" )== 0 ) nb -- ;
308321 token = strtok (NULL ,";" );
309322 }
310323
311324 fclose (file );
312- return nb - 3 ;//-3 because of the first two columns (not events) and bc line ends with ';'
325+ return nb - 2 ;//-2 because of the first two columns (not events)
313326}
314327
315328const int is_papioutput (const char * filename ) {
@@ -321,10 +334,48 @@ void html_init(FILE* htmlfile){
321334 fprintf (htmlfile , "<html><head><meta content=\"text/html; charset=ISO-8859-1\" http-equiv=\"content-type\"><title></title></head>"
322335 "<body><h1>Papify stats processed with PapiPlot</h1><hr style=\"width: 100%; height: 2px;\">" );
323336}
324- void html_close (FILE * htmlfile ){
337+ void html_close (FILE * htmlfile , char * path ){
325338 fprintf (htmlfile , "<h2>Overall: Events per actor</h2><img alt=\"\""
326- "src=\"papiplot_overall_.png\">"
327- "</body></html>" );
339+ "src=\"papiplot_overall_.png\">" );
340+
341+
342+
343+ int events_nb = get_events_nb (path )+ 1 ;
344+ int i , j ;
345+ char * token ;
346+ char buf [1500 ];
347+
348+ FILE * ofile = fopen (path , "r" );
349+
350+ fprintf (htmlfile ,"<table border=\"1\">"
351+ "<td>Actor<br></td>" );
352+ fgets (buf , 1500 , ofile );
353+ token = strtok (buf ,";" );
354+ for (i = 0 ;i < events_nb ;i ++ ){
355+ token = strtok (NULL ,";" );
356+ fprintf (htmlfile ,"<td>%s<br></td>\n" , token );
357+ }
358+ fprintf (htmlfile ,"</tr>\n" );
359+
360+ int actors_nb = get_actions_nb_in_file (path );
361+ for (i = 0 ;i < actors_nb ;i ++ ){
362+ fprintf (htmlfile ,"<tr>\n" );
363+ fgets (buf , 1500 , ofile );
364+ token = strtok (buf ,";" );
365+ for (j = 0 ;j < events_nb + 1 ;j ++ ){
366+ fprintf (htmlfile ,"<td>%s<br></td>\n" , token );
367+ token = strtok (NULL ,";" );
368+ }
369+ fprintf (htmlfile ,"</tr>\n" );
370+ }
371+
372+ fprintf (htmlfile ,"</table>\n" );
373+ fprintf (htmlfile ,"<hr style=\"width: 100%; height: 2px;\">\n" );
374+ fprintf (htmlfile ,"<br>\n" );
375+
376+
377+ fprintf (htmlfile , "</body></html>" );
378+ fclose (ofile );
328379}
329380
330381void html_actor (FILE * htmlfile , event_acum_for_actor * data ){
@@ -402,9 +453,10 @@ void search_and_plot(char *path) {
402453 free (data );
403454 }
404455 }
456+ //printf("going for overalls\n");
405457 plot_overall (path , path_to_totals , actors_nb , get_events_nb (path_to_totals )+ 1 );
406458
407- html_close (htmlfile );
459+ html_close (htmlfile , path_to_totals );
408460 remove (path_to_totals );
409461
410462 fclose (htmlfile );
@@ -431,13 +483,14 @@ event_acum_for_actor* process_data (char* path_todir, char* path_tofile, char* f
431483 //get_actions_nb_in_file(path_tofile);
432484 int actions_nb = get_actions_nb_in_file (path_tofile );
433485
434- actor = malloc (sizeof (event_acum_for_actor )+ sizeof (event_acum_for_action * )* (actions_nb * 3 ));
486+ actor = malloc (sizeof (event_acum_for_actor )* 2 + sizeof (event_acum_for_action * )* (actions_nb ) * 3 ); //weird memory is weird..
435487 actor -> actor_name = malloc (strlen (actor_name ));
436488 strcpy (actor -> actor_name ,actor_name );
437489 actor -> proc_file_path = path_todatafile ;
438490 actor -> actions_nb = actions_nb ;
439491 int i , j ;
440492
493+
441494 for (i = 0 ;i < actions_nb * 3 ;i ++ ){
442495 actor -> actions [i ] = malloc (sizeof (event_acum_for_action )* 2 + sizeof (event_acumulator )* events_nb * 3 );//weird memory is weird..
443496 actor -> actions [i ]-> events_nb = events_nb ;
@@ -462,6 +515,7 @@ event_acum_for_actor* process_data (char* path_todir, char* path_tofile, char* f
462515 for (i = 0 ;i < actor -> actions [0 ]-> events_nb ;i ++ ){
463516 token = strtok (NULL ,";" );
464517 for (j = 0 ; j < actor -> actions_nb ; j ++ ){
518+ if (token [strlen (token )- 1 ]== '\n' ) token [strlen (token )- 1 ] = '\0' ;
465519 actor -> actions [j ]-> acumulator [i ]-> event_name = malloc (strlen (token )+ 1 );
466520 strcpy (actor -> actions [j ]-> acumulator [i ]-> event_name , token );
467521 //acum->acumulator->event_name[i] = malloc(strlen(token)+1);
0 commit comments