一个问题,难倒无数英雄啊...

jking1989 2011-05-19 11:27:43
实现日统计:选择日期,UserID,InterfaceID,动态实现统计选择时期内每个小时的上行总数、状态同步统计、成功率统计。如:

用户<select><item>UserID</item></select>
通道<select><item>InterfaceID</item></select>
日期:自己用插件或脚本实现均可(如从2010-5-1 到 2010-5-1,即2010-5-1当天)

表格:
同步数 10 25 。。。。
上行数 10 28 。。。。
成功率 100% 89.3% 。。。。
时间 0点 1点 2点 。。。



数据库字段

表和主要字段:
T_User 用户表:ID,UserName,password...
T_Mo 上行表:InterfaceID(通道) UserID RegDate(日期)
T_Report 状态同步表(status=1表示成功):UserID,InterfaceID,Status,RegDate




给点思路啊 谢了!
...全文
1234 29 打赏 收藏 转发到动态 举报
写回复
用AI写文章
29 条回复
切换为时间正序
请发表友善的回复…
发表回复
香烟 2011-05-21
  • 打赏
  • 举报
回复
一点也看不懂
deping_chen 2011-05-21
  • 打赏
  • 举报
回复
小伎俩,无非是骗人家给你干活。切!
--小F-- 2011-05-19
  • 打赏
  • 举报
回复
没有看懂
jxqn_liu 2011-05-19
  • 打赏
  • 举报
回复

create table #T_User ([ID] int identity(1,1) not null primary key, [UserName] varchar(20) default '', [Password] varchar(20) default '')
create table #T_Mo (InterfaceID int not null primary key,UserID int default 0, RegDate datetime default getdate())
create table #T_Report ([ID] int identity(1,1) not null primary key, UserId int default 0, InterfaceID int default 0, Status int, RegDate datetime)

/*

--加入测试数据

insert into #T_User(UserName, Password)
select 'A','A' union All
select 'B','B' union All
select 'C','C' union All
select 'D','D' union All
select 'E','E' union All
select 'F','F' union All
select 'G','G' union All
select 'H','H'
Go

declare @i int
set @i = 1
while @i < 100
begin
Insert Into #T_Mo
select @i, (select top 1 [ID] from #T_User order by newid()), getdate()

set @i = @i + 1
end


declare @i int
set @i = 1
while @i < 100
begin
Insert Into #T_Report
select (select top 1 [ID] from #T_User order by newid()), (select top 1 [InterfaceID] from #T_Mo order by newid()), 1, getdate()

set @i = @i + 1
end


select * from #T_Mo
select * from #T_Report

Update #T_Mo set RegDate = Dateadd(hh, 1, RegDate) where InterfaceID between 0 and 10
Update #T_Mo set RegDate = Dateadd(hh, 2, RegDate) where InterfaceID between 11 and 31
Update #T_Mo set RegDate = Dateadd(hh, 3, RegDate) where InterfaceID between 32 and 60
Update #T_Mo set RegDate = Dateadd(hh, 4, RegDate) where InterfaceID between 61 and 100

Update #T_Report set RegDate = Dateadd(hh, 1, RegDate) where [ID] between 0 and 10
Update #T_Report set RegDate = Dateadd(hh, 2, RegDate) where [ID] between 11 and 30
Update #T_Report set RegDate = Dateadd(hh, 3, RegDate) where [ID] between 32 and 56
Update #T_Report set RegDate = Dateadd(hh, 4, RegDate) where [ID] between 61 and 100
*/

select Year(RegDate) iYear, Month(RegDate) iMonth, Day(RegDate) iDay, (substring(convert(varchar(20),RegDate, 121),12,2)) iHour, Count(1) iCount into #T_Mo1 from #T_Mo group by RegDate

select Year(RegDate) iYear, Month(RegDate) iMonth, Day(RegDate) iDay, (substring(convert(varchar(20),RegDate, 121),12,2)) iHour, Count(1) iCount into #T_Report1 from #T_Report group by RegDate

select A.iCount iMoCount, B.iCount iRptCount, Round(((B.iCount*0.1) / (A.iCount*0.1)), 2) fRate, A.iHour from #T_Mo1 A inner join #T_Report1 B on A.iYear=B.iYear and A.iMonth=B.iMonth and A.iDay=B.iDay and A.iHour=B.iHour

jxqn_liu 2011-05-19
  • 打赏
  • 举报
回复

create table #T_User ([ID] int identity(1,1) not null primary key, [UserName] varchar(20) default '', [Password] varchar(20) default '')
create table #T_Mo (InterfaceID int not null primary key,UserID int default 0, RegDate datetime default getdate())
create table #T_Report ([ID] int identity(1,1) not null primary key, UserId int default 0, InterfaceID int default 0, Status int, RegDate datetime)


insert into #T_User(UserName, Password)
select 'A','A' union All
select 'B','B' union All
select 'C','C' union All
select 'D','D' union All
select 'E','E' union All
select 'F','F' union All
select 'G','G' union All
select 'H','H'
Go

declare @i int
set @i = 1
while @i < 100
begin
Insert Into #T_Mo
select @i, (select top 1 [ID] from #T_User order by newid()), getdate()

set @i = @i + 1
end


declare @i int
set @i = 1
while @i < 100
begin
Insert Into #T_Report
select (select top 1 [ID] from #T_User order by newid()), (select top 1 [InterfaceID] from #T_Mo order by newid()), 1, getdate()

set @i = @i + 1
end


select * from #T_Mo
select * from #T_Report

Update #T_Mo set RegDate = Dateadd(hh, 1, RegDate) where InterfaceID between 0 and 10
Update #T_Mo set RegDate = Dateadd(hh, 2, RegDate) where InterfaceID between 11 and 31
Update #T_Mo set RegDate = Dateadd(hh, 3, RegDate) where InterfaceID between 32 and 60
Update #T_Mo set RegDate = Dateadd(hh, 4, RegDate) where InterfaceID between 61 and 100

Update #T_Report set RegDate = Dateadd(hh, 1, RegDate) where [ID] between 0 and 10
Update #T_Report set RegDate = Dateadd(hh, 2, RegDate) where [ID] between 11 and 30
Update #T_Report set RegDate = Dateadd(hh, 3, RegDate) where [ID] between 32 and 56
Update #T_Report set RegDate = Dateadd(hh, 4, RegDate) where [ID] between 61 and 100


select Year(RegDate) iYear, Month(RegDate) iMonth, Day(RegDate) iDay, (substring(convert(varchar(20),RegDate, 121),12,2)) iHour, Count(1) iCount into #T_Mo1 from #T_Mo group by RegDate

select Year(RegDate) iYear, Month(RegDate) iMonth, Day(RegDate) iDay, (substring(convert(varchar(20),RegDate, 121),12,2)) iHour, Count(1) iCount into #T_Report1 from #T_Report group by RegDate

select A.iCount iMoCount, B.iCount iRptCount, Round(((B.iCount*0.1) / (A.iCount*0.1)), 2) fRate, A.iHour from #T_Mo1 A inner join #T_Report1 B on A.iYear=B.iYear and A.iMonth=B.iMonth and A.iDay=B.iDay and A.iHour=B.iHour



都不知道是不是这样的,也就糊里糊涂的写了个,你们看看
yangzihao525 2011-05-19
  • 打赏
  • 举报
回复
迫切想知道这个答案,哎,高人回答吧
yangzihao525 2011-05-19
  • 打赏
  • 举报
回复
顶。。。建
yangzihao525 2011-05-19
  • 打赏
  • 举报
回复
顶死清
jking1989 2011-05-19
  • 打赏
  • 举报
回复
没错 就是要的数据是要从数据库里原有的数据进行统计后得出的 而数据库的数据又是相当的大
jxqn_liu 2011-05-19
  • 打赏
  • 举报
回复
我想我大概明白了一点,你的意思想从T_Mo 上行表和T_Report 状态同步表中的数据得到你想要的结果,不知道有木有理解错误
yangzihao525 2011-05-19
  • 打赏
  • 举报
回复
CREATE     PROCEDURE [dbo].[Total_pag] 
@UserID int,--用户ID
@InterfaceID int,--通道ID
@Start_Times datetime,
@End_Times datetime,
@style int
AS

declare @times1 int
declare @times2 int
declare @Up_sum int
declare @Stau_sum int

if @style =1

begin


select count(DATEPART(HH,RegDate)) as Up_sum,DATEPART(HH,RegDate) as TR into #T_Mo from dbo.T_Mo where RegDate between @Start_Times and @End_Times and UserID=@UserID and InterfaceID=@InterfaceID GROUP BY DATEPART(HH,RegDate) order by DATEPART(HH,RegDate) desc
select count(DATEPART(HH,RegDate)) as Stau_sum,DATEPART(HH,RegDate) as RR into #T_Report from dbo.T_Report where RegDate between @Start_Times and @End_Times and UserID=@UserID and InterfaceID=@InterfaceID and Status=1 GROUP BY DATEPART(HH,RegDate) order by DATEPART(HH,RegDate) desc

select *,LTRIM(CONVERT(DEC(18,2),Stau_sum*100.0/Up_sum))+'%' as sty into ##Total from #T_Mo inner join #T_Report on #T_Mo.TR=#T_Report.RR
end
if @style =2

begin


select count(DATEPART(dd,RegDate)) as Up_sum, DATEPART(dd,RegDate) as Mre_Date into #T_Mo from dbo.T_Mo where RegDate between @Start_Times and @End_Times and UserID=@UserID and InterfaceID=@InterfaceID GROUP BY DATEPART(dd,RegDate) order by DATEPART(dd,RegDate) desc
select count(DATEPART(dd,RegDate)) as Stau_sum,DATEPART(dd,RegDate) as Rre_Date into #T_Report from dbo.T_Report where RegDate between @Start_Times and @End_Times and UserID=@UserID and InterfaceID=@InterfaceID and Status=1 GROUP BY DATEPART(dd,RegDate) order by DATEPART(dd,RegDate) desc

select *,LTRIM(CONVERT(DEC(18,2),Stau_sum*100.0/Up_sum))+'%' as sty into ##Total from #T_Mo inner join #T_Report on #T_Mo.Mre_Date=#T_Report.Rre_Date
end
if @style =3

begin


select count(UserID) as Up_sum,UserID into #T_Mo from T_Mo where InterfaceID=@InterfaceID and RegDate between @Start_Times and @End_Times group by UserID order by UserID
select count(UserID) as Stau_sum,UserID as U_ID into #T_Report from T_Report where InterfaceID=@InterfaceID and RegDate between @Start_Times and @End_Times and Status=1 group by UserID order by UserID

select *,LTRIM(CONVERT(DEC(18,2),Stau_sum*100.0/Up_sum))+'%' as sty into ##Total from #T_Mo inner join #T_Report on #T_Mo.UserID=#T_Report.U_ID
end
drop table #T_Mo
drop table #T_Report

drop table ##Total


我的想法是字段在数据库里面构造,然后放在一张临时表,程序读出临时表,但是,我这个代码有错啊,


消息 2714,级别 16,状态 1,过程 Total_pag,第 29 行
数据库中已存在名为 '#T_Mo' 的对象。
消息 2714,级别 16,状态 1,过程 Total_pag,第 30 行
数据库中已存在名为 '#T_Report' 的对象。
消息 2714,级别 16,状态 1,过程 Total_pag,第 32 行
数据库中已存在名为 '##Total' 的对象。
消息 2714,级别 16,状态 1,过程 Total_pag,第 39 行
数据库中已存在名为 '#T_Mo' 的对象。
消息 2714,级别 16,状态 1,过程 Total_pag,第 40 行
数据库中已存在名为 '#T_Report' 的对象。
消息 2714,级别 16,状态 1,过程 Total_pag,第 42 行
数据库中已存在名为 '##Total' 的对象。
jking1989 2011-05-19
  • 打赏
  • 举报
回复
成功率 = 状态同步成功数/上行数

这个是想要的效果:
用户<select><item>UserID</item></select>
通道<select><item>InterfaceID</item></select>
日期:自己用插件或脚本实现均可(如从2010-5-1 到 2010-5-1,即2010-5-1当天)

表格:
同步数 上行数 成功率 时间
10 10 100% 0点
25 28 89.3% 1点



比如说1点,那这个上行数就是上行表在1点的时候,同一个用户,同一个通道,的总数有多少,同步数也类似
jxqn_liu 2011-05-19
  • 打赏
  • 举报
回复
不是很明白
  • 打赏
  • 举报
回复
表示木看明白
yangzihao525 2011-05-19
  • 打赏
  • 举报
回复
英雄啊,犀利啊,我也想知道
KING_314 2011-05-19
  • 打赏
  • 举报
回复
不懂。。。
gundamn 2011-05-19
  • 打赏
  • 举报
回复
建好索引后速度不会有问题的啊,不就500W嘛
gundamn 2011-05-19
  • 打赏
  • 举报
回复
select a.reportcount,a.interfaceid,a.reporthout,b.mocount from (select count(id) reportcount ,interfaceid,datepart(hh,regdate) reporthour from t_report where convert(varchar(10),regdate,111)='2010/05/01' and status=1 group by datepart(hh,regdate),interfaceid) a left join (select count(id) mocount ,interfaceid,datepart(hh,regdate) mohour from t_mo where convert(varchar(10),regdate,111)='2010/05/01' group by datepart(hh,regdate),interfaceid) b on b.interfaceid=a.interfaceid and a.reporthour=b.mohour
jking1989 2011-05-19
  • 打赏
  • 举报
回复
就是题目的目的是想做一个日统计:

根据上行表和同步状态表,统计出每天每小时的上行数量,同步状态成功数,还有成功率,然后在程序里面显示出来,

这个成功率计算是:
条件:同一个时间,同一个用户,同一个通道,
以上为条件的情况下统计上行表里面符合的有多少条,同步状态表(stustr=1)的有多少条,
然后相除就等 于成功率,然后想后台构造出一个临时表,然后程序直接显示这个表就可以了。

主要是这些表的数据量都很大(除用户表外每个表至少500w条) 我想说这样做效率会不会高点
pt1314917 2011-05-19
  • 打赏
  • 举报
回复
汗。还是自己想想怎么才能够把这个问题描述的清楚。这样提问可能事半功倍噢。否则再怎么问,别人要猜你的意图。太难了。
加载更多回复(8)
首先一定要知道 Scrapy爬虫框架 对新手非常的不友好,或者从某些视频网站上跟着视频学或者说从培训机构里学几天技能掌握的,主要原因有以下两个方面。框架模块内容太多,虽然只是实现了一个简单的爬虫工作,但是实际上完成一个页面的抓取在框架里最少要走8个以上的步骤,但是这些步骤都是基本都是依靠配置文件完成的,没有丰富的爬虫经验,这些模块很多都不知道是做什么的,也不知道怎么配置。基于框架内进行数据抓取仅限于那些通用的网站抓取,你就简单理解为一个完成重复工作的机器人就行了。但是如果是那种反爬比较厉害的网站那就是另外一种情况了,完全是爬虫工程师和网站开发者的一个博弈了,所以这种情况不适合任何一种爬虫框架。对于那些想在工作中摸鱼的Python工程师来说就一定要使用爬虫框架,你会发现省不少力气而且效率真心非常高,不过一切都是在对框架熟练掌握的基础上、和对业务的深刻理解来说来说。但凡说 Scrapy 无用的基本上没有认真阅读过 Scrapy 的源码,对于 Scrapy框架 中的众多功能在搭建爬虫系统的时候能想到用几个?而且是基本是没有做过大型的爬虫系统项目的。咱们倒着推这个事,你就知道为什么要用Scrapy框架了。我之前的单位是国家互联网的新闻中心,做的项目中的有一项是复现863课题舆情监控系统中的内容,使用的方法是 Scrapy爬虫框架 结合 Django Web 搭建的数据采集系统,抓取的目标对象包括新闻、博客、论坛等等,其中每天目标检测网站成千上万,如果不用框架去做这种数据采集得累死。1.抓取的数据存哪里?单纯Scrapy爬虫脚本写好了执行抓取任务时数据保存到哪里?ES、Mongodb、MySQL?如果做过开发的人都知道存 Mongodb 中,那些说把数据存到 MySQL 的人基本上99%是从培训机构里出来的,因为大多数培训机构爬虫是不讲 Mongodb 的。通过业务计算逻辑把数据传输到生产 ES 环境中。2.几千、几万个爬虫脚本应该怎么管理?很多刚入行的人都觉得爬虫脚本难写,其实并不是这样。最难的是如何管理密密麻麻数不清的爬虫脚本,这里介绍Python如何处理这个事情。管理方式无非集中,Web管理环境、GUI管理环境、手动管理环境,不管是哪一种都需要一定的开发基础和管理思路。比较省事的用别人写好的Scrapy管理框架,比如Gerapy爬虫管理框架。如同这样web直接一键管理爬虫脚本,更多内容看上面的文章,这里就不重复了。3.Scrapy如何面对反爬的?跟大多数单线抓取某个网站解决其反爬一样,只要把反爬的逻辑设置好,比如最简单的更换代理IP,更换header,解析JS生成cookie访问等等,都可以在框架中设置配置文件。4.如何提高代码编写效率以及数据爬取效率?一定要阅读源码,一定要阅读源码,一定要阅读源码你才能知道这个框架里到底有什么内容可以用。5.基于Python各种框架开发的爬虫定制化项目。

6,129

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 新技术前沿
社区管理员
  • 新技术前沿社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧