如何使用时间间隔数据统计并发用户数?

编程入门 行业动态 更新时间:2024-10-28 17:22:58
本文介绍了如何使用时间间隔数据统计并发用户数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有一个数据集表示来自日志文件的数据,该文件显示用户和机器为服务器建立连接.我在数据集中有一个连接开始时间(可变开始)和结束时间(可变结束):

I have a data set representing data from a log file which shows users and machine taking a connection for a server. I have a connection start time (variable start) and end time (variable end) in the dataset:

tdata <- structure(list(username = structure(c(9L, 6L, 7L, 5L, 3L, 2L, 
4L, 8L, 1L, 4L), .Label = c("ESSAA", "HBRTE", "HPAIUS", 
"KOLA", "MAITAEN", "MARKEA", "MIAINN", "MSALA", 
"PAREDT"), class = "factor"), machine = structure(c(3L, 2L, 
4L, 8L, 1L, 5L, 9L, 6L, 7L, 9L), .Label = c("D5785.domain", 
"D5874.domain", "D5927.domain", "D6000.domain", 
"D6092.domain", "D6147.domain", "D6142.domain", 
"D6169.domain", "D6194.domain"), class = "factor"), 
    start = structure(c(1322672567, 1322687984, 1322465646, 1322696883, 
    1322695042, 1322697073, 1322697547, 1322692794, 1322697694, 
    1322700934), tzone = "", class = c("POSIXct", "POSIXt")), 
    end = structure(c(1322693766, 1322695797, 1322696945, 1322697004, 
    1322697284, 1322697303, 1322697781, 1322700307, 1322700667, 
    1322701224), tzone = "", class = c("POSIXct", "POSIXt"))), .Names = c("username", 
"machine", "start", "end"), row.names = c(NA, 10L), class = "data.frame")

> tdata
   username          machine               start                 end
1    PAREDT D5927.domain 2011-11-30 19:02:47 2011-12-01 00:56:06
2    MARKEA D5874.domain 2011-11-30 23:19:44 2011-12-01 01:29:57
3    MIAINN D6000.domain 2011-11-28 09:34:06 2011-12-01 01:49:05
4   MAITAEN D6169.domain 2011-12-01 01:48:03 2011-12-01 01:50:04
5    HPAIUS D5785.domain 2011-12-01 01:17:22 2011-12-01 01:54:44
6     HBRTE D6092.domain 2011-12-01 01:51:13 2011-12-01 01:55:03
7      KOLA D6194.domain 2011-12-01 01:59:07 2011-12-01 02:03:01
8     MSALA D6147.domain 2011-12-01 00:39:54 2011-12-01 02:45:07
9     ESSAA D6142.domain 2011-12-01 02:01:34 2011-12-01 02:51:07
10     KOLA D6194.domain 2011-12-01 02:55:34 2011-12-01 03:00:24
>

现在我想使用 tdata 数据集中的开始和结束时间来计算每分钟的并发用户数.我已经走到这一步了:

Now I would like to calculate the number of concurrent users for each minute using start and end times from the tdata dataset. I got this far:

#create dataset containing each minute from tdata
start.min <- min(tdata$start, na.rm=T)
end.max <- max(tdata$end, na.rm=T)
tinterval <- seq.POSIXt(start.min, end.max, by = "mins")

对如何进行计算有任何想法吗?

Any ideas how to proceed with the calculation?

推荐答案

这是一个例子

n <- sapply(tinterval, function(tt) sum(tdata$start <= tt & tt <= tdata$end))

然后

@> tail(data.frame(tinterval, n))
               tinterval n
3922 2011-12-01 09:55:06 0
3923 2011-12-01 09:56:06 1
3924 2011-12-01 09:57:06 1
3925 2011-12-01 09:58:06 1
3926 2011-12-01 09:59:06 1
3927 2011-12-01 10:00:06 1
@> plot(tinterval, n, type = "l")

虽然很慢...

这篇关于如何使用时间间隔数据统计并发用户数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 13:11:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1395050.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:用户数   间隔   如何使用   数据统计   时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!