Commits

tuck  committed 3de4f74

retain all pyramid session, add a button to reset db

  • Participants
  • Parent commits f0452fc

Comments (0)

Files changed (4)

File pyramid_perfstat/__init__.py

     add some routes
     """
     config.add_route('pyramid_perfstat.reporting', '/stat')
+    config.add_route('pyramid_perfstat.reset','/reset')
 
-    config.add_route('pyramid_perfstat.reporting.view_detail', '/stat/{id_view}',
-                     custom_predicates=(to_int('id_view'),))
+    config.add_route('pyramid_perfstat.reporting.session_detail', '/stat/{id_session}',
+                     custom_predicates=(to_int('id_session'),))
+    
+    config.add_route('pyramid_perfstat.reporting.view_detail', '/stat/{id_session}/{id_view}',
+                     custom_predicates=(to_int('id_session', 'id_view'),))
 
-    config.add_route('pyramid_perfstat.reporting.url_detail', '/stat/{id_view}/{id_route}',
-                     custom_predicates=(to_int('id_view', 'id_route'),))
+    config.add_route('pyramid_perfstat.reporting.url_detail', '/stat/{id_session}/{id_view}/{id_route}',
+                     custom_predicates=(to_int('id_session', 'id_view', 'id_route'),))
     
     config.add_view('pyramid_perfstat.views.reporting',
                     route_name='pyramid_perfstat.reporting',
                     renderer='pyramid_perfstat:templates/reporting.mako')
 
     config.add_view('pyramid_perfstat.views.reporting',
+                    route_name='pyramid_perfstat.reporting.session_detail',
+                    renderer='pyramid_perfstat:templates/reporting.mako')
+
+    config.add_view('pyramid_perfstat.views.reporting',
                     route_name='pyramid_perfstat.reporting.view_detail',
                     renderer='pyramid_perfstat:templates/reporting.mako')
 
                     route_name='pyramid_perfstat.reporting.url_detail',
                     renderer='pyramid_perfstat:templates/reporting.mako')
 
+    config.add_view('pyramid_perfstat.views.reset_db',
+                    route_name='pyramid_perfstat.reset')
+    
+
 def includeme(config):
     """
     Set up am implicit :term:`tween` to log performance information of each

File pyramid_perfstat/perf_serializer.py

 
             self.view_name = view_callable
 
-    def init_db(self):
+    def init_db(self, from_scratch=False):
         """
         create table and usefull stuff ...
         in the db ...
         """
         
         c = self.conn.cursor()
-        c.execute("""drop table if exists pyramid_measure""")
+        
+        if from_scratch :
+            c.execute("""drop table if exists pyramid_measure""")
 
         c.execute("""create table if not exists pyramid_measure (id integer PRIMARY KEY,
                                                                  date_measure datetime)""")
                                                   (datetime.datetime.now(),))
         PerfDbManager.session_perf_id = c.lastrowid
 
-        c.execute("""drop table if exists pyramid_perf""")
+        if from_scratch :
+            c.execute("""drop table if exists pyramid_perf""")
+            
         c.execute("""create table if not exists pyramid_perf ( id integer PRIMARY KEY,
                                                                id_measure integer,
                                                                url text,
                                                                view_name text,
                                                                measure real,
                                                                date_measure datetime )""")
-
-        c.execute("""drop table if exists pyramid_agg_route_perf""")
+        if from_scratch :
+            c.execute("""drop table if exists pyramid_agg_route_perf""")
+            
         c.execute("""create table if not exists pyramid_agg_route_perf ( id integer PRIMARY KEY,
                                                                id_measure integer,
                                                                url text,
                                                                measure real,
                                                                fetch_count integer )""")
 
-        c.execute("""drop table if exists pyramid_agg_view_perf""")
+        if from_scratch :
+            c.execute("""drop table if exists pyramid_agg_view_perf""")
+            
         c.execute("""create table if not exists pyramid_agg_view_perf ( id integer PRIMARY KEY,
                                                                id_measure integer,
                                                                view_name text,
         return sessions liste
         """
         c = self.conn.cursor()
-        c.execute("""select id, date_measure from pyramid_measure""")
+        c.execute("""select m.id, m.date_measure, count(p.id) 
+                    from pyramid_measure m
+                        left join pyramid_agg_view_perf p on p.id_measure=m.id
+                group BY m.id order by m.id asc""")
         rows = c.fetchall()
         c.close()
         return rows

File pyramid_perfstat/templates/reporting.mako

 		<td>${get_color_perf(avg_time)}</td>
 		<td>${url}</td>
 		<td>
-                  <a href="${request.route_url("pyramid_perfstat.reporting.url_detail", id_view=id_view, id_route=id)}">${route_name}</a>
+                  <a href="${request.route_url("pyramid_perfstat.reporting.url_detail", id_session=id_session, id_view=id_view, id_route=id)}">${route_name}</a>
                 </td>
 		<td>${view_name}</td>
 		<td>${cpt}</td>
 	<tr>
 		<td>${id}</td>
 		<td>${get_color_perf(avg_time)}</td>
-		<td><a href="${request.route_url("pyramid_perfstat.reporting.view_detail",id_view=id)}">${view_name}</a></td>
+		<td><a href="${request.route_url("pyramid_perfstat.reporting.view_detail",id_session=id_session, id_view=id)}">${view_name}</a></td>
 		<td>${cpt}</td>
 	</tr>
 </%def>
 		
 	</head>
 	<body>
-		<select>
-			% for id, dt_label in lst_ids_measures_date :
-				<option value="${id}">${dt_label}</option>
-			% endfor	
+		<select onchange="javascript: goTo('${request.route_url(route_name='pyramid_perfstat.reporting.session_detail',id_session='')}'+$(this).val());">
+			% for id, dt_label, nb_rows in lst_ids_measures_date :
+				<option value="${id}" ${"selected='selected'" if id==id_session else ''}>SESSION-${id}: ${dt_label} nb of records : ${nb_rows}</option>
+			% endfor
 		</select>
+		
+		<button onclick="goTo('${request.route_url(route_name='pyramid_perfstat.reset')}')">reset db</button>
+		
 		<br />
 		<br />
 		<table id="perf_views_reporting_table" class="tablesorter">
 	<script type="text/javascript" src="${static_path}js/jquery-1.6.4.min.js"></script>
 	
 	<script>
+		function goTo(page)
+		{
+			window.location.assign(page);
+		}	
 		$(document).ready(function() { 
 		    $("#perf_views_reporting_table").tablesorter({}); 
-		    $("#perf_routes_reporting_table").tablesorter({}); 		    
+		    
+		    $("#perf_routes_reporting_table").tablesorter({});
+		    
+		    % if lst_urls_measures is not None :
+		    	$("#perf_urls_reporting_table").tablesorter({});
+		    % endif
 		});
 	</script>
 	

File pyramid_perfstat/views.py

 # New field:   ----------
 #-----------------------------------------------------------------------------
 
+from pyramid.httpexceptions import HTTPFound
+
 from pyramid_perfstat.perf_serializer import PerfDbManager
 from pyramid_perfstat import utils
 
 def reporting(request):
     """
-    display table with all reports ...
+    display tables with all reports ...
     """
+    
+    id_session = None
+    if 'id_session' in request.matchdict :
+       id_session = request.matchdict['id_session']    
+    
     id_view = None
     if 'id_view' in request.matchdict :
        id_view = request.matchdict['id_view']
 
     perf_manager = PerfDbManager(None)
     lst_ids_measures_date = perf_manager.get_session_liste()
-    first_id_measure = lst_ids_measures_date[0][0]
+
+    if id_session is None :
+        id_session = lst_ids_measures_date[-1][0]
 
     lst_agg_routes_measures = None
     lst_urls_measures = None
 
     if id_view : 
-         lst_agg_routes_measures = perf_manager.get_route_measure_summary_liste(first_id_measure, id_view)
+         lst_agg_routes_measures = perf_manager.get_route_measure_summary_liste(id_session, id_view)
 
     if id_route : 
-         lst_urls_measures = perf_manager.get_urls_measure_liste(first_id_measure, id_route)
+         lst_urls_measures = perf_manager.get_urls_measure_liste(id_session, id_route)
 
-    lst_agg_views_measures = perf_manager.get_view_measure_summary_liste(first_id_measure)
+    lst_agg_views_measures = perf_manager.get_view_measure_summary_liste(id_session)
     
+    # absolute is better
     static_path = request.static_url(utils.STATIC_PATH)
-    local_static_path = request.static_path(utils.STATIC_PATH)
     
     return {
-                'static_path':local_static_path,
+                'static_path':static_path,
+                'id_session':id_session,
                 'lst_ids_measures_date':lst_ids_measures_date,
                 'lst_agg_routes_measures':lst_agg_routes_measures,
                 'lst_agg_views_measures':lst_agg_views_measures,
                 'lst_urls_measures':lst_urls_measures
             }
+
+def reset_db(request):
+    """
+    """
+    perf_manager = PerfDbManager(request)
+    perf_manager.init_db(from_scratch=True)
+    return HTTPFound(request.route_url(route_name='pyramid_perfstat.reporting'))