r90441 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90440‎ | r90441 | r90442 >
Date:08:08, 20 June 2011
Author:rfaulk
Status:deferred
Tags:
Comment:
Added several views that enable the copying, listing, and mining of logs by the user
Added documentation
Modified paths:
  • /trunk/fundraiser-statistics/fundraiser-scripts/web_reporting/LML/urls.py (modified) (history)
  • /trunk/fundraiser-statistics/fundraiser-scripts/web_reporting/LML/views.py (modified) (history)

Diff [purge]

Index: trunk/fundraiser-statistics/fundraiser-scripts/web_reporting/LML/views.py
@@ -1,3 +1,26 @@
 2+"""
 3+ DJANGO VIEW DEFINITIONS:
 4+ ========================
 5+
 6+ Defines the views for Log Miner Logging (LML) application. The LML is meant to provide functionality for observing log mining activity and to
 7+ copy and mine logs at the users request.
 8+
 9+ Views:
 10+
 11+ index -- the index page shows a listing of loaded/mined logs by start time and and the time of log mining
 12+ copy_logs_form -- this renders a form where the user can request logs to be copied over for a certain hour
 13+ copy_logs_process -- the target of the copy form that executes the copying using a DataMapper
 14+ log_list -- Shows a listing of all copied logs. The links allow mining to be initiated.
 15+ mine_logs_form -- this renders a form where the user can request logs of a certain hour timestamop to be mined
 16+ mine_logs_process -- the target of the mine form that executes the mining using a DataMapper
 17+ mine_logs_process_file -- target of the link from the log_list page ... mines log associated to link via DataMapper
 18+"""
 19+
 20+__author__ = "Ryan Faulkner"
 21+__revision__ = "$Rev$"
 22+__date__ = "June 20th, 2011"
 23+
 24+
225 from django.shortcuts import render_to_response
326 from django.http import Http404
427 from django.shortcuts import render_to_response, get_object_or_404
@@ -7,11 +30,14 @@
831
932 import sys
1033 import os
 34+import re
1135 import datetime
1236
1337 import Fundraiser_Tools.classes.Helper as Hlp
1438 import Fundraiser_Tools.classes.DataReporting as DR
1539 import Fundraiser_Tools.classes.DataLoader as DL
 40+import Fundraiser_Tools.classes.DataMapper as DM
 41+import Fundraiser_Tools.classes.FundraiserDataThreading as FDT
1642 import Fundraiser_Tools.classes.FundraiserDataHandler as FDH
1743 import Fundraiser_Tools.classes.TimestampProcessor as TP
1844 import Fundraiser_Tools.settings as projSet
@@ -26,15 +52,109 @@
2753
2854 sltl = DL.SquidLogTableLoader()
2955
30 - # Show the squid log table
 56+ """ Show the squid log table """
3157 squid_table = sltl.get_all_rows_unique_start_time()
3258
33 - # Show the latest log that has been or is loading and its progress
 59+ """ Show the latest log that has been or is loading and its progress """
3460 completion_rate = sltl.get_completion_rate_of_latest_log()
3561
3662 return render_to_response('LML/index.html', {'squid_table' : squid_table, 'completion_rate' : completion_rate}, context_instance=RequestContext(request))
 63+
 64+
 65+"""
 66+ Display log on squid archive server with the option to copy
3767
 68+"""
 69+def copy_logs_form(request):
 70+ now = datetime.datetime.now() + datetime.timedelta(hours=7)
 71+ return render_to_response('LML/copy_logs.html', {'year': now.year, 'month': now.month, 'day': now.day, 'hour': now.hour}, context_instance=RequestContext(request))
3872
 73+"""
 74+ !! MODIFY -- integrate this into a new thread !!
3975
 76+ 1 Show a full file listing of the logs on the log server
 77+ 2 Enable selection of logs to copy over
 78+"""
 79+def copy_logs_process(request):
 80+
 81+ try:
 82+
 83+ year_var = request.POST['year']
 84+ month_var = request.POST['month']
 85+ day_var = request.POST['day']
 86+ hour_var = request.POST['hour']
 87+
 88+ except KeyError as e:
 89+ """ flag an error here for the user """
 90+ return HttpResponseRedirect(reverse('LML.views.index'))
 91+ # pass
4092
 93+ """ Initialize the datamapper and then copy the banner and lp logs """
 94+ dm = DM.DataMapper()
 95+ dm.copy_logs('banner', year=year_var, month=month_var, day=day_var, hour=hour_var)
 96+ dm.copy_logs('lp', year=year_var, month=month_var, day=day_var, hour=hour_var)
 97+
 98+
 99+ return render_to_response('LML/log_list.html', {'log_file_list' : dm.get_list_of_logs()}, context_instance=RequestContext(request))
 100+
 101+def log_list(request):
 102+ dm = DM.DataMapper()
 103+ return render_to_response('LML/log_list.html', {'log_file_list' : dm.get_list_of_logs()}, context_instance=RequestContext(request))
 104+
 105+
 106+"""
 107+ Form view that enables user to enter a squid log hour
 108+ *All* available logs from that hour are loaded
 109+"""
 110+def mine_logs_form(request):
 111+ now = datetime.datetime.now() + datetime.timedelta(hours=7)
 112+ return render_to_response('LML/mine_logs.html', {'year': now.year, 'month': now.month, 'day': now.day, 'hour': now.hour}, context_instance=RequestContext(request))
 113+
 114+"""
 115+ !! FIXME -- this needs to be tested !!
 116+ Process mining logs for a given hour - linked from the mine logs form
 117+"""
 118+def mine_logs_process(request):
 119+
 120+ try:
 121+
 122+ year_var = request.POST['year']
 123+ month_var = request.POST['month']
 124+ day_var = request.POST['day']
 125+ hour_var = request.POST['hour']
 126+
 127+ except KeyError as e:
 128+ """ flag an error here for the user """
 129+ return HttpResponseRedirect(reverse('LML.views.index'))
 130+ # pass
 131+
 132+ """ Initialize the datamapper and then copy the banner and lp logs """
 133+ fdm = DM.FundraiserDataMapper()
 134+ log_files_list = fdm.get_list_of_logs()
 135+
 136+ log_names = list()
 137+
 138+ date_string = year_var + '-' + month_var + '-' + day_var + '-' + hour_var
 139+
 140+ for lf in log_files_list:
 141+ if re.search(date_string, lf):
 142+ FDT.MinerThread(lf).start()
 143+
 144+ return HttpResponseRedirect(reverse('LML.views.index'))
 145+
 146+
 147+"""
 148+ Executed when the user selects a log file to mine
 149+
 150+ Kicks off a thread to load a squid log into the db
 151+
 152+"""
 153+def mine_logs_process_file(request, log_name):
 154+
 155+ mt = FDT.MinerThread(log_name)
 156+ mt.start()
 157+
 158+ return HttpResponseRedirect(reverse('LML.views.index'))
 159+
 160+
41161
\ No newline at end of file
Index: trunk/fundraiser-statistics/fundraiser-scripts/web_reporting/LML/urls.py
@@ -3,4 +3,10 @@
44
55 urlpatterns = patterns('',
66 (r'^$', 'LML.views.index'),
 7+ (r'^copy_logs_form$', 'LML.views.copy_logs_form'),
 8+ (r'^copy_logs_process$', 'LML.views.copy_logs_process'),
 9+ (r'^log_list$', 'LML.views.log_list'),
 10+ (r'^mine_logs_form$', 'LML.views.mine_logs_form'),
 11+ (r'^mine_logs_process$', 'LML.views.mine_logs_process'),
 12+ (r'^mine_logs_process/(?P<log_name>[a-zA-Z0-9_-]+)$', 'LML.views.mine_logs_process_file'),
713 )

Status & tagging log