Next-action-verb-analysis.mmbas

From ActivityOwnerWiki
Jump to: navigation, search
Option Explicit
Sub Main
    ' next-action-verb-analysis.mmbas
    ' Open your daily action dashboard and run this script
    ' It will mark "physical" next actions with thumbs up, project verbs with thumbs down and
    ' add a red check to verbs it finds in your mindreader.mmap file (if you have one)
    '14Jul07 http://creativecommons.org/licenses/by-sa/2.5/ http://www.activityowner.com/
    Dim verbs(200) As String 'verbs found (1st words)
    Dim vc(200) As Integer	 'number of each verb
    Dim vlink(200) As String 'hyperlink for task associated with 1st occurance
    Dim tv As Integer 'number of 1st words found
    Dim uv As Integer 'number of unique 1st words found
    Dim uvmax As Integer 'maximum number of occurrences of a unique 1st word
    Dim i,j,k As Integer 'loop counters
    Dim mtopic As Topic 'main topic
    Dim stopic As Topic 'subtopics of next action branch (contexts)
    Dim sstopic As Topic 'action item topic under each context
    Dim reporttopic, reportsubtopic, reportsubsubtopic As Topic 'report map topic
    Dim na As String 'next action string
    Dim eow As Integer 'location of 1st space in next action string
    Dim fw As String 'first word in next action string
    Dim found As Boolean 'verb already seen
    Dim report As Document 'report map
    Dim doc As Document
    Dim f As String 'name for report map
    Dim actionverbs(16) As String
    Dim projectverbs(15) As String
    Dim mrf As String
    Dim nadoc As Document
    Dim mindreaderDoc As Document
    Dim hasmindreader As Boolean
    Dim mrtopic As Topic
    Dim ta As Integer
    Dim key As Topic
    Dim keyitem As Topic
    Dim agecount As Integer
    Dim totalage As Double
    Dim oldtopic As Topic
    Dim oldtopicbranch As Topic
    Dim enumerateverbs As Boolean
    Dim age As Long
    Dim maxage As Long
    Dim bin As Integer
    Dim bins(11) As Integer
    Dim ttopic As Topic
    Dim numbins As Integer
    Dim mrmapStr As String
    Dim mrmapVisible As Boolean
	Dim haskey As Boolean
    '

    enumerateverbs=True
    agecount=0
    totalage=0
    ta=0
    uv=0
    tv=0
    numbins=5
    'action and project verbs reproduced from the OOP GTD Fast booklet, ©1998-2001 David Allen & Co.
    actionverbs(1)="call"
    actionverbs(2)="organize"
    actionverbs(3)="review"
    actionverbs(4)="buy"
    actionverbs(5)="fill out"
    actionverbs(6)="find"
    actionverbs(7)="look into"
    actionverbs(8)="gather"
    actionverbs(9)="print"
    actionverbs(10)="take"
    actionverbs(11)="waiting for"
    actionverbs(12)="load"
    actionverbs(13)="draft"
    actionverbs(14)="email"
    actionverbs(15)="e-mail"
    actionverbs(16)="purge"
    projectverbs(1)="Finalize"
    projectverbs(2)="Resolve"
    projectverbs(3)="Handle"
    projectverbs(4)="Look into"
    projectverbs(5)="Submit"
    projectverbs(6)="Maximize"
    projectverbs(7)="organize"
    projectverbs(8)="Design"
    projectverbs(9)="Complete"
    projectverbs(10)="Ensure"
    projectverbs(11)="Roll out"
    projectverbs(12)="Update"
    projectverbs(13)="Install"
	projectverbs(14)="Implement"
	projectverbs(15)="Set-up"

    f =   GetPath(mmDirectoryMyMaps) & "FirstWordReport.mmap"
    mrf = GetPath(mmDirectoryMyMaps) & "mindreader.mmap"
    For Each doc In Documents
       If InStr(doc.CentralTopic.Text,"Daily Actions")>0 Then  Set nadoc=doc
    Next
    Debug.Print nadoc.Path
    If nadoc.Path ="" Then
       MsgBox("Please save your Daily Action Dashboard and then run macro again")
       Exit Sub
    End If
    For Each mtopic In nadoc.CentralTopic.AllSubTopics
    	If mtopic.Text="My committed Next Actions towards success" Then
			For Each stopic In mtopic.AllSubTopics
				If Not InStr(stopic.Text,"Contact")>0 Then
		    		For Each sstopic In stopic.AllSubTopics
		    		    ta=ta+1
	    				na=LCase(sstopic.Text)
	        			eow=InStr(na," ")
	          			If eow>0 Then
		            		fw=Mid(na,1,eow-1)
			          	Else
			            	fw=na
	    		      	End If
	        		  	tv=tv+1
	          			found=False
	          			If uv>0 Then
	          		   		For i=1 To uv
		          				If fw=verbs(i) Then
		          				    vc(i)=vc(i)+1
	    	      				    found=True
	        	  				End If
	          				Next
		          		End If
    	   				If Not found Then
       					    uv=uv+1
       			 			verbs(uv)=fw
       		 				vc(uv)=1
       		 				vlink(uv)=sstopic.Guid
	       		 		End If
	       		 		If sstopic.Task.StartDate>0 Then
	       		 		   agecount=agecount+1
	       		 		   totalage=totalage + Round(Now-sstopic.Task.StartDate)
	       		 		End If
		     		Next
		     	End If
	 		Next
		End If
	Next
	uvmax=0
	For i=1 To uv
	 	If vc(i)>uvmax Then uvmax=vc(i)
	Next
	On Error GoTo X
	Set report=Documents.Open(f)
	If Err.Number>0 Then
    	 X: Err.Clear
     	Set report=Documents.Add
     	report.CentralTopic.Text="Next Action Verb Analysis"
     	report.SaveAs(f)
	End If

	mrmapVisible=False
	For Each doc In VisibleDocuments
   		If doc.FullName=mrf Then mrmapVisible=True
	Next
	On Error GoTo Y
	Set mindreaderDoc = Documents.Open(mrf,"",mrmapVisible)
	hasmindreader=True
	If Err.Number>0 Then
		Y: Err.Clear
		hasmindreader=False
	End If
	On Error GoTo 0
	If hasmindreader Then
	  For Each mtopic In mindreaderDoc.CentralTopic.AllSubTopics
	  	If mtopic.Text="contexts" Then Set mrtopic=mtopic
	  Next
	End If
	report.Activate

	Set reporttopic= report.CentralTopic.AddSubTopic(Str(Now))
	Set reportsubtopic = reporttopic.AddSubTopic("Summary:")
	Set reportsubsubtopic = reportsubtopic.AddSubTopic(Str(uv) & " unique 1st words")
	Set reportsubsubtopic = reportsubtopic.AddSubTopic(ta & " next actions")
	Set reportsubsubtopic = reportsubtopic.AddSubTopic(Str(agecount) & " with start dates")
	Set reportsubsubtopic = reportsubtopic.AddSubTopic("Average age:" & Str(Round(totalage/agecount)))
	haskey=False
	For Each mtopic In report.CentralTopic.AllSubTopics
	    If mtopic.Text = "How to interpret this report" Then haskey=True
	Next
	If Not haskey Then
		Set key=report.CentralTopic.AddSubTopic("How to interpret this report")
		Set keyitem = key.AddSubTopic("Link is to raw map for 1st occurrence")
		Set keyitem = key.AddSubTopic("thumbs up for good action verb")
		keyitem.Icons.AddStockIcon(mmStockIconThumbsUp)
		Set keyitem = key.AddSubTopic("thumbs down for project verbs")
		keyitem.Icons.AddStockIcon(mmStockIconThumbsDown)
		Set keyitem = key.AddSubTopic("check mark for verbs already in your mindreader.mmap")
		keyitem.Icons.AddStockIcon(mmStockIconCheck)
	End If
    If enumerateverbs Then
	For i= uvmax To 1 Step -1
	    Set reportsubtopic = reporttopic.AddSubTopic(Str(i))
		For j=1 To uv
		    If i=vc(j) Then
		        Set reportsubsubtopic = reportsubtopic.AddSubTopic(verbs(j))
		        reporttopic.Notes.Text = reporttopic.Notes.Text & Chr(13) & Chr(10) & Round(i*100/ta,0) & "% : " & verbs(j)
		        For k =1 To 16
		          If LCase(verbs(j))=LCase(actionverbs(k)) Then reportsubsubtopic.Icons.AddStockIcon(mmStockIconThumbsUp)
				Next
		        For k =1 To 15
		          If LCase(verbs(j))=LCase(projectverbs(k)) Then reportsubsubtopic.Icons.AddStockIcon(mmStockIconThumbsDown)
				Next
				If hasmindreader Then
					For Each mtopic In mrtopic.AllSubTopics
						If LCase(verbs(j))=LCase(mtopic.Text) Then reportsubsubtopic.Icons.AddStockIcon(mmStockIconCheck)
					Next
				End If
		        reportsubsubtopic.CreateHyperlinkToTopicByGuid(vlink(j),nadoc.FullName)
		 	End If
		Next

		If reportsubtopic.AllSubTopics.Count=0 Then  reportsubtopic.Delete
	Next
	End If
	'aging tasks
	Set oldtopicbranch= reporttopic.AddSubTopic("Aging")
	maxage=0
   For Each mtopic In nadoc.CentralTopic.AllSubTopics
    	If mtopic.Text="My committed Next Actions towards success" Then
			For Each stopic In mtopic.AllSubTopics
				If Not InStr(stopic.Text,"Contact")>0 Then
		    		For Each sstopic In stopic.AllSubTopics
		    			If sstopic.Task.StartDate>0 Then
		    			      age=Now-sstopic.Task.StartDate
		    				If age>(2* totalage/agecount) Then
		    					Set oldtopic=oldtopicbranch.AddSubTopic(Str(Round(Now-sstopic.Task.StartDate)) &" days: " & sstopic.Text)
		    			        oldtopic.CreateHyperlinkToTopicByGuid(sstopic.Guid,nadoc.FullName)
		    				End If
		    				If age>maxage Then maxage=age
		    			End If
		    		Next
		    	End If
		    Next
		End If
	Next
    'try a graph
    For i=1 To 11
    	bins(i)=0
    Next
    For Each mtopic In nadoc.CentralTopic.AllSubTopics
    	If mtopic.Text="My committed Next Actions towards success" Then
			For Each stopic In mtopic.AllSubTopics
				If Not InStr(stopic.Text,"Contact")>0 Then
		    		For Each sstopic In stopic.AllSubTopics
		    			If sstopic.Task.StartDate>0 Then
		    			    age =(Now-sstopic.Task.StartDate)
		    			    bin=Round(((age/maxage)*(numbins-1))+1)
		    			    bins(bin)=bins(bin)+1
		    			End If
		    		Next
		    	End If
		    Next
		End If
	Next
Dim theTable As Table
Set  ttopic = reporttopic.AddSubTopic("graph")
Set theTable = ttopic.DataContainer.InsertTable
theTable.NumberOfColumns = 2
theTable.NumberOfRows = numbins
theTable.Column(1).Header="bin"
theTable.Column(2).Header="count"
For i = 1 To numbins
	theTable.Cell(i,1).Value = Str(Round(i*maxage/numbins))
	theTable.Cell(i,2).Value = Str(bins(i))
Next
report.Save
End Sub