如何使用javascript,php,shell脚本从xml subversion日志文件中获取每天的提交次数?
Having XML Subversion commits log:
<?xml version="1.0"?>
<log>
<logentry
revision="2">
<author>20070299</author>
<date>2012-06-06T05:23:21.999470Z</date>
<msg>add part</msg>
</logentry>
<logentry
revision="1">
<author>20070299</author>
<date>2012-05-22T08:35:55.663875Z</date>
<msg></msg>
</logentry>
</log>
And I want a result as array grouped by date and numbers of commit each day on my site php-javascript. similar to this one:
date[0]=2012-05-22
value[0]=1
date[1]=2012-05-23
value[1]=0
...
date[15]=2012-06-06
value[15]=1
is there a solution to do it?
I consulted this link
But it don't work, non result non error log (apache, php), and i don't know how to send $number[] from PHP code to javascript code
You can play with XPath :
$ xmllint --shell foo.xml
/ > cat //log/*[@revision]/@revision
-------
revision="2"
-------
revision="1"
/ > cat //log/*[@revision]/date/text()
-------
2012-06-06T05:23:21.999470Z
-------
2012-05-22T08:35:55.663875Z
/ >
This is in a shell, but you can iterate on the XPath expressions with any languages you like instead.
! If anyone here knows how to tell XPath to get only the numbers in revision="2"
, please tell us =)
I realize that you are asking for a Linux solution but since you have not had any proffered here is a way to achieve your goal with PowerShell (and hence Windows-only). Perhaps by presenting this algorithm, another contributor can map it to Linux shell commands for you.
([xml](svn log -v --xml)).log.logentry |
Select-Object -Property `
Author, `
@{n='Revision'; e={([int]$_.Revision)}}, `
@{n='Date'; e={Get-Date $_.Date }}, `
Paths |
Group-Object {$_.Date.ToString("yyyy-MM-dd")} |
Sort-Object name -Descending |
Select-Object @{n='Date'; e={$_.Name}}, Count |
Format-Table -AutoSize
You can likely surmise what the code is doing even without fluency in PowerShell, but here is a summary of key points:
- The first line sets up an implicit loop through all log/logentry nodes.
- The first
Select-Object
statement (5 lines) pulls out XML elements and attributes converting them to fields of a PowerShell object; Revision and Date are massaged into appropriate types making them more useful than just as string data. - The
Group-Object
statement converts what are now true date objects into a format suitable for sorting. - The second
Select-Object
statement simply modifies the default group names (name and count) to more relevant names (date and count). - The final
Format-Table
makes the resultant column sizes compact.
Here is a portion of output from my system:
Date Count
---- -----
2012-06-29 4
2012-06-28 6
2012-06-27 8
2012-06-26 16
2012-06-25 1
2012-06-24 1
2012-06-22 5
2012-06-21 8
2012-06-20 8