简体   繁体   English

如何使用javascript,php,shell脚本从xml颠覆日志文件中获取每天的提交次数?

[英]how to get number of commit each day from xml subversion log file with javascript, php, shell script?

Having XML Subversion commits log: 具有XML Subversion提交日志:

<?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. 我想要一个结果,该结果是按日期和每天在我的网站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 但这不起作用,非结果非错误日志(Apache,PHP),而且我不知道如何从PHP代码向JavaScript代码发送$ number []

You can play with XPath : 您可以使用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. 它在外壳中,但是您可以使用任何喜欢的语言在XPath表达式上进行迭代。

! If anyone here knows how to tell XPath to get only the numbers in revision="2" , please tell us =) 如果这里有人知道如何告诉XPath仅获取revision="2"的数字,请告诉我们=)

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). 我意识到您正在寻求Linux解决方案,但是由于此处没有提供任何帮助,因此是使用PowerShell(因此仅Windows)实现目标的一种方法。 Perhaps by presenting this algorithm, another contributor can map it to Linux shell commands for you. 也许通过介绍此算法,其他贡献者可以为您将其映射到Linux Shell命令。

([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: 您可能会猜测代码在做什么,即使在PowerShell中没有流利性也是如此,但这是关键点的摘要:

  • 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; 第一条Select-Object语句(5行)提取出XML元素和属性,将它们转换为PowerShell对象的字段。 Revision and Date are massaged into appropriate types making them more useful than just as string data. Revision和Date被压缩为适当的类型,使它们比字符串数据更有用。
  • The Group-Object statement converts what are now true date objects into a format suitable for sorting. Group-Object语句将现在是真实日期的对象转换为适合排序的格式。
  • The second Select-Object statement simply modifies the default group names (name and count) to more relevant names (date and count). 第二个Select-Object语句只是将默认组名(名称和计数)修改为更相关的名称(日期和计数)。
  • The final Format-Table makes the resultant column sizes compact. 最终的Format-Table使结果列的大小紧凑。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM